mirror of
https://github.com/audacity/linuxdeploy.git
synced 2026-04-17 08:32:53 -05:00
Add namespace and prepare unittest
This commit is contained in:
@@ -13,68 +13,69 @@ using namespace linuxdeploy::core::log;
|
||||
using namespace linuxdeploy::util;
|
||||
namespace bf = boost::filesystem;
|
||||
|
||||
namespace linuxdeploy {
|
||||
int deployAppDirRootFiles(args::ValueFlagList<std::string>& desktopFilePaths,
|
||||
args::ValueFlag<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;
|
||||
|
||||
int deployAppDirRootFiles(args::ValueFlagList<std::string>& desktopFilePaths,
|
||||
args::ValueFlag<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)
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
#include <linuxdeploy/core/log.h>
|
||||
#include <linuxdeploy/util/util.h>
|
||||
#include <args.hxx>
|
||||
|
||||
int deployAppDirRootFiles(args::ValueFlagList<std::string>& desktopFilePaths,
|
||||
args::ValueFlag<std::string>& customAppRunPath,
|
||||
linuxdeploy::core::appdir::AppDir& appDir);
|
||||
namespace linuxdeploy {
|
||||
int deployAppDirRootFiles(args::ValueFlagList<std::string>& desktopFilePaths,
|
||||
args::ValueFlag<std::string>& customAppRunPath,
|
||||
linuxdeploy::core::appdir::AppDir& appDir);
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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="$<TARGET_FILE:simple_library>"
|
||||
-DSIMPLE_EXECUTABLE_PATH="$<TARGET_FILE:simple_executable>"
|
||||
-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)
|
||||
|
||||
74
tests/core/test_linuxdeploy.cpp
Normal file
74
tests/core/test_linuxdeploy.cpp
Normal file
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user