use size_t in for loops
This commit is contained in:
parent
38f7687b2c
commit
767a6f9a9b
|
@ -176,8 +176,7 @@ void Dependency::print()
|
|||
{
|
||||
std::cout << "\n * " << filename << " from " << prefix << "\n";
|
||||
|
||||
const int symamount = symlinks.size();
|
||||
for (int n=0; n<symamount; ++n)
|
||||
for (size_t n=0; n<symlinks.size(); ++n)
|
||||
std::cout << " symlink --> " << symlinks[n] << "\n";;
|
||||
}
|
||||
|
||||
|
@ -202,9 +201,8 @@ void Dependency::addSymlink(std::string s)
|
|||
bool Dependency::mergeIfSameAs(Dependency& dep2)
|
||||
{
|
||||
if (dep2.getOriginalFileName().compare(filename) == 0) {
|
||||
const int samount = getSymlinkAmount();
|
||||
for (int n=0; n<samount; ++n)
|
||||
dep2.addSymlink(getSymlink(n));
|
||||
for (size_t n=0; n<symlinks.size(); ++n)
|
||||
dep2.addSymlink(symlinks[n]);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -278,8 +276,7 @@ void Dependency::fixFileThatDependsOnMe(std::string file_to_fix)
|
|||
}
|
||||
|
||||
// for symlinks
|
||||
const int symamount = symlinks.size();
|
||||
for (int n=0; n<symamount; ++n) {
|
||||
for (size_t n=0; n<symlinks.size(); ++n) {
|
||||
command = std::string("install_name_tool -change ") + symlinks[n] + " " + getInnerPath() + " " + file_to_fix;
|
||||
if (systemp(command) != 0) {
|
||||
std::cerr << "\n\nError: An error occured while trying to fix dependencies of " << file_to_fix << "\n";
|
||||
|
@ -297,7 +294,7 @@ void Dependency::fixFileThatDependsOnMe(std::string file_to_fix)
|
|||
}
|
||||
|
||||
// for symlinks
|
||||
for (int n=0; n<symamount; ++n) {
|
||||
for (size_t n=0; n<symlinks.size(); ++n) {
|
||||
command = std::string("install_name_tool -change ") + symlinks[n] + " " + getInnerPath() + " " + file_to_fix;
|
||||
if (systemp(command) != 0) {
|
||||
std::cerr << "\n\nError: An error occured while trying to fix dependencies of " << file_to_fix << "\n";
|
||||
|
|
|
@ -17,7 +17,7 @@ public:
|
|||
std::string getInnerPath();
|
||||
|
||||
void addSymlink(std::string s);
|
||||
int getSymlinkAmount() const { return symlinks.size(); }
|
||||
size_t symlinksCount() const { return symlinks.size(); }
|
||||
|
||||
std::string getSymlink(int i) const { return symlinks[i]; }
|
||||
std::string getPrefix() const { return prefix; }
|
||||
|
@ -37,13 +37,6 @@ private:
|
|||
|
||||
// installation
|
||||
std::string new_name;
|
||||
|
||||
// the paths to search for dylibs, store it globally to parse the environment variables only once
|
||||
// std::vector<std::string> paths;
|
||||
|
||||
// if some libs are missing prefixes, this will be set to true
|
||||
// more stuff will then be necessary to do
|
||||
// bool missing_prefixes;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -16,9 +16,10 @@
|
|||
|
||||
std::vector<Dependency> deps;
|
||||
std::map<std::string, std::vector<Dependency>> deps_per_file;
|
||||
std::map<std::string, bool> deps_collected;
|
||||
std::set<std::string> frameworks;
|
||||
std::set<std::string> rpaths;
|
||||
std::map<std::string, std::vector<std::string>> rpaths_per_file;
|
||||
std::map<std::string, bool> deps_collected;
|
||||
|
||||
void changeLibPathsOnFile(std::string file_to_fix)
|
||||
{
|
||||
|
@ -29,7 +30,7 @@ void changeLibPathsOnFile(std::string file_to_fix)
|
|||
|
||||
std::vector<Dependency> deps_in_file = deps_per_file[file_to_fix];
|
||||
const int dep_amount = deps_in_file.size();
|
||||
for (int n=0; n<dep_amount; ++n)
|
||||
for (size_t n=0; n<dep_amount; ++n)
|
||||
deps_in_file[n].fixFileThatDependsOnMe(file_to_fix);
|
||||
}
|
||||
|
||||
|
@ -148,16 +149,14 @@ void addDependency(std::string path, std::string filename)
|
|||
|
||||
// check if this library was already added to |deps| to avoid duplicates
|
||||
bool in_deps = false;
|
||||
const int dep_amount = deps.size();
|
||||
for (int n=0; n<dep_amount; n++)
|
||||
for (size_t n=0; n<deps.size(); ++n)
|
||||
if (dep.mergeIfSameAs(deps[n]))
|
||||
in_deps = true;
|
||||
|
||||
// check if this library was already added to |deps_per_file[filename]| to avoid duplicates
|
||||
std::vector<Dependency> deps_in_file = deps_per_file[filename];
|
||||
bool in_deps_per_file = false;
|
||||
for (int n=0; n<deps_in_file.size(); n++)
|
||||
if (dep.mergeIfSameAs(deps_in_file[n]))
|
||||
for (size_t n=0; n<deps_per_file[filename].size(); ++n)
|
||||
if (dep.mergeIfSameAs(deps_per_file[filename][n]))
|
||||
in_deps_per_file = true;
|
||||
|
||||
// check if this library is in /usr/lib, /System/Library, or in ignored list
|
||||
|
@ -167,10 +166,8 @@ void addDependency(std::string path, std::string filename)
|
|||
if (!in_deps)
|
||||
deps.push_back(dep);
|
||||
|
||||
if (!in_deps_per_file) {
|
||||
deps_in_file.push_back(dep);
|
||||
deps_per_file[filename] = deps_in_file;
|
||||
}
|
||||
if (!in_deps_per_file)
|
||||
deps_per_file[filename].push_back(dep);
|
||||
}
|
||||
|
||||
// Fill |lines| with dependencies of given |filename|
|
||||
|
@ -195,8 +192,7 @@ void collectDependencies(std::string filename)
|
|||
std::vector<std::string> lines;
|
||||
collectDependencies(filename, lines);
|
||||
|
||||
const int line_amount = lines.size();
|
||||
for (int n=0; n<line_amount; n++) {
|
||||
for (size_t n=0; n<lines.size(); n++) {
|
||||
if (!Settings::bundleFrameworks())
|
||||
if (lines[n].find(".framework") != std::string::npos)
|
||||
continue;
|
||||
|
@ -214,13 +210,13 @@ void collectDependencies(std::string filename)
|
|||
|
||||
void collectSubDependencies()
|
||||
{
|
||||
int dep_amount = deps.size();
|
||||
size_t deps_size = deps.size();
|
||||
|
||||
// recursively collect each dependency's dependencies
|
||||
while (true) {
|
||||
dep_amount = deps.size();
|
||||
deps_size = deps.size();
|
||||
|
||||
for (int n=0; n<dep_amount; n++) {
|
||||
for (size_t n=0; n<deps_size; n++) {
|
||||
std::string original_path = deps[n].getOriginalPath();
|
||||
if (Settings::verboseOutput())
|
||||
std::cout << "original path: " << original_path << std::endl;
|
||||
|
@ -232,8 +228,7 @@ void collectSubDependencies()
|
|||
std::vector<std::string> lines;
|
||||
collectDependencies(original_path, lines);
|
||||
|
||||
const int line_amount = lines.size();
|
||||
for (int n=0; n<line_amount; n++) {
|
||||
for (size_t n=0; n<lines.size(); ++n) {
|
||||
if (!Settings::bundleFrameworks())
|
||||
if (lines[n].find(".framework") != std::string::npos)
|
||||
continue;
|
||||
|
@ -252,7 +247,7 @@ void collectSubDependencies()
|
|||
}
|
||||
}
|
||||
// if no more dependencies were added on this iteration, stop searching
|
||||
if (deps.size() == dep_amount)
|
||||
if (deps.size() == deps_size)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -293,10 +288,10 @@ void createDestDir()
|
|||
|
||||
void doneWithDeps_go()
|
||||
{
|
||||
const int dep_amount = deps.size();
|
||||
const size_t deps_size = deps.size();
|
||||
|
||||
std::cout << "\n";
|
||||
for (int n=0; n<dep_amount; n++)
|
||||
for (size_t n=0; n<deps_size; ++n)
|
||||
deps[n].print();
|
||||
std::cout << "\n";
|
||||
|
||||
|
@ -304,15 +299,15 @@ void doneWithDeps_go()
|
|||
if (Settings::bundleLibs()) {
|
||||
createDestDir();
|
||||
|
||||
for (int i=0; i<dep_amount; ++i) {
|
||||
for (size_t i=0; i<deps_size; ++i) {
|
||||
deps[i].copyYourself();
|
||||
changeLibPathsOnFile(deps[i].getInstallPath());
|
||||
fixRpathsOnFile(deps[i].getOriginalPath(), deps[i].getInstallPath());
|
||||
}
|
||||
}
|
||||
|
||||
const int fileToFixAmount = Settings::fileToFixAmount();
|
||||
for (int n=0; n<fileToFixAmount; n++) {
|
||||
const size_t filesToFixSize = Settings::filesToFix().size();
|
||||
for (size_t n=0; n<filesToFixSize; ++n) {
|
||||
changeLibPathsOnFile(Settings::fileToFix(n));
|
||||
fixRpathsOnFile(Settings::fileToFix(n), Settings::fileToFix(n));
|
||||
}
|
||||
|
|
|
@ -38,9 +38,9 @@ void destFolder(std::string path)
|
|||
|
||||
std::vector<std::string> files;
|
||||
void addFileToFix(std::string path) { files.push_back(path); }
|
||||
int fileToFixAmount() { return files.size(); }
|
||||
std::string fileToFix(const int n) { return files[n]; }
|
||||
std::vector<std::string> filesToFix() { return files; }
|
||||
size_t filesToFixCount() { return files.size(); }
|
||||
|
||||
std::string insideLibPath() { return inside_path_str; }
|
||||
void insideLibPath(std::string p)
|
||||
|
@ -61,8 +61,7 @@ void ignorePrefix(std::string prefix)
|
|||
|
||||
bool isPrefixIgnored(std::string prefix)
|
||||
{
|
||||
const int prefix_amount = prefixes_to_ignore.size();
|
||||
for (int n=0; n<prefix_amount; n++) {
|
||||
for (size_t n=0; n<prefixes_to_ignore.size(); n++) {
|
||||
if (prefix.compare(prefixes_to_ignore[n]) == 0)
|
||||
return true;
|
||||
}
|
||||
|
@ -88,7 +87,7 @@ bool isPrefixBundled(std::string prefix)
|
|||
|
||||
std::vector<std::string> searchPaths;
|
||||
void addSearchPath(std::string path) { searchPaths.push_back(path); }
|
||||
int searchPathAmount() { return searchPaths.size(); }
|
||||
int searchPathCount() { return searchPaths.size(); }
|
||||
std::string searchPath(const int n) { return searchPaths[n]; }
|
||||
|
||||
bool quietOutput() { return quiet_output; }
|
||||
|
|
|
@ -29,15 +29,15 @@ std::string destFolder();
|
|||
void destFolder(std::string path);
|
||||
|
||||
void addFileToFix(std::string path);
|
||||
int fileToFixAmount();
|
||||
std::string fileToFix(int n);
|
||||
std::vector<std::string> filesToFix();
|
||||
size_t filesToFixCount();
|
||||
|
||||
std::string insideLibPath();
|
||||
void insideLibPath(std::string p);
|
||||
|
||||
void addSearchPath(std::string path);
|
||||
int searchPathAmount();
|
||||
int searchPathCount();
|
||||
std::string searchPath(int n);
|
||||
|
||||
bool quietOutput();
|
||||
|
|
|
@ -134,8 +134,8 @@ int systemp(const std::string& cmd)
|
|||
|
||||
std::string getUserInputDirForFile(const std::string& filename)
|
||||
{
|
||||
const int searchPathAmount = Settings::searchPathAmount();
|
||||
for (int n=0; n<searchPathAmount; ++n) {
|
||||
const size_t searchPathCount = Settings::searchPathCount();
|
||||
for (size_t n=0; n<searchPathCount; ++n) {
|
||||
auto searchPath = Settings::searchPath(n);
|
||||
if (!searchPath.empty() && searchPath[searchPath.size()-1] != '/')
|
||||
searchPath += "/";
|
||||
|
|
|
@ -115,15 +115,15 @@ int main (int argc, char * const argv[])
|
|||
}
|
||||
}
|
||||
|
||||
if (!Settings::bundleLibs() && Settings::fileToFixAmount() < 1) {
|
||||
if (!Settings::bundleLibs() && Settings::filesToFixCount() < 1) {
|
||||
showHelp();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
std::cout << "* Collecting dependencies...\n";
|
||||
|
||||
const int amount = Settings::fileToFixAmount();
|
||||
for (int n=0; n<amount; n++)
|
||||
const size_t count = Settings::filesToFixCount();
|
||||
for (size_t n=0; n<count; ++n)
|
||||
collectDependencies(Settings::fileToFix(n));
|
||||
|
||||
collectSubDependencies();
|
||||
|
|
Loading…
Reference in New Issue