code cleanup
This commit is contained in:
parent
ee0c02888a
commit
3d57da2b0e
|
@ -118,9 +118,8 @@ void Dependency::AddSymlink(const std::string& path)
|
|||
bool Dependency::MergeIfIdentical(Dependency& dependency)
|
||||
{
|
||||
if (dependency.OriginalFilename() == filename) {
|
||||
for (const auto& symlink : symlinks) {
|
||||
for (const auto& symlink : symlinks)
|
||||
dependency.AddSymlink(symlink);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -161,22 +160,19 @@ void Dependency::CopyToBundle() const
|
|||
void Dependency::FixDependentFile(const std::string& dependent_file) const
|
||||
{
|
||||
changeInstallName(dependent_file, OriginalPath(), InnerPath());
|
||||
for (const auto& symlink : symlinks) {
|
||||
for (const auto& symlink : symlinks)
|
||||
changeInstallName(dependent_file, symlink, InnerPath());
|
||||
}
|
||||
|
||||
if (Settings::missingPrefixes()) {
|
||||
changeInstallName(dependent_file, filename, InnerPath());
|
||||
for (const auto& symlink : symlinks) {
|
||||
changeInstallName(dependent_file, symlink, InnerPath());
|
||||
}
|
||||
}
|
||||
if (!Settings::missingPrefixes()) return;
|
||||
|
||||
changeInstallName(dependent_file, filename, InnerPath());
|
||||
for (const auto& symlink : symlinks)
|
||||
changeInstallName(dependent_file, symlink, InnerPath());
|
||||
}
|
||||
|
||||
void Dependency::Print() const
|
||||
{
|
||||
std::cout << "\n* " << filename << " from " << prefix << std::endl;
|
||||
for (const auto& symlink : symlinks) {
|
||||
for (const auto& symlink : symlinks)
|
||||
std::cout << " symlink --> " << symlink << std::endl;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ void addDependency(const std::string& path, const std::string& dependent_file)
|
|||
deps_per_file[dependent_file].push_back(dependency);
|
||||
}
|
||||
|
||||
void collectDependencies(const std::string& dependent_file)
|
||||
void collectDependenciesRpaths(const std::string& dependent_file)
|
||||
{
|
||||
if (deps_collected.find(dependent_file) != deps_collected.end() && Settings::fileHasRpath(dependent_file))
|
||||
return;
|
||||
|
@ -92,40 +92,6 @@ void collectDependencies(const std::string& dependent_file)
|
|||
}
|
||||
}
|
||||
|
||||
//void collectDependencies(const std::string& dependent_file, std::vector<std::string>& lines)
|
||||
//{
|
||||
// if (deps_collected.find(dependent_file) == deps_collected.end())
|
||||
// parseLoadCommands(dependent_file, std::string("LC_LOAD_DYLIB"), std::string("name"), lines);
|
||||
//}
|
||||
|
||||
//void collectDependencies(const std::string& dependent_file)
|
||||
//{
|
||||
// std::vector<std::string> lines;
|
||||
// collectDependencies(dependent_file, lines);
|
||||
// collectRpaths(dependent_file);
|
||||
//
|
||||
// for (const auto& line : lines) {
|
||||
// if (!Settings::isPrefixBundled(line))
|
||||
// continue; // skip system/ignored prefixes
|
||||
// addDependency(line, dependent_file);
|
||||
// }
|
||||
// deps_collected[dependent_file] = true;
|
||||
//}
|
||||
|
||||
//void collectRpaths(const std::string& filename)
|
||||
//{
|
||||
// if (!Settings::fileHasRpath(filename)) {
|
||||
// std::vector<std::string> lines;
|
||||
// parseLoadCommands(filename, std::string("LC_RPATH"), std::string("path"), lines);
|
||||
// for (const auto &line : lines) {
|
||||
// rpaths.insert(line);
|
||||
// Settings::addRpathForFile(filename, line);
|
||||
// if (Settings::verboseOutput())
|
||||
// std::cout << " rpath: " << line << std::endl;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
void collectSubDependencies()
|
||||
{
|
||||
size_t dep_counter = deps.size();
|
||||
|
@ -143,18 +109,7 @@ void collectSubDependencies()
|
|||
std::cout << " (collect sub deps) original path: " << original_path << std::endl;
|
||||
if (isRpath(original_path))
|
||||
original_path = searchFilenameInRpaths(original_path);
|
||||
|
||||
// std::vector<std::string> lines;
|
||||
// collectDependencies(original_path, lines);
|
||||
// collectRpaths(original_path);
|
||||
//
|
||||
// for (const auto& line : lines) {
|
||||
// if (!Settings::isPrefixBundled(line))
|
||||
// continue; // skip system/ignored prefixes
|
||||
// addDependency(line, original_path);
|
||||
// }
|
||||
|
||||
collectDependencies(original_path);
|
||||
collectDependenciesRpaths(original_path);
|
||||
}
|
||||
// if no more dependencies were added on this iteration, stop searching
|
||||
if (deps.size() == deps_size)
|
||||
|
@ -174,14 +129,13 @@ void collectSubDependencies()
|
|||
void changeLibPathsOnFile(const std::string& file_to_fix)
|
||||
{
|
||||
if (deps_collected.find(file_to_fix) == deps_collected.end() || rpaths_collected.find(file_to_fix) == rpaths_collected.end())
|
||||
collectDependencies(file_to_fix);
|
||||
collectDependenciesRpaths(file_to_fix);
|
||||
|
||||
std::cout << "* Fixing dependencies on " << file_to_fix << "\n";
|
||||
|
||||
std::vector<Dependency> dependencies = deps_per_file[file_to_fix];
|
||||
for (auto& dependency : dependencies) {
|
||||
for (auto& dependency : dependencies)
|
||||
dependency.FixDependentFile(file_to_fix);
|
||||
}
|
||||
}
|
||||
|
||||
void fixRpathsOnFile(const std::string& original_file, const std::string& file_to_fix)
|
||||
|
@ -204,16 +158,15 @@ void fixRpathsOnFile(const std::string& original_file, const std::string& file_t
|
|||
|
||||
void bundleDependencies()
|
||||
{
|
||||
for (const auto& dep : deps) {
|
||||
for (const auto& dep : deps)
|
||||
dep.Print();
|
||||
}
|
||||
std::cout << "\n";
|
||||
if (Settings::verboseOutput()) {
|
||||
std::cout << "rpaths:" << std::endl;
|
||||
for (const auto& rpath : rpaths) {
|
||||
for (const auto& rpath : rpaths)
|
||||
std::cout << "* " << rpath << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// copy & fix up dependencies
|
||||
if (Settings::bundleLibs()) {
|
||||
createDestDir();
|
||||
|
@ -294,7 +247,7 @@ void bundleQtPlugins()
|
|||
std::vector<std::string> files = lsDir(dest + plugin+"/");
|
||||
for (const auto& file : files) {
|
||||
Settings::addFileToFix(dest + plugin+"/"+file);
|
||||
collectDependencies(dest + plugin + "/" + file);
|
||||
collectDependenciesRpaths(dest + plugin + "/" + file);
|
||||
changeId(dest + plugin+"/"+file, "@rpath/" + plugin+"/"+file);
|
||||
}
|
||||
}
|
||||
|
@ -309,7 +262,7 @@ void bundleQtPlugins()
|
|||
mkdir(dest + "platforms");
|
||||
copyFile(qt_plugins_prefix + "platforms/libqcocoa.dylib", dest + "platforms");
|
||||
Settings::addFileToFix(dest + "platforms/libqcocoa.dylib");
|
||||
collectDependencies(dest + "platforms/libqcocoa.dylib");
|
||||
collectDependenciesRpaths(dest + "platforms/libqcocoa.dylib");
|
||||
|
||||
fixupPlugin("printsupport");
|
||||
fixupPlugin("styles");
|
||||
|
|
|
@ -7,21 +7,11 @@
|
|||
#include <vector>
|
||||
|
||||
void addDependency(const std::string& path, const std::string& dependent_file);
|
||||
|
||||
// fill |lines| with dependencies of |dependent_file|
|
||||
//void collectDependencies(const std::string& dependent_file, std::vector<std::string>& lines);
|
||||
void collectDependencies(const std::string& dependent_file);
|
||||
|
||||
//void collectRpaths(const std::string& filename);
|
||||
|
||||
// recursively collect each dependency's dependencies
|
||||
void collectDependenciesRpaths(const std::string& dependent_file);
|
||||
void collectSubDependencies();
|
||||
|
||||
void changeLibPathsOnFile(const std::string& file_to_fix);
|
||||
void fixRpathsOnFile(const std::string& original_file, const std::string& file_to_fix);
|
||||
|
||||
void bundleDependencies();
|
||||
|
||||
void bundleQtPlugins();
|
||||
|
||||
#endif
|
||||
|
|
|
@ -7,9 +7,7 @@
|
|||
#include <regex>
|
||||
#include <sstream>
|
||||
|
||||
// #include <stdio.h>
|
||||
#include <sys/param.h>
|
||||
// #include <sys/stat.h>
|
||||
#ifndef __clang__
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
@ -315,40 +313,6 @@ void otool(const std::string& flags, const std::string& file, std::vector<std::s
|
|||
tokenize(output, "\n", &lines);
|
||||
}
|
||||
|
||||
void parseLoadCommands(const std::string& file, const std::string& cmd, const std::string& value, std::vector<std::string>& lines)
|
||||
{
|
||||
std::vector<std::string> raw_lines;
|
||||
otool("-l", file, raw_lines);
|
||||
|
||||
bool searching = false;
|
||||
std::string cmd_line = std::string("cmd ") + cmd;
|
||||
std::string value_line = std::string(value + std::string(" "));
|
||||
for (const auto& raw_line : raw_lines) {
|
||||
if (raw_line.find(cmd_line) != std::string::npos) {
|
||||
if (searching) {
|
||||
std::cerr << "\n\n/!\\ ERROR: Failed to find " << value << " before next cmd\n";
|
||||
exit(1);
|
||||
}
|
||||
searching = true;
|
||||
}
|
||||
else if (searching) {
|
||||
size_t start_pos = raw_line.find(value_line);
|
||||
if (start_pos == std::string::npos)
|
||||
continue;
|
||||
size_t start = start_pos + value.size() + 1; // exclude data label "|value| "
|
||||
size_t end = std::string::npos;
|
||||
if (value == "name" || value == "path") {
|
||||
size_t end_pos = raw_line.find(" (");
|
||||
if (end_pos == std::string::npos)
|
||||
continue;
|
||||
end = end_pos - start;
|
||||
}
|
||||
lines.push_back(raw_line.substr(start, end));
|
||||
searching = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void parseLoadCommands(const std::string& file, const std::map<std::string,std::string>& cmds_values, std::map<std::string,std::vector<std::string>>& cmds_results)
|
||||
{
|
||||
std::vector<std::string> raw_lines;
|
||||
|
|
|
@ -46,7 +46,6 @@ void createDestDir();
|
|||
std::string getUserInputDirForFile(const std::string& filename, const std::string& dependent_file);
|
||||
|
||||
void otool(const std::string& flags, const std::string& file, std::vector<std::string>& lines);
|
||||
void parseLoadCommands(const std::string& file, const std::string& cmd, const std::string& value, std::vector<std::string>& lines);
|
||||
void parseLoadCommands(const std::string& file, const std::map<std::string,std::string>& cmds_values, std::map<std::string,std::vector<std::string>>& cmds_results);
|
||||
|
||||
std::string searchFilenameInRpaths(const std::string& rpath_file, const std::string& dependent_file);
|
||||
|
|
|
@ -125,9 +125,8 @@ int main(int argc, const char* argv[])
|
|||
std::cout << "Collecting dependencies...\n";
|
||||
|
||||
const std::vector<std::string> files_to_fix = Settings::filesToFix();
|
||||
for (const auto& file_to_fix : files_to_fix) {
|
||||
collectDependencies(file_to_fix);
|
||||
}
|
||||
for (const auto& file_to_fix : files_to_fix)
|
||||
collectDependenciesRpaths(file_to_fix);
|
||||
collectSubDependencies();
|
||||
bundleDependencies();
|
||||
|
||||
|
|
Loading…
Reference in New Issue