From 1b4d70cbb7c0372b4515c3339948401bdb7525f2 Mon Sep 17 00:00:00 2001 From: SCG82 Date: Fri, 13 Dec 2019 01:35:17 -0800 Subject: [PATCH] revert nested parallel_for_each. try another nested parallel_for_each --- src/Dependency.cpp | 34 ++++++++++++++--------------- src/DylibBundler.cpp | 50 +++++++++++-------------------------------- src/ParallelForEach.h | 22 +++++++++++++++++++ src/Utils.cpp | 15 ++++++------- 4 files changed, 58 insertions(+), 63 deletions(-) create mode 100644 src/ParallelForEach.h diff --git a/src/Dependency.cpp b/src/Dependency.cpp index f1e23db..6616035 100644 --- a/src/Dependency.cpp +++ b/src/Dependency.cpp @@ -1,19 +1,21 @@ -#include -#include -#include -#include #include "Dependency.h" -#include + +#include +#include #include #include +#include +#include +#include +#include +#include +#include #include + #include "Utils.h" #include "Settings.h" #include "DylibBundler.h" - -#include -#include -#include +#include "ParallelForEach.h" std::string stripPrefix(std::string in) { @@ -193,14 +195,13 @@ void Dependency::fixFileThatDependsOnMe(std::string file_to_fix) } // for symlinks - const int symamount = symlinks.size(); - for(int n=0; n #include #include -#include +#include #include #include -#include +#include #ifdef __linux #include #endif -#include "Utils.h" -#include "Settings.h" #include "Dependency.h" -// #include "ParallelFor.h" +#include "ParallelForEach.h" +#include "Settings.h" +#include "Utils.h" std::vector deps; std::set rpaths; -std::map > rpaths_per_file; - -template -inline void parallel_for_each(It a, It b, F&& f) -{ - size_t count = std::distance(a,b); - using data_t = std::pair; - data_t helper = data_t(a, std::forward(f)); - dispatch_apply_f(count, - dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), - &helper, - [](void* ctx, size_t cnt) { - data_t* d = static_cast(ctx); - auto elem_it = std::next(d->first, cnt); - (*d).second(*(elem_it)); - }); -} - +std::map> rpaths_per_file; void changeLibPathsOnFile(std::string file_to_fix) { @@ -131,17 +113,18 @@ void fixRpathsOnFile(const std::string& original_file, const std::string& file_t if (found != rpaths_per_file.end()) rpaths_to_fix = found->second; - for (size_t i=0; i < rpaths_to_fix.size(); ++i) { + // for (size_t i=0; i < rpaths_to_fix.size(); ++i) { + parallel_for_each(rpaths_to_fix.begin(), rpaths_to_fix.end(), [&](const std::string& rpath_to_fix) { std::string command = std::string("install_name_tool -rpath ") - + rpaths_to_fix[i] + " " + + rpath_to_fix + " " + Settings::inside_lib_path() + " " + 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; exit(1); } - } + }); } void addDependency(std::string path) @@ -317,23 +300,14 @@ void doneWithDeps_go() createDestDir(); parallel_for_each(deps.begin(), deps.end(), [](Dependency& dep) { dep.copyYourself(); - std::cout << "\n* Fixing dependencies on " << dep.getInstallPath().c_str() << std::endl; - parallel_for_each(deps.begin(), deps.end(), [&](Dependency& dep) { - dep.fixFileThatDependsOnMe(dep.getInstallPath()); - }); + changeLibPathsOnFile(dep.getInstallPath()); fixRpathsOnFile(dep.getOriginalPath(), dep.getInstallPath()); }); } auto files = Settings::filesToFix(); - const int fileToFixAmount = Settings::fileToFixAmount(); - parallel_for_each(files.begin(), files.end(), [](const std::string& file) { - std::cout << "\n* Fixing dependencies on " << file.c_str() << std::endl; - const int dep_amount = deps.size(); - parallel_for_each(deps.begin(), deps.end(), [&](Dependency& dep) { - dep.fixFileThatDependsOnMe(file); - }); + changeLibPathsOnFile(file); fixRpathsOnFile(file, file); }); } diff --git a/src/ParallelForEach.h b/src/ParallelForEach.h new file mode 100644 index 0000000..43232ce --- /dev/null +++ b/src/ParallelForEach.h @@ -0,0 +1,22 @@ +#ifndef _ParallelForEach_h_ +#define _ParallelForEach_h_ + +#include + +template +inline void parallel_for_each(It a, It b, F&& f) +{ + size_t count = std::distance(a,b); + using data_t = std::pair; + data_t helper = data_t(a, std::forward(f)); + dispatch_apply_f(count, + dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), + &helper, + [](void* ctx, size_t cnt) { + data_t* d = static_cast(ctx); + auto elem_it = std::next(d->first, cnt); + (*d).second(*(elem_it)); + }); +} + +#endif diff --git a/src/Utils.cpp b/src/Utils.cpp index ebc2f79..dbb85cb 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -56,11 +56,9 @@ bool fileExists( std::string filename ) void copyFile(string from, string to) { bool overwrite = Settings::canOverwriteFiles(); - if (!overwrite) { - if (fileExists(to)) { - cerr << "\n\nError : File " << to.c_str() << " already exists. Remove it or enable overwriting." << endl; - exit(1); - } + if (fileExists(to) && !overwrite) { + cerr << "\n\nError : File " << to.c_str() << " already exists. Remove it or enable overwriting." << endl; + exit(1); } string overwrite_permission = string(overwrite ? "-f " : "-n "); @@ -130,12 +128,13 @@ std::string getUserInputDirForFile(const std::string& filename) const int searchPathAmount = Settings::searchPathAmount(); for (int n=0; n