From d9070ddc73b61916fb956f8e7a7230c7db5a489f Mon Sep 17 00:00:00 2001 From: Joel 'Aaron' Cohen Date: Tue, 25 Oct 2022 02:17:39 -0400 Subject: [PATCH] Don't fail if missing dependency is in excludeLibraryPatterns --- include/linuxdeploy/core/elf_file.h | 2 +- include/linuxdeploy/util/misc.h | 21 +++++++++++++++++++++ src/core/appdir.cpp | 26 ++------------------------ src/core/elf_file.cpp | 7 +++++-- 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/include/linuxdeploy/core/elf_file.h b/include/linuxdeploy/core/elf_file.h index 9ffebc4d..3ced6a23 100644 --- a/include/linuxdeploy/core/elf_file.h +++ b/include/linuxdeploy/core/elf_file.h @@ -46,7 +46,7 @@ namespace linuxdeploy { // this works for both libraries and executables // the resulting vector consists of absolute paths to the libraries determined by the same methods a system's // linker would use - std::vector traceDynamicDependencies(); + std::vector traceDynamicDependencies(const std::vector& excludeLibraryPatterns={}); // fetch rpath stored in binary // it appears that according to the ELF standard, the rpath is ignored in libraries, therefore if the path diff --git a/include/linuxdeploy/util/misc.h b/include/linuxdeploy/util/misc.h index 7ac7d948..eceac1f8 100644 --- a/include/linuxdeploy/util/misc.h +++ b/include/linuxdeploy/util/misc.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -146,6 +147,26 @@ namespace linuxdeploy { } return result; } + + static bool isInExcludelist(const std::filesystem::path& fileName, const std::vector &excludeList) { + for (const auto& excludePattern : excludeList) { + // simple string match is faster than using fnmatch + if (excludePattern == fileName) + return true; + + auto fnmatchResult = fnmatch(excludePattern.c_str(), fileName.string().c_str(), FNM_PATHNAME); + switch (fnmatchResult) { + case 0: + return true; + case FNM_NOMATCH: + break; + default: + return false; + } + } + + return false; + } } } } diff --git a/src/core/appdir.cpp b/src/core/appdir.cpp index 6f918e51..8f31102d 100644 --- a/src/core/appdir.cpp +++ b/src/core/appdir.cpp @@ -8,7 +8,6 @@ // library headers #include -#include // local headers @@ -366,7 +365,7 @@ namespace linuxdeploy { ldLog() << "Deploying dependencies for ELF file" << path << std::endl; try { - for (const auto &dependencyPath : elfFile.traceDynamicDependencies()) + for (const auto &dependencyPath : elfFile.traceDynamicDependencies(excludeLibraryPatterns)) if (!deployLibrary(dependencyPath, false, false)) return false; } catch (const elf_file::DependencyNotFoundError& e) { @@ -410,28 +409,7 @@ namespace linuxdeploy { return false; } - static auto isInExcludelist = [](const fs::path& fileName, const std::vector &excludeList) { - for (const auto& excludePattern : excludeList) { - // simple string match is faster than using fnmatch - if (excludePattern == fileName) - return true; - - auto fnmatchResult = fnmatch(excludePattern.c_str(), fileName.string().c_str(), FNM_PATHNAME); - switch (fnmatchResult) { - case 0: - return true; - case FNM_NOMATCH: - break; - default: - ldLog() << LD_ERROR << "fnmatch() reported error:" << fnmatchResult << std::endl; - return false; - } - } - - return false; - }; - - if (!forceDeploy && (isInExcludelist(path.filename(), generatedExcludelist) || isInExcludelist(path.filename(), excludeLibraryPatterns))) { + if (!forceDeploy && (util::isInExcludelist(path.filename(), generatedExcludelist) || util::isInExcludelist(path.filename(), excludeLibraryPatterns))) { ldLog() << "Skipping deployment of blacklisted library" << path << std::endl; // mark file as visited diff --git a/src/core/elf_file.cpp b/src/core/elf_file.cpp index f199b217..c8772ac3 100644 --- a/src/core/elf_file.cpp +++ b/src/core/elf_file.cpp @@ -183,7 +183,7 @@ namespace linuxdeploy { delete d; } - std::vector ElfFile::traceDynamicDependencies() { + std::vector ElfFile::traceDynamicDependencies(const std::vector& excludeLibraryPatterns) { // this method's purpose is to abstract this process // the caller doesn't care _how_ it's done, after all @@ -247,7 +247,10 @@ namespace linuxdeploy { missingLib.erase(missingLib.find(pattern), pattern.size()); util::trim(missingLib); util::trim(missingLib, '\t'); - throw DependencyNotFoundError("Could not find dependency: " + missingLib); + if (!util::isInExcludelist(missingLib, excludeLibraryPatterns)) { + throw DependencyNotFoundError("Could not find dependency: " + missingLib); + } + ldLog() << LD_WARNING << resolvedPath.string() << "depends on excluded library:" << missingLib << std::endl; } else { ldLog() << LD_DEBUG << "Invalid ldd output: " << line << std::endl; }