add namespace macDylibBundler
This commit is contained in:
parent
a459e157b4
commit
4fb9a74882
|
@ -13,6 +13,8 @@
|
|||
#include "DylibBundler.h"
|
||||
#include "Utils.h"
|
||||
|
||||
namespace macDylibBundler {
|
||||
|
||||
Dependency::Dependency(std::string path, const std::string &dependent_file, DylibBundler *db)
|
||||
: is_framework(false), db(db)
|
||||
{
|
||||
|
@ -23,11 +25,9 @@ Dependency::Dependency(std::string path, const std::string& dependent_file, Dyli
|
|||
|
||||
if (isRpath(path)) {
|
||||
original_file = db->searchFilenameInRpaths(path, dependent_file);
|
||||
}
|
||||
else if (realpath(path.c_str(), buffer)) {
|
||||
} else if (realpath(path.c_str(), buffer)) {
|
||||
original_file = buffer;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
warning_msg = "\n/!\\ WARNING: Cannot resolve path '" + path + "'\n";
|
||||
original_file = path;
|
||||
}
|
||||
|
@ -177,3 +177,5 @@ void Dependency::FixDependentFile(const std::string& dependent_file) const
|
|||
for (const auto &symlink : symlinks)
|
||||
db->changeInstallName(dependent_file, symlink, InnerPath());
|
||||
}
|
||||
|
||||
} //namespace macDylibBundler
|
|
@ -1,11 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#ifndef DYLIBBUNDLER_DEPENDENCY_H
|
||||
#define DYLIBBUNDLER_DEPENDENCY_H
|
||||
#ifndef MACDYLIBBUNDLER_DEPENDENCY_H
|
||||
#define MACDYLIBBUNDLER_DEPENDENCY_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace macDylibBundler {
|
||||
|
||||
class DylibBundler;
|
||||
|
||||
class Dependency {
|
||||
|
@ -13,20 +15,19 @@ public:
|
|||
Dependency(std::string path, const std::string &dependent_file, DylibBundler *db);
|
||||
|
||||
[[nodiscard]] bool IsFramework() const { return is_framework; }
|
||||
|
||||
[[nodiscard]] std::string Prefix() const { return prefix; }
|
||||
[[nodiscard]] std::string OriginalFilename() const { return filename; }
|
||||
[[nodiscard]] std::string OriginalPath() const { return prefix + filename; }
|
||||
|
||||
[[nodiscard]] std::string InnerPath() const;
|
||||
[[nodiscard]] std::string InstallPath() const;
|
||||
|
||||
void AddSymlink(const std::string &path);
|
||||
// Compare the |dependency| with |this|. Merge entries if both refer to the same file.
|
||||
bool MergeIfIdentical(Dependency *dependency);
|
||||
|
||||
void Print() const;
|
||||
|
||||
void CopyToBundle() const;
|
||||
|
||||
void FixDependentFile(const std::string &dependent_file) const;
|
||||
|
||||
private:
|
||||
|
@ -44,3 +45,5 @@ private:
|
|||
};
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace macDylibBundler
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <numeric>
|
||||
#include <regex>
|
||||
#include <sstream>
|
||||
|
@ -15,7 +14,10 @@
|
|||
#include "Dependency.h"
|
||||
#include "Utils.h"
|
||||
|
||||
namespace macDylibBundler {
|
||||
|
||||
DylibBundler::DylibBundler() : qt_plugins_called(false) {}
|
||||
|
||||
DylibBundler::~DylibBundler() = default;
|
||||
|
||||
void DylibBundler::addDependency(const std::string &path, const std::string &dependent_file)
|
||||
|
@ -86,12 +88,14 @@ void DylibBundler::collectDependenciesRpaths(const std::string& dependent_file)
|
|||
|
||||
void DylibBundler::collectSubDependencies()
|
||||
{
|
||||
if (verboseOutput()) {
|
||||
std::cout << "(pre sub) # OF FILES: " << filesToFixCount() << std::endl;
|
||||
std::cout << "(pre sub) # OF DEPS: " << deps.size() << std::endl;
|
||||
}
|
||||
std::vector<std::string> files_to_fix = filesToFix();
|
||||
size_t dep_counter = deps.size();
|
||||
size_t deps_size = deps.size();
|
||||
if (verboseOutput()) {
|
||||
std::cout << "(pre sub) # OF FILES: " << files_to_fix.size() << std::endl;
|
||||
std::cout << "(pre sub) # OF DEPS: " << deps.size() << std::endl;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
deps_size = deps.size();
|
||||
for (size_t n = 0; n < deps_size; ++n) {
|
||||
|
@ -100,7 +104,6 @@ void DylibBundler::collectSubDependencies()
|
|||
std::cout << " (collect sub deps) original path: " << original_path << std::endl;
|
||||
if (isRpath(original_path))
|
||||
original_path = searchFilenameInRpaths(original_path);
|
||||
|
||||
collectDependenciesRpaths(original_path);
|
||||
}
|
||||
// if no more dependencies were added on this iteration, stop searching
|
||||
|
@ -109,7 +112,8 @@ void DylibBundler::collectSubDependencies()
|
|||
}
|
||||
|
||||
if (verboseOutput()) {
|
||||
std::cout << "(post sub) # OF FILES: " << filesToFixCount() << std::endl;
|
||||
files_to_fix = filesToFix();
|
||||
std::cout << "(post sub) # OF FILES: " << files_to_fix.size() << std::endl;
|
||||
std::cout << "(post sub) # OF DEPS: " << deps.size() << std::endl;
|
||||
}
|
||||
if (bundleLibs() && bundleFrameworks()) {
|
||||
|
@ -120,8 +124,10 @@ void DylibBundler::collectSubDependencies()
|
|||
|
||||
void DylibBundler::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())
|
||||
if (deps_collected.find(file_to_fix) == deps_collected.end()
|
||||
|| rpaths_collected.find(file_to_fix) == rpaths_collected.end()) {
|
||||
collectDependenciesRpaths(file_to_fix);
|
||||
}
|
||||
|
||||
std::cout << "* Fixing dependencies on " << file_to_fix << "\n";
|
||||
std::vector<Dependency *> dependencies = deps_per_file[file_to_fix];
|
||||
|
@ -137,10 +143,11 @@ void DylibBundler::fixRpathsOnFile(const std::string& original_file, const std::
|
|||
|
||||
rpaths_to_fix = getRpathsForFile(original_file);
|
||||
for (const auto& rpath_to_fix : rpaths_to_fix) {
|
||||
std::string command = std::string("/usr/bin/install_name_tool -rpath ").append(rpath_to_fix);
|
||||
command += std::string(" ").append(insideLibPath()).append(" ").append(file_to_fix);
|
||||
std::string command = std::string("/usr/bin/install_name_tool -rpath ");
|
||||
command += rpath_to_fix + " " + insideLibPath() + " " + file_to_fix;
|
||||
if (systemp(command) != 0) {
|
||||
std::cerr << "\n\n/!\\ ERROR: An error occured while trying to fix rpath " << rpath_to_fix << " of " << file_to_fix << std::endl;
|
||||
std::cerr << "\n\n/!\\ ERROR: An error occured while trying to fix rpath " << rpath_to_fix << " of "
|
||||
<< file_to_fix << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
@ -323,8 +330,7 @@ std::string DylibBundler::getUserInputDirForFile(const std::string& filename, co
|
|||
if (!fileExists(prefix + filename)) {
|
||||
std::cerr << (prefix + filename) << " does not exist. Try again...\n";
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
std::cerr << (prefix + filename) << " was found\n"
|
||||
<< "/!\\ WARNING: dylibbundler MAY NOT CORRECTLY HANDLE THIS DEPENDENCY: Check the executable with 'otool -L'\n";
|
||||
addUserSearchPath(prefix);
|
||||
|
@ -363,8 +369,7 @@ std::string DylibBundler::searchFilenameInRpaths(const std::string& rpath_file,
|
|||
rpathToFullPath(rpath_file, fullpath);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (path.find("@rpath") != std::string::npos) {
|
||||
} else if (path.find("@rpath") != std::string::npos) {
|
||||
if (appBundleProvided()) {
|
||||
std::string pathE = std::regex_replace(path, std::regex("@rpath/"), executableFolder());
|
||||
if (verboseOutput())
|
||||
|
@ -392,8 +397,7 @@ std::string DylibBundler::searchFilenameInRpaths(const std::string& rpath_file,
|
|||
// fullpath previously stored
|
||||
if (rpathFound(rpath_file)) {
|
||||
fullpath = getFullPath(rpath_file);
|
||||
}
|
||||
else if (!check_path(rpath_file)) {
|
||||
} else if (!check_path(rpath_file)) {
|
||||
auto rpaths_for_file = getRpathsForFile(dependent_file);
|
||||
for (auto rpath : rpaths_for_file) {
|
||||
if (rpath[rpath.size() - 1] != '/')
|
||||
|
@ -426,12 +430,10 @@ std::string DylibBundler::searchFilenameInRpaths(const std::string& rpath_file,
|
|||
std::cerr << "\n/!\\ WARNING: Can't get path for '" << rpath_file << "'\n";
|
||||
if (realpath(fullpath.c_str(), fullpath_buffer))
|
||||
fullpath = fullpath_buffer;
|
||||
}
|
||||
else if (verboseOutput()) {
|
||||
} else if (verboseOutput()) {
|
||||
std::cout << " ** rpath fullpath: " << fullpath << std::endl;
|
||||
}
|
||||
}
|
||||
else if (verboseOutput()) {
|
||||
} else if (verboseOutput()) {
|
||||
std::cout << " ** rpath fullpath: " << fullpath << std::endl;
|
||||
}
|
||||
return fullpath;
|
||||
|
@ -480,7 +482,7 @@ void DylibBundler::createDestDir()
|
|||
bool dest_exists = fileExists(dest_folder);
|
||||
if (dest_exists && canOverwriteDir()) {
|
||||
std::cout << "Erasing old output directory " << dest_folder << "\n";
|
||||
std::string command = std::string("/bin/rm -r ").append(dest_folder);
|
||||
std::string command = std::string("/bin/rm -r ") + dest_folder;
|
||||
if (systemp(command) != 0) {
|
||||
std::cerr << "\n\n/!\\ ERROR: An error occured while attempting to overwrite destination folder\n";
|
||||
exit(1);
|
||||
|
@ -495,9 +497,9 @@ void DylibBundler::createDestDir()
|
|||
std::cerr << "\n/!\\ ERROR: An error occured while creating " << dest_folder << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
std::cerr << "\n\n/!\\ ERROR: Destination folder does not exist. Create it or pass the '-cd' or '-od' flag\n";
|
||||
} else {
|
||||
std::cerr
|
||||
<< "\n\n/!\\ ERROR: Destination folder does not exist. Create it or pass the '-cd' or '-od' flag\n";
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
@ -505,17 +507,19 @@ void DylibBundler::createDestDir()
|
|||
|
||||
void DylibBundler::changeId(const std::string &binary_file, const std::string &new_id)
|
||||
{
|
||||
std::string command = std::string("/usr/bin/install_name_tool -id ").append(new_id).append(" ").append(binary_file);
|
||||
std::string command = std::string("/usr/bin/install_name_tool -id ") + new_id + " " + binary_file;
|
||||
if (systemp(command) != 0) {
|
||||
std::cerr << "\n\nError: An error occured while trying to change identity of library " << binary_file << std::endl;
|
||||
std::cerr << "\n\nError: An error occured while trying to change identity of library " << binary_file
|
||||
<< std::endl;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void DylibBundler::changeInstallName(const std::string& binary_file, const std::string& old_name, const std::string& new_name)
|
||||
void DylibBundler::changeInstallName(const std::string &binary_file, const std::string &old_name,
|
||||
const std::string &new_name)
|
||||
{
|
||||
std::string command = std::string("/usr/bin/install_name_tool -change ").append(old_name).append(" ");
|
||||
command.append(new_name).append(" ").append(binary_file);
|
||||
std::string command = std::string("/usr/bin/install_name_tool -change ");
|
||||
command += old_name + " " + new_name + " " + binary_file;
|
||||
if (systemp(command) != 0) {
|
||||
std::cerr << "\n\nError: An error occured while trying to fix dependencies of " << binary_file << std::endl;
|
||||
exit(1);
|
||||
|
@ -532,15 +536,14 @@ void DylibBundler::copyFile(const std::string& from, const std::string& to)
|
|||
|
||||
// copy file/directory
|
||||
std::string overwrite_permission = std::string(overwrite ? "-f " : "-n ");
|
||||
std::string command = std::string("/bin/cp -R ").append(overwrite_permission);
|
||||
command.append(from).append(" ").append(to);
|
||||
std::string command = std::string("/bin/cp -R ") + overwrite_permission + from + " " + to;
|
||||
if (from != to && systemp(command) != 0) {
|
||||
std::cerr << "\n\nError: An error occured while trying to copy file " << from << " to " << to << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// give file/directory write permission
|
||||
std::string command2 = std::string("/bin/chmod -R +w ").append(to);
|
||||
std::string command2 = std::string("/bin/chmod -R +w ") + to;
|
||||
if (systemp(command2) != 0) {
|
||||
std::cerr << "\n\nError: An error occured while trying to set write permissions on file " << to << std::endl;
|
||||
exit(1);
|
||||
|
@ -550,7 +553,7 @@ void DylibBundler::copyFile(const std::string& from, const std::string& to)
|
|||
void DylibBundler::deleteFile(const std::string &path, bool overwrite)
|
||||
{
|
||||
std::string overwrite_permission = std::string(overwrite ? "-f " : " ");
|
||||
std::string command = std::string("/bin/rm -r ").append(overwrite_permission).append(path);
|
||||
std::string command = std::string("/bin/rm -r ") + overwrite_permission + path;
|
||||
if (systemp(command) != 0) {
|
||||
std::cerr << "\n\nError: An error occured while trying to delete " << path << std::endl;
|
||||
exit(1);
|
||||
|
@ -567,7 +570,7 @@ bool DylibBundler::mkdir(const std::string& path)
|
|||
{
|
||||
if (verboseOutput())
|
||||
std::cout << "Creating directory " << path << std::endl;
|
||||
std::string command = std::string("/bin/mkdir -p ").append(path);
|
||||
std::string command = std::string("/bin/mkdir -p ") + path;
|
||||
if (systemp(command) != 0) {
|
||||
std::cerr << "\n/!\\ ERROR: An error occured while creating " << path << std::endl;
|
||||
return false;
|
||||
|
@ -581,3 +584,5 @@ int DylibBundler::systemp(const std::string& cmd)
|
|||
std::cout << " " << cmd << "\n";
|
||||
return system(cmd.c_str());
|
||||
}
|
||||
|
||||
} // namespace macDylibBundler
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#ifndef DYLIBBUNDLER_DYLIBBUNDLER_H
|
||||
#define DYLIBBUNDLER_DYLIBBUNDLER_H
|
||||
#ifndef MACDYLIBBUNDLER_DYLIBBUNDLER_H
|
||||
#define MACDYLIBBUNDLER_DYLIBBUNDLER_H
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
@ -10,11 +10,14 @@
|
|||
|
||||
#include "Settings.h"
|
||||
|
||||
namespace macDylibBundler {
|
||||
|
||||
class Dependency;
|
||||
|
||||
class DylibBundler : public Settings {
|
||||
public:
|
||||
DylibBundler();
|
||||
|
||||
~DylibBundler() override;
|
||||
|
||||
void addDependency(const std::string &path, const std::string &dependent_file);
|
||||
|
@ -28,19 +31,14 @@ public:
|
|||
std::string getUserInputDirForFile(const std::string &filename, 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);
|
||||
|
||||
// check the same paths the system would search for dylibs
|
||||
void initSearchPaths();
|
||||
void createDestDir();
|
||||
|
||||
void changeId(const std::string &binary_file, const std::string &new_id);
|
||||
void changeInstallName(const std::string &binary_file, const std::string &old_name, const std::string &new_name);
|
||||
|
||||
void copyFile(const std::string &from, const std::string &to);
|
||||
void deleteFile(const std::string &path, bool overwrite);
|
||||
void deleteFile(const std::string &path);
|
||||
bool mkdir(const std::string &path);
|
||||
|
||||
// run a command in the system shell (like 'system') but also print the command to stdout
|
||||
int systemp(const std::string &cmd);
|
||||
|
||||
|
@ -54,4 +52,6 @@ private:
|
|||
bool qt_plugins_called;
|
||||
};
|
||||
|
||||
} // namespace macDylibBundler
|
||||
|
||||
#endif
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include "Utils.h"
|
||||
|
||||
namespace macDylibBundler {
|
||||
|
||||
Settings::Settings() : overwrite_files(false),
|
||||
overwrite_dir(false),
|
||||
create_dir(false),
|
||||
|
@ -24,8 +26,7 @@ Settings::Settings() : overwrite_files(false),
|
|||
|
||||
Settings::~Settings() = default;
|
||||
|
||||
void Settings::appBundle(std::string path)
|
||||
{
|
||||
void Settings::appBundle(std::string path) {
|
||||
app_bundle = std::move(path);
|
||||
char buffer[PATH_MAX];
|
||||
if (realpath(app_bundle.c_str(), buffer))
|
||||
|
@ -109,3 +110,5 @@ bool Settings::isPrefixBundled(const std::string& prefix)
|
|||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace macDylibBundler
|
||||
|
|
114
src/Settings.h
114
src/Settings.h
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#ifndef DYLIBBUNDLER_SETTINGS_H
|
||||
#define DYLIBBUNDLER_SETTINGS_H
|
||||
#ifndef MACDYLIBBUNDLER_SETTINGS_H
|
||||
#define MACDYLIBBUNDLER_SETTINGS_H
|
||||
|
||||
#include <cstdlib>
|
||||
#include <map>
|
||||
|
@ -13,71 +13,83 @@
|
|||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
namespace macDylibBundler {
|
||||
|
||||
class Settings {
|
||||
public:
|
||||
Settings();
|
||||
|
||||
virtual ~Settings();
|
||||
|
||||
virtual bool isPrefixBundled(const std::string &prefix);
|
||||
virtual bool isPrefixIgnored(const std::string &prefix);
|
||||
virtual void ignorePrefix(std::string prefix);
|
||||
virtual std::string appBundle() { return app_bundle; }
|
||||
virtual void appBundle(std::string path);
|
||||
virtual bool isPrefixBundled(const string &prefix);
|
||||
virtual bool isPrefixIgnored(const string &prefix);
|
||||
virtual void ignorePrefix(string prefix);
|
||||
|
||||
virtual string appBundle() { return app_bundle; }
|
||||
virtual void appBundle(string path);
|
||||
virtual bool appBundleProvided() { return !app_bundle.empty(); }
|
||||
|
||||
virtual std::string destFolder() { return dest_path; }
|
||||
virtual void destFolder(std::string path);
|
||||
virtual std::string insideLibPath() { return inside_path; }
|
||||
virtual void insideLibPath(std::string p);
|
||||
virtual string destFolder() { return dest_path; }
|
||||
virtual void destFolder(string path);
|
||||
virtual string insideLibPath() { return inside_path; }
|
||||
virtual void insideLibPath(string p);
|
||||
|
||||
virtual std::string executableFolder() { return app_bundle + "Contents/MacOS/"; }
|
||||
virtual std::string frameworksFolder() { return app_bundle + "Contents/Frameworks/"; }
|
||||
virtual std::string pluginsFolder() { return app_bundle + "Contents/PlugIns/"; }
|
||||
virtual std::string resourcesFolder() { return app_bundle + "Contents/Resources/"; }
|
||||
virtual string executableFolder() { return app_bundle + "Contents/MacOS/"; }
|
||||
virtual string frameworksFolder() { return app_bundle + "Contents/Frameworks/"; }
|
||||
virtual string pluginsFolder() { return app_bundle + "Contents/PlugIns/"; }
|
||||
virtual string resourcesFolder() { return app_bundle + "Contents/Resources/"; }
|
||||
|
||||
virtual std::vector<std::string> filesToFix() { return files; }
|
||||
virtual void addFileToFix(std::string path);
|
||||
virtual size_t filesToFixCount() { return files.size(); }
|
||||
virtual vector<string> filesToFix() { return files; }
|
||||
virtual void addFileToFix(string path);
|
||||
|
||||
virtual std::vector<std::string> searchPaths() { return search_paths; }
|
||||
virtual void addSearchPath(const std::string& path) { search_paths.push_back(path); }
|
||||
|
||||
virtual std::vector<std::string> userSearchPaths() { return user_search_paths; }
|
||||
virtual void addUserSearchPath(const std::string& path) { user_search_paths.push_back(path); }
|
||||
virtual vector<string> searchPaths() { return search_paths; }
|
||||
virtual void addSearchPath(const string &path) { search_paths.push_back(path); }
|
||||
virtual vector<string> userSearchPaths() { return user_search_paths; }
|
||||
virtual void addUserSearchPath(const string &path) { user_search_paths.push_back(path); }
|
||||
|
||||
virtual bool canCreateDir() { return create_dir; }
|
||||
virtual void canCreateDir(bool permission) { create_dir = permission; }
|
||||
|
||||
virtual bool canOverwriteDir() { return overwrite_dir; }
|
||||
virtual void canOverwriteDir(bool permission) { overwrite_dir = permission; }
|
||||
|
||||
virtual bool canOverwriteFiles() { return overwrite_files; }
|
||||
virtual void canOverwriteFiles(bool permission) { overwrite_files = permission; }
|
||||
|
||||
virtual bool bundleLibs() { return bundle_libs; }
|
||||
virtual void bundleLibs(bool status) { bundle_libs = status; }
|
||||
|
||||
virtual bool bundleFrameworks() { return bundle_frameworks; }
|
||||
virtual void bundleFrameworks(bool status) { bundle_frameworks = status; }
|
||||
|
||||
virtual bool quietOutput() { return quiet_output; }
|
||||
virtual void quietOutput(bool status) { quiet_output = status; }
|
||||
|
||||
virtual bool verboseOutput() { return verbose_output; }
|
||||
virtual void verboseOutput(bool status) { verbose_output = status; }
|
||||
|
||||
virtual bool missingPrefixes() { return missing_prefixes; }
|
||||
virtual void missingPrefixes(bool status) { missing_prefixes = status; }
|
||||
|
||||
virtual std::string getFullPath(const std::string& rpath) { return rpath_to_fullpath[rpath]; }
|
||||
virtual void rpathToFullPath(const std::string& rpath, const std::string& fullpath) { rpath_to_fullpath[rpath] = fullpath; }
|
||||
virtual bool rpathFound(const std::string& rpath) { return rpath_to_fullpath.find(rpath) != rpath_to_fullpath.end(); }
|
||||
virtual string getFullPath(const string &rpath) { return rpath_to_fullpath[rpath]; }
|
||||
virtual void rpathToFullPath(const string &rpath, const string &fullpath)
|
||||
{
|
||||
rpath_to_fullpath[rpath] = fullpath;
|
||||
}
|
||||
virtual bool rpathFound(const string &rpath)
|
||||
{
|
||||
return rpath_to_fullpath.find(rpath) != rpath_to_fullpath.end();
|
||||
}
|
||||
|
||||
virtual std::vector<std::string> getRpathsForFile(const std::string& file) { return rpaths_per_file[file]; }
|
||||
virtual void addRpathForFile(const std::string& file, const std::string& rpath) { rpaths_per_file[file].push_back(rpath); }
|
||||
virtual bool fileHasRpath(const std::string& file) { return rpaths_per_file.find(file) != rpaths_per_file.end(); }
|
||||
virtual vector<string> getRpathsForFile(const string &file)
|
||||
{
|
||||
return rpaths_per_file[file];
|
||||
}
|
||||
virtual void addRpathForFile(const string &file, const string &rpath)
|
||||
{
|
||||
rpaths_per_file[file].push_back(rpath);
|
||||
}
|
||||
virtual bool fileHasRpath(const string &file)
|
||||
{
|
||||
return rpaths_per_file.find(file) != rpaths_per_file.end();
|
||||
}
|
||||
|
||||
protected:
|
||||
private:
|
||||
bool overwrite_files;
|
||||
bool overwrite_dir;
|
||||
bool create_dir;
|
||||
|
@ -87,23 +99,25 @@ protected:
|
|||
bool bundle_frameworks;
|
||||
bool missing_prefixes;
|
||||
|
||||
std::string dest_folder_str;
|
||||
std::string dest_folder_str_app;
|
||||
std::string dest_folder;
|
||||
std::string dest_path;
|
||||
string dest_folder_str;
|
||||
string dest_folder_str_app;
|
||||
string dest_folder;
|
||||
string dest_path;
|
||||
|
||||
std::string inside_path_str;
|
||||
std::string inside_path_str_app;
|
||||
std::string inside_path;
|
||||
string inside_path_str;
|
||||
string inside_path_str_app;
|
||||
string inside_path;
|
||||
|
||||
std::string app_bundle;
|
||||
std::vector<std::string> prefixes_to_ignore;
|
||||
std::vector<std::string> search_paths;
|
||||
std::vector<std::string> files;
|
||||
string app_bundle;
|
||||
vector<string> prefixes_to_ignore;
|
||||
vector<string> search_paths;
|
||||
vector<string> files;
|
||||
|
||||
std::vector<std::string> user_search_paths;
|
||||
std::map<std::string, std::string> rpath_to_fullpath;
|
||||
std::map<std::string, std::vector<std::string>> rpaths_per_file;
|
||||
vector<string> user_search_paths;
|
||||
map<string, string> rpath_to_fullpath;
|
||||
map<string, vector<string>> rpaths_per_file;
|
||||
};
|
||||
|
||||
} // namespace macDylibBundler
|
||||
|
||||
#endif
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
#include <unistd.h>
|
||||
|
||||
namespace macDylibBundler {
|
||||
|
||||
std::string filePrefix(const std::string &in)
|
||||
{
|
||||
return in.substr(0, in.rfind('/') + 1);
|
||||
|
@ -51,7 +53,6 @@ void tokenize(const std::string& str, const char* delim, std::vector<std::string
|
|||
{
|
||||
std::vector<std::string> &out = *tokens;
|
||||
std::string delimiters(delim);
|
||||
|
||||
// skip delimiters at beginning
|
||||
std::string::size_type end = str.find_first_not_of(delimiters, 0);
|
||||
// find first non-delimiter
|
||||
|
@ -114,8 +115,7 @@ std::string systemOutput(const std::string& cmd)
|
|||
amount_read = fread(output, 1, 127, command_output);
|
||||
if (amount_read <= 0) {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
output[amount_read] = '\0';
|
||||
full_output += output;
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ std::string systemOutput(const std::string& cmd)
|
|||
|
||||
void otool(const std::string &flags, const std::string &file, std::vector<std::string> &lines)
|
||||
{
|
||||
std::string command = std::string("/usr/bin/otool ").append(flags).append(" ").append(file);
|
||||
std::string command = std::string("/usr/bin/otool ") + flags + " " + file;
|
||||
std::string output = systemOutput(command);
|
||||
|
||||
if (output.find("can't open file") != std::string::npos
|
||||
|
@ -147,41 +147,8 @@ 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 ").append(cmd);
|
||||
std::string value_line = std::string(value).append(" ");
|
||||
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)
|
||||
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;
|
||||
otool("-l", file, raw_lines);
|
||||
|
@ -190,8 +157,8 @@ void parseLoadCommands(const std::string& file, const std::map<std::string,std::
|
|||
std::vector<std::string> lines;
|
||||
std::string cmd = cmd_value.first;
|
||||
std::string value = cmd_value.second;
|
||||
std::string cmd_line = std::string("cmd ").append(cmd);
|
||||
std::string value_line = std::string(value).append(" ");
|
||||
std::string cmd_line = std::string("cmd ") + cmd;
|
||||
std::string value_line = std::string(value) + " ";
|
||||
bool searching = false;
|
||||
for (const auto &raw_line : raw_lines) {
|
||||
if (raw_line.find(cmd_line) != std::string::npos) {
|
||||
|
@ -232,3 +199,5 @@ void createQtConf(std::string directory)
|
|||
out << contents;
|
||||
out.close();
|
||||
}
|
||||
|
||||
} //namespace macDylibBundler
|
25
src/Utils.h
25
src/Utils.h
|
@ -1,33 +1,50 @@
|
|||
#pragma once
|
||||
|
||||
#ifndef DYLIBBUNDLER_UTILS_H
|
||||
#define DYLIBBUNDLER_UTILS_H
|
||||
#ifndef MACDYLIBBUNDLER_UTILS_H
|
||||
#define MACDYLIBBUNDLER_UTILS_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace macDylibBundler {
|
||||
|
||||
std::string filePrefix(const std::string &in);
|
||||
|
||||
std::string stripPrefix(const std::string &in);
|
||||
|
||||
std::string stripLSlash(const std::string &in);
|
||||
|
||||
std::string getFrameworkRoot(const std::string &in);
|
||||
|
||||
std::string getFrameworkPath(const std::string &in);
|
||||
|
||||
void rtrim_in_place(std::string &s);
|
||||
|
||||
std::string rtrim(std::string s);
|
||||
|
||||
void tokenize(const std::string &str, const char *delimiters, std::vector<std::string> *tokens);
|
||||
|
||||
bool fileExists(const std::string &filename);
|
||||
|
||||
bool isRpath(const std::string &path);
|
||||
|
||||
std::string bundleExecutableName(const std::string &app_bundle_path);
|
||||
|
||||
std::vector<std::string> lsDir(const std::string &path);
|
||||
|
||||
std::string systemOutput(const std::string &cmd);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
void createQtConf(std::string directory);
|
||||
|
||||
} // namespace macDylibBundler
|
||||
|
||||
#endif
|
||||
|
|
10
src/main.cpp
10
src/main.cpp
|
@ -34,7 +34,7 @@ void showHelp()
|
|||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
DylibBundler* db = new DylibBundler();
|
||||
macDylibBundler::DylibBundler* db = new macDylibBundler::DylibBundler();
|
||||
// parse arguments
|
||||
for (int i=0; i<argc; i++) {
|
||||
if (strcmp(argv[i],"-a") == 0 || strcmp(argv[i],"--app") == 0) {
|
||||
|
@ -116,17 +116,15 @@ int main(int argc, const char* argv[])
|
|||
}
|
||||
}
|
||||
|
||||
if (db->filesToFixCount() < 1) {
|
||||
const std::vector<std::string> files_to_fix = db->filesToFix();
|
||||
if (files_to_fix.empty()) {
|
||||
showHelp();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
std::cout << "Collecting dependencies...\n";
|
||||
|
||||
const std::vector<std::string> files_to_fix = db->filesToFix();
|
||||
for (const auto& file_to_fix : files_to_fix) {
|
||||
for (const auto& file_to_fix : files_to_fix)
|
||||
db->collectDependenciesRpaths(file_to_fix);
|
||||
}
|
||||
db->collectSubDependencies();
|
||||
db->bundleDependencies();
|
||||
|
||||
|
|
Loading…
Reference in New Issue