From 37b640fa8619ef28acdf4be43b6f8f9347d08929 Mon Sep 17 00:00:00 2001 From: Daniel Collins Date: Sun, 1 May 2022 14:37:35 +0100 Subject: [PATCH] Add --exclude-library option. --- include/linuxdeploy/core/appdir.h | 3 +++ src/core/appdir.cpp | 13 +++++++++---- src/main.cpp | 2 ++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/include/linuxdeploy/core/appdir.h b/include/linuxdeploy/core/appdir.h index d67ff957..facb70b5 100644 --- a/include/linuxdeploy/core/appdir.h +++ b/include/linuxdeploy/core/appdir.h @@ -38,6 +38,9 @@ namespace linuxdeploy { // shortcut for using a normal string instead of a path explicit AppDir(const std::string& path); + // Set additional shared library name patterns to be excluded from deployment. + void setExcludeLibraryPatterns(const std::vector &excludeLibraryPatterns); + // creates basic directory structure of an AppDir in "FHS" mode bool createBasicStructure() const; diff --git a/src/core/appdir.cpp b/src/core/appdir.cpp index f7971f79..0974371c 100644 --- a/src/core/appdir.cpp +++ b/src/core/appdir.cpp @@ -98,6 +98,7 @@ namespace linuxdeploy { class AppDir::PrivateData { public: bf::path appDirPath; + std::vector excludeLibraryPatterns; // store deferred operations // these can be executed by calling excuteDeferredOperations @@ -121,7 +122,7 @@ namespace linuxdeploy { bool disableCopyrightFilesDeployment = false; public: - PrivateData() : copyOperationsStorage(), stripOperations(), setElfRPathOperations(), visitedFiles(), appDirPath() { + PrivateData() : copyOperationsStorage(), stripOperations(), setElfRPathOperations(), visitedFiles(), appDirPath(), excludeLibraryPatterns() { copyrightFilesManager = copyright::ICopyrightFilesManager::getInstance(); }; @@ -392,8 +393,8 @@ namespace linuxdeploy { return false; } - static auto isInExcludelist = [](const bf::path& fileName) { - for (const auto& excludePattern : generatedExcludelist) { + static auto isInExcludelist = [](const bf::path& fileName, const std::vector &excludeList) { + for (const auto& excludePattern : excludeList) { // simple string match is faster than using fnmatch if (excludePattern == fileName) return true; @@ -413,7 +414,7 @@ namespace linuxdeploy { return false; }; - if (!forceDeploy && isInExcludelist(path.filename())) { + if (!forceDeploy && (isInExcludelist(path.filename(), generatedExcludelist) || isInExcludelist(path.filename(), excludeLibraryPatterns))) { ldLog() << "Skipping deployment of blacklisted library" << path << std::endl; // mark file as visited @@ -639,6 +640,10 @@ namespace linuxdeploy { AppDir::AppDir(const std::string& path) : AppDir(bf::path(path)) {} + void AppDir::setExcludeLibraryPatterns(const std::vector &excludeLibraryPatterns) { + d->excludeLibraryPatterns = excludeLibraryPatterns; + } + bool AppDir::createBasicStructure() const { std::vector dirPaths = { "usr/bin/", diff --git a/src/main.cpp b/src/main.cpp index f249ff3b..84aca696 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,6 +33,7 @@ int main(int argc, char** argv) { args::ValueFlag appDirPath(parser, "appdir", "Path to target AppDir", {"appdir"}); args::ValueFlagList sharedLibraryPaths(parser, "library", "Shared library to deploy", {'l', "library"}); + args::ValueFlagList excludeLibraryPatterns(parser, "pattern", "Shared library to exclude from deployment (glob pattern)", {"exclude-library"}); args::ValueFlagList executablePaths(parser, "executable", "Executable to deploy", {'e', "executable"}); @@ -110,6 +111,7 @@ int main(int argc, char** argv) { } appdir::AppDir appDir(appDirPath.Get()); + appDir.setExcludeLibraryPatterns(excludeLibraryPatterns.Get()); // allow disabling copyright files deployment via environment variable if (getenv("DISABLE_COPYRIGHT_FILES_DEPLOYMENT") != nullptr) {