From fa944fc371516f38796477069d9beccc418cea0d Mon Sep 17 00:00:00 2001 From: Korenevskiy Denis Date: Fri, 1 Nov 2024 11:52:34 +0300 Subject: [PATCH 1/9] feat: add '--install-libs-path' and '--ignore-existing' options --- src/Dependency.cpp | 12 +++++++++--- src/Dependency.h | 6 +++--- src/DylibBundler.cpp | 13 ++++++++----- src/Settings.cpp | 22 +++++++++++++++++----- src/Settings.h | 10 ++++++++-- src/Utils.cpp | 11 ++++++++++- src/Utils.h | 2 +- src/main.cpp | 34 ++++++++++++++++++++++++++-------- 8 files changed, 82 insertions(+), 28 deletions(-) diff --git a/src/Dependency.cpp b/src/Dependency.cpp index f67d06d..8ac4ebd 100644 --- a/src/Dependency.cpp +++ b/src/Dependency.cpp @@ -169,7 +169,7 @@ std::string Dependency::getInstallPath() } std::string Dependency::getInnerPath() { - return Settings::inside_lib_path() + new_name; + return Settings::inside_lib_load_path() + new_name; } @@ -194,10 +194,14 @@ bool Dependency::mergeIfSameAs(Dependency& dep2) return false; } -void Dependency::copyYourself() +bool Dependency::copyYourself() { - copyFile(getOriginalPath(), getInstallPath()); + const bool should_patch = copyFile(getOriginalPath(), getInstallPath()); + if (!should_patch) { + return false; + } + // Fix the lib's inner name std::string command = std::string("install_name_tool -id \"") + getInnerPath() + "\" \"" + getInstallPath() + "\""; if( systemp( command ) != 0 ) @@ -205,6 +209,8 @@ void Dependency::copyYourself() std::cerr << "\n\nError : An error occured while trying to change identity of library " << getInstallPath() << std::endl; exit(1); } + + return true; } void Dependency::fixFileThatDependsOnMe(const std::string& file_to_fix) diff --git a/src/Dependency.h b/src/Dependency.h index e883494..0aa69d2 100644 --- a/src/Dependency.h +++ b/src/Dependency.h @@ -54,13 +54,13 @@ class Dependency std::string getSymlink(const int i) const{ return symlinks[i]; } std::string getPrefix() const{ return prefix; } - void copyYourself(); + bool copyYourself(); void fixFileThatDependsOnMe(const std::string& file); - + // Compares the given dependency with this one. If both refer to the same file, // it returns true and merges both entries into one. bool mergeIfSameAs(Dependency& dep2); }; -#endif \ No newline at end of file +#endif diff --git a/src/DylibBundler.cpp b/src/DylibBundler.cpp index 5b8674e..4e812c1 100644 --- a/src/DylibBundler.cpp +++ b/src/DylibBundler.cpp @@ -193,7 +193,7 @@ std::string searchFilenameInRpaths(const std::string& rpath_dep) return searchFilenameInRpaths(rpath_dep, rpath_dep); } -void fixRpathsOnFile(const std::string& original_file, const std::string& file_to_fix) +void fixRpathsOnFile(const std::string& original_file, const std::string& file_to_fix, const std::string new_rpath) { std::vector rpaths_to_fix; std::map >::iterator found = rpaths_per_file.find(original_file); @@ -205,7 +205,7 @@ void fixRpathsOnFile(const std::string& original_file, const std::string& file_t for (size_t i=0; i < rpaths_to_fix.size(); ++i) { std::string command = std::string("install_name_tool -rpath \"") + - rpaths_to_fix[i] + "\" \"" + Settings::inside_lib_path() + "\" \"" + file_to_fix + "\""; + rpaths_to_fix[i] + "\" \"" + new_rpath + "\" \"" + file_to_fix + "\""; if ( systemp(command) != 0) { std::cerr << "\n\nError : An error occured while trying to fix dependencies of " << file_to_fix << std::endl; @@ -394,9 +394,12 @@ void doneWithDeps_go() for(int n=dep_amount-1; n>=0; n--) { std::cout << "\n* Processing dependency " << deps[n].getInstallPath() << std::endl; - deps[n].copyYourself(); + const bool should_patch = deps[n].copyYourself(); + if (!should_patch) { + continue; + } changeLibPathsOnFile(deps[n].getInstallPath()); - fixRpathsOnFile(deps[n].getOriginalPath(), deps[n].getInstallPath()); + fixRpathsOnFile(deps[n].getOriginalPath(), deps[n].getInstallPath(), Settings::inside_lib_load_path()); adhocCodeSign(deps[n].getInstallPath()); } } @@ -407,7 +410,7 @@ void doneWithDeps_go() std::cout << "\n* Processing " << Settings::fileToFix(n) << std::endl; copyFile(Settings::fileToFix(n), Settings::fileToFix(n)); // to set write permission changeLibPathsOnFile(Settings::fileToFix(n)); - fixRpathsOnFile(Settings::fileToFix(n), Settings::fileToFix(n)); + fixRpathsOnFile(Settings::fileToFix(n), Settings::fileToFix(n), Settings::inside_bin_load_path()); adhocCodeSign(Settings::fileToFix(n)); } } diff --git a/src/Settings.cpp b/src/Settings.cpp index 1d9674b..d16e016 100644 --- a/src/Settings.cpp +++ b/src/Settings.cpp @@ -29,15 +29,18 @@ namespace Settings { bool overwrite_files = false; +bool ignore_existing = true; bool overwrite_dir = false; bool create_dir = false; bool codesign = true; +bool canIgnoreExisting(){ return ignore_existing; } bool canOverwriteFiles(){ return overwrite_files; } bool canOverwriteDir(){ return overwrite_dir; } bool canCreateDir(){ return create_dir; } bool canCodesign(){ return codesign; } +void canIgnoreExisting(bool permission){ ignore_existing = permission; } void canOverwriteFiles(bool permission){ overwrite_files = permission; } void canOverwriteDir(bool permission){ overwrite_dir = permission; } void canCreateDir(bool permission){ create_dir = permission; } @@ -63,13 +66,22 @@ void addFileToFix(const std::string& path){ files.push_back(path); } int fileToFixAmount(){ return files.size(); } std::string fileToFix(const int n){ return files[n]; } -std::string inside_path_str = "@executable_path/../libs/"; -std::string inside_lib_path(){ return inside_path_str; } -void inside_lib_path(const std::string& p) +std::string inside_bin_load_path_str = "@executable_path/../libs/"; +std::string inside_bin_load_path(){ return inside_bin_load_path_str; } +void inside_bin_load_path(const std::string& p) { - inside_path_str = p; + inside_bin_load_path_str = p; // fix path if needed so it ends with '/' - if( inside_path_str[ inside_path_str.size()-1 ] != '/' ) inside_path_str += "/"; + if( inside_bin_load_path_str[ inside_bin_load_path_str.size()-1 ] != '/' ) inside_bin_load_path_str += "/"; +} + +std::string inside_lib_load_path_str = ""; +std::string inside_lib_load_path(){ return inside_lib_load_path_str; } +void inside_lib_load_path(const std::string& p) +{ + inside_lib_load_path_str = p; + // fix path if needed so it ends with '/' + if( inside_lib_load_path_str[ inside_lib_load_path_str.size()-1 ] != '/' ) inside_lib_load_path_str += "/"; } std::vector prefixes_to_ignore; diff --git a/src/Settings.h b/src/Settings.h index c03afc5..9a825fb 100644 --- a/src/Settings.h +++ b/src/Settings.h @@ -38,6 +38,9 @@ void ignore_prefix(std::string prefix); bool canOverwriteFiles(); void canOverwriteFiles(bool permission); +bool canIgnoreExisting(); +void canIgnoreExisting(bool permission); + bool canOverwriteDir(); void canOverwriteDir(bool permission); @@ -57,8 +60,11 @@ void addFileToFix(const std::string& path); int fileToFixAmount(); std::string fileToFix(const int n); -std::string inside_lib_path(); -void inside_lib_path(const std::string& p); +std::string inside_bin_load_path(); +void inside_bin_load_path(const std::string& p); + +std::string inside_lib_load_path(); +void inside_lib_load_path(const std::string& p); void addSearchPath(const std::string& path); int searchPathAmount(); diff --git a/src/Utils.cpp b/src/Utils.cpp index 168f659..86e85e9 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -93,13 +93,20 @@ bool fileExists(const std::string& filename) } } -void copyFile(const string& from, const string& to) +bool copyFile(const string& from, const string& to) { bool override = Settings::canOverwriteFiles(); + bool ignore = Settings::canIgnoreExisting(); if( from != to && !override ) { if(fileExists( to )) { + if (ignore) + { + cerr << "\n/!\\ WARNING : library " << to.c_str() << " already exists in dest dir and will not be patched." << endl; + return false; + } + cerr << "\n\nError : File " << to.c_str() << " already exists. Remove it or enable overwriting." << endl; exit(1); } @@ -122,6 +129,8 @@ void copyFile(const string& from, const string& to) cerr << "\n\nError : An error occured while trying to set write permissions on file " << to << endl; exit(1); } + + return true; } std::string system_get_output(const std::string& cmd) diff --git a/src/Utils.h b/src/Utils.h index 9026ae8..e723493 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -34,7 +34,7 @@ class Library; void tokenize(const std::string& str, const char* delimiters, std::vector*); bool fileExists(const std::string& filename); -void copyFile(const std::string& from, const std::string& to); +bool copyFile(const std::string& from, const std::string& to); // executes a command in the native shell and returns output in string std::string system_get_output(const std::string& cmd); diff --git a/src/main.cpp b/src/main.cpp index 173fc9d..0462692 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -54,17 +54,19 @@ void showHelp() std::cout << "dylibbundler " << VERSION << std::endl; std::cout << "dylibbundler is a utility that helps bundle dynamic libraries inside macOS app bundles.\n" << std::endl; - std::cout << "-x, --fix-file " << std::endl; - std::cout << "-b, --bundle-deps" << std::endl; - std::cout << "-d, --dest-dir " << std::endl; - std::cout << "-p, --install-path <'inner' path of bundled libraries (usually relative to executable, by default '@executable_path/../libs/')>" << std::endl; - std::cout << "-s, --search-path " << std::endl; + std::cout << " -x, --fix-file " << std::endl; + std::cout << " -b, --bundle-deps" << std::endl; + std::cout << " -d, --dest-dir " << std::endl; + std::cout << " -p, --install-path <'inner' path of bundled libraries when patching files from --fix-file (usually relative to executable, by default '@executable_path/../libs/')>" << std::endl; + std::cout << "-lp, --install-libs-path <'inner' path of bundled libraries to set when patching dependencies ('@loader_path/' can be an option, defaults to '--install-path' value)>" << std::endl; + std::cout << " -s, --search-path " << std::endl; std::cout << "-of, --overwrite-files (allow overwriting files in output directory)" << std::endl; + std::cout << "-ie, --ignore-existing (makes bundler to leave existing files in output directory intact)" << std::endl; std::cout << "-od, --overwrite-dir (totally overwrite output directory if it already exists. implies --create-dir)" << std::endl; std::cout << "-cd, --create-dir (creates output directory if necessary)" << std::endl; std::cout << "-ns, --no-codesign (disables ad-hoc codesigning)" << std::endl; - std::cout << "-i, --ignore (will ignore libraries in this directory)" << std::endl; - std::cout << "-h, --help" << std::endl; + std::cout << " -i, --ignore (will ignore libraries in this directory)" << std::endl; + std::cout << " -h, --help" << std::endl; } int main (int argc, char * const argv[]) @@ -87,7 +89,13 @@ int main (int argc, char * const argv[]) else if(strcmp(argv[i],"-p")==0 or strcmp(argv[i],"--install-path")==0) { i++; - Settings::inside_lib_path(argv[i]); + Settings::inside_bin_load_path(argv[i]); + continue; + } + else if(strcmp(argv[i],"-lp")==0 or strcmp(argv[i],"--install-libs-path")==0) + { + i++; + Settings::inside_lib_load_path(argv[i]); continue; } else if(strcmp(argv[i],"-i")==0 or strcmp(argv[i],"--ignore")==0) @@ -102,6 +110,11 @@ int main (int argc, char * const argv[]) Settings::destFolder(argv[i]); continue; } + else if(strcmp(argv[i],"-ie")==0 or strcmp(argv[i],"--ignore-existing")==0) + { + Settings::canIgnoreExisting(true); + continue; + } else if(strcmp(argv[i],"-of")==0 or strcmp(argv[i],"--overwrite-files")==0) { Settings::canOverwriteFiles(true); @@ -143,6 +156,11 @@ int main (int argc, char * const argv[]) exit(1); } } + + if (Settings::inside_lib_load_path() == "") { + // Default 'libs' load path to be equal to 'bin' load path for backward compatibility with older dylibbundler versions logic + Settings::inside_lib_load_path(Settings::inside_bin_load_path()); + } if(not Settings::bundleLibs() and Settings::fileToFixAmount()<1) { From f73aff9e67dc6dea5e4c8c06350c9b430df1adf3 Mon Sep 17 00:00:00 2001 From: Korenevskiy Denis Date: Fri, 1 Nov 2024 12:04:30 +0300 Subject: [PATCH 2/9] rename option to be more consistent with real logic --- src/Dependency.cpp | 2 +- src/DylibBundler.cpp | 2 +- src/Settings.cpp | 10 +++++----- src/Settings.h | 4 ++-- src/main.cpp | 13 ++++++------- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/Dependency.cpp b/src/Dependency.cpp index 8ac4ebd..6258de1 100644 --- a/src/Dependency.cpp +++ b/src/Dependency.cpp @@ -169,7 +169,7 @@ std::string Dependency::getInstallPath() } std::string Dependency::getInnerPath() { - return Settings::inside_lib_load_path() + new_name; + return Settings::inside_dep_load_path() + new_name; } diff --git a/src/DylibBundler.cpp b/src/DylibBundler.cpp index 4e812c1..9c20197 100644 --- a/src/DylibBundler.cpp +++ b/src/DylibBundler.cpp @@ -399,7 +399,7 @@ void doneWithDeps_go() continue; } changeLibPathsOnFile(deps[n].getInstallPath()); - fixRpathsOnFile(deps[n].getOriginalPath(), deps[n].getInstallPath(), Settings::inside_lib_load_path()); + fixRpathsOnFile(deps[n].getOriginalPath(), deps[n].getInstallPath(), Settings::inside_dep_load_path()); adhocCodeSign(deps[n].getInstallPath()); } } diff --git a/src/Settings.cpp b/src/Settings.cpp index d16e016..14abac2 100644 --- a/src/Settings.cpp +++ b/src/Settings.cpp @@ -75,13 +75,13 @@ void inside_bin_load_path(const std::string& p) if( inside_bin_load_path_str[ inside_bin_load_path_str.size()-1 ] != '/' ) inside_bin_load_path_str += "/"; } -std::string inside_lib_load_path_str = ""; -std::string inside_lib_load_path(){ return inside_lib_load_path_str; } -void inside_lib_load_path(const std::string& p) +std::string inside_dep_load_path_str = ""; +std::string inside_dep_load_path(){ return inside_dep_load_path_str; } +void inside_dep_load_path(const std::string& p) { - inside_lib_load_path_str = p; + inside_dep_load_path_str = p; // fix path if needed so it ends with '/' - if( inside_lib_load_path_str[ inside_lib_load_path_str.size()-1 ] != '/' ) inside_lib_load_path_str += "/"; + if( inside_dep_load_path_str[ inside_dep_load_path_str.size()-1 ] != '/' ) inside_dep_load_path_str += "/"; } std::vector prefixes_to_ignore; diff --git a/src/Settings.h b/src/Settings.h index 9a825fb..b5c1e06 100644 --- a/src/Settings.h +++ b/src/Settings.h @@ -63,8 +63,8 @@ std::string fileToFix(const int n); std::string inside_bin_load_path(); void inside_bin_load_path(const std::string& p); -std::string inside_lib_load_path(); -void inside_lib_load_path(const std::string& p); +std::string inside_dep_load_path(); +void inside_dep_load_path(const std::string& p); void addSearchPath(const std::string& path); int searchPathAmount(); diff --git a/src/main.cpp b/src/main.cpp index 0462692..959d80d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -58,7 +58,7 @@ void showHelp() std::cout << " -b, --bundle-deps" << std::endl; std::cout << " -d, --dest-dir " << std::endl; std::cout << " -p, --install-path <'inner' path of bundled libraries when patching files from --fix-file (usually relative to executable, by default '@executable_path/../libs/')>" << std::endl; - std::cout << "-lp, --install-libs-path <'inner' path of bundled libraries to set when patching dependencies ('@loader_path/' can be an option, defaults to '--install-path' value)>" << std::endl; + std::cout << "-dp, --install-deps-path <'inner' path of bundled libraries to set when patching dependencies ('@loader_path/' can be an option, defaults to '--install-path' value)>" << std::endl; std::cout << " -s, --search-path " << std::endl; std::cout << "-of, --overwrite-files (allow overwriting files in output directory)" << std::endl; std::cout << "-ie, --ignore-existing (makes bundler to leave existing files in output directory intact)" << std::endl; @@ -71,7 +71,6 @@ void showHelp() int main (int argc, char * const argv[]) { - // parse arguments for(int i=0; i Date: Fri, 1 Nov 2024 12:32:30 +0300 Subject: [PATCH 3/9] use 'bin' install paths in '--fix-file' target --- src/Dependency.cpp | 16 ++++++++-------- src/Dependency.h | 4 ++-- src/DylibBundler.cpp | 8 ++++---- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Dependency.cpp b/src/Dependency.cpp index 6258de1..23a8de7 100644 --- a/src/Dependency.cpp +++ b/src/Dependency.cpp @@ -167,9 +167,9 @@ std::string Dependency::getInstallPath() { return Settings::destFolder() + new_name; } -std::string Dependency::getInnerPath() +std::string Dependency::getInnerPath(const std::string& new_rpath) { - return Settings::inside_dep_load_path() + new_name; + return new_rpath + new_name; } @@ -203,7 +203,7 @@ bool Dependency::copyYourself() } // Fix the lib's inner name - std::string command = std::string("install_name_tool -id \"") + getInnerPath() + "\" \"" + getInstallPath() + "\""; + std::string command = std::string("install_name_tool -id \"") + getInnerPath(Settings::inside_dep_load_path()) + "\" \"" + getInstallPath() + "\""; if( systemp( command ) != 0 ) { std::cerr << "\n\nError : An error occured while trying to change identity of library " << getInstallPath() << std::endl; @@ -213,27 +213,27 @@ bool Dependency::copyYourself() return true; } -void Dependency::fixFileThatDependsOnMe(const std::string& file_to_fix) +void Dependency::fixFileThatDependsOnMe(const std::string& file_to_fix, const std::string& new_rpath) { // for main lib file - changeInstallName(file_to_fix, getOriginalPath(), getInnerPath()); + changeInstallName(file_to_fix, getOriginalPath(), getInnerPath(new_rpath)); // for symlinks const int symamount = symlinks.size(); for(int n=0; n deps_collected; std::map > rpaths_per_file; std::map rpath_to_fullpath; -void changeLibPathsOnFile(std::string file_to_fix) +void changeLibPathsOnFile(std::string file_to_fix, const std::string& new_rpath) { if (deps_collected.find(file_to_fix) == deps_collected.end()) { @@ -58,7 +58,7 @@ void changeLibPathsOnFile(std::string file_to_fix) const int dep_amount = deps_in_file.size(); for(int n=0; n Date: Thu, 7 Nov 2024 13:19:53 +0300 Subject: [PATCH 4/9] add 'ignore-missing' and 'skip-patching' options to collect what we can --- src/DylibBundler.cpp | 10 +++++++++- src/Settings.cpp | 7 +++++++ src/Settings.h | 6 ++++++ src/main.cpp | 12 ++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/DylibBundler.cpp b/src/DylibBundler.cpp index 3251a02..dd2316b 100644 --- a/src/DylibBundler.cpp +++ b/src/DylibBundler.cpp @@ -252,6 +252,10 @@ void collectDependencies(const std::string& filename, std::vector& if(output.find("can't open file")!=std::string::npos or output.find("No such file")!=std::string::npos or output.size()<1) { std::cerr << "Cannot find file " << filename << " to read its dependencies" << std::endl; + if (Settings::ignoreMissing()) { + return; + } + exit(1); } @@ -395,7 +399,7 @@ void doneWithDeps_go() { std::cout << "\n* Processing dependency " << deps[n].getInstallPath() << std::endl; const bool should_patch = deps[n].copyYourself(); - if (!should_patch) { + if (!should_patch || Settings::skipPatching()) { continue; } changeLibPathsOnFile(deps[n].getInstallPath(), Settings::inside_dep_load_path()); @@ -409,6 +413,10 @@ void doneWithDeps_go() { std::cout << "\n* Processing " << Settings::fileToFix(n) << std::endl; copyFile(Settings::fileToFix(n), Settings::fileToFix(n)); // to set write permission + + if (Settings::skipPatching()) { + continue; + } changeLibPathsOnFile(Settings::fileToFix(n), Settings::inside_bin_load_path()); fixRpathsOnFile(Settings::fileToFix(n), Settings::fileToFix(n), Settings::inside_bin_load_path()); adhocCodeSign(Settings::fileToFix(n)); diff --git a/src/Settings.cpp b/src/Settings.cpp index 14abac2..6098e71 100644 --- a/src/Settings.cpp +++ b/src/Settings.cpp @@ -51,6 +51,13 @@ bool bundleLibs_bool = false; bool bundleLibs(){ return bundleLibs_bool; } void bundleLibs(bool on){ bundleLibs_bool = on; } +bool skipPatching_bool = false; +bool skipPatching(){ return skipPatching_bool && bundleLibs_bool; } +void skipPatching(bool on){ skipPatching_bool = on; } + +bool ignoreMissing_bool = false; +bool ignoreMissing(){ return ignoreMissing_bool; } +void ignoreMissing(bool on){ ignoreMissing_bool = on; } std::string dest_folder_str = "./libs/"; std::string destFolder(){ return dest_folder_str; } diff --git a/src/Settings.h b/src/Settings.h index b5c1e06..e56c742 100644 --- a/src/Settings.h +++ b/src/Settings.h @@ -53,6 +53,12 @@ void canCodesign(bool permission); bool bundleLibs(); void bundleLibs(bool on); +bool skipPatching(); +void skipPatching(bool on); + +bool ignoreMissing(); +void ignoreMissing(bool on); + std::string destFolder(); void destFolder(const std::string& path); diff --git a/src/main.cpp b/src/main.cpp index 959d80d..6b8e8d4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -56,6 +56,8 @@ void showHelp() std::cout << " -x, --fix-file " << std::endl; std::cout << " -b, --bundle-deps" << std::endl; + std::cout << "-sp, --skip-patching (do not change load paths in binaries, just collect all dependencies. Has effect only when --bundle-deps is set)" << std::endl; + std::cout << "-im, --ignore-missing (just skip missing dependencies and collect what is possible)" << std::endl; std::cout << " -d, --dest-dir " << std::endl; std::cout << " -p, --install-path <'inner' path of bundled libraries when patching files from --fix-file (usually relative to executable, by default '@executable_path/../libs/')>" << std::endl; std::cout << "-dp, --install-deps-path <'inner' path of bundled libraries to set when patching dependencies ('@loader_path/' can be an option, defaults to '--install-path' value)>" << std::endl; @@ -85,6 +87,16 @@ int main (int argc, char * const argv[]) Settings::bundleLibs(true); continue; } + else if(strcmp(argv[i],"-sp")==0 or strcmp(argv[i],"--skip-patching")==0) + { + Settings::skipPatching(true); + continue; + } + else if(strcmp(argv[i],"-im")==0 or strcmp(argv[i],"--ignore-missing")==0) + { + Settings::ignoreMissing(true); + continue; + } else if(strcmp(argv[i],"-p")==0 or strcmp(argv[i],"--install-path")==0) { i++; From e6f58557b3e96eb9e0dc4192079a754ed64c0cf7 Mon Sep 17 00:00:00 2001 From: Korenevskiy Denis Date: Thu, 7 Nov 2024 13:29:25 +0300 Subject: [PATCH 5/9] --skip-missing instead of --ignore-missing (consistent naming) --- src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 6b8e8d4..ffe1983 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -53,11 +53,11 @@ void showHelp() { std::cout << "dylibbundler " << VERSION << std::endl; std::cout << "dylibbundler is a utility that helps bundle dynamic libraries inside macOS app bundles.\n" << std::endl; - + std::cout << " -x, --fix-file " << std::endl; std::cout << " -b, --bundle-deps" << std::endl; std::cout << "-sp, --skip-patching (do not change load paths in binaries, just collect all dependencies. Has effect only when --bundle-deps is set)" << std::endl; - std::cout << "-im, --ignore-missing (just skip missing dependencies and collect what is possible)" << std::endl; + std::cout << "-sm, --skip-missing (just skip missing dependencies and collect what is possible)" << std::endl; std::cout << " -d, --dest-dir " << std::endl; std::cout << " -p, --install-path <'inner' path of bundled libraries when patching files from --fix-file (usually relative to executable, by default '@executable_path/../libs/')>" << std::endl; std::cout << "-dp, --install-deps-path <'inner' path of bundled libraries to set when patching dependencies ('@loader_path/' can be an option, defaults to '--install-path' value)>" << std::endl; @@ -92,7 +92,7 @@ int main (int argc, char * const argv[]) Settings::skipPatching(true); continue; } - else if(strcmp(argv[i],"-im")==0 or strcmp(argv[i],"--ignore-missing")==0) + else if(strcmp(argv[i],"-sm")==0 or strcmp(argv[i],"--skip-missing")==0) { Settings::ignoreMissing(true); continue; From 82d9938470af33b8c069952e9bfb23dc03bded48 Mon Sep 17 00:00:00 2001 From: Korenevskiy Denis Date: Thu, 7 Nov 2024 18:35:43 +0300 Subject: [PATCH 6/9] do not update name of libraries when --skip-patching is set --- src/Dependency.cpp | 6 +++--- src/DylibBundler.cpp | 10 ++++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Dependency.cpp b/src/Dependency.cpp index 23a8de7..0f1743a 100644 --- a/src/Dependency.cpp +++ b/src/Dependency.cpp @@ -196,10 +196,10 @@ bool Dependency::mergeIfSameAs(Dependency& dep2) bool Dependency::copyYourself() { - const bool should_patch = copyFile(getOriginalPath(), getInstallPath()); + const bool was_copied = copyFile(getOriginalPath(), getInstallPath()); - if (!should_patch) { - return false; + if (!was_copied || Settings::skipPatching()) { + return was_copied; } // Fix the lib's inner name diff --git a/src/DylibBundler.cpp b/src/DylibBundler.cpp index dd2316b..edfe77e 100644 --- a/src/DylibBundler.cpp +++ b/src/DylibBundler.cpp @@ -398,10 +398,15 @@ void doneWithDeps_go() for(int n=dep_amount-1; n>=0; n--) { std::cout << "\n* Processing dependency " << deps[n].getInstallPath() << std::endl; - const bool should_patch = deps[n].copyYourself(); - if (!should_patch || Settings::skipPatching()) { + const bool was_copied = deps[n].copyYourself(); + if (!was_copied) { continue; } + + if (Settings::skipPatching()) { + continue; + } + changeLibPathsOnFile(deps[n].getInstallPath(), Settings::inside_dep_load_path()); fixRpathsOnFile(deps[n].getOriginalPath(), deps[n].getInstallPath(), Settings::inside_dep_load_path()); adhocCodeSign(deps[n].getInstallPath()); @@ -417,6 +422,7 @@ void doneWithDeps_go() if (Settings::skipPatching()) { continue; } + changeLibPathsOnFile(Settings::fileToFix(n), Settings::inside_bin_load_path()); fixRpathsOnFile(Settings::fileToFix(n), Settings::fileToFix(n), Settings::inside_bin_load_path()); adhocCodeSign(Settings::fileToFix(n)); From e1edbe17546700c05bc9c71b92de6c5199a72b99 Mon Sep 17 00:00:00 2001 From: Korenevskiy Denis Date: Thu, 7 Nov 2024 20:40:06 +0300 Subject: [PATCH 7/9] rename ignoreMissing -> skipMissing in internal code --- src/Dependency.cpp | 2 +- src/DylibBundler.cpp | 2 +- src/Settings.cpp | 6 +++--- src/Settings.h | 4 ++-- src/main.cpp | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Dependency.cpp b/src/Dependency.cpp index 0f1743a..2682e95 100644 --- a/src/Dependency.cpp +++ b/src/Dependency.cpp @@ -141,7 +141,7 @@ Dependency::Dependency(std::string path, const std::string& dependent_file) } //If the location is still unknown, ask the user for search path - if( !Settings::isPrefixIgnored(prefix) + if( !Settings::isPrefixIgnored(prefix) && !Settings::skipMissing() && ( prefix.empty() || !fileExists( prefix+filename ) ) ) { std::cerr << "\n/!\\ WARNING : Library " << filename << " has an incomplete name (location unknown)" << std::endl; diff --git a/src/DylibBundler.cpp b/src/DylibBundler.cpp index edfe77e..606c7b5 100644 --- a/src/DylibBundler.cpp +++ b/src/DylibBundler.cpp @@ -252,7 +252,7 @@ void collectDependencies(const std::string& filename, std::vector& if(output.find("can't open file")!=std::string::npos or output.find("No such file")!=std::string::npos or output.size()<1) { std::cerr << "Cannot find file " << filename << " to read its dependencies" << std::endl; - if (Settings::ignoreMissing()) { + if (Settings::skipMissing()) { return; } diff --git a/src/Settings.cpp b/src/Settings.cpp index 6098e71..6c297b4 100644 --- a/src/Settings.cpp +++ b/src/Settings.cpp @@ -55,9 +55,9 @@ bool skipPatching_bool = false; bool skipPatching(){ return skipPatching_bool && bundleLibs_bool; } void skipPatching(bool on){ skipPatching_bool = on; } -bool ignoreMissing_bool = false; -bool ignoreMissing(){ return ignoreMissing_bool; } -void ignoreMissing(bool on){ ignoreMissing_bool = on; } +bool skipMissing_bool = false; +bool skipMissing(){ return skipMissing_bool; } +void skipMissing(bool on){ skipMissing_bool = on; } std::string dest_folder_str = "./libs/"; std::string destFolder(){ return dest_folder_str; } diff --git a/src/Settings.h b/src/Settings.h index e56c742..7e2b377 100644 --- a/src/Settings.h +++ b/src/Settings.h @@ -56,8 +56,8 @@ void bundleLibs(bool on); bool skipPatching(); void skipPatching(bool on); -bool ignoreMissing(); -void ignoreMissing(bool on); +bool skipMissing(); +void skipMissing(bool on); std::string destFolder(); void destFolder(const std::string& path); diff --git a/src/main.cpp b/src/main.cpp index ffe1983..cc1b0ee 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -94,7 +94,7 @@ int main (int argc, char * const argv[]) } else if(strcmp(argv[i],"-sm")==0 or strcmp(argv[i],"--skip-missing")==0) { - Settings::ignoreMissing(true); + Settings::skipMissing(true); continue; } else if(strcmp(argv[i],"-p")==0 or strcmp(argv[i],"--install-path")==0) From 693822d4df57d05604283a5217c016eea0f26c12 Mon Sep 17 00:00:00 2001 From: Korenevskiy Denis Date: Mon, 11 Nov 2024 16:09:12 +0300 Subject: [PATCH 8/9] rename --ignore-existing to --skip-existing for consistency --- src/Settings.cpp | 6 +++--- src/Settings.h | 4 ++-- src/Utils.cpp | 2 +- src/main.cpp | 12 ++++++------ 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Settings.cpp b/src/Settings.cpp index 6c297b4..b2bd6c3 100644 --- a/src/Settings.cpp +++ b/src/Settings.cpp @@ -29,18 +29,18 @@ namespace Settings { bool overwrite_files = false; -bool ignore_existing = true; +bool skip_existing = true; bool overwrite_dir = false; bool create_dir = false; bool codesign = true; -bool canIgnoreExisting(){ return ignore_existing; } +bool skipExisting(){ return skip_existing; } bool canOverwriteFiles(){ return overwrite_files; } bool canOverwriteDir(){ return overwrite_dir; } bool canCreateDir(){ return create_dir; } bool canCodesign(){ return codesign; } -void canIgnoreExisting(bool permission){ ignore_existing = permission; } +void skipExisting(bool permission){ skip_existing = permission; } void canOverwriteFiles(bool permission){ overwrite_files = permission; } void canOverwriteDir(bool permission){ overwrite_dir = permission; } void canCreateDir(bool permission){ create_dir = permission; } diff --git a/src/Settings.h b/src/Settings.h index 7e2b377..de33884 100644 --- a/src/Settings.h +++ b/src/Settings.h @@ -38,8 +38,8 @@ void ignore_prefix(std::string prefix); bool canOverwriteFiles(); void canOverwriteFiles(bool permission); -bool canIgnoreExisting(); -void canIgnoreExisting(bool permission); +bool skipExisting(); +void skipExisting(bool permission); bool canOverwriteDir(); void canOverwriteDir(bool permission); diff --git a/src/Utils.cpp b/src/Utils.cpp index 86e85e9..36200db 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -96,7 +96,7 @@ bool fileExists(const std::string& filename) bool copyFile(const string& from, const string& to) { bool override = Settings::canOverwriteFiles(); - bool ignore = Settings::canIgnoreExisting(); + bool ignore = Settings::skipExisting(); if( from != to && !override ) { if(fileExists( to )) diff --git a/src/main.cpp b/src/main.cpp index cc1b0ee..f86050d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -58,12 +58,12 @@ void showHelp() std::cout << " -b, --bundle-deps" << std::endl; std::cout << "-sp, --skip-patching (do not change load paths in binaries, just collect all dependencies. Has effect only when --bundle-deps is set)" << std::endl; std::cout << "-sm, --skip-missing (just skip missing dependencies and collect what is possible)" << std::endl; + std::cout << "-se, --skip-existing (makes bundler to leave existing files in output directory intact)" << std::endl; std::cout << " -d, --dest-dir " << std::endl; std::cout << " -p, --install-path <'inner' path of bundled libraries when patching files from --fix-file (usually relative to executable, by default '@executable_path/../libs/')>" << std::endl; std::cout << "-dp, --install-deps-path <'inner' path of bundled libraries to set when patching dependencies ('@loader_path/' can be an option, defaults to '--install-path' value)>" << std::endl; std::cout << " -s, --search-path " << std::endl; std::cout << "-of, --overwrite-files (allow overwriting files in output directory)" << std::endl; - std::cout << "-ie, --ignore-existing (makes bundler to leave existing files in output directory intact)" << std::endl; std::cout << "-od, --overwrite-dir (totally overwrite output directory if it already exists. implies --create-dir)" << std::endl; std::cout << "-cd, --create-dir (creates output directory if necessary)" << std::endl; std::cout << "-ns, --no-codesign (disables ad-hoc codesigning)" << std::endl; @@ -97,6 +97,11 @@ int main (int argc, char * const argv[]) Settings::skipMissing(true); continue; } + else if(strcmp(argv[i],"-se")==0 or strcmp(argv[i],"--skip-existing")==0) + { + Settings::skipExisting(true); + continue; + } else if(strcmp(argv[i],"-p")==0 or strcmp(argv[i],"--install-path")==0) { i++; @@ -121,11 +126,6 @@ int main (int argc, char * const argv[]) Settings::destFolder(argv[i]); continue; } - else if(strcmp(argv[i],"-ie")==0 or strcmp(argv[i],"--ignore-existing")==0) - { - Settings::canIgnoreExisting(true); - continue; - } else if(strcmp(argv[i],"-of")==0 or strcmp(argv[i],"--overwrite-files")==0) { Settings::canOverwriteFiles(true); From 27f196a8d76c2a400ff5294ae4b3ae7768b60419 Mon Sep 17 00:00:00 2001 From: Korenevskiy Denis Date: Tue, 12 Nov 2024 18:29:55 +0300 Subject: [PATCH 9/9] do not skip existing files by default, only when flag is set --- src/Settings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Settings.cpp b/src/Settings.cpp index b2bd6c3..5e8c053 100644 --- a/src/Settings.cpp +++ b/src/Settings.cpp @@ -29,7 +29,7 @@ namespace Settings { bool overwrite_files = false; -bool skip_existing = true; +bool skip_existing = false; bool overwrite_dir = false; bool create_dir = false; bool codesign = true;