/* * Fill vector 'lines' with dependencies of given 'filename' */ void collectDependencies(std::string filename, std::vector<std::string>& lines) { // execute "otool -L" on the given file and collect the command's output std::string cmd = "otool -L " + filename; std::string output = system_get_output(cmd); if(output.find("can't open file")!=std::string::npos or output.find("No such file")!=std::string::npos or output.size()<1) { std::cerr << "Cannot find file " << filename << " to read its dependencies" << std::endl; exit(1); } // split output tokenize(output, "\n", &lines); }
void collectRpaths(const std::string& filename) { if (!fileExists(filename)) { std::cerr << "\n/!\\ WARNING : can't collect rpaths for inexistent file '" << filename << "'\n"; return; } std::string cmd = "otool -l " + filename; std::string output = system_get_output(cmd); std::vector<std::string> lc_lines; tokenize(output, "\n", &lc_lines); size_t pos = 0; bool read_rpath = false; while (pos < lc_lines.size()) { std::string line = lc_lines[pos]; pos++; if (read_rpath) { size_t start_pos = line.find("path "); size_t end_pos = line.find(" ("); if (start_pos == std::string::npos || end_pos == std::string::npos) { std::cerr << "\n/!\\ WARNING: Unexpected LC_RPATH format\n"; continue; } start_pos += 5; std::string rpath = line.substr(start_pos, end_pos - start_pos); rpaths.insert(rpath); rpaths_per_file[filename].push_back(rpath); read_rpath = false; continue; } if (line.find("LC_RPATH") != std::string::npos) { read_rpath = true; pos++; } } }