code cleanup
This commit is contained in:
parent
f02982dfa9
commit
7f41661132
|
@ -52,7 +52,8 @@ Dependency::Dependency(std::string path, const std::string& dependent_file) : is
|
|||
prefix += "/";
|
||||
|
||||
// check if this dependency is in /usr/lib, /System/Library, or in ignored list
|
||||
if (!Settings::isPrefixBundled(prefix)) return;
|
||||
if (!Settings::isPrefixBundled(prefix))
|
||||
return;
|
||||
|
||||
if (original_file.find(".framework") != std::string::npos) {
|
||||
is_framework = true;
|
||||
|
@ -70,15 +71,13 @@ Dependency::Dependency(std::string path, const std::string& dependent_file) : is
|
|||
|
||||
// check if the lib is in a known location
|
||||
if (prefix.empty() || !fileExists(prefix+filename)) {
|
||||
std::vector<std::string> search_paths = Settings::searchPaths();
|
||||
// the paths contains at least /usr/lib so if it is empty we have not initialized it
|
||||
size_t search_path_count = Settings::searchPathCount();
|
||||
if (search_path_count == 0)
|
||||
if (search_paths.empty())
|
||||
initSearchPaths();
|
||||
|
||||
// check if file is contained in one of the paths
|
||||
search_path_count = Settings::searchPathCount();
|
||||
for (size_t i=0; i<search_path_count; ++i) {
|
||||
std::string search_path = Settings::searchPath(i);
|
||||
for (const auto& search_path : search_paths) {
|
||||
if (fileExists(search_path+filename)) {
|
||||
warning_msg += "FOUND " + filename + " in " + search_path + "\n";
|
||||
prefix = search_path;
|
||||
|
@ -98,7 +97,7 @@ Dependency::Dependency(std::string path, const std::string& dependent_file) : is
|
|||
if (Settings::verboseOutput())
|
||||
std::cout << " path: " << (prefix+filename) << std::endl;
|
||||
Settings::missingPrefixes(true);
|
||||
Settings::addSearchPath(getUserInputDirForFile(filename));
|
||||
Settings::addSearchPath(getUserInputDirForFile(filename, dependent_file));
|
||||
}
|
||||
|
||||
new_name = filename;
|
||||
|
|
|
@ -40,8 +40,6 @@ private:
|
|||
|
||||
// installation
|
||||
std::string new_name;
|
||||
|
||||
void print();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -25,33 +25,34 @@ std::set<std::string> frameworks;
|
|||
std::set<std::string> rpaths;
|
||||
bool qt_plugins_called = false;
|
||||
|
||||
void addDependency(std::string path, const std::string& dependent_file)
|
||||
void addDependency(const std::string& path, const std::string& dependent_file)
|
||||
{
|
||||
Dependency dep(std::move(path), dependent_file);
|
||||
Dependency dependency(path, dependent_file);
|
||||
|
||||
// check if this library was already added to |deps| to avoid duplicates
|
||||
bool in_deps = false;
|
||||
for (auto& n : deps) {
|
||||
if (dep.mergeIfSameAs(n))
|
||||
for (auto& dep : deps) {
|
||||
if (dependency.mergeIfSameAs(dep))
|
||||
in_deps = true;
|
||||
}
|
||||
|
||||
// check if this library was already added to |deps_per_file[dependent_file]| to avoid duplicates
|
||||
bool in_deps_per_file = false;
|
||||
for (auto& n : deps_per_file[dependent_file]) {
|
||||
if (dep.mergeIfSameAs(n))
|
||||
for (auto& dep : deps_per_file[dependent_file]) {
|
||||
if (dependency.mergeIfSameAs(dep))
|
||||
in_deps_per_file = true;
|
||||
}
|
||||
|
||||
// check if this library is in /usr/lib, /System/Library, or in ignored list
|
||||
if (!Settings::isPrefixBundled(dep.getPrefix())) return;
|
||||
if (!Settings::isPrefixBundled(dependency.getPrefix()))
|
||||
return;
|
||||
|
||||
if (!in_deps && dep.isFramework())
|
||||
frameworks.insert(dep.getOriginalPath());
|
||||
if (!in_deps && dependency.isFramework())
|
||||
frameworks.insert(dependency.getOriginalPath());
|
||||
if (!in_deps)
|
||||
deps.push_back(dep);
|
||||
deps.push_back(dependency);
|
||||
if (!in_deps_per_file)
|
||||
deps_per_file[dependent_file].push_back(dep);
|
||||
deps_per_file[dependent_file].push_back(dependency);
|
||||
}
|
||||
|
||||
void collectDependencies(const std::string& dependent_file, std::vector<std::string>& lines)
|
||||
|
@ -72,7 +73,8 @@ void collectDependenciesForFile(const std::string& dependent_file)
|
|||
collectRpathsForFilename(dependent_file);
|
||||
|
||||
for (const auto& line : lines) {
|
||||
if (!Settings::isPrefixBundled(line)) continue; // skip system/ignored prefixes
|
||||
if (!Settings::isPrefixBundled(line))
|
||||
continue; // skip system/ignored prefixes
|
||||
addDependency(line, dependent_file);
|
||||
}
|
||||
deps_collected[dependent_file] = true;
|
||||
|
@ -119,12 +121,14 @@ void collectSubDependencies()
|
|||
collectRpathsForFilename(original_path);
|
||||
|
||||
for (const auto& line : lines) {
|
||||
if (!Settings::isPrefixBundled(line)) continue; // skip system/ignored prefixes
|
||||
if (!Settings::isPrefixBundled(line))
|
||||
continue; // skip system/ignored prefixes
|
||||
addDependency(line, original_path);
|
||||
}
|
||||
}
|
||||
// if no more dependencies were added on this iteration, stop searching
|
||||
if (deps.size() == deps_size) break;
|
||||
if (deps.size() == deps_size)
|
||||
break;
|
||||
}
|
||||
|
||||
if (Settings::verboseOutput()) {
|
||||
|
@ -180,17 +184,17 @@ void bundleDependencies()
|
|||
// copy & fix up dependencies
|
||||
if (Settings::bundleLibs()) {
|
||||
createDestDir();
|
||||
for (auto& dep : deps) {
|
||||
for (const auto& dep : deps) {
|
||||
dep.copyToAppBundle();
|
||||
changeLibPathsOnFile(dep.getInstallPath());
|
||||
fixRpathsOnFile(dep.getOriginalPath(), dep.getInstallPath());
|
||||
}
|
||||
}
|
||||
// fix up selected files
|
||||
const auto files_to_fix = Settings::filesToFix();
|
||||
for (const auto& file_to_fix : files_to_fix) {
|
||||
changeLibPathsOnFile(file_to_fix);
|
||||
fixRpathsOnFile(file_to_fix, file_to_fix);
|
||||
const auto files = Settings::filesToFix();
|
||||
for (const auto& file : files) {
|
||||
changeLibPathsOnFile(file);
|
||||
fixRpathsOnFile(file, file);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
void addDependency(std::string path, const std::string& dependent_file);
|
||||
void addDependency(const std::string& path, const std::string& dependent_file);
|
||||
|
||||
// std::string searchFilenameInRpaths(const std::string& rpath_file, const std::string& dependent_file);
|
||||
// std::string searchFilenameInRpaths(const std::string& rpath_file);
|
||||
|
|
|
@ -28,7 +28,6 @@ std::string inside_path_str_app = "@executable_path/../Frameworks/";
|
|||
std::string inside_path = inside_path_str;
|
||||
|
||||
std::string app_bundle;
|
||||
bool appBundleProvided() { return !app_bundle.empty(); }
|
||||
std::string appBundle() { return app_bundle; }
|
||||
void appBundle(std::string path)
|
||||
{
|
||||
|
@ -56,6 +55,7 @@ void appBundle(std::string path)
|
|||
if (dest_path[dest_path.size()-1] != '/')
|
||||
dest_path += "/";
|
||||
}
|
||||
bool appBundleProvided() { return !app_bundle.empty(); }
|
||||
|
||||
std::string destFolder() { return dest_path; }
|
||||
void destFolder(std::string path)
|
||||
|
@ -70,6 +70,14 @@ void destFolder(std::string path)
|
|||
dest_path += "/";
|
||||
}
|
||||
|
||||
std::string insideLibPath() { return inside_path; }
|
||||
void insideLibPath(std::string p)
|
||||
{
|
||||
inside_path = std::move(p);
|
||||
if (inside_path[inside_path.size()-1] != '/')
|
||||
inside_path += "/";
|
||||
}
|
||||
|
||||
std::string executableFolder() { return app_bundle + "Contents/MacOS/"; }
|
||||
std::string frameworksFolder() { return app_bundle + "Contents/Frameworks/"; }
|
||||
std::string pluginsFolder() { return app_bundle + "Contents/PlugIns/"; }
|
||||
|
@ -83,18 +91,10 @@ void addFileToFix(std::string path)
|
|||
path = buffer;
|
||||
files.push_back(path);
|
||||
}
|
||||
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; }
|
||||
void insideLibPath(std::string p)
|
||||
{
|
||||
inside_path = std::move(p);
|
||||
if (inside_path[inside_path.size()-1] != '/')
|
||||
inside_path += "/";
|
||||
}
|
||||
|
||||
std::vector<std::string> prefixes_to_ignore;
|
||||
void ignorePrefix(std::string prefix)
|
||||
{
|
||||
|
@ -104,8 +104,8 @@ void ignorePrefix(std::string prefix)
|
|||
}
|
||||
bool isPrefixIgnored(const std::string& prefix)
|
||||
{
|
||||
for (size_t n=0; n<prefixes_to_ignore.size(); n++) {
|
||||
if (prefix == prefixes_to_ignore[n])
|
||||
for (const auto& prefix_to_ignore : prefixes_to_ignore) {
|
||||
if (prefix == prefix_to_ignore)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -127,16 +127,12 @@ bool isPrefixBundled(const std::string& prefix)
|
|||
}
|
||||
|
||||
std::vector<std::string> search_paths;
|
||||
void addSearchPath(const std::string& path) { search_paths.push_back(path); }
|
||||
std::vector<std::string> searchPaths() { return search_paths; }
|
||||
std::string searchPath(const int n) { return search_paths[n]; }
|
||||
size_t searchPathCount() { return search_paths.size(); }
|
||||
void addSearchPath(const std::string& path) { search_paths.push_back(path); }
|
||||
|
||||
std::vector<std::string> user_search_paths;
|
||||
void addUserSearchPath(const std::string& path) { user_search_paths.push_back(path); }
|
||||
std::vector<std::string> userSearchPaths() { return user_search_paths; }
|
||||
std::string userSearchPath(const int n) { return user_search_paths[n]; }
|
||||
size_t userSearchPathCount() { return user_search_paths.size(); }
|
||||
void addUserSearchPath(const std::string& path) { user_search_paths.push_back(path); }
|
||||
|
||||
bool canCreateDir() { return create_dir; }
|
||||
void canCreateDir(bool permission) { create_dir = permission; }
|
||||
|
|
|
@ -16,35 +16,30 @@ bool isPrefixBundled(const std::string& prefix);
|
|||
bool isPrefixIgnored(const std::string& prefix);
|
||||
void ignorePrefix(std::string prefix);
|
||||
|
||||
bool appBundleProvided();
|
||||
std::string appBundle();
|
||||
void appBundle(std::string path);
|
||||
bool appBundleProvided();
|
||||
|
||||
std::string destFolder();
|
||||
void destFolder(std::string path);
|
||||
|
||||
std::string insideLibPath();
|
||||
void insideLibPath(std::string p);
|
||||
|
||||
std::string executableFolder();
|
||||
std::string frameworksFolder();
|
||||
std::string pluginsFolder();
|
||||
std::string resourcesFolder();
|
||||
|
||||
void addFileToFix(std::string path);
|
||||
std::string fileToFix(int n);
|
||||
std::vector<std::string> filesToFix();
|
||||
void addFileToFix(std::string path);
|
||||
size_t filesToFixCount();
|
||||
|
||||
std::string insideLibPath();
|
||||
void insideLibPath(std::string p);
|
||||
|
||||
void addSearchPath(const std::string& path);
|
||||
std::vector<std::string> searchPaths();
|
||||
std::string searchPath(int n);
|
||||
size_t searchPathCount();
|
||||
void addSearchPath(const std::string& path);
|
||||
|
||||
void addUserSearchPath(const std::string& path);
|
||||
std::vector<std::string> userSearchPaths();
|
||||
std::string userSearchPath(int n);
|
||||
size_t userSearchPathCount();
|
||||
void addUserSearchPath(const std::string& path);
|
||||
|
||||
bool canCreateDir();
|
||||
void canCreateDir(bool permission);
|
||||
|
|
|
@ -66,7 +66,8 @@ std::string systemOutput(const std::string& cmd)
|
|||
|
||||
try {
|
||||
command_output = popen(cmd.c_str(), "r");
|
||||
if (command_output == nullptr) throw;
|
||||
if (command_output == nullptr)
|
||||
throw;
|
||||
|
||||
while (amount_read > 0) {
|
||||
amount_read = fread(output, 1, 127, command_output);
|
||||
|
@ -86,7 +87,8 @@ std::string systemOutput(const std::string& cmd)
|
|||
}
|
||||
|
||||
int return_value = pclose(command_output);
|
||||
if (return_value != 0) return "";
|
||||
if (return_value != 0)
|
||||
return "";
|
||||
|
||||
return full_output;
|
||||
}
|
||||
|
@ -253,25 +255,24 @@ void createDestDir()
|
|||
}
|
||||
}
|
||||
|
||||
std::string getUserInputDirForFile(const std::string& filename)
|
||||
std::string getUserInputDirForFile(const std::string& filename, const std::string& dependent_file)
|
||||
{
|
||||
const size_t searchPathCount = Settings::userSearchPathCount();
|
||||
for (size_t n=0; n<searchPathCount; ++n) {
|
||||
auto searchPath = Settings::userSearchPath(n);
|
||||
if (!searchPath.empty() && searchPath[searchPath.size()-1] != '/')
|
||||
searchPath += "/";
|
||||
if (fileExists(searchPath+filename)) {
|
||||
std::vector<std::string> search_paths = Settings::userSearchPaths();
|
||||
for (auto& search_path : search_paths) {
|
||||
if (!search_path.empty() && search_path[search_path.size() - 1] != '/')
|
||||
search_path += "/";
|
||||
if (fileExists(search_path + filename)) {
|
||||
if (!Settings::quietOutput()) {
|
||||
std::cerr << (searchPath+filename) << " was found\n"
|
||||
std::cerr << (search_path + filename) << " was found\n"
|
||||
<< "/!\\ WARNING: dylibbundler MAY NOT CORRECTLY HANDLE THIS DEPENDENCY: Check the executable with 'otool -L'\n";
|
||||
}
|
||||
return searchPath;
|
||||
return search_path;
|
||||
}
|
||||
}
|
||||
|
||||
while (true) {
|
||||
if (Settings::quietOutput())
|
||||
std::cerr << "\n/!\\ WARNING: Dependency " << filename << " has an incomplete name (location unknown)\n";
|
||||
std::cerr << "\n/!\\ WARNING: Dependency " << filename << " of " << dependent_file << " not found\n";
|
||||
std::cout << "\nPlease specify the directory where this file is located (or enter 'quit' to abort): ";
|
||||
fflush(stdout);
|
||||
|
||||
|
@ -432,7 +433,7 @@ std::string searchFilenameInRpaths(const std::string& rpath_file, const std::str
|
|||
std::cout << " ** rpath fullpath: not found" << std::endl;
|
||||
if (!Settings::quietOutput())
|
||||
std::cerr << "\n/!\\ WARNING: Can't get path for '" << rpath_file << "'\n";
|
||||
fullpath = getUserInputDirForFile(suffix) + suffix;
|
||||
fullpath = getUserInputDirForFile(suffix, dependent_file) + suffix;
|
||||
if (Settings::quietOutput() && fullpath.empty())
|
||||
std::cerr << "\n/!\\ WARNING: Can't get path for '" << rpath_file << "'\n";
|
||||
if (realpath(fullpath.c_str(), fullpath_buffer))
|
||||
|
|
|
@ -42,7 +42,7 @@ bool mkdir(const std::string& path);
|
|||
|
||||
void createDestDir();
|
||||
|
||||
std::string getUserInputDirForFile(const std::string& filename);
|
||||
std::string getUserInputDirForFile(const std::string& filename, const std::string& dependent_file);
|
||||
|
||||
void parseLoadCommands(const std::string& file, const std::string& cmd, const std::string& value, std::vector<std::string>& lines);
|
||||
|
||||
|
|
Loading…
Reference in New Issue