From a18ba5fdd3a3774fd02036149b13ec4adca8df69 Mon Sep 17 00:00:00 2001 From: SCG82 Date: Sat, 11 Jan 2020 04:12:54 -0800 Subject: [PATCH] switch from vector to set for rpaths_per_file --- src/DylibBundler.cpp | 6 +++--- src/Settings.cpp | 6 +++--- src/Settings.h | 3 ++- src/Utils.cpp | 7 +++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/DylibBundler.cpp b/src/DylibBundler.cpp index ebbc6a8..848bf54 100644 --- a/src/DylibBundler.cpp +++ b/src/DylibBundler.cpp @@ -160,13 +160,13 @@ void changeLibPathsOnFile(const std::string& file_to_fix) void fixRpathsOnFile(const std::string& original_file, const std::string& file_to_fix) { - std::vector rpaths_to_fix; + std::set rpaths_to_fix; if (Settings::fileHasRpath(original_file)) rpaths_to_fix = Settings::getRpathsForFile(original_file); - for (const auto& i : rpaths_to_fix) { + for (const auto& rpath_to_fix : rpaths_to_fix) { std::string command = std::string("install_name_tool -rpath "); - command += i + " " + Settings::insideLibPath() + " " + file_to_fix; + command += rpath_to_fix + " " + Settings::insideLibPath() + " " + file_to_fix; if (systemp(command) != 0) { std::cerr << "\n\n/!\\ ERROR: An error occured while trying to fix dependencies of " << file_to_fix << "\n"; exit(1); diff --git a/src/Settings.cpp b/src/Settings.cpp index d1804a1..7e31808 100644 --- a/src/Settings.cpp +++ b/src/Settings.cpp @@ -165,9 +165,9 @@ std::string getFullPath(const std::string& rpath) { return rpath_to_fullpath[rpa void rpathToFullPath(const std::string& rpath, const std::string& fullpath) { rpath_to_fullpath[rpath] = fullpath; } bool rpathFound(const std::string& rpath) { return rpath_to_fullpath.find(rpath) != rpath_to_fullpath.end(); } -std::map> rpaths_per_file; -std::vector getRpathsForFile(const std::string& file) { return rpaths_per_file[file]; } -void addRpathForFile(const std::string& file, const std::string& rpath) { rpaths_per_file[file].push_back(rpath); } +std::map> rpaths_per_file; +std::set getRpathsForFile(const std::string& file) { return rpaths_per_file[file]; } +void addRpathForFile(const std::string& file, const std::string& rpath) { rpaths_per_file[file].insert(rpath); } bool fileHasRpath(const std::string& file) { return rpaths_per_file.find(file) != rpaths_per_file.end(); } } // namespace Settings diff --git a/src/Settings.h b/src/Settings.h index f4b480c..18e57ff 100644 --- a/src/Settings.h +++ b/src/Settings.h @@ -3,6 +3,7 @@ #ifndef _settings_ #define _settings_ +#include #include #include @@ -69,7 +70,7 @@ std::string getFullPath(const std::string& rpath); void rpathToFullPath(const std::string& rpath, const std::string& fullpath); bool rpathFound(const std::string& rpath); -std::vector getRpathsForFile(const std::string& file); +std::set getRpathsForFile(const std::string& file); void addRpathForFile(const std::string& file, const std::string& rpath); bool fileHasRpath(const std::string& file); diff --git a/src/Utils.cpp b/src/Utils.cpp index 6bde190..779c578 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -354,10 +354,9 @@ std::string searchFilenameInRpaths(const std::string& rpath_file, const std::str std::string fullpath; std::string suffix = rpath_file.substr(rpath_file.rfind('/')+1); - char fullpath_buffer[PATH_MAX]; + char buffer[PATH_MAX]; const auto check_path = [&](std::string path) { - char buffer[PATH_MAX]; std::string file_prefix = filePrefix(dependent_file); if (path.find("@executable_path") != std::string::npos || path.find("@loader_path") != std::string::npos) { if (path.find("@executable_path") != std::string::npos) { @@ -436,8 +435,8 @@ std::string searchFilenameInRpaths(const std::string& rpath_file, const std::str fullpath = getUserInputDirForFile(suffix, dependent_file) + suffix; if (Settings::quietOutput() && fullpath.empty()) std::cerr << "\n/!\\ WARNING: Can't get path for '" << rpath_file << "'\n"; - if (realpath(fullpath.c_str(), fullpath_buffer)) - fullpath = fullpath_buffer; + if (realpath(fullpath.c_str(), buffer)) + fullpath = buffer; } else if (Settings::verboseOutput()) { std::cout << " ** rpath fullpath: " << fullpath << std::endl;