Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Don't fail if missing dependency is in excludeLibraryPatterns #226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/linuxdeploy/core/elf_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::filesystem::path> traceDynamicDependencies();
std::vector<std::filesystem::path> traceDynamicDependencies(const std::vector<std::string>& excludeLibraryPatterns={});

// fetch rpath stored in binary
// it appears that according to the ELF standard, the rpath is ignored in libraries, therefore if the path
Expand Down
22 changes: 22 additions & 0 deletions include/linuxdeploy/util/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <climits>
#include <cstring>
#include <filesystem>
#include <fnmatch.h>
#include <sstream>
#include <string>
#include <unistd.h>
Expand Down Expand Up @@ -136,6 +137,27 @@ namespace linuxdeploy {

return {};
};

static bool isInExcludelist(const std::filesystem::path& fileName, const std::vector<std::string> &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;
};

}
}
}
26 changes: 2 additions & 24 deletions src/core/appdir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

// library headers
#include <CImg.h>
#include <fnmatch.h>


// local headers
Expand Down Expand Up @@ -358,7 +357,7 @@ namespace linuxdeploy {
bool deployElfDependencies(const fs::path& path) {
ldLog() << "Deploying dependencies for ELF file" << path << std::endl;
try {
for (const auto &dependencyPath : elf_file::ElfFile(path).traceDynamicDependencies())
for (const auto &dependencyPath : elf_file::ElfFile(path).traceDynamicDependencies(excludeLibraryPatterns))
if (!deployLibrary(dependencyPath, false, false))
return false;
} catch (const elf_file::DependencyNotFoundError& e) {
Expand Down Expand Up @@ -402,28 +401,7 @@ namespace linuxdeploy {
return false;
}

static auto isInExcludelist = [](const fs::path& fileName, const std::vector<std::string> &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
Expand Down
7 changes: 5 additions & 2 deletions src/core/elf_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ namespace linuxdeploy {
delete d;
}

std::vector<fs::path> ElfFile::traceDynamicDependencies() {
std::vector<fs::path> ElfFile::traceDynamicDependencies(const std::vector<std::string>& excludeLibraryPatterns) {
// this method's purpose is to abstract this process
// the caller doesn't care _how_ it's done, after all

Expand Down Expand Up @@ -244,7 +244,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;
}
Expand Down