From 3cf89cca1b4dd807d372a256277b13e52437b451 Mon Sep 17 00:00:00 2001 From: SCG82 Date: Fri, 27 Dec 2019 02:40:02 -0800 Subject: [PATCH] frameworks: don't copy Headers directory --- src/Dependency.cpp | 17 +++++++++++++++++ src/DylibBundler.cpp | 4 ++-- src/Utils.cpp | 20 ++++++++++++++++++-- src/Utils.h | 8 +++++--- 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/Dependency.cpp b/src/Dependency.cpp index 1e6415a..9f33de5 100644 --- a/src/Dependency.cpp +++ b/src/Dependency.cpp @@ -211,11 +211,13 @@ void Dependency::copyYourself() std::string dest_path = getInstallPath(); std::string inner_path = getInnerPath(); std::string install_path = dest_path; + bool framework = false; if (Settings::verboseOutput()) std::cout << "original path: " << original_path << std::endl; if (original_path.find(".framework") != std::string::npos) { + framework = true; std::string framework_root = getFrameworkRoot(original_path); std::string framework_path = getFrameworkPath(original_path); std::string framework_name = stripPrefix(framework_root); @@ -238,6 +240,21 @@ void Dependency::copyYourself() copyFile(original_path, dest_path); + if (framework) { + std::string headers_path = dest_path + std::string("/Headers"); + std::string headers_realpath = headers_path; + char buffer[PATH_MAX]; + + if (realpath(rtrim(headers_path).c_str(), buffer)) + headers_realpath = buffer; + + if (Settings::verboseOutput()) + std::cout << "headers path: " << headers_realpath << std::endl; + + deleteFile(headers_path, true); + deleteFile(headers_realpath, true); + } + // fix the lib's inner name std::string command = std::string("install_name_tool -id ") + inner_path + " " + install_path; if (systemp(command) != 0) { diff --git a/src/DylibBundler.cpp b/src/DylibBundler.cpp index ae40efe..b3a0363 100644 --- a/src/DylibBundler.cpp +++ b/src/DylibBundler.cpp @@ -46,7 +46,7 @@ void collectRpaths(const std::string& filename) } std::string cmd = "otool -l " + filename; - std::string output = system_get_output(cmd); + std::string output = systemOutput(cmd); std::vector lc_lines; tokenize(output, "\n", &lc_lines); @@ -177,7 +177,7 @@ void addDependency(std::string path, std::string filename) void collectDependencies(std::string filename, std::vector& lines) { std::string cmd = "otool -L " + filename; - std::string output = system_get_output(cmd); + std::string output = systemOutput(cmd); if (output.find("can't open file") != std::string::npos || output.find("No such file") != std::string::npos diff --git a/src/Utils.cpp b/src/Utils.cpp index 8cc06e8..493710b 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -72,7 +72,23 @@ void copyFile(std::string from, std::string to) } } -std::string system_get_output(std::string cmd) +void deleteFile(std::string path, bool overwrite) +{ + std::string overwrite_permission = std::string(overwrite ? "-f " : " "); + std::string command = std::string("rm -r ") + overwrite_permission + path; + if (systemp(command) != 0) { + std::cerr << "\n\nError: An error occured while trying to delete " << path << "\n"; + exit(1); + } +} + +void deleteFile(std::string path) +{ + bool overwrite = Settings::canOverwriteFiles(); + deleteFile(path, overwrite); +} + +std::string systemOutput(const std::string& cmd) { FILE* command_output; char output[128]; @@ -108,7 +124,7 @@ std::string system_get_output(std::string cmd) return full_output; } -int systemp(std::string& cmd) +int systemp(const std::string& cmd) { if (!Settings::quietOutput()) { std::cout << " " << cmd << "\n"; diff --git a/src/Utils.h b/src/Utils.h index 9cd24b0..4c2d35e 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -4,18 +4,20 @@ #include #include -class Library; +// class Library; void tokenize(const std::string& str, const char* delimiters, std::vector*); bool fileExists(std::string filename); void copyFile(std::string from, std::string to); +void deleteFile(std::string path, bool overwrite); +void deleteFile(std::string path); // executes a command in the native shell and returns output in string -std::string system_get_output(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. -int systemp(std::string& cmd); +int systemp(const std::string& cmd); std::string getUserInputDirForFile(const std::string& filename); #endif