diff --git a/src/Dependency.cpp b/src/Dependency.cpp index 9f222eb..9ef1041 100644 --- a/src/Dependency.cpp +++ b/src/Dependency.cpp @@ -118,9 +118,8 @@ void Dependency::AddSymlink(const std::string& path) bool Dependency::MergeIfIdentical(Dependency& dependency) { if (dependency.OriginalFilename() == filename) { - for (const auto& symlink : symlinks) { + for (const auto& symlink : symlinks) dependency.AddSymlink(symlink); - } return true; } return false; @@ -161,22 +160,19 @@ void Dependency::CopyToBundle() const void Dependency::FixDependentFile(const std::string& dependent_file) const { changeInstallName(dependent_file, OriginalPath(), InnerPath()); - for (const auto& symlink : symlinks) { + for (const auto& symlink : symlinks) changeInstallName(dependent_file, symlink, InnerPath()); - } - if (Settings::missingPrefixes()) { - changeInstallName(dependent_file, filename, InnerPath()); - for (const auto& symlink : symlinks) { - changeInstallName(dependent_file, symlink, InnerPath()); - } - } + if (!Settings::missingPrefixes()) return; + + changeInstallName(dependent_file, filename, InnerPath()); + for (const auto& symlink : symlinks) + changeInstallName(dependent_file, symlink, InnerPath()); } void Dependency::Print() const { std::cout << "\n* " << filename << " from " << prefix << std::endl; - for (const auto& symlink : symlinks) { + for (const auto& symlink : symlinks) std::cout << " symlink --> " << symlink << std::endl; - } } diff --git a/src/DylibBundler.cpp b/src/DylibBundler.cpp index 0549dda..2b32f51 100644 --- a/src/DylibBundler.cpp +++ b/src/DylibBundler.cpp @@ -56,7 +56,7 @@ void addDependency(const std::string& path, const std::string& dependent_file) deps_per_file[dependent_file].push_back(dependency); } -void collectDependencies(const std::string& dependent_file) +void collectDependenciesRpaths(const std::string& dependent_file) { if (deps_collected.find(dependent_file) != deps_collected.end() && Settings::fileHasRpath(dependent_file)) return; @@ -92,40 +92,6 @@ void collectDependencies(const std::string& dependent_file) } } -//void collectDependencies(const std::string& dependent_file, std::vector& lines) -//{ -// if (deps_collected.find(dependent_file) == deps_collected.end()) -// parseLoadCommands(dependent_file, std::string("LC_LOAD_DYLIB"), std::string("name"), lines); -//} - -//void collectDependencies(const std::string& dependent_file) -//{ -// std::vector lines; -// collectDependencies(dependent_file, lines); -// collectRpaths(dependent_file); -// -// for (const auto& line : lines) { -// if (!Settings::isPrefixBundled(line)) -// continue; // skip system/ignored prefixes -// addDependency(line, dependent_file); -// } -// deps_collected[dependent_file] = true; -//} - -//void collectRpaths(const std::string& filename) -//{ -// if (!Settings::fileHasRpath(filename)) { -// std::vector lines; -// parseLoadCommands(filename, std::string("LC_RPATH"), std::string("path"), lines); -// for (const auto &line : lines) { -// rpaths.insert(line); -// Settings::addRpathForFile(filename, line); -// if (Settings::verboseOutput()) -// std::cout << " rpath: " << line << std::endl; -// } -// } -//} - void collectSubDependencies() { size_t dep_counter = deps.size(); @@ -143,18 +109,7 @@ void collectSubDependencies() std::cout << " (collect sub deps) original path: " << original_path << std::endl; if (isRpath(original_path)) original_path = searchFilenameInRpaths(original_path); - -// std::vector lines; -// collectDependencies(original_path, lines); -// collectRpaths(original_path); -// -// for (const auto& line : lines) { -// if (!Settings::isPrefixBundled(line)) -// continue; // skip system/ignored prefixes -// addDependency(line, original_path); -// } - - collectDependencies(original_path); + collectDependenciesRpaths(original_path); } // if no more dependencies were added on this iteration, stop searching if (deps.size() == deps_size) @@ -174,14 +129,13 @@ void collectSubDependencies() void changeLibPathsOnFile(const std::string& file_to_fix) { if (deps_collected.find(file_to_fix) == deps_collected.end() || rpaths_collected.find(file_to_fix) == rpaths_collected.end()) - collectDependencies(file_to_fix); + collectDependenciesRpaths(file_to_fix); std::cout << "* Fixing dependencies on " << file_to_fix << "\n"; std::vector dependencies = deps_per_file[file_to_fix]; - for (auto& dependency : dependencies) { + for (auto& dependency : dependencies) dependency.FixDependentFile(file_to_fix); - } } void fixRpathsOnFile(const std::string& original_file, const std::string& file_to_fix) @@ -204,16 +158,15 @@ void fixRpathsOnFile(const std::string& original_file, const std::string& file_t void bundleDependencies() { - for (const auto& dep : deps) { + for (const auto& dep : deps) dep.Print(); - } std::cout << "\n"; if (Settings::verboseOutput()) { std::cout << "rpaths:" << std::endl; - for (const auto& rpath : rpaths) { + for (const auto& rpath : rpaths) std::cout << "* " << rpath << std::endl; - } } + // copy & fix up dependencies if (Settings::bundleLibs()) { createDestDir(); @@ -294,7 +247,7 @@ void bundleQtPlugins() std::vector files = lsDir(dest + plugin+"/"); for (const auto& file : files) { Settings::addFileToFix(dest + plugin+"/"+file); - collectDependencies(dest + plugin + "/" + file); + collectDependenciesRpaths(dest + plugin + "/" + file); changeId(dest + plugin+"/"+file, "@rpath/" + plugin+"/"+file); } } @@ -309,7 +262,7 @@ void bundleQtPlugins() mkdir(dest + "platforms"); copyFile(qt_plugins_prefix + "platforms/libqcocoa.dylib", dest + "platforms"); Settings::addFileToFix(dest + "platforms/libqcocoa.dylib"); - collectDependencies(dest + "platforms/libqcocoa.dylib"); + collectDependenciesRpaths(dest + "platforms/libqcocoa.dylib"); fixupPlugin("printsupport"); fixupPlugin("styles"); diff --git a/src/DylibBundler.h b/src/DylibBundler.h index f67243b..f3d69fa 100644 --- a/src/DylibBundler.h +++ b/src/DylibBundler.h @@ -7,21 +7,11 @@ #include void addDependency(const std::string& path, const std::string& dependent_file); - -// fill |lines| with dependencies of |dependent_file| -//void collectDependencies(const std::string& dependent_file, std::vector& lines); -void collectDependencies(const std::string& dependent_file); - -//void collectRpaths(const std::string& filename); - -// recursively collect each dependency's dependencies +void collectDependenciesRpaths(const std::string& dependent_file); void collectSubDependencies(); - void changeLibPathsOnFile(const std::string& file_to_fix); void fixRpathsOnFile(const std::string& original_file, const std::string& file_to_fix); - void bundleDependencies(); - void bundleQtPlugins(); #endif diff --git a/src/Utils.cpp b/src/Utils.cpp index 35c3388..2e1dae2 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -7,9 +7,7 @@ #include #include -// #include #include -// #include #ifndef __clang__ #include #endif @@ -315,40 +313,6 @@ void otool(const std::string& flags, const std::string& file, std::vector& lines) -{ - std::vector raw_lines; - otool("-l", file, raw_lines); - - bool searching = false; - std::string cmd_line = std::string("cmd ") + cmd; - std::string value_line = std::string(value + std::string(" ")); - for (const auto& raw_line : raw_lines) { - if (raw_line.find(cmd_line) != std::string::npos) { - if (searching) { - std::cerr << "\n\n/!\\ ERROR: Failed to find " << value << " before next cmd\n"; - exit(1); - } - searching = true; - } - else if (searching) { - size_t start_pos = raw_line.find(value_line); - if (start_pos == std::string::npos) - continue; - size_t start = start_pos + value.size() + 1; // exclude data label "|value| " - size_t end = std::string::npos; - if (value == "name" || value == "path") { - size_t end_pos = raw_line.find(" ("); - if (end_pos == std::string::npos) - continue; - end = end_pos - start; - } - lines.push_back(raw_line.substr(start, end)); - searching = false; - } - } -} - void parseLoadCommands(const std::string& file, const std::map& cmds_values, std::map>& cmds_results) { std::vector raw_lines; diff --git a/src/Utils.h b/src/Utils.h index bde0bba..9ce29e6 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -46,7 +46,6 @@ void createDestDir(); std::string getUserInputDirForFile(const std::string& filename, const std::string& dependent_file); void otool(const std::string& flags, const std::string& file, std::vector& lines); -void parseLoadCommands(const std::string& file, const std::string& cmd, const std::string& value, std::vector& lines); void parseLoadCommands(const std::string& file, const std::map& cmds_values, std::map>& cmds_results); std::string searchFilenameInRpaths(const std::string& rpath_file, const std::string& dependent_file); diff --git a/src/main.cpp b/src/main.cpp index 203be8d..03500f2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -125,9 +125,8 @@ int main(int argc, const char* argv[]) std::cout << "Collecting dependencies...\n"; const std::vector files_to_fix = Settings::filesToFix(); - for (const auto& file_to_fix : files_to_fix) { - collectDependencies(file_to_fix); - } + for (const auto& file_to_fix : files_to_fix) + collectDependenciesRpaths(file_to_fix); collectSubDependencies(); bundleDependencies();