refine threading

This commit is contained in:
SCG82 2019-12-12 04:13:49 -08:00
parent ebbd955abd
commit 6625f27f0e
3 changed files with 43 additions and 54 deletions

View File

@ -107,23 +107,19 @@ Dependency::Dependency(std::string path)
char original_file_buffer[PATH_MAX]; char original_file_buffer[PATH_MAX];
std::string original_file; std::string original_file;
if (isRpath(path)) if (isRpath(path)) {
{
original_file = searchFilenameInRpaths(path); original_file = searchFilenameInRpaths(path);
} }
else if (not realpath(rtrim(path).c_str(), original_file_buffer)) else if (not realpath(rtrim(path).c_str(), original_file_buffer)) {
{
std::cerr << "\n/!\\ WARNING : Cannot resolve path '" << path.c_str() << "'" << std::endl; std::cerr << "\n/!\\ WARNING : Cannot resolve path '" << path.c_str() << "'" << std::endl;
original_file = path; original_file = path;
} }
else else {
{
original_file = original_file_buffer; original_file = original_file_buffer;
} }
// check if given path is a symlink // check if given path is a symlink
if (original_file != rtrim(path)) if (original_file != rtrim(path)) {
{
filename = stripPrefix(original_file); filename = stripPrefix(original_file);
prefix = original_file.substr(0, original_file.rfind("/")+1); prefix = original_file.substr(0, original_file.rfind("/")+1);
addSymlink(path); addSymlink(path);
@ -235,18 +231,16 @@ void Dependency::fixFileThatDependsOnMe(std::string file_to_fix)
// for symlinks // for symlinks
const int symamount = symlinks.size(); const int symamount = symlinks.size();
parallel_for(symamount, [&](int start, int end) for(int n=0; n<symamount; n++)
{ {
for (int i=0; i<end; ++i) command = std::string("install_name_tool -change ") + symlinks[n] + " " + getInnerPath() + " " + file_to_fix;
if(systemp(command) != 0)
{ {
command = std::string("install_name_tool -change ") + symlinks[i] + " " + getInnerPath() + " " + file_to_fix; std::cerr << "\n\nError : An error occured while trying to fix dependencies of " << file_to_fix << std::endl;
if (systemp(command) != 0) exit(1);
{
std::cerr << "\n\nError : An error occured while trying to fix dependencies of " << file_to_fix << std::endl;
exit(1);
}
} }
}); }
// FIXME - hackish // FIXME - hackish
if (missing_prefixes) if (missing_prefixes)
@ -261,17 +255,14 @@ void Dependency::fixFileThatDependsOnMe(std::string file_to_fix)
// for symlinks // for symlinks
const int symamount = symlinks.size(); const int symamount = symlinks.size();
parallel_for(symamount, [&](int start, int end) for(int n=0; n<symamount; n++)
{ {
for (int i=0; i<end; ++i) command = std::string("install_name_tool -change ") + symlinks[n] + " " + getInnerPath() + " " + file_to_fix;
if (systemp(command) != 0)
{ {
command = std::string("install_name_tool -change ") + symlinks[i] + " " + getInnerPath() + " " + file_to_fix; std::cerr << "\n\nError : An error occured while trying to fix dependencies of " << file_to_fix << std::endl;
if (systemp(command) != 0) exit(1);
{
std::cerr << "\n\nError : An error occured while trying to fix dependencies of " << file_to_fix << std::endl;
exit(1);
}
} }
}); }//next
} }// end if(missing_prefixes)
} }

View File

@ -46,6 +46,7 @@ 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;
const int dep_amount = deps.size(); const int dep_amount = deps.size();
std::cout << "changeLibPaths: # of deps: " << dep_amount << std::endl;
parallel_for(dep_amount, [&](int start, int end) parallel_for(dep_amount, [&](int start, int end)
{ {
for(int i=start; i<end; ++i) for(int i=start; i<end; ++i)
@ -154,7 +155,7 @@ void fixRpathsOnFile(const std::string& original_file, const std::string& file_t
int start = 0; int start = 0;
int end = rpaths_to_fix.size(); int end = rpaths_to_fix.size();
std::cout << "# of rpaths to fix: " << rpaths_to_fix.size() << std::endl;
// parallel_for(rpaths_to_fix.size(), [&](int start, int end) // parallel_for(rpaths_to_fix.size(), [&](int start, int end)
// { // {
for(int i=start; i<end; ++i) for(int i=start; i<end; ++i)
@ -177,17 +178,10 @@ void addDependency(std::string path)
// we need to check if this library was already added to avoid duplicates // we need to check if this library was already added to avoid duplicates
const int dep_amount = deps.size(); const int dep_amount = deps.size();
int start = 0; for(int n=0; n<dep_amount; n++)
int end = dep_amount; {
// parallel_for(dep_amount, [&](int start, int end) if(dep.mergeIfSameAs(deps[n])) return;
// { }
for(int i=start; i<end; ++i)
{
if(dep.mergeIfSameAs(deps[i]))
return;
}
// pthread_exit(NULL);
// });
if(!Settings::isPrefixBundled(dep.getPrefix())) return; if(!Settings::isPrefixBundled(dep.getPrefix())) return;
@ -205,7 +199,6 @@ void collectDependencies(std::string filename, std::vector<std::string>& lines)
if(output.find("can't open file")!=std::string::npos or output.find("No such file")!=std::string::npos or output.size()<1) if(output.find("can't open file")!=std::string::npos or output.find("No such file")!=std::string::npos or output.size()<1)
{ {
std::cerr << output << std::endl;
std::cerr << "Cannot find file " << filename << " to read its dependencies" << std::endl; std::cerr << "Cannot find file " << filename << " to read its dependencies" << std::endl;
exit(1); exit(1);
} }
@ -225,6 +218,7 @@ void collectDependencies(std::string filename)
const int line_amount = lines.size(); const int line_amount = lines.size();
int start = 0; int start = 0;
int end = line_amount; int end = line_amount;
std::cout << "collectDeps: # of lines: " << line_amount << std::endl;
// parallel_for(line_amount, [&](int start, int end) // parallel_for(line_amount, [&](int start, int end)
// { // {
for(int i=start; i<end; ++i) for(int i=start; i<end; ++i)
@ -258,6 +252,7 @@ void collectSubDependencies()
dep_amount = deps.size(); dep_amount = deps.size();
int start = 0; int start = 0;
int end = deps.size(); int end = deps.size();
std::cout << "collectSubDeps: # of deps: " << dep_amount << std::endl;
// parallel_for(dep_amount, [&](int start, int end) // parallel_for(dep_amount, [&](int start, int end)
// { // {
for(int i=start; i<end; ++i) for(int i=start; i<end; ++i)
@ -274,6 +269,7 @@ void collectSubDependencies()
const int line_amount = lines.size(); const int line_amount = lines.size();
int s = 0; int s = 0;
int e = line_amount; int e = line_amount;
std::cout << "collectSubDeps: # of lines: " << line_amount << std::endl;
// parallel_for(line_amount, [&](int s, int e) // parallel_for(line_amount, [&](int s, int e)
// { // {
for(int j=s; j<e; ++j) for(int j=s; j<e; ++j)
@ -356,26 +352,32 @@ void doneWithDeps_go()
createDestDir(); createDestDir();
// for(int n=0; n<dep_amount; n++) // for(int n=0; n<dep_amount; n++)
parallel_for(dep_amount, [&](int start, int end) std::cout << "donewithDeps_go: # of deps: " << dep_amount << std::endl;
{ int start = 0;
int end = dep_amount;
// parallel_for(dep_amount, [&](int start, int end)
// {
for(int i=start; i<end; ++i) for(int i=start; i<end; ++i)
{ {
deps[i].copyYourself(); deps[i].copyYourself();
changeLibPathsOnFile(deps[i].getInstallPath()); changeLibPathsOnFile(deps[i].getInstallPath());
fixRpathsOnFile(deps[i].getOriginalPath(), deps[i].getInstallPath()); fixRpathsOnFile(deps[i].getOriginalPath(), deps[i].getInstallPath());
} }
}); // });
} }
const int fileToFixAmount = Settings::fileToFixAmount(); const int fileToFixAmount = Settings::fileToFixAmount();
parallel_for(fileToFixAmount, [&](int start, int end) std::cout << "# of files to fix: " << fileToFixAmount << std::endl;
{ int s = 0;
for(int i=start; i<end; ++i) int e = fileToFixAmount;
// parallel_for(fileToFixAmount, [&](int start, int end)
// {
for(int i=s; i<e; ++i)
{ {
changeLibPathsOnFile(Settings::fileToFix(i)); changeLibPathsOnFile(Settings::fileToFix(i));
fixRpathsOnFile(Settings::fileToFix(i), Settings::fileToFix(i)); fixRpathsOnFile(Settings::fileToFix(i), Settings::fileToFix(i));
} }
}); // });
} }

View File

@ -154,13 +154,9 @@ int main (int argc, char * const argv[])
std::cout << "* Collecting dependencies"; fflush(stdout); std::cout << "* Collecting dependencies"; fflush(stdout);
const int amount = Settings::fileToFixAmount(); const int amount = Settings::fileToFixAmount();
int start = 0; std::cout << "# of files to fix: " << amount << std::endl;
int end = amount; for(int n=0; n<amount; n++)
// parallel_for(amount, [&](int start, int end) collectDependencies(Settings::fileToFix(n));
// {
for(int i=start; i<end; ++i)
collectDependencies(Settings::fileToFix(i));
// });
collectSubDependencies(); collectSubDependencies();
doneWithDeps_go(); doneWithDeps_go();