Merge pull request #200 from solemnwarning/exclude-library

Add --exclude-library option.
This commit is contained in:
TheAssassin 2022-05-03 19:09:03 +02:00 committed by GitHub
commit 097212aa1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 4 deletions

View File

@ -38,6 +38,9 @@ namespace linuxdeploy {
// shortcut for using a normal string instead of a path // shortcut for using a normal string instead of a path
explicit AppDir(const std::string& path); explicit AppDir(const std::string& path);
// Set additional shared library name patterns to be excluded from deployment.
void setExcludeLibraryPatterns(const std::vector<std::string> &excludeLibraryPatterns);
// creates basic directory structure of an AppDir in "FHS" mode // creates basic directory structure of an AppDir in "FHS" mode
bool createBasicStructure() const; bool createBasicStructure() const;

View File

@ -98,6 +98,7 @@ namespace linuxdeploy {
class AppDir::PrivateData { class AppDir::PrivateData {
public: public:
bf::path appDirPath; bf::path appDirPath;
std::vector<std::string> excludeLibraryPatterns;
// store deferred operations // store deferred operations
// these can be executed by calling excuteDeferredOperations // these can be executed by calling excuteDeferredOperations
@ -121,7 +122,7 @@ namespace linuxdeploy {
bool disableCopyrightFilesDeployment = false; bool disableCopyrightFilesDeployment = false;
public: public:
PrivateData() : copyOperationsStorage(), stripOperations(), setElfRPathOperations(), visitedFiles(), appDirPath() { PrivateData() : copyOperationsStorage(), stripOperations(), setElfRPathOperations(), visitedFiles(), appDirPath(), excludeLibraryPatterns() {
copyrightFilesManager = copyright::ICopyrightFilesManager::getInstance(); copyrightFilesManager = copyright::ICopyrightFilesManager::getInstance();
}; };
@ -392,8 +393,8 @@ namespace linuxdeploy {
return false; return false;
} }
static auto isInExcludelist = [](const bf::path& fileName) { static auto isInExcludelist = [](const bf::path& fileName, const std::vector<std::string> &excludeList) {
for (const auto& excludePattern : generatedExcludelist) { for (const auto& excludePattern : excludeList) {
// simple string match is faster than using fnmatch // simple string match is faster than using fnmatch
if (excludePattern == fileName) if (excludePattern == fileName)
return true; return true;
@ -413,7 +414,7 @@ namespace linuxdeploy {
return false; 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; ldLog() << "Skipping deployment of blacklisted library" << path << std::endl;
// mark file as visited // mark file as visited
@ -639,6 +640,10 @@ namespace linuxdeploy {
AppDir::AppDir(const std::string& path) : AppDir(bf::path(path)) {} AppDir::AppDir(const std::string& path) : AppDir(bf::path(path)) {}
void AppDir::setExcludeLibraryPatterns(const std::vector<std::string> &excludeLibraryPatterns) {
d->excludeLibraryPatterns = excludeLibraryPatterns;
}
bool AppDir::createBasicStructure() const { bool AppDir::createBasicStructure() const {
std::vector<std::string> dirPaths = { std::vector<std::string> dirPaths = {
"usr/bin/", "usr/bin/",

View File

@ -33,6 +33,7 @@ int main(int argc, char** argv) {
args::ValueFlag<std::string> appDirPath(parser, "appdir", "Path to target AppDir", {"appdir"}); args::ValueFlag<std::string> appDirPath(parser, "appdir", "Path to target AppDir", {"appdir"});
args::ValueFlagList<std::string> sharedLibraryPaths(parser, "library", "Shared library to deploy", {'l', "library"}); args::ValueFlagList<std::string> sharedLibraryPaths(parser, "library", "Shared library to deploy", {'l', "library"});
args::ValueFlagList<std::string> excludeLibraryPatterns(parser, "pattern", "Shared library to exclude from deployment (glob pattern)", {"exclude-library"});
args::ValueFlagList<std::string> executablePaths(parser, "executable", "Executable to deploy", {'e', "executable"}); args::ValueFlagList<std::string> executablePaths(parser, "executable", "Executable to deploy", {'e', "executable"});
@ -110,6 +111,7 @@ int main(int argc, char** argv) {
} }
appdir::AppDir appDir(appDirPath.Get()); appdir::AppDir appDir(appDirPath.Get());
appDir.setExcludeLibraryPatterns(excludeLibraryPatterns.Get());
// allow disabling copyright files deployment via environment variable // allow disabling copyright files deployment via environment variable
if (getenv("DISABLE_COPYRIGHT_FILES_DEPLOYMENT") != nullptr) { if (getenv("DISABLE_COPYRIGHT_FILES_DEPLOYMENT") != nullptr) {