revert nested parallel_for_each. try another nested parallel_for_each

This commit is contained in:
SCG82 2019-12-13 01:35:17 -08:00
parent a8f7f48b70
commit 1b4d70cbb7
4 changed files with 58 additions and 63 deletions

View File

@ -1,19 +1,21 @@
#include <algorithm>
#include <functional>
#include <cctype>
#include <locale>
#include "Dependency.h"
#include <iostream>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <locale>
#include <iostream>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <sys/param.h>
#include "Utils.h"
#include "Settings.h"
#include "DylibBundler.h"
#include <stdlib.h>
#include <sstream>
#include <vector>
#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<symamount; n++) {
command = std::string("install_name_tool -change ") + symlinks[n] + " " + getInnerPath() + " " + file_to_fix;
parallel_for_each(symlinks.begin(), symlinks.end(), [&](const std::string& symlink) {
command = std::string("install_name_tool -change ") + symlink + " " + getInnerPath() + " " + 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);
}
}
});
// FIXME - hackish
if (missing_prefixes) {
@ -212,13 +213,12 @@ void Dependency::fixFileThatDependsOnMe(std::string file_to_fix)
}
// for symlinks
const int symamount = symlinks.size();
for(int n=0; n<symamount; n++) {
command = std::string("install_name_tool -change ") + symlinks[n] + " " + getInnerPath() + " " + file_to_fix;
parallel_for_each(symlinks.begin(), symlinks.end(), [&](const std::string& symlink) {
command = std::string("install_name_tool -change ") + symlink + " " + getInnerPath() + " " + 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);
}
}
});
}
}

View File

@ -1,41 +1,23 @@
#include "DylibBundler.h"
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <iostream>
#include <map>
#include <numeric>
#include <dispatch/dispatch.h>
#include <set>
#ifdef __linux
#include <linux/limits.h>
#endif
#include "Utils.h"
#include "Settings.h"
#include "Dependency.h"
// #include "ParallelFor.h"
#include "ParallelForEach.h"
#include "Settings.h"
#include "Utils.h"
std::vector<Dependency> deps;
std::set<std::string> rpaths;
std::map<std::string, std::vector<std::string> > rpaths_per_file;
template<typename It, typename F>
inline void parallel_for_each(It a, It b, F&& f)
{
size_t count = std::distance(a,b);
using data_t = std::pair<It, F>;
data_t helper = data_t(a, std::forward<F>(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<data_t*>(ctx);
auto elem_it = std::next(d->first, cnt);
(*d).second(*(elem_it));
});
}
std::map<std::string, std::vector<std::string>> 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);
});
}

22
src/ParallelForEach.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef _ParallelForEach_h_
#define _ParallelForEach_h_
#include <dispatch/dispatch.h>
template<typename It, typename F>
inline void parallel_for_each(It a, It b, F&& f)
{
size_t count = std::distance(a,b);
using data_t = std::pair<It, F>;
data_t helper = data_t(a, std::forward<F>(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<data_t*>(ctx);
auto elem_it = std::next(d->first, cnt);
(*d).second(*(elem_it));
});
}
#endif

View File

@ -56,12 +56,10 @@ bool fileExists( std::string filename )
void copyFile(string from, string to)
{
bool overwrite = Settings::canOverwriteFiles();
if (!overwrite) {
if (fileExists(to)) {
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<searchPathAmount; n++) {
auto searchPath = Settings::searchPath(n);
if(!searchPath.empty() && searchPath[searchPath.size()-1] != '/')
if (!searchPath.empty() && searchPath[searchPath.size()-1] != '/')
searchPath += "/";
if (!fileExists(searchPath+filename)) {
continue;
} else {
}
else {
std::cerr << (searchPath+filename) << " was found.\n"
<< "/!\\ DylibBundler MAY NOT CORRECTLY HANDLE THIS DEPENDENCY: "
<< "Check the executable with 'otool -L'" << std::endl;
@ -157,7 +156,7 @@ std::string getUserInputDirForFile(const std::string& filename)
if (!prefix.empty() && prefix[prefix.size()-1] != '/')
prefix += "/";
if (!fileExists( prefix+filename)) {
if (!fileExists(prefix+filename)) {
std::cerr << (prefix+filename) << " does not exist. Try again" << std::endl;
continue;
}