From 31f20a398f0428cdd8b66a73f58cdae9d220efee Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Sat, 3 Nov 2018 14:50:53 -0600 Subject: [PATCH 01/32] Add integration test to build a minimal appimage with custom AppRun --- tests/CMakeLists.txt | 9 +++ ...ild_minimal_appimage_with_custom_apprun.sh | 69 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100755 tests/scripts/build_minimal_appimage_with_custom_apprun.sh diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9c9d1b6..87f7c8d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -4,3 +4,12 @@ add_subdirectory(simple_executable) # now include actual tests add_subdirectory(core) + +add_test(NAME build_minial_appimage + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/build_minimal_appimage_with_custom_apprun.sh + $ + $ + "${CMAKE_CURRENT_SOURCE_DIR}/data/simple_app.desktop" + "${CMAKE_CURRENT_SOURCE_DIR}/data/simple_icon.svg" +) +SET_TESTS_PROPERTIES(build_minial_appimage PROPERTIES DEPENDS "linuxdeploy simple_executable") diff --git a/tests/scripts/build_minimal_appimage_with_custom_apprun.sh b/tests/scripts/build_minimal_appimage_with_custom_apprun.sh new file mode 100755 index 0000000..7246e6d --- /dev/null +++ b/tests/scripts/build_minimal_appimage_with_custom_apprun.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash + +if [[ -z ${ARCH+x} ]]; then + echo "ARCH not set." + exit -1; +fi + +LINUXDEPLOY=$1 +if [[ -z ${LINUXDEPLOY+x} ]]; then + echo "LINUXDEPLOY path not set." + exit -1; +fi + +RUNNABLE=$2 +if [[ -z ${RUNNABLE+x} ]]; then + echo "RUNNABLE path not set." + exit -1; +fi + +DESKTOP_FILE=$3 +if [[ -z ${DESKTOP_FILE+x} ]]; then + echo "DESKTOP_FILE path not set." + exit -1; +fi + +ICON=$4 +if [[ -z ${ICON+x} ]]; then + echo "ICON path not set." + exit -1; +fi + + +LINUXDEPLOYDIR=`mktemp -d` +pushd "$LINUXDEPLOYDIR" + + cp "$LINUXDEPLOY" . + + wget https://github.com/TheAssassin/linuxdeploy-plugin-appimage/releases/download/continuous/linuxdeploy-plugin-appimage-"$ARCH".AppImage + chmod +x linuxdeploy-plugin-appimage-"$ARCH".AppImage + + filename=$(basename -- "$LINUXDEPLOY") + LINUXDEPLOY="$LINUXDEPLOYDIR/$filename" +popd + +APPDIR=`mktemp -d` + +cp $RUNNABLE "$APPDIR/AppRun" + +mkdir -p "$APPDIR/usr/bin" +cp "$RUNNABLE" "$APPDIR/usr/bin" + +mkdir -p "$APPDIR/usr/share/applications" +cp "$DESKTOP_FILE" "$APPDIR/usr/share/applications" + +mkdir -p "$APPDIR/usr/share/icons/hicolor/scalable/apps" +cp "$ICON" "$APPDIR/usr/share/icons/hicolor/scalable/apps" + +"$LINUXDEPLOY" --appdir "$APPDIR" --output=appimage +SUCCEED=$? + +echo " " +echo " AppDir contents: " +find "$APPDIR" +echo " " + +rm -rf "$APPDIR" +rm -rf "$LINUXDEPLOYDIR" + +exit "$SUCCEED" From e5f4755da714af489eda278df4845c0b20efaff9 Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Sun, 4 Nov 2018 14:10:16 -0600 Subject: [PATCH 02/32] Move deploy AppDir root files into a separated function --- src/main.cpp | 126 +++++++++++++++++++++++++++++---------------------- 1 file changed, 71 insertions(+), 55 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a545bbf..b93196e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,11 +14,14 @@ #include "linuxdeploy/util/util.h" using namespace linuxdeploy::core; + using namespace linuxdeploy::core::log; using namespace linuxdeploy::util; - namespace bf = boost::filesystem; +int deployAppDirRootFiles(args::ValueFlagList& desktopFilePaths, + args::ValueFlag& customAppRunPath, appdir::AppDir& appDir); + int main(int argc, char** argv) { args::ArgumentParser parser( "linuxdeploy -- create AppDir bundles with ease" @@ -253,60 +256,8 @@ int main(int argc, char** argv) { return 1; } } - - // search for desktop file and deploy it to AppDir root - ldLog() << std::endl << "-- Deploying files into AppDir root directory --" << std::endl; - - if (bf::is_regular_file(appDir.path() / "AppRun")) { - if (customAppRunPath) - ldLog() << LD_WARNING << "AppRun exists but custom AppRun specified, overwriting existing AppRun" << std::endl; - else - ldLog() << LD_WARNING << "AppRun exists, skipping deployment" << std::endl; - } else { - auto deployedDesktopFiles = appDir.deployedDesktopFiles(); - - desktopfile::DesktopFile desktopFile; - - if (deployedDesktopFiles.empty()) { - ldLog() << LD_WARNING << "Could not find desktop file in AppDir, cannot create links for AppRun, desktop file and icon in AppDir root" << std::endl; - } else { - if (!desktopFilePaths.Get().empty()) { - auto firstDeployedDesktopFileName = bf::path(desktopFilePaths.Get().front()).filename().string(); - - auto desktopFileMatchingName = std::find_if( - deployedDesktopFiles.begin(), - deployedDesktopFiles.end(), - [&firstDeployedDesktopFileName](const desktopfile::DesktopFile& desktopFile) { - auto fileName = desktopFile.path().filename().string(); - return fileName == firstDeployedDesktopFileName; - } - ); - - if (desktopFileMatchingName != deployedDesktopFiles.end()) { - desktopFile = *desktopFileMatchingName; - } else { - ldLog() << LD_ERROR << "Could not find desktop file deployed earlier any more:" << firstDeployedDesktopFileName << std::endl; - return 1; - } - } else { - desktopFile = deployedDesktopFiles[0]; - ldLog() << LD_WARNING << "No desktop file specified, using first desktop file found:" << desktopFile.path() << std::endl; - } - - ldLog() << "Deploying desktop file:" << desktopFile.path() << std::endl; - - bool rv; - - if (customAppRunPath) { - rv = appDir.createLinksInAppDirRoot(desktopFile, customAppRunPath.Get()); - } else { - rv = appDir.createLinksInAppDirRoot(desktopFile); - } - - if (!rv) - return 1; - } - } + if (!deployAppDirRootFiles(desktopFilePaths, customAppRunPath, appDir)) + return 1; if (outputPlugins) { for (const auto& pluginName : outputPlugins.Get()) { @@ -342,3 +293,68 @@ int main(int argc, char** argv) { return 0; } + +int deployAppDirRootFiles(args::ValueFlagList& desktopFilePaths, + args::ValueFlag& customAppRunPath, appdir::AppDir& appDir) { + // search for desktop file and deploy it to AppDir root + ldLog() << std::endl << "-- Deploying files into AppDir root directory --" << std::endl; + + if (is_regular_file(appDir.path() / "AppRun")) { + if (customAppRunPath) + ldLog() << LD_WARNING << "AppRun exists but custom AppRun specified, overwriting existing AppRun" + << std::endl; + else + ldLog() << LD_WARNING << "AppRun exists, skipping deployment" << std::endl; + } else { + auto deployedDesktopFiles = appDir.deployedDesktopFiles(); + + desktopfile::DesktopFile desktopFile; + + if (deployedDesktopFiles.empty()) { + ldLog() << LD_WARNING + << "Could not find desktop file in AppDir, cannot create links for AppRun, desktop file and icon in AppDir root" + << std::endl; + } else { + if (!desktopFilePaths.Get().empty()) { + auto firstDeployedDesktopFileName = boost::filesystem::path( + desktopFilePaths.Get().front()).filename().string(); + + auto desktopFileMatchingName = find_if( + deployedDesktopFiles.begin(), + deployedDesktopFiles.end(), + [&firstDeployedDesktopFileName](const desktopfile::DesktopFile& desktopFile) { + auto fileName = desktopFile.path().filename().string(); + return fileName == firstDeployedDesktopFileName; + } + ); + + if (desktopFileMatchingName != deployedDesktopFiles.end()) { + desktopFile = *desktopFileMatchingName; + } else { + ldLog() << LD_ERROR << "Could not find desktop file deployed earlier any more:" + << firstDeployedDesktopFileName << std::endl; + return 1; + } + } else { + desktopFile = deployedDesktopFiles[0]; + ldLog() << LD_WARNING << "No desktop file specified, using first desktop file found:" + << desktopFile.path() << std::endl; + } + + ldLog() << "Deploying desktop file:" << desktopFile.path() << std::endl; + + bool rv; + + if (customAppRunPath) { + rv = appDir.createLinksInAppDirRoot(desktopFile, customAppRunPath.Get()); + } else { + rv = appDir.createLinksInAppDirRoot(desktopFile); + } + + if (!rv) { + return 1; + } + } + } + return true; +} From 7318d68c9632c746115ad1247cc346c958755416 Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Sun, 4 Nov 2018 14:24:04 -0600 Subject: [PATCH 03/32] Move deployAppDirRootFiles function into a separated file to allow unit testing --- src/CMakeLists.txt | 2 +- src/linuxdeploy.cpp | 80 +++++++++++++++++++++++++++++++++++++++++++++ src/linuxdeploy.h | 13 ++++++++ src/main.cpp | 68 +------------------------------------- 4 files changed, 95 insertions(+), 68 deletions(-) create mode 100644 src/linuxdeploy.cpp create mode 100644 src/linuxdeploy.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7c55683..b597b8b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -45,7 +45,7 @@ add_subdirectory(util) add_subdirectory(plugin) add_subdirectory(core) -add_executable(linuxdeploy main.cpp) +add_executable(linuxdeploy main.cpp linuxdeploy.cpp) target_link_libraries(linuxdeploy linuxdeploy_core args) set_target_properties(linuxdeploy PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin") diff --git a/src/linuxdeploy.cpp b/src/linuxdeploy.cpp new file mode 100644 index 0000000..39ae85f --- /dev/null +++ b/src/linuxdeploy.cpp @@ -0,0 +1,80 @@ +#include +#include + +#include +#include +#include + +#include "linuxdeploy.h" + +using namespace linuxdeploy::core; + +using namespace linuxdeploy::core::log; +using namespace linuxdeploy::util; +namespace bf = boost::filesystem; + + +int deployAppDirRootFiles(args::ValueFlagList& desktopFilePaths, + args::ValueFlag& customAppRunPath, appdir::AppDir& appDir) { + // search for desktop file and deploy it to AppDir root + ldLog() << std::endl << "-- Deploying files into AppDir root directory --" << std::endl; + + if (is_regular_file(appDir.path() / "AppRun")) { + if (customAppRunPath) + ldLog() << LD_WARNING << "AppRun exists but custom AppRun specified, overwriting existing AppRun" + << std::endl; + else + ldLog() << LD_WARNING << "AppRun exists, skipping deployment" << std::endl; + } else { + auto deployedDesktopFiles = appDir.deployedDesktopFiles(); + + desktopfile::DesktopFile desktopFile; + + if (deployedDesktopFiles.empty()) { + ldLog() << LD_WARNING + << "Could not find desktop file in AppDir, cannot create links for AppRun, desktop file and icon in AppDir root" + << std::endl; + } else { + if (!desktopFilePaths.Get().empty()) { + auto firstDeployedDesktopFileName = boost::filesystem::path( + desktopFilePaths.Get().front()).filename().string(); + + auto desktopFileMatchingName = find_if( + deployedDesktopFiles.begin(), + deployedDesktopFiles.end(), + [&firstDeployedDesktopFileName](const desktopfile::DesktopFile& desktopFile) { + auto fileName = desktopFile.path().filename().string(); + return fileName == firstDeployedDesktopFileName; + } + ); + + if (desktopFileMatchingName != deployedDesktopFiles.end()) { + desktopFile = *desktopFileMatchingName; + } else { + ldLog() << LD_ERROR << "Could not find desktop file deployed earlier any more:" + << firstDeployedDesktopFileName << std::endl; + return 1; + } + } else { + desktopFile = deployedDesktopFiles[0]; + ldLog() << LD_WARNING << "No desktop file specified, using first desktop file found:" + << desktopFile.path() << std::endl; + } + + ldLog() << "Deploying desktop file:" << desktopFile.path() << std::endl; + + bool rv; + + if (customAppRunPath) { + rv = appDir.createLinksInAppDirRoot(desktopFile, customAppRunPath.Get()); + } else { + rv = appDir.createLinksInAppDirRoot(desktopFile); + } + + if (!rv) { + return 1; + } + } + } + return true; +} diff --git a/src/linuxdeploy.h b/src/linuxdeploy.h new file mode 100644 index 0000000..6cdf4be --- /dev/null +++ b/src/linuxdeploy.h @@ -0,0 +1,13 @@ +#pragma once + +#include +#include + +#include +#include +#include +#include + +int deployAppDirRootFiles(args::ValueFlagList& desktopFilePaths, + args::ValueFlag& customAppRunPath, + linuxdeploy::core::appdir::AppDir& appDir); diff --git a/src/main.cpp b/src/main.cpp index b93196e..6fd93fe 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,6 +12,7 @@ #include "linuxdeploy/core/log.h" #include "linuxdeploy/plugin/plugin.h" #include "linuxdeploy/util/util.h" +#include "linuxdeploy.h" using namespace linuxdeploy::core; @@ -19,9 +20,6 @@ using namespace linuxdeploy::core::log; using namespace linuxdeploy::util; namespace bf = boost::filesystem; -int deployAppDirRootFiles(args::ValueFlagList& desktopFilePaths, - args::ValueFlag& customAppRunPath, appdir::AppDir& appDir); - int main(int argc, char** argv) { args::ArgumentParser parser( "linuxdeploy -- create AppDir bundles with ease" @@ -294,67 +292,3 @@ int main(int argc, char** argv) { return 0; } -int deployAppDirRootFiles(args::ValueFlagList& desktopFilePaths, - args::ValueFlag& customAppRunPath, appdir::AppDir& appDir) { - // search for desktop file and deploy it to AppDir root - ldLog() << std::endl << "-- Deploying files into AppDir root directory --" << std::endl; - - if (is_regular_file(appDir.path() / "AppRun")) { - if (customAppRunPath) - ldLog() << LD_WARNING << "AppRun exists but custom AppRun specified, overwriting existing AppRun" - << std::endl; - else - ldLog() << LD_WARNING << "AppRun exists, skipping deployment" << std::endl; - } else { - auto deployedDesktopFiles = appDir.deployedDesktopFiles(); - - desktopfile::DesktopFile desktopFile; - - if (deployedDesktopFiles.empty()) { - ldLog() << LD_WARNING - << "Could not find desktop file in AppDir, cannot create links for AppRun, desktop file and icon in AppDir root" - << std::endl; - } else { - if (!desktopFilePaths.Get().empty()) { - auto firstDeployedDesktopFileName = boost::filesystem::path( - desktopFilePaths.Get().front()).filename().string(); - - auto desktopFileMatchingName = find_if( - deployedDesktopFiles.begin(), - deployedDesktopFiles.end(), - [&firstDeployedDesktopFileName](const desktopfile::DesktopFile& desktopFile) { - auto fileName = desktopFile.path().filename().string(); - return fileName == firstDeployedDesktopFileName; - } - ); - - if (desktopFileMatchingName != deployedDesktopFiles.end()) { - desktopFile = *desktopFileMatchingName; - } else { - ldLog() << LD_ERROR << "Could not find desktop file deployed earlier any more:" - << firstDeployedDesktopFileName << std::endl; - return 1; - } - } else { - desktopFile = deployedDesktopFiles[0]; - ldLog() << LD_WARNING << "No desktop file specified, using first desktop file found:" - << desktopFile.path() << std::endl; - } - - ldLog() << "Deploying desktop file:" << desktopFile.path() << std::endl; - - bool rv; - - if (customAppRunPath) { - rv = appDir.createLinksInAppDirRoot(desktopFile, customAppRunPath.Get()); - } else { - rv = appDir.createLinksInAppDirRoot(desktopFile); - } - - if (!rv) { - return 1; - } - } - } - return true; -} From 1fa90fbd5cf66ae50cc148c347157b857af48d8b Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Sun, 4 Nov 2018 14:59:27 -0600 Subject: [PATCH 04/32] Add namespace and prepare unittest --- src/linuxdeploy.cpp | 109 ++++++++++++++++---------------- src/linuxdeploy.h | 9 +-- src/main.cpp | 2 +- tests/core/CMakeLists.txt | 21 ++++++ tests/core/test_linuxdeploy.cpp | 74 ++++++++++++++++++++++ 5 files changed, 156 insertions(+), 59 deletions(-) create mode 100644 tests/core/test_linuxdeploy.cpp diff --git a/src/linuxdeploy.cpp b/src/linuxdeploy.cpp index 39ae85f..cc8e74d 100644 --- a/src/linuxdeploy.cpp +++ b/src/linuxdeploy.cpp @@ -13,68 +13,69 @@ using namespace linuxdeploy::core::log; using namespace linuxdeploy::util; namespace bf = boost::filesystem; +namespace linuxdeploy { + int deployAppDirRootFiles(args::ValueFlagList& desktopFilePaths, + args::ValueFlag& customAppRunPath, appdir::AppDir& appDir) { + // search for desktop file and deploy it to AppDir root + ldLog() << std::endl << "-- Deploying files into AppDir root directory --" << std::endl; -int deployAppDirRootFiles(args::ValueFlagList& desktopFilePaths, - args::ValueFlag& customAppRunPath, appdir::AppDir& appDir) { - // search for desktop file and deploy it to AppDir root - ldLog() << std::endl << "-- Deploying files into AppDir root directory --" << std::endl; - - if (is_regular_file(appDir.path() / "AppRun")) { - if (customAppRunPath) - ldLog() << LD_WARNING << "AppRun exists but custom AppRun specified, overwriting existing AppRun" - << std::endl; - else - ldLog() << LD_WARNING << "AppRun exists, skipping deployment" << std::endl; - } else { - auto deployedDesktopFiles = appDir.deployedDesktopFiles(); - - desktopfile::DesktopFile desktopFile; - - if (deployedDesktopFiles.empty()) { - ldLog() << LD_WARNING - << "Could not find desktop file in AppDir, cannot create links for AppRun, desktop file and icon in AppDir root" - << std::endl; + if (is_regular_file(appDir.path() / "AppRun")) { + if (customAppRunPath) + ldLog() << LD_WARNING << "AppRun exists but custom AppRun specified, overwriting existing AppRun" + << std::endl; + else + ldLog() << LD_WARNING << "AppRun exists, skipping deployment" << std::endl; } else { - if (!desktopFilePaths.Get().empty()) { - auto firstDeployedDesktopFileName = boost::filesystem::path( - desktopFilePaths.Get().front()).filename().string(); + auto deployedDesktopFiles = appDir.deployedDesktopFiles(); - auto desktopFileMatchingName = find_if( - deployedDesktopFiles.begin(), - deployedDesktopFiles.end(), - [&firstDeployedDesktopFileName](const desktopfile::DesktopFile& desktopFile) { - auto fileName = desktopFile.path().filename().string(); - return fileName == firstDeployedDesktopFileName; + desktopfile::DesktopFile desktopFile; + + if (deployedDesktopFiles.empty()) { + ldLog() << LD_WARNING + << "Could not find desktop file in AppDir, cannot create links for AppRun, desktop file and icon in AppDir root" + << std::endl; + } else { + if (!desktopFilePaths.Get().empty()) { + auto firstDeployedDesktopFileName = boost::filesystem::path( + desktopFilePaths.Get().front()).filename().string(); + + auto desktopFileMatchingName = find_if( + deployedDesktopFiles.begin(), + deployedDesktopFiles.end(), + [&firstDeployedDesktopFileName](const desktopfile::DesktopFile& desktopFile) { + auto fileName = desktopFile.path().filename().string(); + return fileName == firstDeployedDesktopFileName; + } + ); + + if (desktopFileMatchingName != deployedDesktopFiles.end()) { + desktopFile = *desktopFileMatchingName; + } else { + ldLog() << LD_ERROR << "Could not find desktop file deployed earlier any more:" + << firstDeployedDesktopFileName << std::endl; + return 1; } - ); - - if (desktopFileMatchingName != deployedDesktopFiles.end()) { - desktopFile = *desktopFileMatchingName; } else { - ldLog() << LD_ERROR << "Could not find desktop file deployed earlier any more:" - << firstDeployedDesktopFileName << std::endl; + desktopFile = deployedDesktopFiles[0]; + ldLog() << LD_WARNING << "No desktop file specified, using first desktop file found:" + << desktopFile.path() << std::endl; + } + + ldLog() << "Deploying desktop file:" << desktopFile.path() << std::endl; + + bool rv; + + if (customAppRunPath) { + rv = appDir.createLinksInAppDirRoot(desktopFile, customAppRunPath.Get()); + } else { + rv = appDir.createLinksInAppDirRoot(desktopFile); + } + + if (!rv) { return 1; } - } else { - desktopFile = deployedDesktopFiles[0]; - ldLog() << LD_WARNING << "No desktop file specified, using first desktop file found:" - << desktopFile.path() << std::endl; - } - - ldLog() << "Deploying desktop file:" << desktopFile.path() << std::endl; - - bool rv; - - if (customAppRunPath) { - rv = appDir.createLinksInAppDirRoot(desktopFile, customAppRunPath.Get()); - } else { - rv = appDir.createLinksInAppDirRoot(desktopFile); - } - - if (!rv) { - return 1; } } + return true; } - return true; } diff --git a/src/linuxdeploy.h b/src/linuxdeploy.h index 6cdf4be..0434b4b 100644 --- a/src/linuxdeploy.h +++ b/src/linuxdeploy.h @@ -7,7 +7,8 @@ #include #include #include - -int deployAppDirRootFiles(args::ValueFlagList& desktopFilePaths, - args::ValueFlag& customAppRunPath, - linuxdeploy::core::appdir::AppDir& appDir); +namespace linuxdeploy { + int deployAppDirRootFiles(args::ValueFlagList& desktopFilePaths, + args::ValueFlag& customAppRunPath, + linuxdeploy::core::appdir::AppDir& appDir); +} diff --git a/src/main.cpp b/src/main.cpp index 6fd93fe..0ccaa88 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -254,7 +254,7 @@ int main(int argc, char** argv) { return 1; } } - if (!deployAppDirRootFiles(desktopFilePaths, customAppRunPath, appDir)) + if (!linuxdeploy::deployAppDirRootFiles(desktopFilePaths, customAppRunPath, appDir)) return 1; if (outputPlugins) { diff --git a/tests/core/CMakeLists.txt b/tests/core/CMakeLists.txt index 58c3fc4..3c71c67 100644 --- a/tests/core/CMakeLists.txt +++ b/tests/core/CMakeLists.txt @@ -16,3 +16,24 @@ add_test(test_appdir test_appdir) # make sure library and executable are built before test_appdir add_dependencies(test_appdir simple_library simple_executable) + + + +add_executable(test_linuxdeploy test_linuxdeploy.cpp ../../src/linuxdeploy.cpp) +target_link_libraries(test_linuxdeploy PRIVATE linuxdeploy_core args gtest gtest_main) +target_include_directories(test_linuxdeploy PRIVATE ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/src) + +# calculate paths to resources using CMake and hardcode them in the test binary +target_compile_definitions(test_linuxdeploy PRIVATE + -DSIMPLE_LIBRARY_PATH="$" + -DSIMPLE_EXECUTABLE_PATH="$" + -DSIMPLE_DESKTOP_ENTRY_PATH="${CMAKE_CURRENT_SOURCE_DIR}/../data/simple_app.desktop" + -DSIMPLE_ICON_PATH="${CMAKE_CURRENT_SOURCE_DIR}/../data/simple_icon.svg" + -DSIMPLE_FILE_PATH="${CMAKE_CURRENT_SOURCE_DIR}/../data/simple_file.txt" + ) + +# register in CTest +add_test(test_linuxdeploy test_linuxdeploy) + +# make sure library and executable are built before test_appdir +add_dependencies(test_linuxdeploy simple_library simple_executable) diff --git a/tests/core/test_linuxdeploy.cpp b/tests/core/test_linuxdeploy.cpp new file mode 100644 index 0000000..d5544e6 --- /dev/null +++ b/tests/core/test_linuxdeploy.cpp @@ -0,0 +1,74 @@ +#include "gtest/gtest.h" + +#include "linuxdeploy.h" + +using namespace boost::filesystem; + +namespace LinuxDeployTest { + class LinuxDeployTestsFixture : public ::testing::Test { + public: + path tmpAppDir; + + public: + LinuxDeployTestsFixture() = default; + + void SetUp() override { + tmpAppDir = temp_directory_path() / unique_path("linuxdeploy-tests-%%%%-%%%%-%%%%"); + create_directories(tmpAppDir); + } + + void TearDown() override { + remove_all(tmpAppDir); + } + + ~LinuxDeployTestsFixture() override = default; + + void listDeployedFiles() { + std::cout << "Files deployed in AppDir:" << std::endl; + recursive_directory_iterator end_itr; // default construction yields past-the-end + for (recursive_directory_iterator itr(tmpAppDir); itr != end_itr; itr++) { + std::cout << relative(itr->path(), tmpAppDir).string() << std::endl; + } + } + + void fillRegularAppDir() { + add_executable(); + add_desktop(); + add_icon(); + } + + void add_executable() const { + path source_executable_path = SIMPLE_EXECUTABLE_PATH; + path target_executable_path = tmpAppDir / "usr/bin" / source_executable_path.filename(); + create_directories(target_executable_path.parent_path()); + copy_file(source_executable_path, target_executable_path); + } + + void add_desktop() const { + path source_desktop_path = SIMPLE_DESKTOP_ENTRY_PATH; + path target_desktop_path = tmpAppDir / "usr/share/applications" / source_desktop_path.filename(); + create_directories(target_desktop_path.parent_path()); + copy_file(source_desktop_path, target_desktop_path); + } + + void add_icon() const { + path source_icon_path = SIMPLE_ICON_PATH; + path target_icon_path = tmpAppDir / "usr/share/icons/hicolor/scalable/apps" / source_icon_path.filename(); + create_directories(target_icon_path.parent_path()); + copy_file(source_icon_path, target_icon_path); + } + + void add_apprun() const { + path source_apprun_path = SIMPLE_FILE_PATH; + path target_apprun_path = tmpAppDir / "AppRun"; + copy_file(source_apprun_path, target_apprun_path); + } + }; + + TEST_F(LinuxDeployTestsFixture, deployAppDirRootFilesWithExistentAppRun) { + fillRegularAppDir(); + add_apprun(); + + listDeployedFiles(); + } +} From 2cdedc252ca67f168c92a90ff2b60b668ba51d60 Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Sun, 4 Nov 2018 15:05:49 -0600 Subject: [PATCH 05/32] Replace args::ValueFlagList by vector in deployAppDirRootFiles function signature --- src/linuxdeploy.cpp | 14 +++++++------- src/linuxdeploy.h | 6 +++--- src/main.cpp | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/linuxdeploy.cpp b/src/linuxdeploy.cpp index cc8e74d..15b13e3 100644 --- a/src/linuxdeploy.cpp +++ b/src/linuxdeploy.cpp @@ -14,13 +14,13 @@ using namespace linuxdeploy::util; namespace bf = boost::filesystem; namespace linuxdeploy { - int deployAppDirRootFiles(args::ValueFlagList& desktopFilePaths, - args::ValueFlag& customAppRunPath, appdir::AppDir& appDir) { + int deployAppDirRootFiles(std::vector desktopFilePaths, + std::string customAppRunPath, appdir::AppDir& appDir) { // search for desktop file and deploy it to AppDir root ldLog() << std::endl << "-- Deploying files into AppDir root directory --" << std::endl; if (is_regular_file(appDir.path() / "AppRun")) { - if (customAppRunPath) + if (!customAppRunPath.empty()) ldLog() << LD_WARNING << "AppRun exists but custom AppRun specified, overwriting existing AppRun" << std::endl; else @@ -35,9 +35,9 @@ namespace linuxdeploy { << "Could not find desktop file in AppDir, cannot create links for AppRun, desktop file and icon in AppDir root" << std::endl; } else { - if (!desktopFilePaths.Get().empty()) { + if (!desktopFilePaths.empty()) { auto firstDeployedDesktopFileName = boost::filesystem::path( - desktopFilePaths.Get().front()).filename().string(); + desktopFilePaths.front()).filename().string(); auto desktopFileMatchingName = find_if( deployedDesktopFiles.begin(), @@ -65,8 +65,8 @@ namespace linuxdeploy { bool rv; - if (customAppRunPath) { - rv = appDir.createLinksInAppDirRoot(desktopFile, customAppRunPath.Get()); + if (!customAppRunPath.empty()) { + rv = appDir.createLinksInAppDirRoot(desktopFile, customAppRunPath); } else { rv = appDir.createLinksInAppDirRoot(desktopFile); } diff --git a/src/linuxdeploy.h b/src/linuxdeploy.h index 0434b4b..433b918 100644 --- a/src/linuxdeploy.h +++ b/src/linuxdeploy.h @@ -6,9 +6,9 @@ #include #include #include -#include + namespace linuxdeploy { - int deployAppDirRootFiles(args::ValueFlagList& desktopFilePaths, - args::ValueFlag& customAppRunPath, + int deployAppDirRootFiles(std::vector desktopFilePaths, + std::string customAppRunPath, linuxdeploy::core::appdir::AppDir& appDir); } diff --git a/src/main.cpp b/src/main.cpp index 0ccaa88..2de1c6f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -254,7 +254,7 @@ int main(int argc, char** argv) { return 1; } } - if (!linuxdeploy::deployAppDirRootFiles(desktopFilePaths, customAppRunPath, appDir)) + if (!linuxdeploy::deployAppDirRootFiles(desktopFilePaths.Get(), customAppRunPath.Get(), appDir)) return 1; if (outputPlugins) { From bd12fefc358318ab6606dbe94574871c1297c37a Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Sun, 4 Nov 2018 15:19:29 -0600 Subject: [PATCH 06/32] Complete deployAppDirRootFilesWithExistentAppRun definition --- tests/core/test_linuxdeploy.cpp | 41 +++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/tests/core/test_linuxdeploy.cpp b/tests/core/test_linuxdeploy.cpp index d5544e6..1145b88 100644 --- a/tests/core/test_linuxdeploy.cpp +++ b/tests/core/test_linuxdeploy.cpp @@ -2,18 +2,39 @@ #include "linuxdeploy.h" +using namespace std; using namespace boost::filesystem; namespace LinuxDeployTest { class LinuxDeployTestsFixture : public ::testing::Test { public: path tmpAppDir; + path source_executable_path; + path target_executable_path; + path source_desktop_path; + path target_desktop_path; + + path source_icon_path; + path target_icon_path; + + path source_apprun_path; + path target_apprun_path; public: LinuxDeployTestsFixture() = default; void SetUp() override { tmpAppDir = temp_directory_path() / unique_path("linuxdeploy-tests-%%%%-%%%%-%%%%"); + source_executable_path = SIMPLE_EXECUTABLE_PATH; + target_executable_path = tmpAppDir / "usr/bin" / source_executable_path.filename(); + + source_desktop_path = SIMPLE_DESKTOP_ENTRY_PATH; + target_desktop_path = tmpAppDir / "usr/share/applications" / source_desktop_path.filename(); + source_icon_path = SIMPLE_ICON_PATH; + target_icon_path = tmpAppDir / "usr/share/icons/hicolor/scalable/apps" / source_icon_path.filename(); + source_apprun_path = SIMPLE_FILE_PATH; + target_apprun_path = tmpAppDir / "AppRun"; + create_directories(tmpAppDir); } @@ -37,30 +58,24 @@ namespace LinuxDeployTest { add_icon(); } - void add_executable() const { - path source_executable_path = SIMPLE_EXECUTABLE_PATH; - path target_executable_path = tmpAppDir / "usr/bin" / source_executable_path.filename(); + path add_executable() const { create_directories(target_executable_path.parent_path()); copy_file(source_executable_path, target_executable_path); + + return target_executable_path; } void add_desktop() const { - path source_desktop_path = SIMPLE_DESKTOP_ENTRY_PATH; - path target_desktop_path = tmpAppDir / "usr/share/applications" / source_desktop_path.filename(); create_directories(target_desktop_path.parent_path()); copy_file(source_desktop_path, target_desktop_path); } void add_icon() const { - path source_icon_path = SIMPLE_ICON_PATH; - path target_icon_path = tmpAppDir / "usr/share/icons/hicolor/scalable/apps" / source_icon_path.filename(); create_directories(target_icon_path.parent_path()); copy_file(source_icon_path, target_icon_path); } void add_apprun() const { - path source_apprun_path = SIMPLE_FILE_PATH; - path target_apprun_path = tmpAppDir / "AppRun"; copy_file(source_apprun_path, target_apprun_path); } }; @@ -69,6 +84,12 @@ namespace LinuxDeployTest { fillRegularAppDir(); add_apprun(); - listDeployedFiles(); + linuxdeploy::core::appdir::AppDir appDir(tmpAppDir); + linuxdeploy::deployAppDirRootFiles({}, "", appDir); + + ASSERT_TRUE(exists(tmpAppDir / source_desktop_path.filename())); + ASSERT_TRUE(exists(tmpAppDir / source_icon_path.filename())); + ASSERT_TRUE(exists(tmpAppDir / ".DirIcon")); + ASSERT_TRUE(exists(target_apprun_path)); } } From 93fea697e5082018e7f8c2f9457f9ecd13dcddbc Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Sun, 4 Nov 2018 17:42:11 -0600 Subject: [PATCH 07/32] Move desktop file deployment away from desktop file lookup --- src/linuxdeploy.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/linuxdeploy.cpp b/src/linuxdeploy.cpp index 15b13e3..f0b7bba 100644 --- a/src/linuxdeploy.cpp +++ b/src/linuxdeploy.cpp @@ -61,19 +61,20 @@ namespace linuxdeploy { << desktopFile.path() << std::endl; } - ldLog() << "Deploying desktop file:" << desktopFile.path() << std::endl; + } - bool rv; + ldLog() << "Deploying desktop file:" << desktopFile.path() << std::endl; - if (!customAppRunPath.empty()) { - rv = appDir.createLinksInAppDirRoot(desktopFile, customAppRunPath); - } else { - rv = appDir.createLinksInAppDirRoot(desktopFile); - } + bool rv; - if (!rv) { - return 1; - } + if (!customAppRunPath.empty()) { + rv = appDir.createLinksInAppDirRoot(desktopFile, customAppRunPath); + } else { + rv = appDir.createLinksInAppDirRoot(desktopFile); + } + + if (!rv) { + return 1; } } return true; From cab57f86d62aacd73d7567774bb131b83ffc7241 Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Sun, 4 Nov 2018 17:47:43 -0600 Subject: [PATCH 08/32] Put main desktop file lookup into a separated function --- src/linuxdeploy.cpp | 95 ++++++++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 41 deletions(-) diff --git a/src/linuxdeploy.cpp b/src/linuxdeploy.cpp index f0b7bba..5fed249 100644 --- a/src/linuxdeploy.cpp +++ b/src/linuxdeploy.cpp @@ -14,6 +14,9 @@ using namespace linuxdeploy::util; namespace bf = boost::filesystem; namespace linuxdeploy { + desktopfile::DesktopFile getMainDesktopFile(std::vector& desktopFilePaths, + std::vector& deployedDesktopFiles); + int deployAppDirRootFiles(std::vector desktopFilePaths, std::string customAppRunPath, appdir::AppDir& appDir) { // search for desktop file and deploy it to AppDir root @@ -28,55 +31,65 @@ namespace linuxdeploy { } else { auto deployedDesktopFiles = appDir.deployedDesktopFiles(); - desktopfile::DesktopFile desktopFile; + try { + desktopfile::DesktopFile desktopFile = getMainDesktopFile(desktopFilePaths, deployedDesktopFiles); - if (deployedDesktopFiles.empty()) { - ldLog() << LD_WARNING - << "Could not find desktop file in AppDir, cannot create links for AppRun, desktop file and icon in AppDir root" - << std::endl; - } else { - if (!desktopFilePaths.empty()) { - auto firstDeployedDesktopFileName = boost::filesystem::path( - desktopFilePaths.front()).filename().string(); + ldLog() << "Deploying desktop file:" << desktopFile.path() << std::endl; - auto desktopFileMatchingName = find_if( - deployedDesktopFiles.begin(), - deployedDesktopFiles.end(), - [&firstDeployedDesktopFileName](const desktopfile::DesktopFile& desktopFile) { - auto fileName = desktopFile.path().filename().string(); - return fileName == firstDeployedDesktopFileName; - } - ); + bool rv; - if (desktopFileMatchingName != deployedDesktopFiles.end()) { - desktopFile = *desktopFileMatchingName; - } else { - ldLog() << LD_ERROR << "Could not find desktop file deployed earlier any more:" - << firstDeployedDesktopFileName << std::endl; - return 1; - } + if (!customAppRunPath.empty()) { + rv = appDir.createLinksInAppDirRoot(desktopFile, customAppRunPath); } else { - desktopFile = deployedDesktopFiles[0]; - ldLog() << LD_WARNING << "No desktop file specified, using first desktop file found:" - << desktopFile.path() << std::endl; + rv = appDir.createLinksInAppDirRoot(desktopFile); } - } - - ldLog() << "Deploying desktop file:" << desktopFile.path() << std::endl; - - bool rv; - - if (!customAppRunPath.empty()) { - rv = appDir.createLinksInAppDirRoot(desktopFile, customAppRunPath); - } else { - rv = appDir.createLinksInAppDirRoot(desktopFile); - } - - if (!rv) { - return 1; + if (!rv) { + return 1; + } + } catch (const std::runtime_error& er) { + return -1; } } return true; } + + desktopfile::DesktopFile getMainDesktopFile(std::vector& desktopFilePaths, + std::vector& deployedDesktopFiles) { + desktopfile::DesktopFile desktopFile; + + if (deployedDesktopFiles.empty()) { + ldLog() << LD_WARNING + << "Could not find desktop file in AppDir, cannot create links for AppRun, desktop file and icon in AppDir root" + << std::endl; + } else { + if (!desktopFilePaths.empty()) { + auto firstDeployedDesktopFileName = boost::filesystem::path( + desktopFilePaths.front()).filename().string(); + + auto desktopFileMatchingName = find_if( + deployedDesktopFiles.begin(), + deployedDesktopFiles.end(), + [&firstDeployedDesktopFileName](const desktopfile::DesktopFile& desktopFile) { + auto fileName = desktopFile.path().filename().string(); + return fileName == firstDeployedDesktopFileName; + } + ); + + if (desktopFileMatchingName != deployedDesktopFiles.end()) { + desktopFile = *desktopFileMatchingName; + } else { + ldLog() << LD_ERROR << "Could not find desktop file deployed earlier any more:" + << firstDeployedDesktopFileName << std::endl; + throw std::runtime_error("Old desktop file is not reachable."); + } + } else { + desktopFile = deployedDesktopFiles[0]; + ldLog() << LD_WARNING << "No desktop file specified, using first desktop file found:" + << desktopFile.path() << std::endl; + } + + } + return desktopFile; + } } From 7ff05ca98e4922bd65bd5b3be6b2f5d4ea8604a9 Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Sun, 4 Nov 2018 18:03:43 -0600 Subject: [PATCH 09/32] Removing AppRun file existence check as createLinksInAppDirRoot also perform this check --- src/linuxdeploy.cpp | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/src/linuxdeploy.cpp b/src/linuxdeploy.cpp index 5fed249..9d135d7 100644 --- a/src/linuxdeploy.cpp +++ b/src/linuxdeploy.cpp @@ -22,35 +22,28 @@ namespace linuxdeploy { // search for desktop file and deploy it to AppDir root ldLog() << std::endl << "-- Deploying files into AppDir root directory --" << std::endl; - if (is_regular_file(appDir.path() / "AppRun")) { - if (!customAppRunPath.empty()) - ldLog() << LD_WARNING << "AppRun exists but custom AppRun specified, overwriting existing AppRun" - << std::endl; - else - ldLog() << LD_WARNING << "AppRun exists, skipping deployment" << std::endl; - } else { - auto deployedDesktopFiles = appDir.deployedDesktopFiles(); + auto deployedDesktopFiles = appDir.deployedDesktopFiles(); - try { - desktopfile::DesktopFile desktopFile = getMainDesktopFile(desktopFilePaths, deployedDesktopFiles); + try { + desktopfile::DesktopFile desktopFile = getMainDesktopFile(desktopFilePaths, deployedDesktopFiles); - ldLog() << "Deploying desktop file:" << desktopFile.path() << std::endl; + ldLog() << "Deploying desktop file:" << desktopFile.path() << std::endl; - bool rv; + bool rv; - if (!customAppRunPath.empty()) { - rv = appDir.createLinksInAppDirRoot(desktopFile, customAppRunPath); - } else { - rv = appDir.createLinksInAppDirRoot(desktopFile); - } - - if (!rv) { - return 1; - } - } catch (const std::runtime_error& er) { - return -1; + if (!customAppRunPath.empty()) { + rv = appDir.createLinksInAppDirRoot(desktopFile, customAppRunPath); + } else { + rv = appDir.createLinksInAppDirRoot(desktopFile); } + + if (!rv) { + return 1; + } + } catch (const std::runtime_error& er) { + return -1; } + return true; } From 41569a4f53ac5b8b2369ab4d3039deac94dc358a Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Sun, 4 Nov 2018 18:04:57 -0600 Subject: [PATCH 10/32] The ".DirIcon" creation seems not to be responsibility of deployAppDirRootFiles --- tests/core/test_linuxdeploy.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/core/test_linuxdeploy.cpp b/tests/core/test_linuxdeploy.cpp index 1145b88..92c6412 100644 --- a/tests/core/test_linuxdeploy.cpp +++ b/tests/core/test_linuxdeploy.cpp @@ -89,7 +89,6 @@ namespace LinuxDeployTest { ASSERT_TRUE(exists(tmpAppDir / source_desktop_path.filename())); ASSERT_TRUE(exists(tmpAppDir / source_icon_path.filename())); - ASSERT_TRUE(exists(tmpAppDir / ".DirIcon")); ASSERT_TRUE(exists(target_apprun_path)); } } From 16b0a5948a9ea2b224660559edfc7396dee90982 Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Sun, 4 Nov 2018 18:10:00 -0600 Subject: [PATCH 11/32] createLinksInAppDirRoot is capable of dealing with an empty customAppRunPath so there is no need to check it --- src/linuxdeploy.cpp | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/linuxdeploy.cpp b/src/linuxdeploy.cpp index 9d135d7..5a3bdef 100644 --- a/src/linuxdeploy.cpp +++ b/src/linuxdeploy.cpp @@ -26,25 +26,15 @@ namespace linuxdeploy { try { desktopfile::DesktopFile desktopFile = getMainDesktopFile(desktopFilePaths, deployedDesktopFiles); - ldLog() << "Deploying desktop file:" << desktopFile.path() << std::endl; + if (!appDir.createLinksInAppDirRoot(desktopFile, customAppRunPath)) + return -1; - bool rv; - - if (!customAppRunPath.empty()) { - rv = appDir.createLinksInAppDirRoot(desktopFile, customAppRunPath); - } else { - rv = appDir.createLinksInAppDirRoot(desktopFile); - } - - if (!rv) { - return 1; - } } catch (const std::runtime_error& er) { return -1; } - - return true; + + return 1; } desktopfile::DesktopFile getMainDesktopFile(std::vector& desktopFilePaths, From 29cda3b1ac62d532abc424a8787f7ade7ccf90e1 Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Sun, 4 Nov 2018 18:11:40 -0600 Subject: [PATCH 12/32] Change return type to bool --- src/linuxdeploy.cpp | 10 +++++----- src/linuxdeploy.h | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/linuxdeploy.cpp b/src/linuxdeploy.cpp index 5a3bdef..246bbe9 100644 --- a/src/linuxdeploy.cpp +++ b/src/linuxdeploy.cpp @@ -17,8 +17,8 @@ namespace linuxdeploy { desktopfile::DesktopFile getMainDesktopFile(std::vector& desktopFilePaths, std::vector& deployedDesktopFiles); - int deployAppDirRootFiles(std::vector desktopFilePaths, - std::string customAppRunPath, appdir::AppDir& appDir) { + bool deployAppDirRootFiles(std::vector desktopFilePaths, + std::string customAppRunPath, appdir::AppDir& appDir) { // search for desktop file and deploy it to AppDir root ldLog() << std::endl << "-- Deploying files into AppDir root directory --" << std::endl; @@ -28,13 +28,13 @@ namespace linuxdeploy { desktopfile::DesktopFile desktopFile = getMainDesktopFile(desktopFilePaths, deployedDesktopFiles); ldLog() << "Deploying desktop file:" << desktopFile.path() << std::endl; if (!appDir.createLinksInAppDirRoot(desktopFile, customAppRunPath)) - return -1; + return false; } catch (const std::runtime_error& er) { - return -1; + return false; } - return 1; + return true; } desktopfile::DesktopFile getMainDesktopFile(std::vector& desktopFilePaths, diff --git a/src/linuxdeploy.h b/src/linuxdeploy.h index 433b918..3581138 100644 --- a/src/linuxdeploy.h +++ b/src/linuxdeploy.h @@ -8,7 +8,7 @@ #include namespace linuxdeploy { - int deployAppDirRootFiles(std::vector desktopFilePaths, - std::string customAppRunPath, - linuxdeploy::core::appdir::AppDir& appDir); + bool deployAppDirRootFiles(std::vector desktopFilePaths, + std::string customAppRunPath, + linuxdeploy::core::appdir::AppDir& appDir); } From cc800588d202790f4e7445c5ea5910ddf136ee51 Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Mon, 5 Nov 2018 15:22:48 -0600 Subject: [PATCH 13/32] Optimize imports --- src/linuxdeploy.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/linuxdeploy.cpp b/src/linuxdeploy.cpp index 246bbe9..03e0aff 100644 --- a/src/linuxdeploy.cpp +++ b/src/linuxdeploy.cpp @@ -3,14 +3,11 @@ #include #include -#include #include "linuxdeploy.h" using namespace linuxdeploy::core; - using namespace linuxdeploy::core::log; -using namespace linuxdeploy::util; namespace bf = boost::filesystem; namespace linuxdeploy { From 2210b7e65d0cdce4edacb4cfbd2b13a568ce6163 Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Mon, 5 Nov 2018 15:33:15 -0600 Subject: [PATCH 14/32] Remove integration test 'build_minimal_appimage_with_custom_apprun' --- tests/CMakeLists.txt | 9 --- ...ild_minimal_appimage_with_custom_apprun.sh | 69 ------------------- 2 files changed, 78 deletions(-) delete mode 100755 tests/scripts/build_minimal_appimage_with_custom_apprun.sh diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 87f7c8d..9c9d1b6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -4,12 +4,3 @@ add_subdirectory(simple_executable) # now include actual tests add_subdirectory(core) - -add_test(NAME build_minial_appimage - COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/build_minimal_appimage_with_custom_apprun.sh - $ - $ - "${CMAKE_CURRENT_SOURCE_DIR}/data/simple_app.desktop" - "${CMAKE_CURRENT_SOURCE_DIR}/data/simple_icon.svg" -) -SET_TESTS_PROPERTIES(build_minial_appimage PROPERTIES DEPENDS "linuxdeploy simple_executable") diff --git a/tests/scripts/build_minimal_appimage_with_custom_apprun.sh b/tests/scripts/build_minimal_appimage_with_custom_apprun.sh deleted file mode 100755 index 7246e6d..0000000 --- a/tests/scripts/build_minimal_appimage_with_custom_apprun.sh +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/env bash - -if [[ -z ${ARCH+x} ]]; then - echo "ARCH not set." - exit -1; -fi - -LINUXDEPLOY=$1 -if [[ -z ${LINUXDEPLOY+x} ]]; then - echo "LINUXDEPLOY path not set." - exit -1; -fi - -RUNNABLE=$2 -if [[ -z ${RUNNABLE+x} ]]; then - echo "RUNNABLE path not set." - exit -1; -fi - -DESKTOP_FILE=$3 -if [[ -z ${DESKTOP_FILE+x} ]]; then - echo "DESKTOP_FILE path not set." - exit -1; -fi - -ICON=$4 -if [[ -z ${ICON+x} ]]; then - echo "ICON path not set." - exit -1; -fi - - -LINUXDEPLOYDIR=`mktemp -d` -pushd "$LINUXDEPLOYDIR" - - cp "$LINUXDEPLOY" . - - wget https://github.com/TheAssassin/linuxdeploy-plugin-appimage/releases/download/continuous/linuxdeploy-plugin-appimage-"$ARCH".AppImage - chmod +x linuxdeploy-plugin-appimage-"$ARCH".AppImage - - filename=$(basename -- "$LINUXDEPLOY") - LINUXDEPLOY="$LINUXDEPLOYDIR/$filename" -popd - -APPDIR=`mktemp -d` - -cp $RUNNABLE "$APPDIR/AppRun" - -mkdir -p "$APPDIR/usr/bin" -cp "$RUNNABLE" "$APPDIR/usr/bin" - -mkdir -p "$APPDIR/usr/share/applications" -cp "$DESKTOP_FILE" "$APPDIR/usr/share/applications" - -mkdir -p "$APPDIR/usr/share/icons/hicolor/scalable/apps" -cp "$ICON" "$APPDIR/usr/share/icons/hicolor/scalable/apps" - -"$LINUXDEPLOY" --appdir "$APPDIR" --output=appimage -SUCCEED=$? - -echo " " -echo " AppDir contents: " -find "$APPDIR" -echo " " - -rm -rf "$APPDIR" -rm -rf "$LINUXDEPLOYDIR" - -exit "$SUCCEED" From f3f30166f2d5b146e00eab175631d82b34886192 Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Mon, 5 Nov 2018 15:38:12 -0600 Subject: [PATCH 15/32] Importing boost::filesystem as bf to keep consistency its usage across the project --- tests/core/test_linuxdeploy.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/core/test_linuxdeploy.cpp b/tests/core/test_linuxdeploy.cpp index 92c6412..eefd3b6 100644 --- a/tests/core/test_linuxdeploy.cpp +++ b/tests/core/test_linuxdeploy.cpp @@ -3,28 +3,28 @@ #include "linuxdeploy.h" using namespace std; -using namespace boost::filesystem; +namespace bf = boost::filesystem; namespace LinuxDeployTest { class LinuxDeployTestsFixture : public ::testing::Test { public: - path tmpAppDir; - path source_executable_path; - path target_executable_path; + bf::path tmpAppDir; + bf::path source_executable_path; + bf::path target_executable_path; - path source_desktop_path; - path target_desktop_path; + bf::path source_desktop_path; + bf::path target_desktop_path; - path source_icon_path; - path target_icon_path; + bf::path source_icon_path; + bf::path target_icon_path; - path source_apprun_path; - path target_apprun_path; + bf::path source_apprun_path; + bf::path target_apprun_path; public: LinuxDeployTestsFixture() = default; void SetUp() override { - tmpAppDir = temp_directory_path() / unique_path("linuxdeploy-tests-%%%%-%%%%-%%%%"); + tmpAppDir = bf::temp_directory_path() / bf::unique_path("linuxdeploy-tests-%%%%-%%%%-%%%%"); source_executable_path = SIMPLE_EXECUTABLE_PATH; target_executable_path = tmpAppDir / "usr/bin" / source_executable_path.filename(); @@ -46,8 +46,8 @@ namespace LinuxDeployTest { void listDeployedFiles() { std::cout << "Files deployed in AppDir:" << std::endl; - recursive_directory_iterator end_itr; // default construction yields past-the-end - for (recursive_directory_iterator itr(tmpAppDir); itr != end_itr; itr++) { + bf::recursive_directory_iterator end_itr; // default construction yields past-the-end + for (bf::recursive_directory_iterator itr(tmpAppDir); itr != end_itr; itr++) { std::cout << relative(itr->path(), tmpAppDir).string() << std::endl; } } @@ -58,7 +58,7 @@ namespace LinuxDeployTest { add_icon(); } - path add_executable() const { + bf::path add_executable() const { create_directories(target_executable_path.parent_path()); copy_file(source_executable_path, target_executable_path); From f0bb1fb47287e16852752c1cc85c761acb03c51e Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Mon, 5 Nov 2018 15:39:00 -0600 Subject: [PATCH 16/32] bring empty line back --- src/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.cpp b/src/main.cpp index 2de1c6f..be39a6b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,6 +18,7 @@ using namespace linuxdeploy::core; using namespace linuxdeploy::core::log; using namespace linuxdeploy::util; + namespace bf = boost::filesystem; int main(int argc, char** argv) { From fc3d80c2816cd30a4db7642a20ed0f59136c9097 Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Mon, 5 Nov 2018 15:39:47 -0600 Subject: [PATCH 17/32] remove duplicated 'public' --- tests/core/test_linuxdeploy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/core/test_linuxdeploy.cpp b/tests/core/test_linuxdeploy.cpp index eefd3b6..d5e517b 100644 --- a/tests/core/test_linuxdeploy.cpp +++ b/tests/core/test_linuxdeploy.cpp @@ -20,7 +20,7 @@ namespace LinuxDeployTest { bf::path source_apprun_path; bf::path target_apprun_path; - public: + LinuxDeployTestsFixture() = default; void SetUp() override { From 906dcab283c6b3768404e1fd4072b03c01df1e06 Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Mon, 5 Nov 2018 15:40:15 -0600 Subject: [PATCH 18/32] Fix code style --- tests/core/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/core/CMakeLists.txt b/tests/core/CMakeLists.txt index 3c71c67..cdbd3b5 100644 --- a/tests/core/CMakeLists.txt +++ b/tests/core/CMakeLists.txt @@ -30,7 +30,7 @@ target_compile_definitions(test_linuxdeploy PRIVATE -DSIMPLE_DESKTOP_ENTRY_PATH="${CMAKE_CURRENT_SOURCE_DIR}/../data/simple_app.desktop" -DSIMPLE_ICON_PATH="${CMAKE_CURRENT_SOURCE_DIR}/../data/simple_icon.svg" -DSIMPLE_FILE_PATH="${CMAKE_CURRENT_SOURCE_DIR}/../data/simple_file.txt" - ) +) # register in CTest add_test(test_linuxdeploy test_linuxdeploy) From 553bb9fcb0705f20fda9edff6f964e9d7d32ac2c Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Mon, 5 Nov 2018 15:41:06 -0600 Subject: [PATCH 19/32] No need to override constructor --- tests/core/test_linuxdeploy.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/core/test_linuxdeploy.cpp b/tests/core/test_linuxdeploy.cpp index d5e517b..b30ed87 100644 --- a/tests/core/test_linuxdeploy.cpp +++ b/tests/core/test_linuxdeploy.cpp @@ -21,8 +21,6 @@ namespace LinuxDeployTest { bf::path source_apprun_path; bf::path target_apprun_path; - LinuxDeployTestsFixture() = default; - void SetUp() override { tmpAppDir = bf::temp_directory_path() / bf::unique_path("linuxdeploy-tests-%%%%-%%%%-%%%%"); source_executable_path = SIMPLE_EXECUTABLE_PATH; From 6c674aa184767233fe031a61bf3b636d696a5bb0 Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Mon, 5 Nov 2018 15:43:35 -0600 Subject: [PATCH 20/32] Making getMainDesktopFile parameters constant references --- src/linuxdeploy.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/linuxdeploy.cpp b/src/linuxdeploy.cpp index 03e0aff..164359c 100644 --- a/src/linuxdeploy.cpp +++ b/src/linuxdeploy.cpp @@ -11,8 +11,8 @@ using namespace linuxdeploy::core::log; namespace bf = boost::filesystem; namespace linuxdeploy { - desktopfile::DesktopFile getMainDesktopFile(std::vector& desktopFilePaths, - std::vector& deployedDesktopFiles); + desktopfile::DesktopFile getMainDesktopFile(const std::vector& desktopFilePaths, + const std::vector& deployedDesktopFiles); bool deployAppDirRootFiles(std::vector desktopFilePaths, std::string customAppRunPath, appdir::AppDir& appDir) { @@ -34,8 +34,8 @@ namespace linuxdeploy { return true; } - desktopfile::DesktopFile getMainDesktopFile(std::vector& desktopFilePaths, - std::vector& deployedDesktopFiles) { + desktopfile::DesktopFile getMainDesktopFile(const std::vector& desktopFilePaths, + const std::vector& deployedDesktopFiles) { desktopfile::DesktopFile desktopFile; if (deployedDesktopFiles.empty()) { From 012e621ec5ce33846e90317ac0a1a8cf2fbc2475 Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Mon, 5 Nov 2018 15:47:11 -0600 Subject: [PATCH 21/32] Throw an exception when no deskotp files are found --- src/linuxdeploy.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/linuxdeploy.cpp b/src/linuxdeploy.cpp index 164359c..d868159 100644 --- a/src/linuxdeploy.cpp +++ b/src/linuxdeploy.cpp @@ -42,6 +42,7 @@ namespace linuxdeploy { ldLog() << LD_WARNING << "Could not find desktop file in AppDir, cannot create links for AppRun, desktop file and icon in AppDir root" << std::endl; + throw std::runtime_error("Can't find desktop files in AppDir."); } else { if (!desktopFilePaths.empty()) { auto firstDeployedDesktopFileName = boost::filesystem::path( From 700f6fe15f6bb5e342082830d4eb5d19e444af9e Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Mon, 5 Nov 2018 15:54:59 -0600 Subject: [PATCH 22/32] Remove declaration of getMainDesktopFile --- src/linuxdeploy.cpp | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/src/linuxdeploy.cpp b/src/linuxdeploy.cpp index d868159..bbf603c 100644 --- a/src/linuxdeploy.cpp +++ b/src/linuxdeploy.cpp @@ -11,29 +11,6 @@ using namespace linuxdeploy::core::log; namespace bf = boost::filesystem; namespace linuxdeploy { - desktopfile::DesktopFile getMainDesktopFile(const std::vector& desktopFilePaths, - const std::vector& deployedDesktopFiles); - - bool deployAppDirRootFiles(std::vector desktopFilePaths, - std::string customAppRunPath, appdir::AppDir& appDir) { - // search for desktop file and deploy it to AppDir root - ldLog() << std::endl << "-- Deploying files into AppDir root directory --" << std::endl; - - auto deployedDesktopFiles = appDir.deployedDesktopFiles(); - - try { - desktopfile::DesktopFile desktopFile = getMainDesktopFile(desktopFilePaths, deployedDesktopFiles); - ldLog() << "Deploying desktop file:" << desktopFile.path() << std::endl; - if (!appDir.createLinksInAppDirRoot(desktopFile, customAppRunPath)) - return false; - - } catch (const std::runtime_error& er) { - return false; - } - - return true; - } - desktopfile::DesktopFile getMainDesktopFile(const std::vector& desktopFilePaths, const std::vector& deployedDesktopFiles) { desktopfile::DesktopFile desktopFile; @@ -73,4 +50,24 @@ namespace linuxdeploy { } return desktopFile; } + + bool deployAppDirRootFiles(std::vector desktopFilePaths, + std::string customAppRunPath, appdir::AppDir& appDir) { + // search for desktop file and deploy it to AppDir root + ldLog() << std::endl << "-- Deploying files into AppDir root directory --" << std::endl; + + auto deployedDesktopFiles = appDir.deployedDesktopFiles(); + + try { + desktopfile::DesktopFile desktopFile = getMainDesktopFile(desktopFilePaths, deployedDesktopFiles); + ldLog() << "Deploying desktop file:" << desktopFile.path() << std::endl; + if (!appDir.createLinksInAppDirRoot(desktopFile, customAppRunPath)) + return false; + + } catch (const std::runtime_error& er) { + return false; + } + + return true; + } } From d7c0e94f11b4958af5e3699c013d12f985f708aa Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Mon, 5 Nov 2018 15:55:13 -0600 Subject: [PATCH 23/32] Reformat --- src/linuxdeploy.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/linuxdeploy.h b/src/linuxdeploy.h index 3581138..752f317 100644 --- a/src/linuxdeploy.h +++ b/src/linuxdeploy.h @@ -8,7 +8,6 @@ #include namespace linuxdeploy { - bool deployAppDirRootFiles(std::vector desktopFilePaths, - std::string customAppRunPath, + bool deployAppDirRootFiles(std::vector desktopFilePaths, std::string customAppRunPath, linuxdeploy::core::appdir::AppDir& appDir); } From f201c571777feb023200154874945cbf9f27a5a5 Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Mon, 5 Nov 2018 15:57:37 -0600 Subject: [PATCH 24/32] Optimize imports --- src/linuxdeploy.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/linuxdeploy.h b/src/linuxdeploy.h index 752f317..6126c7e 100644 --- a/src/linuxdeploy.h +++ b/src/linuxdeploy.h @@ -3,9 +3,7 @@ #include #include -#include -#include -#include +#include "linuxdeploy/core/appdir.h" namespace linuxdeploy { bool deployAppDirRootFiles(std::vector desktopFilePaths, std::string customAppRunPath, From 4bf1948774fe95c3b8ddef516891b2836b7f8264 Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Mon, 5 Nov 2018 16:07:01 -0600 Subject: [PATCH 25/32] Document linuxdeploy::getMainDesktopFile --- src/linuxdeploy.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/linuxdeploy.cpp b/src/linuxdeploy.cpp index bbf603c..100ce25 100644 --- a/src/linuxdeploy.cpp +++ b/src/linuxdeploy.cpp @@ -11,6 +11,14 @@ using namespace linuxdeploy::core::log; namespace bf = boost::filesystem; namespace linuxdeploy { + /** + * Resolved the 'MAIN' desktop file from all the available. + * + * @param desktopFilePaths + * @param deployedDesktopFiles + * @return the MAIN DesktopFile + * @throw std::runtime_error in case of error + */ desktopfile::DesktopFile getMainDesktopFile(const std::vector& desktopFilePaths, const std::vector& deployedDesktopFiles) { desktopfile::DesktopFile desktopFile; From 0e92331a12180c03a8d2e90ac7f0827979cec75f Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Mon, 5 Nov 2018 16:13:05 -0600 Subject: [PATCH 26/32] Document linuxdeploy::deployAppDirRootFiles --- src/linuxdeploy.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/linuxdeploy.h b/src/linuxdeploy.h index 6126c7e..9559689 100644 --- a/src/linuxdeploy.h +++ b/src/linuxdeploy.h @@ -6,6 +6,15 @@ #include "linuxdeploy/core/appdir.h" namespace linuxdeploy { + /** + * Deploy the application ".deskop", icon, and runnable files in the AppDir root path. According to the + * AppDir spec at: https://docs.appimage.org/reference/appdir.html + * + * @param desktopFilePaths to be deployed in the AppDir root + * @param customAppRunPath AppRun to be used, if empty the application executable will be used instead + * @param appDir + * @return true on success otherwise false + */ bool deployAppDirRootFiles(std::vector desktopFilePaths, std::string customAppRunPath, linuxdeploy::core::appdir::AppDir& appDir); } From 19ecbb2d7071faefc68910b7cd9f576ebcb30bfa Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Mon, 5 Nov 2018 16:24:09 -0600 Subject: [PATCH 27/32] remove empty line --- src/main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index be39a6b..91478c8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,7 +15,6 @@ #include "linuxdeploy.h" using namespace linuxdeploy::core; - using namespace linuxdeploy::core::log; using namespace linuxdeploy::util; From 5055efdc0570f5fdadf8540547faa167087a617c Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Mon, 5 Nov 2018 18:33:14 -0600 Subject: [PATCH 28/32] Rename linuxdeploy.cpp and linuxdeploy.h to core.cpp and core.h --- src/CMakeLists.txt | 2 +- src/{linuxdeploy.cpp => core.cpp} | 2 +- src/{linuxdeploy.h => core.h} | 0 src/main.cpp | 2 +- tests/core/CMakeLists.txt | 2 +- tests/core/test_linuxdeploy.cpp | 2 +- 6 files changed, 5 insertions(+), 5 deletions(-) rename src/{linuxdeploy.cpp => core.cpp} (99%) rename src/{linuxdeploy.h => core.h} (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b597b8b..d7bba6d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -45,7 +45,7 @@ add_subdirectory(util) add_subdirectory(plugin) add_subdirectory(core) -add_executable(linuxdeploy main.cpp linuxdeploy.cpp) +add_executable(linuxdeploy main.cpp core.cpp) target_link_libraries(linuxdeploy linuxdeploy_core args) set_target_properties(linuxdeploy PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin") diff --git a/src/linuxdeploy.cpp b/src/core.cpp similarity index 99% rename from src/linuxdeploy.cpp rename to src/core.cpp index 100ce25..7d9f532 100644 --- a/src/linuxdeploy.cpp +++ b/src/core.cpp @@ -4,7 +4,7 @@ #include #include -#include "linuxdeploy.h" +#include "core.h" using namespace linuxdeploy::core; using namespace linuxdeploy::core::log; diff --git a/src/linuxdeploy.h b/src/core.h similarity index 100% rename from src/linuxdeploy.h rename to src/core.h diff --git a/src/main.cpp b/src/main.cpp index 91478c8..47f0d0e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,7 +12,7 @@ #include "linuxdeploy/core/log.h" #include "linuxdeploy/plugin/plugin.h" #include "linuxdeploy/util/util.h" -#include "linuxdeploy.h" +#include "core.h" using namespace linuxdeploy::core; using namespace linuxdeploy::core::log; diff --git a/tests/core/CMakeLists.txt b/tests/core/CMakeLists.txt index cdbd3b5..dcef6fc 100644 --- a/tests/core/CMakeLists.txt +++ b/tests/core/CMakeLists.txt @@ -19,7 +19,7 @@ add_dependencies(test_appdir simple_library simple_executable) -add_executable(test_linuxdeploy test_linuxdeploy.cpp ../../src/linuxdeploy.cpp) +add_executable(test_linuxdeploy test_linuxdeploy.cpp ../../src/core.cpp) target_link_libraries(test_linuxdeploy PRIVATE linuxdeploy_core args gtest gtest_main) target_include_directories(test_linuxdeploy PRIVATE ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/src) diff --git a/tests/core/test_linuxdeploy.cpp b/tests/core/test_linuxdeploy.cpp index b30ed87..dd6349d 100644 --- a/tests/core/test_linuxdeploy.cpp +++ b/tests/core/test_linuxdeploy.cpp @@ -1,6 +1,6 @@ #include "gtest/gtest.h" -#include "linuxdeploy.h" +#include "core.h" using namespace std; namespace bf = boost::filesystem; From 9f20e5829d67f594f605fadb29fc7bbb2f8c002a Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Mon, 5 Nov 2018 21:26:48 -0600 Subject: [PATCH 29/32] Restructure the code in order to make it more clear --- src/core.cpp | 82 ++++++++++++++++++++++++---------------------------- 1 file changed, 38 insertions(+), 44 deletions(-) diff --git a/src/core.cpp b/src/core.cpp index 7d9f532..bdb2fa1 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -11,71 +11,65 @@ using namespace linuxdeploy::core::log; namespace bf = boost::filesystem; namespace linuxdeploy { + class DeployError : public std::runtime_error { + public: + explicit DeployError(const std::string& what) : std::runtime_error(what) {}; + }; + /** - * Resolved the 'MAIN' desktop file from all the available. + * Resolve the 'MAIN' desktop file from all the available. * * @param desktopFilePaths * @param deployedDesktopFiles * @return the MAIN DesktopFile - * @throw std::runtime_error in case of error + * @throw DeployError in case of 'deployed desktop file not found' */ desktopfile::DesktopFile getMainDesktopFile(const std::vector& desktopFilePaths, const std::vector& deployedDesktopFiles) { - desktopfile::DesktopFile desktopFile; - - if (deployedDesktopFiles.empty()) { - ldLog() << LD_WARNING - << "Could not find desktop file in AppDir, cannot create links for AppRun, desktop file and icon in AppDir root" - << std::endl; - throw std::runtime_error("Can't find desktop files in AppDir."); - } else { - if (!desktopFilePaths.empty()) { - auto firstDeployedDesktopFileName = boost::filesystem::path( - desktopFilePaths.front()).filename().string(); - - auto desktopFileMatchingName = find_if( - deployedDesktopFiles.begin(), - deployedDesktopFiles.end(), - [&firstDeployedDesktopFileName](const desktopfile::DesktopFile& desktopFile) { - auto fileName = desktopFile.path().filename().string(); - return fileName == firstDeployedDesktopFileName; - } - ); - - if (desktopFileMatchingName != deployedDesktopFiles.end()) { - desktopFile = *desktopFileMatchingName; - } else { - ldLog() << LD_ERROR << "Could not find desktop file deployed earlier any more:" - << firstDeployedDesktopFileName << std::endl; - throw std::runtime_error("Old desktop file is not reachable."); - } - } else { - desktopFile = deployedDesktopFiles[0]; - ldLog() << LD_WARNING << "No desktop file specified, using first desktop file found:" - << desktopFile.path() << std::endl; - } - + if (desktopFilePaths.empty()) { + ldLog() << LD_WARNING << "No desktop file specified, using first desktop file found:" + << deployedDesktopFiles[0].path() << std::endl; + return deployedDesktopFiles[0]; + } + + auto firstDeployedDesktopFileName = boost::filesystem::path( + desktopFilePaths.front()).filename().string(); + + auto desktopFileMatchingName = find_if( + deployedDesktopFiles.begin(), + deployedDesktopFiles.end(), + [&firstDeployedDesktopFileName](const desktopfile::DesktopFile& desktopFile) { + auto fileName = desktopFile.path().filename().string(); + return fileName == firstDeployedDesktopFileName; + } + ); + + if (desktopFileMatchingName != deployedDesktopFiles.end()) { + return *desktopFileMatchingName; + } else { + ldLog() << LD_ERROR << "Could not find desktop file deployed earlier any more:" + << firstDeployedDesktopFileName << std::endl; + throw DeployError("Old desktop file is not reachable."); } - return desktopFile; } bool deployAppDirRootFiles(std::vector desktopFilePaths, std::string customAppRunPath, appdir::AppDir& appDir) { - // search for desktop file and deploy it to AppDir root ldLog() << std::endl << "-- Deploying files into AppDir root directory --" << std::endl; auto deployedDesktopFiles = appDir.deployedDesktopFiles(); + if (deployedDesktopFiles.empty()) { + ldLog() << LD_WARNING << "Could not find desktop file in AppDir, cannot create links for AppRun, " + "desktop file and icon in AppDir root" << std::endl; + return true; + } try { desktopfile::DesktopFile desktopFile = getMainDesktopFile(desktopFilePaths, deployedDesktopFiles); ldLog() << "Deploying desktop file:" << desktopFile.path() << std::endl; - if (!appDir.createLinksInAppDirRoot(desktopFile, customAppRunPath)) - return false; - - } catch (const std::runtime_error& er) { + return appDir.createLinksInAppDirRoot(desktopFile, customAppRunPath); + } catch (const DeployError& er) { return false; } - - return true; } } From 9d78e0786bb68a555e59b20d46cef4426b27c949 Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Tue, 6 Nov 2018 07:48:12 -0600 Subject: [PATCH 30/32] Ensure that custom AppRun are deployed even if no desktop files are found --- src/core.cpp | 6 ++++++ tests/core/test_linuxdeploy.cpp | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/src/core.cpp b/src/core.cpp index bdb2fa1..bec36b8 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -57,6 +57,12 @@ namespace linuxdeploy { std::string customAppRunPath, appdir::AppDir& appDir) { ldLog() << std::endl << "-- Deploying files into AppDir root directory --" << std::endl; + if (!customAppRunPath.empty()) { + ldLog() << LD_WARNING << "Deploying custom AppRun: " << customAppRunPath << std::endl; + appDir.deployFile(customAppRunPath, appDir.path() / "AppRun"); + appDir.executeDeferredOperations(); + } + auto deployedDesktopFiles = appDir.deployedDesktopFiles(); if (deployedDesktopFiles.empty()) { ldLog() << LD_WARNING << "Could not find desktop file in AppDir, cannot create links for AppRun, " diff --git a/tests/core/test_linuxdeploy.cpp b/tests/core/test_linuxdeploy.cpp index dd6349d..042b692 100644 --- a/tests/core/test_linuxdeploy.cpp +++ b/tests/core/test_linuxdeploy.cpp @@ -89,4 +89,11 @@ namespace LinuxDeployTest { ASSERT_TRUE(exists(tmpAppDir / source_icon_path.filename())); ASSERT_TRUE(exists(target_apprun_path)); } + + TEST_F(LinuxDeployTestsFixture, deployAppDirRootFilesWithCustomAppRun) { + linuxdeploy::core::appdir::AppDir appDir(tmpAppDir); + linuxdeploy::deployAppDirRootFiles({}, source_apprun_path.string(), appDir); + + ASSERT_TRUE(exists(target_apprun_path)); + } } From 9d25fee1dc62f9846eadb93069e8b18c101ac372 Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Tue, 6 Nov 2018 08:26:15 -0600 Subject: [PATCH 31/32] Make "Deploying custom AppRun" a regular message --- src/core.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core.cpp b/src/core.cpp index bec36b8..d834e6b 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -58,7 +58,7 @@ namespace linuxdeploy { ldLog() << std::endl << "-- Deploying files into AppDir root directory --" << std::endl; if (!customAppRunPath.empty()) { - ldLog() << LD_WARNING << "Deploying custom AppRun: " << customAppRunPath << std::endl; + ldLog() << LD_INFO << "Deploying custom AppRun: " << customAppRunPath << std::endl; appDir.deployFile(customAppRunPath, appDir.path() / "AppRun"); appDir.executeDeferredOperations(); } From 4e33e395de826852e3f042c18b53bbcb2116bd0b Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Tue, 6 Nov 2018 15:39:35 +0100 Subject: [PATCH 32/32] Show warning if existing AppRun is overwritten --- src/core.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/core.cpp b/src/core.cpp index d834e6b..9ea74d9 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -59,6 +59,13 @@ namespace linuxdeploy { if (!customAppRunPath.empty()) { ldLog() << LD_INFO << "Deploying custom AppRun: " << customAppRunPath << std::endl; + + const auto& appRunPathInAppDir = appDir.path() / "AppRun"; + if (bf::exists(appRunPathInAppDir)) { + ldLog() << LD_WARNING << "File exists, replacing with custom AppRun" << std::endl; + bf::remove(appRunPathInAppDir); + } + appDir.deployFile(customAppRunPath, appDir.path() / "AppRun"); appDir.executeDeferredOperations(); }