refine using clang-tidy suggestions
This commit is contained in:
parent
e5849e59b9
commit
577c3206d1
|
@ -1,27 +1,19 @@
|
||||||
#include "Dependency.h"
|
#include "Dependency.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cctype>
|
|
||||||
#include <cstdio>
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <locale>
|
|
||||||
#include <sstream>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
// #include <stdlib.h>
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
// #include <sys/stat.h>
|
|
||||||
#ifndef __clang__
|
#ifndef __clang__
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#endif
|
#endif
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
|
||||||
Dependency::Dependency(std::string path, std::string dependent_file) : is_framework(false)
|
Dependency::Dependency(std::string path, const std::string& dependent_file) : is_framework(false)
|
||||||
{
|
{
|
||||||
char original_file_buffer[PATH_MAX];
|
char original_file_buffer[PATH_MAX];
|
||||||
std::string original_file;
|
std::string original_file;
|
||||||
|
@ -60,8 +52,7 @@ Dependency::Dependency(std::string path, std::string dependent_file) : is_framew
|
||||||
prefix += "/";
|
prefix += "/";
|
||||||
|
|
||||||
// check if this dependency is in /usr/lib, /System/Library, or in ignored list
|
// check if this dependency is in /usr/lib, /System/Library, or in ignored list
|
||||||
if (!Settings::isPrefixBundled(prefix))
|
if (!Settings::isPrefixBundled(prefix)) return;
|
||||||
return;
|
|
||||||
|
|
||||||
if (original_file.find(".framework") != std::string::npos) {
|
if (original_file.find(".framework") != std::string::npos) {
|
||||||
is_framework = true;
|
is_framework = true;
|
||||||
|
@ -71,9 +62,9 @@ Dependency::Dependency(std::string path, std::string dependent_file) : is_framew
|
||||||
prefix = filePrefix(framework_root);
|
prefix = filePrefix(framework_root);
|
||||||
filename = framework_name + "/" + framework_path;
|
filename = framework_name + "/" + framework_path;
|
||||||
if (Settings::verboseOutput()) {
|
if (Settings::verboseOutput()) {
|
||||||
std::cout << "framework root: " << framework_root << std::endl;
|
std::cout << " framework root: " << framework_root << std::endl;
|
||||||
std::cout << "framework path: " << framework_path << std::endl;
|
std::cout << " framework path: " << framework_path << std::endl;
|
||||||
std::cout << "framework name: " << framework_name << std::endl;
|
std::cout << " framework name: " << framework_name << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,17 +104,25 @@ Dependency::Dependency(std::string path, std::string dependent_file) : is_framew
|
||||||
new_name = filename;
|
new_name = filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Dependency::getInstallPath()
|
std::string Dependency::getInstallPath() const
|
||||||
{
|
{
|
||||||
return Settings::destFolder() + new_name;
|
return Settings::destFolder() + new_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Dependency::getInnerPath()
|
std::string Dependency::getInnerPath() const
|
||||||
{
|
{
|
||||||
return Settings::insideLibPath() + new_name;
|
return Settings::insideLibPath() + new_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dependency::addSymlink(std::string s)
|
void Dependency::print() const
|
||||||
|
{
|
||||||
|
std::cout << "\n* " << filename << " from " << prefix << std::endl;
|
||||||
|
for (const auto& symlink : symlinks) {
|
||||||
|
std::cout << " symlink --> " << symlink << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Dependency::addSymlink(const std::string& s)
|
||||||
{
|
{
|
||||||
if (std::find(symlinks.begin(), symlinks.end(), s) == symlinks.end())
|
if (std::find(symlinks.begin(), symlinks.end(), s) == symlinks.end())
|
||||||
symlinks.push_back(s);
|
symlinks.push_back(s);
|
||||||
|
@ -131,25 +130,16 @@ void Dependency::addSymlink(std::string s)
|
||||||
|
|
||||||
bool Dependency::mergeIfSameAs(Dependency& dep2)
|
bool Dependency::mergeIfSameAs(Dependency& dep2)
|
||||||
{
|
{
|
||||||
if (dep2.getOriginalFileName().compare(filename) == 0) {
|
if (dep2.getOriginalFileName() == filename) {
|
||||||
for (size_t n=0; n<symlinks.size(); ++n) {
|
for (const auto& symlink : symlinks) {
|
||||||
dep2.addSymlink(symlinks[n]);
|
dep2.addSymlink(symlink);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dependency::print()
|
void Dependency::copyToAppBundle() const
|
||||||
{
|
|
||||||
std::cout << "\n* " << filename << " from " << prefix << std::endl;
|
|
||||||
|
|
||||||
for (size_t n=0; n<symlinks.size(); ++n) {
|
|
||||||
std::cout << " symlink --> " << symlinks[n] << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Dependency::copyYourself()
|
|
||||||
{
|
{
|
||||||
std::string original_path = getOriginalPath();
|
std::string original_path = getOriginalPath();
|
||||||
std::string dest_path = getInstallPath();
|
std::string dest_path = getInstallPath();
|
||||||
|
@ -161,10 +151,10 @@ void Dependency::copyYourself()
|
||||||
|
|
||||||
if (Settings::verboseOutput()) {
|
if (Settings::verboseOutput()) {
|
||||||
std::string inner_path = getInnerPath();
|
std::string inner_path = getInnerPath();
|
||||||
std::cout << "original path: " << original_path << std::endl;
|
std::cout << " - original path: " << original_path << std::endl;
|
||||||
std::cout << "inner path: " << inner_path << std::endl;
|
std::cout << " - inner path: " << inner_path << std::endl;
|
||||||
std::cout << "dest_path: " << dest_path << std::endl;
|
std::cout << " - dest_path: " << dest_path << std::endl;
|
||||||
std::cout << "install path: " << getInstallPath() << std::endl;
|
std::cout << " - install path: " << getInstallPath() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
copyFile(original_path, dest_path);
|
copyFile(original_path, dest_path);
|
||||||
|
@ -172,13 +162,8 @@ void Dependency::copyYourself()
|
||||||
if (is_framework) {
|
if (is_framework) {
|
||||||
std::string headers_path = dest_path + std::string("/Headers");
|
std::string headers_path = dest_path + std::string("/Headers");
|
||||||
char buffer[PATH_MAX];
|
char buffer[PATH_MAX];
|
||||||
|
|
||||||
if (realpath(rtrim(headers_path).c_str(), buffer))
|
if (realpath(rtrim(headers_path).c_str(), buffer))
|
||||||
headers_path = buffer;
|
headers_path = buffer;
|
||||||
|
|
||||||
if (Settings::verboseOutput())
|
|
||||||
std::cout << "headers path: " << headers_path << std::endl;
|
|
||||||
|
|
||||||
deleteFile(headers_path, true);
|
deleteFile(headers_path, true);
|
||||||
deleteFile(dest_path + "/*.prl");
|
deleteFile(dest_path + "/*.prl");
|
||||||
}
|
}
|
||||||
|
@ -186,17 +171,17 @@ void Dependency::copyYourself()
|
||||||
changeId(getInstallPath(), "@rpath/"+new_name);
|
changeId(getInstallPath(), "@rpath/"+new_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dependency::fixFileThatDependsOnMe(std::string file_to_fix)
|
void Dependency::fixDependentFiles(const std::string& file) const
|
||||||
{
|
{
|
||||||
changeInstallName(file_to_fix, getOriginalPath(), getInnerPath());
|
changeInstallName(file, getOriginalPath(), getInnerPath());
|
||||||
for (size_t n=0; n<symlinks.size(); ++n) {
|
for (const auto& symlink : symlinks) {
|
||||||
changeInstallName(file_to_fix, symlinks[n], getInnerPath());
|
changeInstallName(file, symlink, getInnerPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings::missingPrefixes()) {
|
if (Settings::missingPrefixes()) {
|
||||||
changeInstallName(file_to_fix, filename, getInnerPath());
|
changeInstallName(file, filename, getInnerPath());
|
||||||
for (size_t n=0; n<symlinks.size(); ++n) {
|
for (const auto& symlink : symlinks) {
|
||||||
changeInstallName(file_to_fix, symlinks[n], getInnerPath());
|
changeInstallName(file, symlink, getInnerPath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,30 +8,27 @@
|
||||||
|
|
||||||
class Dependency {
|
class Dependency {
|
||||||
public:
|
public:
|
||||||
Dependency(std::string path, std::string dependent_file);
|
Dependency(std::string path, const std::string& dependent_file);
|
||||||
|
|
||||||
std::string getOriginalFileName() const { return filename; }
|
[[nodiscard]] bool isFramework() const { return is_framework; }
|
||||||
std::string getOriginalPath() const { return prefix + filename; }
|
|
||||||
|
|
||||||
std::string getInstallPath();
|
[[nodiscard]] std::string getPrefix() const { return prefix; }
|
||||||
std::string getInnerPath();
|
[[nodiscard]] std::string getOriginalFileName() const { return filename; }
|
||||||
|
[[nodiscard]] std::string getOriginalPath() const { return prefix + filename; }
|
||||||
|
|
||||||
bool isFramework() { return is_framework; }
|
[[nodiscard]] std::string getInstallPath() const;
|
||||||
|
[[nodiscard]] std::string getInnerPath() const;
|
||||||
|
|
||||||
void addSymlink(std::string s);
|
void print() const;
|
||||||
size_t symlinksCount() const { return symlinks.size(); }
|
|
||||||
|
|
||||||
std::string getSymlink(int i) const { return symlinks[i]; }
|
void addSymlink(const std::string& s);
|
||||||
std::string getPrefix() const { return prefix; }
|
|
||||||
|
|
||||||
// Compare the given dependency with this one. If both refer to the same file,
|
// Compare the given dependency with this one. If both refer to the same file,
|
||||||
// merge both entries into one and return true.
|
// merge both entries into one and return true.
|
||||||
bool mergeIfSameAs(Dependency& dep2);
|
bool mergeIfSameAs(Dependency& dep2);
|
||||||
|
|
||||||
void print();
|
void copyToAppBundle() const;
|
||||||
|
void fixDependentFiles(const std::string& file) const;
|
||||||
void copyYourself();
|
|
||||||
void fixFileThatDependsOnMe(std::string file);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool is_framework;
|
bool is_framework;
|
||||||
|
@ -43,6 +40,8 @@ private:
|
||||||
|
|
||||||
// installation
|
// installation
|
||||||
std::string new_name;
|
std::string new_name;
|
||||||
|
|
||||||
|
void print();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
#include "DylibBundler.h"
|
#include "DylibBundler.h"
|
||||||
|
|
||||||
#include <cstdio>
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#ifdef __linux
|
#ifdef __linux
|
||||||
#include <linux/limits.h>
|
#include <linux/limits.h>
|
||||||
|
@ -25,34 +25,31 @@ std::set<std::string> frameworks;
|
||||||
std::set<std::string> rpaths;
|
std::set<std::string> rpaths;
|
||||||
bool qt_plugins_called = false;
|
bool qt_plugins_called = false;
|
||||||
|
|
||||||
void addDependency(std::string path, std::string dependent_file)
|
void addDependency(std::string path, const std::string& dependent_file)
|
||||||
{
|
{
|
||||||
Dependency dep(path, dependent_file);
|
Dependency dep(std::move(path), dependent_file);
|
||||||
|
|
||||||
// check if this library was already added to |deps| to avoid duplicates
|
// check if this library was already added to |deps| to avoid duplicates
|
||||||
bool in_deps = false;
|
bool in_deps = false;
|
||||||
for (size_t n=0; n<deps.size(); ++n) {
|
for (auto& n : deps) {
|
||||||
if (dep.mergeIfSameAs(deps[n]))
|
if (dep.mergeIfSameAs(n))
|
||||||
in_deps = true;
|
in_deps = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if this library was already added to |deps_per_file[dependent_file]| to avoid duplicates
|
// check if this library was already added to |deps_per_file[dependent_file]| to avoid duplicates
|
||||||
bool in_deps_per_file = false;
|
bool in_deps_per_file = false;
|
||||||
for (size_t n=0; n<deps_per_file[dependent_file].size(); ++n) {
|
for (auto& n : deps_per_file[dependent_file]) {
|
||||||
if (dep.mergeIfSameAs(deps_per_file[dependent_file][n]))
|
if (dep.mergeIfSameAs(n))
|
||||||
in_deps_per_file = true;
|
in_deps_per_file = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if this library is in /usr/lib, /System/Library, or in ignored list
|
// check if this library is in /usr/lib, /System/Library, or in ignored list
|
||||||
if (!Settings::isPrefixBundled(dep.getPrefix()))
|
if (!Settings::isPrefixBundled(dep.getPrefix())) return;
|
||||||
return;
|
|
||||||
|
|
||||||
if (!in_deps && dep.isFramework())
|
if (!in_deps && dep.isFramework())
|
||||||
frameworks.insert(dep.getOriginalPath());
|
frameworks.insert(dep.getOriginalPath());
|
||||||
|
|
||||||
if (!in_deps)
|
if (!in_deps)
|
||||||
deps.push_back(dep);
|
deps.push_back(dep);
|
||||||
|
|
||||||
if (!in_deps_per_file)
|
if (!in_deps_per_file)
|
||||||
deps_per_file[dependent_file].push_back(dep);
|
deps_per_file[dependent_file].push_back(dep);
|
||||||
}
|
}
|
||||||
|
@ -74,10 +71,9 @@ void collectDependenciesForFile(const std::string& dependent_file)
|
||||||
collectDependenciesForFile(dependent_file, lines);
|
collectDependenciesForFile(dependent_file, lines);
|
||||||
collectRpathsForFilename(dependent_file);
|
collectRpathsForFilename(dependent_file);
|
||||||
|
|
||||||
for (size_t i=0; i<lines.size(); ++i) {
|
for (const auto& line : lines) {
|
||||||
if (!Settings::isPrefixBundled(lines[i]))
|
if (!Settings::isPrefixBundled(line)) continue; // skip system/ignored prefixes
|
||||||
continue; // skip system/ignored prefixes
|
addDependency(line, dependent_file);
|
||||||
addDependency(lines[i], dependent_file);
|
|
||||||
}
|
}
|
||||||
deps_collected[dependent_file] = true;
|
deps_collected[dependent_file] = true;
|
||||||
}
|
}
|
||||||
|
@ -122,16 +118,13 @@ void collectSubDependencies()
|
||||||
collectDependenciesForFile(original_path, lines);
|
collectDependenciesForFile(original_path, lines);
|
||||||
collectRpathsForFilename(original_path);
|
collectRpathsForFilename(original_path);
|
||||||
|
|
||||||
for (size_t i=0; i<lines.size(); ++i) {
|
for (const auto& line : lines) {
|
||||||
if (!Settings::isPrefixBundled(lines[i]))
|
if (!Settings::isPrefixBundled(line)) continue; // skip system/ignored prefixes
|
||||||
continue; // skip system/ignored prefixes
|
addDependency(line, original_path);
|
||||||
addDependency(lines[i], original_path);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if no more dependencies were added on this iteration, stop searching
|
// if no more dependencies were added on this iteration, stop searching
|
||||||
if (deps.size() == deps_size) {
|
if (deps.size() == deps_size) break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings::verboseOutput()) {
|
if (Settings::verboseOutput()) {
|
||||||
|
@ -140,11 +133,11 @@ void collectSubDependencies()
|
||||||
}
|
}
|
||||||
if (Settings::bundleLibs() && Settings::bundleFrameworks()) {
|
if (Settings::bundleLibs() && Settings::bundleFrameworks()) {
|
||||||
if (!qt_plugins_called || (deps.size() != dep_counter))
|
if (!qt_plugins_called || (deps.size() != dep_counter))
|
||||||
copyQtPlugins();
|
bundleQtPlugins();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void changeLibPathsOnFile(std::string file_to_fix)
|
void changeLibPathsOnFile(const std::string& file_to_fix)
|
||||||
{
|
{
|
||||||
if (deps_collected.find(file_to_fix) == deps_collected.end())
|
if (deps_collected.find(file_to_fix) == deps_collected.end())
|
||||||
collectDependenciesForFile(file_to_fix);
|
collectDependenciesForFile(file_to_fix);
|
||||||
|
@ -153,7 +146,7 @@ void changeLibPathsOnFile(std::string file_to_fix)
|
||||||
|
|
||||||
const size_t dep_amount = deps_per_file[file_to_fix].size();
|
const size_t dep_amount = deps_per_file[file_to_fix].size();
|
||||||
for (size_t n=0; n<dep_amount; ++n) {
|
for (size_t n=0; n<dep_amount; ++n) {
|
||||||
deps_per_file[file_to_fix][n].fixFileThatDependsOnMe(file_to_fix);
|
deps_per_file[file_to_fix][n].fixDependentFiles(file_to_fix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,12 +156,9 @@ void fixRpathsOnFile(const std::string& original_file, const std::string& file_t
|
||||||
if (Settings::fileHasRpath(original_file))
|
if (Settings::fileHasRpath(original_file))
|
||||||
rpaths_to_fix = Settings::getRpathsForFile(original_file);
|
rpaths_to_fix = Settings::getRpathsForFile(original_file);
|
||||||
|
|
||||||
for (size_t i=0; i < rpaths_to_fix.size(); ++i) {
|
for (const auto& i : rpaths_to_fix) {
|
||||||
std::string command =
|
std::string command = std::string("install_name_tool -rpath ");
|
||||||
std::string("install_name_tool -rpath ")
|
command += i + " " + Settings::insideLibPath() + " " + file_to_fix;
|
||||||
+ rpaths_to_fix[i] + " "
|
|
||||||
+ Settings::insideLibPath() + " "
|
|
||||||
+ file_to_fix;
|
|
||||||
if (systemp(command) != 0) {
|
if (systemp(command) != 0) {
|
||||||
std::cerr << "\n\n/!\\ ERROR: An error occured while trying to fix dependencies of " << file_to_fix << "\n";
|
std::cerr << "\n\n/!\\ ERROR: An error occured while trying to fix dependencies of " << file_to_fix << "\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -176,36 +166,35 @@ void fixRpathsOnFile(const std::string& original_file, const std::string& file_t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void doneWithDeps_go()
|
void bundleDependencies()
|
||||||
{
|
{
|
||||||
const size_t deps_size = deps.size();
|
for (const auto& dep : deps) {
|
||||||
for (size_t n=0; n<deps_size; ++n) {
|
dep.print();
|
||||||
deps[n].print();
|
|
||||||
}
|
}
|
||||||
std::cout << "\n";
|
std::cout << "\n";
|
||||||
if (Settings::verboseOutput()) {
|
if (Settings::verboseOutput()) {
|
||||||
for (std::set<std::string>::iterator it = rpaths.begin(); it != rpaths.end(); ++it) {
|
for (const auto& rpath : rpaths) {
|
||||||
std::cout << "rpaths: " << *it << std::endl;
|
std::cout << "rpaths: " << rpath << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// copy & fix up dependencies
|
// copy & fix up dependencies
|
||||||
if (Settings::bundleLibs()) {
|
if (Settings::bundleLibs()) {
|
||||||
createDestDir();
|
createDestDir();
|
||||||
for (size_t n=0; n<deps_size; ++n) {
|
for (auto& dep : deps) {
|
||||||
deps[n].copyYourself();
|
dep.copyToAppBundle();
|
||||||
changeLibPathsOnFile(deps[n].getInstallPath());
|
changeLibPathsOnFile(dep.getInstallPath());
|
||||||
fixRpathsOnFile(deps[n].getOriginalPath(), deps[n].getInstallPath());
|
fixRpathsOnFile(dep.getOriginalPath(), dep.getInstallPath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// fix up selected files
|
// fix up selected files
|
||||||
const size_t filesToFixSize = Settings::filesToFix().size();
|
const auto files_to_fix = Settings::filesToFix();
|
||||||
for (size_t j=0; j<filesToFixSize; ++j) {
|
for (const auto& file_to_fix : files_to_fix) {
|
||||||
changeLibPathsOnFile(Settings::fileToFix(j));
|
changeLibPathsOnFile(file_to_fix);
|
||||||
fixRpathsOnFile(Settings::fileToFix(j), Settings::fileToFix(j));
|
fixRpathsOnFile(file_to_fix, file_to_fix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void copyQtPlugins()
|
void bundleQtPlugins()
|
||||||
{
|
{
|
||||||
bool qtCoreFound = false;
|
bool qtCoreFound = false;
|
||||||
bool qtGuiFound = false;
|
bool qtGuiFound = false;
|
||||||
|
@ -221,12 +210,13 @@ void copyQtPlugins()
|
||||||
bool qtWebViewFound = false;
|
bool qtWebViewFound = false;
|
||||||
std::string original_file;
|
std::string original_file;
|
||||||
|
|
||||||
for (std::set<std::string>::iterator it = frameworks.begin(); it != frameworks.end(); ++it) {
|
for (const auto& framework : frameworks) {
|
||||||
std::string framework = *it;
|
|
||||||
if (framework.find("QtCore") != std::string::npos) {
|
if (framework.find("QtCore") != std::string::npos) {
|
||||||
qtCoreFound = true;
|
qtCoreFound = true;
|
||||||
original_file = framework;
|
original_file = framework;
|
||||||
}
|
}
|
||||||
|
if (framework.find("QtGui") != std::string::npos)
|
||||||
|
qtGuiFound = true;
|
||||||
if (framework.find("QtNetwork") != std::string::npos)
|
if (framework.find("QtNetwork") != std::string::npos)
|
||||||
qtNetworkFound = true;
|
qtNetworkFound = true;
|
||||||
if (framework.find("QtSql") != std::string::npos)
|
if (framework.find("QtSql") != std::string::npos)
|
||||||
|
@ -255,7 +245,7 @@ void copyQtPlugins()
|
||||||
createQtConf(Settings::resourcesFolder());
|
createQtConf(Settings::resourcesFolder());
|
||||||
qt_plugins_called = true;
|
qt_plugins_called = true;
|
||||||
|
|
||||||
const auto fixupPlugin = [original_file](std::string plugin) {
|
const auto fixupPlugin = [original_file](const std::string& plugin) {
|
||||||
std::string dest = Settings::pluginsFolder();
|
std::string dest = Settings::pluginsFolder();
|
||||||
std::string framework_root = getFrameworkRoot(original_file);
|
std::string framework_root = getFrameworkRoot(original_file);
|
||||||
std::string prefix = filePrefix(framework_root);
|
std::string prefix = filePrefix(framework_root);
|
||||||
|
@ -316,5 +306,6 @@ void copyQtPlugins()
|
||||||
fixupPlugin("texttospeech");
|
fixupPlugin("texttospeech");
|
||||||
if (qtWebViewFound)
|
if (qtWebViewFound)
|
||||||
fixupPlugin("webview");
|
fixupPlugin("webview");
|
||||||
|
|
||||||
collectSubDependencies();
|
collectSubDependencies();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
void addDependency(std::string path, std::string dependent_file);
|
void addDependency(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, const std::string& dependent_file);
|
||||||
// std::string searchFilenameInRpaths(const std::string& rpath_file);
|
// std::string searchFilenameInRpaths(const std::string& rpath_file);
|
||||||
|
@ -22,11 +22,11 @@ void collectRpathsForFilename(const std::string& filename);
|
||||||
// recursively collect each dependency's dependencies
|
// recursively collect each dependency's dependencies
|
||||||
void collectSubDependencies();
|
void collectSubDependencies();
|
||||||
|
|
||||||
void changeLibPathsOnFile(std::string file_to_fix);
|
void changeLibPathsOnFile(const std::string& file_to_fix);
|
||||||
void fixRpathsOnFile(const std::string& original_file, const std::string& file_to_fix);
|
void fixRpathsOnFile(const std::string& original_file, const std::string& file_to_fix);
|
||||||
|
|
||||||
void doneWithDeps_go();
|
void bundleDependencies();
|
||||||
|
|
||||||
void copyQtPlugins();
|
void bundleQtPlugins();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
|
||||||
|
@ -31,7 +32,7 @@ bool appBundleProvided() { return !app_bundle.empty(); }
|
||||||
std::string appBundle() { return app_bundle; }
|
std::string appBundle() { return app_bundle; }
|
||||||
void appBundle(std::string path)
|
void appBundle(std::string path)
|
||||||
{
|
{
|
||||||
app_bundle = path;
|
app_bundle = std::move(path);
|
||||||
char buffer[PATH_MAX];
|
char buffer[PATH_MAX];
|
||||||
if (realpath(app_bundle.c_str(), buffer))
|
if (realpath(app_bundle.c_str(), buffer))
|
||||||
app_bundle = buffer;
|
app_bundle = buffer;
|
||||||
|
@ -59,7 +60,7 @@ void appBundle(std::string path)
|
||||||
std::string destFolder() { return dest_path; }
|
std::string destFolder() { return dest_path; }
|
||||||
void destFolder(std::string path)
|
void destFolder(std::string path)
|
||||||
{
|
{
|
||||||
dest_path = path;
|
dest_path = std::move(path);
|
||||||
if (appBundleProvided())
|
if (appBundleProvided())
|
||||||
dest_path = app_bundle + "Contents/" + stripLSlash(dest_folder);
|
dest_path = app_bundle + "Contents/" + stripLSlash(dest_folder);
|
||||||
char buffer[PATH_MAX];
|
char buffer[PATH_MAX];
|
||||||
|
@ -89,7 +90,7 @@ size_t filesToFixCount() { return files.size(); }
|
||||||
std::string insideLibPath() { return inside_path; }
|
std::string insideLibPath() { return inside_path; }
|
||||||
void insideLibPath(std::string p)
|
void insideLibPath(std::string p)
|
||||||
{
|
{
|
||||||
inside_path = p;
|
inside_path = std::move(p);
|
||||||
if (inside_path[inside_path.size()-1] != '/')
|
if (inside_path[inside_path.size()-1] != '/')
|
||||||
inside_path += "/";
|
inside_path += "/";
|
||||||
}
|
}
|
||||||
|
@ -101,16 +102,16 @@ void ignorePrefix(std::string prefix)
|
||||||
prefix += "/";
|
prefix += "/";
|
||||||
prefixes_to_ignore.push_back(prefix);
|
prefixes_to_ignore.push_back(prefix);
|
||||||
}
|
}
|
||||||
bool isPrefixIgnored(std::string prefix)
|
bool isPrefixIgnored(const std::string& prefix)
|
||||||
{
|
{
|
||||||
for (size_t n=0; n<prefixes_to_ignore.size(); n++) {
|
for (size_t n=0; n<prefixes_to_ignore.size(); n++) {
|
||||||
if (prefix.compare(prefixes_to_ignore[n]) == 0)
|
if (prefix == prefixes_to_ignore[n])
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isPrefixBundled(std::string prefix)
|
bool isPrefixBundled(const std::string& prefix)
|
||||||
{
|
{
|
||||||
if (!bundle_frameworks && prefix.find(".framework") != std::string::npos)
|
if (!bundle_frameworks && prefix.find(".framework") != std::string::npos)
|
||||||
return false;
|
return false;
|
||||||
|
@ -125,15 +126,17 @@ bool isPrefixBundled(std::string prefix)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> searchPaths;
|
std::vector<std::string> search_paths;
|
||||||
void addSearchPath(std::string path) { searchPaths.push_back(path); }
|
void addSearchPath(const std::string& path) { search_paths.push_back(path); }
|
||||||
std::string searchPath(const int n) { return searchPaths[n]; }
|
std::vector<std::string> searchPaths() { return search_paths; }
|
||||||
size_t searchPathCount() { return searchPaths.size(); }
|
std::string searchPath(const int n) { return search_paths[n]; }
|
||||||
|
size_t searchPathCount() { return search_paths.size(); }
|
||||||
|
|
||||||
std::vector<std::string> userSearchPaths;
|
std::vector<std::string> user_search_paths;
|
||||||
void addUserSearchPath(std::string path) { userSearchPaths.push_back(path); }
|
void addUserSearchPath(const std::string& path) { user_search_paths.push_back(path); }
|
||||||
std::string userSearchPath(const int n) { return userSearchPaths[n]; }
|
std::vector<std::string> userSearchPaths() { return user_search_paths; }
|
||||||
size_t userSearchPathCount() { return userSearchPaths.size(); }
|
std::string userSearchPath(const int n) { return user_search_paths[n]; }
|
||||||
|
size_t userSearchPathCount() { return user_search_paths.size(); }
|
||||||
|
|
||||||
bool canCreateDir() { return create_dir; }
|
bool canCreateDir() { return create_dir; }
|
||||||
void canCreateDir(bool permission) { create_dir = permission; }
|
void canCreateDir(bool permission) { create_dir = permission; }
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
|
|
||||||
namespace Settings {
|
namespace Settings {
|
||||||
|
|
||||||
bool isPrefixBundled(std::string prefix);
|
bool isPrefixBundled(const std::string& prefix);
|
||||||
bool isPrefixIgnored(std::string prefix);
|
bool isPrefixIgnored(const std::string& prefix);
|
||||||
void ignorePrefix(std::string prefix);
|
void ignorePrefix(std::string prefix);
|
||||||
|
|
||||||
bool appBundleProvided();
|
bool appBundleProvided();
|
||||||
|
@ -36,11 +36,13 @@ size_t filesToFixCount();
|
||||||
std::string insideLibPath();
|
std::string insideLibPath();
|
||||||
void insideLibPath(std::string p);
|
void insideLibPath(std::string p);
|
||||||
|
|
||||||
void addSearchPath(std::string path);
|
void addSearchPath(const std::string& path);
|
||||||
|
std::vector<std::string> searchPaths();
|
||||||
std::string searchPath(int n);
|
std::string searchPath(int n);
|
||||||
size_t searchPathCount();
|
size_t searchPathCount();
|
||||||
|
|
||||||
void addUserSearchPath(std::string path);
|
void addUserSearchPath(const std::string& path);
|
||||||
|
std::vector<std::string> userSearchPaths();
|
||||||
std::string userSearchPath(int n);
|
std::string userSearchPath(int n);
|
||||||
size_t userSearchPathCount();
|
size_t userSearchPathCount();
|
||||||
|
|
||||||
|
@ -79,5 +81,3 @@ bool fileHasRpath(const std::string& file);
|
||||||
} // namespace Settings
|
} // namespace Settings
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::string stripLSlash(const std::string& in);
|
|
||||||
|
|
|
@ -19,12 +19,12 @@
|
||||||
|
|
||||||
std::string filePrefix(const std::string& in)
|
std::string filePrefix(const std::string& in)
|
||||||
{
|
{
|
||||||
return in.substr(0, in.rfind("/")+1);
|
return in.substr(0, in.rfind('/')+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string stripPrefix(const std::string& in)
|
std::string stripPrefix(const std::string& in)
|
||||||
{
|
{
|
||||||
return in.substr(in.rfind("/")+1);
|
return in.substr(in.rfind('/')+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getFrameworkRoot(const std::string& in)
|
std::string getFrameworkRoot(const std::string& in)
|
||||||
|
@ -59,15 +59,14 @@ std::string rtrim(std::string s)
|
||||||
|
|
||||||
std::string systemOutput(const std::string& cmd)
|
std::string systemOutput(const std::string& cmd)
|
||||||
{
|
{
|
||||||
FILE* command_output;
|
FILE *command_output = nullptr;
|
||||||
char output[128];
|
char output[128];
|
||||||
int amount_read = 1;
|
int amount_read = 1;
|
||||||
std::string full_output;
|
std::string full_output;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
command_output = popen(cmd.c_str(), "r");
|
command_output = popen(cmd.c_str(), "r");
|
||||||
if (command_output == NULL)
|
if (command_output == nullptr) throw;
|
||||||
throw;
|
|
||||||
|
|
||||||
while (amount_read > 0) {
|
while (amount_read > 0) {
|
||||||
amount_read = fread(output, 1, 127, command_output);
|
amount_read = fread(output, 1, 127, command_output);
|
||||||
|
@ -87,17 +86,15 @@ std::string systemOutput(const std::string& cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
int return_value = pclose(command_output);
|
int return_value = pclose(command_output);
|
||||||
if (return_value != 0)
|
if (return_value != 0) return "";
|
||||||
return "";
|
|
||||||
|
|
||||||
return full_output;
|
return full_output;
|
||||||
}
|
}
|
||||||
|
|
||||||
int systemp(const std::string& cmd)
|
int systemp(const std::string& cmd)
|
||||||
{
|
{
|
||||||
if (!Settings::quietOutput()) {
|
if (!Settings::quietOutput())
|
||||||
std::cout << " " << cmd << "\n";
|
std::cout << " " << cmd << "\n";
|
||||||
}
|
|
||||||
return system(cmd.c_str());
|
return system(cmd.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,17 +103,17 @@ void tokenize(const std::string& str, const char* delim, std::vector<std::string
|
||||||
std::vector<std::string>& tokens = *vectorarg;
|
std::vector<std::string>& tokens = *vectorarg;
|
||||||
std::string delimiters(delim);
|
std::string delimiters(delim);
|
||||||
|
|
||||||
// skip delimiters at beginning.
|
// skip delimiters at beginning
|
||||||
std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
|
std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
|
||||||
// find first "non-delimiter".
|
// find first non-delimiter
|
||||||
std::string::size_type pos = str.find_first_of(delimiters, lastPos);
|
std::string::size_type pos = str.find_first_of(delimiters, lastPos);
|
||||||
|
|
||||||
while (pos != std::string::npos || lastPos != std::string::npos) {
|
while (pos != std::string::npos || lastPos != std::string::npos) {
|
||||||
// found a token, add it to the vector.
|
// found a token, add it to the vector
|
||||||
tokens.push_back(str.substr(lastPos, pos - lastPos));
|
tokens.push_back(str.substr(lastPos, pos - lastPos));
|
||||||
// skip delimiters. Note the "not_of"
|
// skip delimiters
|
||||||
lastPos = str.find_first_not_of(delimiters, pos);
|
lastPos = str.find_first_not_of(delimiters, pos);
|
||||||
// find next "non-delimiter"
|
// find next non-delimiter
|
||||||
pos = str.find_first_of(delimiters, lastPos);
|
pos = str.find_first_of(delimiters, lastPos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,9 +129,8 @@ std::vector<std::string> lsDir(const std::string& path)
|
||||||
|
|
||||||
bool fileExists(const std::string& filename)
|
bool fileExists(const std::string& filename)
|
||||||
{
|
{
|
||||||
if (access(filename.c_str(), F_OK) != -1) {
|
if (access(filename.c_str(), F_OK) != -1)
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
std::string delims = " \f\n\r\t\v";
|
std::string delims = " \f\n\r\t\v";
|
||||||
std::string rtrimmed = filename.substr(0, filename.find_last_not_of(delims)+1);
|
std::string rtrimmed = filename.substr(0, filename.find_last_not_of(delims)+1);
|
||||||
std::string ftrimmed = rtrimmed.substr(rtrimmed.find_first_not_of(delims));
|
std::string ftrimmed = rtrimmed.substr(rtrimmed.find_first_not_of(delims));
|
||||||
|
@ -145,7 +141,7 @@ bool fileExists(const std::string& filename)
|
||||||
|
|
||||||
bool isRpath(const std::string& path)
|
bool isRpath(const std::string& path)
|
||||||
{
|
{
|
||||||
return path.find("@rpath") == 0 || path.find("@loader_path") == 0;
|
return path.find("@rpath") != std::string::npos || path.find("@loader_path") != std::string::npos;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string bundleExecutableName(const std::string& app_bundle_path)
|
std::string bundleExecutableName(const std::string& app_bundle_path)
|
||||||
|
@ -283,7 +279,7 @@ std::string getUserInputDirForFile(const std::string& filename)
|
||||||
std::cin >> prefix;
|
std::cin >> prefix;
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
||||||
if (prefix.compare("quit") == 0 || prefix.compare("exit") == 0 || prefix.compare("abort") == 0)
|
if (prefix == "quit" || prefix == "exit" || prefix == "abort")
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
if (!prefix.empty() && prefix[prefix.size()-1] != '/')
|
if (!prefix.empty() && prefix[prefix.size()-1] != '/')
|
||||||
|
@ -310,7 +306,7 @@ void parseLoadCommands(const std::string& file, const std::string& cmd, const st
|
||||||
if (output.find("can't open file") != std::string::npos
|
if (output.find("can't open file") != std::string::npos
|
||||||
|| output.find("No such file") != std::string::npos
|
|| output.find("No such file") != std::string::npos
|
||||||
|| output.find("at least one file must be specified") != std::string::npos
|
|| output.find("at least one file must be specified") != std::string::npos
|
||||||
|| output.size() < 1) {
|
|| output.empty()) {
|
||||||
std::cerr << "\n\n/!\\ ERROR: Cannot find file " << file << " to read its load commands\n";
|
std::cerr << "\n\n/!\\ ERROR: Cannot find file " << file << " to read its load commands\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -356,7 +352,7 @@ std::string searchFilenameInRpaths(const std::string& rpath_file, const std::str
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string fullpath;
|
std::string fullpath;
|
||||||
std::string suffix = rpath_file.substr(rpath_file.rfind("/")+1);
|
std::string suffix = rpath_file.substr(rpath_file.rfind('/')+1);
|
||||||
char fullpath_buffer[PATH_MAX];
|
char fullpath_buffer[PATH_MAX];
|
||||||
|
|
||||||
const auto check_path = [&](std::string path) {
|
const auto check_path = [&](std::string path) {
|
||||||
|
@ -410,8 +406,7 @@ std::string searchFilenameInRpaths(const std::string& rpath_file, const std::str
|
||||||
}
|
}
|
||||||
else if (!check_path(rpath_file)) {
|
else if (!check_path(rpath_file)) {
|
||||||
auto rpaths_for_file = Settings::getRpathsForFile(dependent_file);
|
auto rpaths_for_file = Settings::getRpathsForFile(dependent_file);
|
||||||
for (auto it = rpaths_for_file.begin(); it != rpaths_for_file.end(); ++it) {
|
for (auto rpath : rpaths_for_file) {
|
||||||
std::string rpath = *it;
|
|
||||||
if (rpath[rpath.size()-1] != '/')
|
if (rpath[rpath.size()-1] != '/')
|
||||||
rpath += "/";
|
rpath += "/";
|
||||||
std::string path = rpath + suffix;
|
std::string path = rpath + suffix;
|
||||||
|
@ -423,9 +418,8 @@ std::string searchFilenameInRpaths(const std::string& rpath_file, const std::str
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fullpath.empty()) {
|
if (fullpath.empty()) {
|
||||||
size_t search_path_count = Settings::searchPathCount();
|
std::vector<std::string> search_paths = Settings::searchPaths();
|
||||||
for (size_t i=0; i<search_path_count; ++i) {
|
for (const auto& search_path : search_paths) {
|
||||||
std::string search_path = Settings::searchPath(i);
|
|
||||||
if (fileExists(search_path+suffix)) {
|
if (fileExists(search_path+suffix)) {
|
||||||
if (Settings::verboseOutput())
|
if (Settings::verboseOutput())
|
||||||
std::cout << "FOUND " << suffix << " in " << search_path << std::endl;
|
std::cout << "FOUND " << suffix << " in " << search_path << std::endl;
|
||||||
|
@ -464,16 +458,16 @@ void initSearchPaths()
|
||||||
{
|
{
|
||||||
std::string searchPaths;
|
std::string searchPaths;
|
||||||
char *dyldLibPath = std::getenv("DYLD_LIBRARY_PATH");
|
char *dyldLibPath = std::getenv("DYLD_LIBRARY_PATH");
|
||||||
if (dyldLibPath != 0)
|
if (dyldLibPath != nullptr)
|
||||||
searchPaths = dyldLibPath;
|
searchPaths = dyldLibPath;
|
||||||
dyldLibPath = std::getenv("DYLD_FALLBACK_FRAMEWORK_PATH");
|
dyldLibPath = std::getenv("DYLD_FALLBACK_FRAMEWORK_PATH");
|
||||||
if (dyldLibPath != 0) {
|
if (dyldLibPath != nullptr) {
|
||||||
if (!searchPaths.empty() && searchPaths[searchPaths.size()-1] != ':')
|
if (!searchPaths.empty() && searchPaths[searchPaths.size()-1] != ':')
|
||||||
searchPaths += ":";
|
searchPaths += ":";
|
||||||
searchPaths += dyldLibPath;
|
searchPaths += dyldLibPath;
|
||||||
}
|
}
|
||||||
dyldLibPath = std::getenv("DYLD_FALLBACK_LIBRARY_PATH");
|
dyldLibPath = std::getenv("DYLD_FALLBACK_LIBRARY_PATH");
|
||||||
if (dyldLibPath != 0) {
|
if (dyldLibPath != nullptr) {
|
||||||
if (!searchPaths.empty() && searchPaths[searchPaths.size()-1] != ':')
|
if (!searchPaths.empty() && searchPaths[searchPaths.size()-1] != ':')
|
||||||
searchPaths += ":";
|
searchPaths += ":";
|
||||||
searchPaths += dyldLibPath;
|
searchPaths += dyldLibPath;
|
||||||
|
|
|
@ -19,9 +19,9 @@ void rtrim_in_place(std::string& s);
|
||||||
// trim from end (copying)
|
// trim from end (copying)
|
||||||
std::string rtrim(std::string s);
|
std::string rtrim(std::string s);
|
||||||
|
|
||||||
// executes a command in the native shell and returns output in string
|
// execute a command in the native shell and return output in string
|
||||||
std::string systemOutput(const std::string& cmd);
|
std::string systemOutput(const std::string& cmd);
|
||||||
// like 'system', runs a command on the system shell, but also prints the command to stdout.
|
// run a command in the system shell (like 'system') but also print the command to stdout
|
||||||
int systemp(const std::string& cmd);
|
int systemp(const std::string& cmd);
|
||||||
|
|
||||||
void tokenize(const std::string& str, const char* delimiters, std::vector<std::string>*);
|
void tokenize(const std::string& str, const char* delimiters, std::vector<std::string>*);
|
||||||
|
|
12
src/main.cpp
12
src/main.cpp
|
@ -4,7 +4,6 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#ifndef __clang__
|
#ifndef __clang__
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -125,13 +124,12 @@ int main(int argc, const char* argv[])
|
||||||
|
|
||||||
std::cout << "Collecting dependencies...\n";
|
std::cout << "Collecting dependencies...\n";
|
||||||
|
|
||||||
const size_t files_count = Settings::filesToFixCount();
|
const std::vector<std::string> files_to_fix = Settings::filesToFix();
|
||||||
|
for (const auto& file_to_fix : files_to_fix) {
|
||||||
for (size_t j=0; j<files_count; ++j)
|
collectDependenciesForFile(file_to_fix);
|
||||||
collectDependenciesForFile(Settings::fileToFix(j));
|
}
|
||||||
|
|
||||||
collectSubDependencies();
|
collectSubDependencies();
|
||||||
doneWithDeps_go();
|
bundleDependencies();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue