| 21 | } |
| 22 | |
| 23 | bool cmBinUtilsLinuxELFObjdumpGetRuntimeDependenciesTool::GetFileInfo( |
| 24 | std::string const& file, std::vector<std::string>& needed, |
| 25 | std::vector<std::string>& rpaths, std::vector<std::string>& runpaths) |
| 26 | { |
| 27 | cmUVProcessChainBuilder builder; |
| 28 | builder.SetBuiltinStream(cmUVProcessChainBuilder::Stream_OUTPUT); |
| 29 | |
| 30 | std::vector<std::string> command; |
| 31 | if (!this->Archive->GetGetRuntimeDependenciesCommand("objdump", command)) { |
| 32 | this->SetError("Could not find objdump"); |
| 33 | return false; |
| 34 | } |
| 35 | command.emplace_back("-p"); |
| 36 | command.push_back(file); |
| 37 | builder.AddCommand(command); |
| 38 | |
| 39 | auto process = builder.Start(); |
| 40 | if (!process.Valid() || process.GetStatus(0).SpawnResult != 0) { |
| 41 | std::ostringstream e; |
| 42 | e << "Failed to start objdump process for:\n " << file; |
| 43 | this->SetError(e.str()); |
| 44 | return false; |
| 45 | } |
| 46 | |
| 47 | std::string line; |
| 48 | static cmsys::RegularExpression const neededRegex("^ *NEEDED *([^\n]*)$"); |
| 49 | static cmsys::RegularExpression const rpathRegex("^ *RPATH *([^\n]*)$"); |
| 50 | static cmsys::RegularExpression const runpathRegex("^ *RUNPATH *([^\n]*)$"); |
| 51 | cmUVIStream output(process.OutputStream()); |
| 52 | while (std::getline(output, line)) { |
| 53 | cmsys::RegularExpressionMatch match; |
| 54 | if (neededRegex.find(line.c_str(), match)) { |
| 55 | needed.push_back(match.match(1)); |
| 56 | } else if (rpathRegex.find(line.c_str(), match)) { |
| 57 | std::vector<std::string> rpathSplit = |
| 58 | cmSystemTools::SplitString(match.match(1), ':'); |
| 59 | rpaths.reserve(rpaths.size() + rpathSplit.size()); |
| 60 | for (auto const& rpath : rpathSplit) { |
| 61 | rpaths.push_back(rpath); |
| 62 | } |
| 63 | } else if (runpathRegex.find(line.c_str(), match)) { |
| 64 | std::vector<std::string> runpathSplit = |
| 65 | cmSystemTools::SplitString(match.match(1), ':'); |
| 66 | runpaths.reserve(runpaths.size() + runpathSplit.size()); |
| 67 | for (auto const& runpath : runpathSplit) { |
| 68 | runpaths.push_back(runpath); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | if (!process.Wait()) { |
| 74 | std::ostringstream e; |
| 75 | e << "Failed to wait on objdump process for:\n " << file; |
| 76 | this->SetError(e.str()); |
| 77 | return false; |
| 78 | } |
| 79 | if (process.GetStatus(0).ExitStatus != 0) { |
| 80 | std::ostringstream e; |
nothing calls this directly
no test coverage detected