revert nested parallel_for_each. try another nested parallel_for_each
This commit is contained in:
parent
a8f7f48b70
commit
1b4d70cbb7
|
@ -1,19 +1,21 @@
|
||||||
#include <algorithm>
|
|
||||||
#include <functional>
|
|
||||||
#include <cctype>
|
|
||||||
#include <locale>
|
|
||||||
#include "Dependency.h"
|
#include "Dependency.h"
|
||||||
#include <iostream>
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cctype>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <functional>
|
||||||
|
#include <locale>
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <vector>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "DylibBundler.h"
|
#include "DylibBundler.h"
|
||||||
|
#include "ParallelForEach.h"
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sstream>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
std::string stripPrefix(std::string in)
|
std::string stripPrefix(std::string in)
|
||||||
{
|
{
|
||||||
|
@ -193,14 +195,13 @@ void Dependency::fixFileThatDependsOnMe(std::string file_to_fix)
|
||||||
}
|
}
|
||||||
|
|
||||||
// for symlinks
|
// for symlinks
|
||||||
const int symamount = symlinks.size();
|
parallel_for_each(symlinks.begin(), symlinks.end(), [&](const std::string& symlink) {
|
||||||
for(int n=0; n<symamount; n++) {
|
command = std::string("install_name_tool -change ") + symlink + " " + getInnerPath() + " " + file_to_fix;
|
||||||
command = std::string("install_name_tool -change ") + symlinks[n] + " " + getInnerPath() + " " + file_to_fix;
|
|
||||||
if(systemp(command) != 0) {
|
if(systemp(command) != 0) {
|
||||||
std::cerr << "\n\nError : An error occured while trying to fix dependencies of " << file_to_fix << std::endl;
|
std::cerr << "\n\nError : An error occured while trying to fix dependencies of " << file_to_fix << std::endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
// FIXME - hackish
|
// FIXME - hackish
|
||||||
if (missing_prefixes) {
|
if (missing_prefixes) {
|
||||||
|
@ -212,13 +213,12 @@ void Dependency::fixFileThatDependsOnMe(std::string file_to_fix)
|
||||||
}
|
}
|
||||||
|
|
||||||
// for symlinks
|
// for symlinks
|
||||||
const int symamount = symlinks.size();
|
parallel_for_each(symlinks.begin(), symlinks.end(), [&](const std::string& symlink) {
|
||||||
for(int n=0; n<symamount; n++) {
|
command = std::string("install_name_tool -change ") + symlink + " " + getInnerPath() + " " + file_to_fix;
|
||||||
command = std::string("install_name_tool -change ") + symlinks[n] + " " + getInnerPath() + " " + file_to_fix;
|
|
||||||
if (systemp(command) != 0) {
|
if (systemp(command) != 0) {
|
||||||
std::cerr << "\n\nError : An error occured while trying to fix dependencies of " << file_to_fix << std::endl;
|
std::cerr << "\n\nError : An error occured while trying to fix dependencies of " << file_to_fix << std::endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,42 +1,24 @@
|
||||||
#include "DylibBundler.h"
|
#include "DylibBundler.h"
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <set>
|
#include <iostream>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <dispatch/dispatch.h>
|
#include <set>
|
||||||
#ifdef __linux
|
#ifdef __linux
|
||||||
#include <linux/limits.h>
|
#include <linux/limits.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "Utils.h"
|
|
||||||
#include "Settings.h"
|
|
||||||
#include "Dependency.h"
|
#include "Dependency.h"
|
||||||
// #include "ParallelFor.h"
|
#include "ParallelForEach.h"
|
||||||
|
#include "Settings.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
std::vector<Dependency> deps;
|
std::vector<Dependency> deps;
|
||||||
std::set<std::string> rpaths;
|
std::set<std::string> rpaths;
|
||||||
std::map<std::string, std::vector<std::string>> rpaths_per_file;
|
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));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void changeLibPathsOnFile(std::string file_to_fix)
|
void changeLibPathsOnFile(std::string file_to_fix)
|
||||||
{
|
{
|
||||||
std::cout << "\n* Fixing dependencies on " << file_to_fix.c_str() << std::endl;
|
std::cout << "\n* Fixing dependencies on " << file_to_fix.c_str() << std::endl;
|
||||||
|
@ -131,17 +113,18 @@ void fixRpathsOnFile(const std::string& original_file, const std::string& file_t
|
||||||
if (found != rpaths_per_file.end())
|
if (found != rpaths_per_file.end())
|
||||||
rpaths_to_fix = found->second;
|
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 command =
|
||||||
std::string("install_name_tool -rpath ")
|
std::string("install_name_tool -rpath ")
|
||||||
+ rpaths_to_fix[i] + " "
|
+ rpath_to_fix + " "
|
||||||
+ Settings::inside_lib_path() + " "
|
+ Settings::inside_lib_path() + " "
|
||||||
+ file_to_fix;
|
+ file_to_fix;
|
||||||
if (systemp(command) != 0) {
|
if (systemp(command) != 0) {
|
||||||
std::cerr << "\n\nError : An error occured while trying to fix dependencies of " << file_to_fix << std::endl;
|
std::cerr << "\n\nError : An error occured while trying to fix dependencies of " << file_to_fix << std::endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void addDependency(std::string path)
|
void addDependency(std::string path)
|
||||||
|
@ -317,23 +300,14 @@ void doneWithDeps_go()
|
||||||
createDestDir();
|
createDestDir();
|
||||||
parallel_for_each(deps.begin(), deps.end(), [](Dependency& dep) {
|
parallel_for_each(deps.begin(), deps.end(), [](Dependency& dep) {
|
||||||
dep.copyYourself();
|
dep.copyYourself();
|
||||||
std::cout << "\n* Fixing dependencies on " << dep.getInstallPath().c_str() << std::endl;
|
changeLibPathsOnFile(dep.getInstallPath());
|
||||||
parallel_for_each(deps.begin(), deps.end(), [&](Dependency& dep) {
|
|
||||||
dep.fixFileThatDependsOnMe(dep.getInstallPath());
|
|
||||||
});
|
|
||||||
fixRpathsOnFile(dep.getOriginalPath(), dep.getInstallPath());
|
fixRpathsOnFile(dep.getOriginalPath(), dep.getInstallPath());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
auto files = Settings::filesToFix();
|
auto files = Settings::filesToFix();
|
||||||
const int fileToFixAmount = Settings::fileToFixAmount();
|
|
||||||
|
|
||||||
parallel_for_each(files.begin(), files.end(), [](const std::string& file) {
|
parallel_for_each(files.begin(), files.end(), [](const std::string& file) {
|
||||||
std::cout << "\n* Fixing dependencies on " << file.c_str() << std::endl;
|
changeLibPathsOnFile(file);
|
||||||
const int dep_amount = deps.size();
|
|
||||||
parallel_for_each(deps.begin(), deps.end(), [&](Dependency& dep) {
|
|
||||||
dep.fixFileThatDependsOnMe(file);
|
|
||||||
});
|
|
||||||
fixRpathsOnFile(file, file);
|
fixRpathsOnFile(file, 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
|
|
@ -56,12 +56,10 @@ bool fileExists( std::string filename )
|
||||||
void copyFile(string from, string to)
|
void copyFile(string from, string to)
|
||||||
{
|
{
|
||||||
bool overwrite = Settings::canOverwriteFiles();
|
bool overwrite = Settings::canOverwriteFiles();
|
||||||
if (!overwrite) {
|
if (fileExists(to) && !overwrite) {
|
||||||
if (fileExists(to)) {
|
|
||||||
cerr << "\n\nError : File " << to.c_str() << " already exists. Remove it or enable overwriting." << endl;
|
cerr << "\n\nError : File " << to.c_str() << " already exists. Remove it or enable overwriting." << endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
string overwrite_permission = string(overwrite ? "-f " : "-n ");
|
string overwrite_permission = string(overwrite ? "-f " : "-n ");
|
||||||
|
|
||||||
|
@ -135,7 +133,8 @@ std::string getUserInputDirForFile(const std::string& filename)
|
||||||
|
|
||||||
if (!fileExists(searchPath+filename)) {
|
if (!fileExists(searchPath+filename)) {
|
||||||
continue;
|
continue;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
std::cerr << (searchPath+filename) << " was found.\n"
|
std::cerr << (searchPath+filename) << " was found.\n"
|
||||||
<< "/!\\ DylibBundler MAY NOT CORRECTLY HANDLE THIS DEPENDENCY: "
|
<< "/!\\ DylibBundler MAY NOT CORRECTLY HANDLE THIS DEPENDENCY: "
|
||||||
<< "Check the executable with 'otool -L'" << std::endl;
|
<< "Check the executable with 'otool -L'" << std::endl;
|
||||||
|
|
Loading…
Reference in New Issue