diff --git a/src/Dependency.cpp b/src/Dependency.cpp index c51e4fe..c5c23aa 100644 --- a/src/Dependency.cpp +++ b/src/Dependency.cpp @@ -21,43 +21,6 @@ #include "Settings.h" #include "Utils.h" -// the paths to search for dylibs, store it globally to parse the environment variables only once -std::vector paths; - -// initialize the dylib search paths -void initSearchPaths() -{ - // check the same paths the system would search for dylibs - std::string searchPaths; - char *dyldLibPath = std::getenv("DYLD_LIBRARY_PATH"); - if (dyldLibPath != 0) - searchPaths = dyldLibPath; - dyldLibPath = std::getenv("DYLD_FALLBACK_FRAMEWORK_PATH"); - if (dyldLibPath != 0) { - if (!searchPaths.empty() && searchPaths[searchPaths.size()-1] != ':') - searchPaths += ":"; - searchPaths += dyldLibPath; - } - dyldLibPath = std::getenv("DYLD_FALLBACK_LIBRARY_PATH"); - if (dyldLibPath != 0) { - if (!searchPaths.empty() && searchPaths[searchPaths.size()-1] != ':') - searchPaths += ":"; - searchPaths += dyldLibPath; - } - if (!searchPaths.empty()) { - std::stringstream ss(searchPaths); - std::string item; - while (std::getline(ss, item, ':')) { - if (item[item.size()-1] != '/') - item += "/"; - paths.push_back(item); - } - } -} - -// if some libs are missing prefixes, then more stuff will be necessary to do -bool missing_prefixes = false; - Dependency::Dependency(std::string path, std::string dependent_file) : is_framework(false) { char original_file_buffer[PATH_MAX]; @@ -93,6 +56,9 @@ Dependency::Dependency(std::string path, std::string dependent_file) : is_framew prefix = filePrefix(original_file); filename = stripPrefix(original_file); + if (!prefix.empty() && prefix[prefix.size()-1] != '/') + prefix += "/"; + // check if this dependency is in /usr/lib, /System/Library, or in ignored list if (!Settings::isPrefixBundled(prefix)) return; @@ -102,8 +68,8 @@ Dependency::Dependency(std::string path, std::string dependent_file) : is_framew std::string framework_root = getFrameworkRoot(original_file); std::string framework_path = getFrameworkPath(original_file); std::string framework_name = stripPrefix(framework_root); - filename = framework_name + "/" + framework_path; prefix = filePrefix(framework_root); + filename = framework_name + "/" + framework_path; if (Settings::verboseOutput()) { std::cout << "framework root: " << framework_root << std::endl; std::cout << "framework path: " << framework_path << std::endl; @@ -112,20 +78,20 @@ Dependency::Dependency(std::string path, std::string dependent_file) : is_framew } // check if the lib is in a known location - if (!prefix.empty() && prefix[prefix.size()-1] != '/') - prefix += "/"; - if (prefix.empty() || !fileExists(prefix+filename)) { // the paths contains at least /usr/lib so if it is empty we have not initialized it - if (paths.empty()) + size_t search_path_count = Settings::searchPathCount(); + if (search_path_count == 0) initSearchPaths(); // check if file is contained in one of the paths - for (size_t i=0; i& lines) +void collectDependencies(const std::string& dependent_file, std::vector& lines) { std::string cmd = "otool -l " + dependent_file; std::string output = systemOutput(cmd); @@ -268,19 +268,17 @@ void collectDependencies(std::string dependent_file, std::vector& l } } -void collectDependencies(std::string dependent_file) +void collectDependencies(const std::string& dependent_file) { std::vector lines; collectDependencies(dependent_file, lines); for (size_t i=0; i lines; collectDependencies(original_path, lines); for (size_t i=0; i& lines); +void collectDependencies(const std::string& dependent_file); void collectSubDependencies(); void doneWithDeps_go(); diff --git a/src/Settings.cpp b/src/Settings.cpp index 5837327..2769a39 100644 --- a/src/Settings.cpp +++ b/src/Settings.cpp @@ -11,18 +11,22 @@ bool verbose_output = false; bool bundle_libs = true; bool bundle_frameworks = false; -std::string dest_folder_str = "Frameworks"; -std::string inside_path_str = "@executable_path/../Frameworks/"; +std::string dest_folder_str = "./libs/"; +std::string dest_folder_str_app = "./Frameworks/"; +std::string dest_folder = dest_folder_str; +std::string dest_path = dest_folder; + +std::string inside_path_str = "@executable_path/../libs/"; +std::string inside_path_str_app = "@executable_path/../Frameworks/"; +std::string inside_path = inside_path_str; std::string app_bundle; -std::string dest_folder; - +bool appBundleProvided() { return !app_bundle.empty(); } std::string appBundle() { return app_bundle; } void appBundle(std::string path) { app_bundle = path; - // fix path if needed so it ends with '/' if (app_bundle[app_bundle.size()-1] != '/') - app_bundle += "/"; + app_bundle += "/"; // fix path if needed so it ends with '/' std::string cmd = "/usr/libexec/PlistBuddy -c 'Print :CFBundleExecutable' "; cmd += app_bundle + "Contents/Info.plist"; @@ -30,60 +34,63 @@ void appBundle(std::string path) { addFileToFix(app_bundle + "Contents/MacOS/" + bundle_executable); - // fix path if needed so it ends with '/' - if (dest_folder_str[dest_folder_str.size()-1] != '/') - dest_folder_str += "/"; - dest_folder = app_bundle + "Contents/" + dest_folder_str; + if (inside_path == inside_path_str) + inside_path = inside_path_str_app; + if (dest_folder == dest_folder_str) + dest_folder = dest_folder_str_app; + + dest_path = app_bundle + "Contents/" + dest_folder; + char buffer[PATH_MAX]; + if (realpath(dest_path.c_str(), buffer)) + dest_path = buffer; + if (dest_path[dest_path.size()-1] != '/') + dest_path += "/"; } -std::string destFolder() { return dest_folder; } +std::string destFolder() { return dest_path; } void destFolder(std::string path) { - dest_folder_str = path; - // fix path if needed so it ends with '/' - if (dest_folder_str[dest_folder_str.size()-1] != '/') - dest_folder_str += "/"; - dest_folder = dest_folder_str; - if (!app_bundle.empty()) - dest_folder = app_bundle + "Contents/" + dest_folder_str; + if (path[path.size()-1] != '/') + path += "/"; + dest_folder = path; + if (appBundleProvided()) { + char buffer[PATH_MAX]; + std::string dest_path = app_bundle + "Contents/" + path; + if (realpath(dest_path.c_str(), buffer)) + dest_path = buffer; + if (dest_path[dest_path.size()-1] != '/') + dest_path += "/"; + dest_folder = dest_path; + } } std::string executableFolder() { return app_bundle + "Contents/MacOS/"; } - std::string frameworksFolder() { return app_bundle + "Contents/Frameworks/"; } - std::string pluginsFolder() { return app_bundle + "Contents/PlugIns/"; } - std::string resourcesFolder() { return app_bundle + "Contents/Resources/"; } std::vector files; - void addFileToFix(std::string path) { files.push_back(path); } - std::string fileToFix(const int n) { return files[n]; } - std::vector filesToFix() { return files; } - size_t filesToFixCount() { return files.size(); } -std::string insideLibPath() { return inside_path_str; } +std::string insideLibPath() { return inside_path; } void insideLibPath(std::string p) { - inside_path_str = p; + inside_path = p; // fix path if needed so it ends with '/' - if (inside_path_str[inside_path_str.size()-1] != '/') - inside_path_str += "/"; + if (inside_path[inside_path.size()-1] != '/') + inside_path += "/"; } std::vector prefixes_to_ignore; - void ignorePrefix(std::string prefix) { if (prefix[prefix.size()-1] != '/') prefix += "/"; prefixes_to_ignore.push_back(prefix); } - bool isPrefixIgnored(std::string prefix) { for (size_t n=0; n #include #include +#include #include #include @@ -290,3 +291,33 @@ std::string getUserInputDirForFile(const std::string& filename) } } } + +void initSearchPaths() +{ + // check the same paths the system would search for dylibs + std::string searchPaths; + char *dyldLibPath = std::getenv("DYLD_LIBRARY_PATH"); + if (dyldLibPath != 0) + searchPaths = dyldLibPath; + dyldLibPath = std::getenv("DYLD_FALLBACK_FRAMEWORK_PATH"); + if (dyldLibPath != 0) { + if (!searchPaths.empty() && searchPaths[searchPaths.size()-1] != ':') + searchPaths += ":"; + searchPaths += dyldLibPath; + } + dyldLibPath = std::getenv("DYLD_FALLBACK_LIBRARY_PATH"); + if (dyldLibPath != 0) { + if (!searchPaths.empty() && searchPaths[searchPaths.size()-1] != ':') + searchPaths += ":"; + searchPaths += dyldLibPath; + } + if (!searchPaths.empty()) { + std::stringstream ss(searchPaths); + std::string item; + while (std::getline(ss, item, ':')) { + if (item[item.size()-1] != '/') + item += "/"; + Settings::addSearchPath(item); + } + } +} diff --git a/src/Utils.h b/src/Utils.h index 7557e92..ba37a2f 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -39,4 +39,7 @@ bool mkdir(std::string path); void createDestDir(); std::string getUserInputDirForFile(const std::string& filename); +// check the same paths the system would search for dylibs +void initSearchPaths(); + #endif