/src/CMake/Source/cmLDConfigLDConfigTool.cxx
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
2 | | file LICENSE.rst or https://cmake.org/licensing for details. */ |
3 | | |
4 | | #include "cmLDConfigLDConfigTool.h" |
5 | | |
6 | | #include <istream> |
7 | | #include <string> |
8 | | #include <vector> |
9 | | |
10 | | #include "cmsys/RegularExpression.hxx" |
11 | | |
12 | | #include "cmList.h" |
13 | | #include "cmMakefile.h" |
14 | | #include "cmRuntimeDependencyArchive.h" |
15 | | #include "cmSystemTools.h" |
16 | | #include "cmUVProcessChain.h" |
17 | | #include "cmUVStream.h" |
18 | | |
19 | | cmLDConfigLDConfigTool::cmLDConfigLDConfigTool( |
20 | | cmRuntimeDependencyArchive* archive) |
21 | 0 | : cmLDConfigTool(archive) |
22 | 0 | { |
23 | 0 | } |
24 | | |
25 | | bool cmLDConfigLDConfigTool::GetLDConfigPaths(std::vector<std::string>& paths) |
26 | 0 | { |
27 | 0 | std::string ldConfigPath = |
28 | 0 | this->Archive->GetMakefile()->GetSafeDefinition("CMAKE_LDCONFIG_COMMAND"); |
29 | 0 | if (ldConfigPath.empty()) { |
30 | 0 | ldConfigPath = cmSystemTools::FindProgram( |
31 | 0 | "ldconfig", { "/sbin", "/usr/sbin", "/usr/local/sbin" }); |
32 | 0 | if (ldConfigPath.empty()) { |
33 | 0 | this->Archive->SetError("Could not find ldconfig"); |
34 | 0 | return false; |
35 | 0 | } |
36 | 0 | } |
37 | | |
38 | 0 | cmList ldConfigCommand{ ldConfigPath }; |
39 | 0 | ldConfigCommand.emplace_back("-v"); |
40 | 0 | ldConfigCommand.emplace_back("-N"); // Don't rebuild the cache. |
41 | 0 | ldConfigCommand.emplace_back("-X"); // Don't update links. |
42 | |
|
43 | 0 | cmUVProcessChainBuilder builder; |
44 | 0 | builder.SetBuiltinStream(cmUVProcessChainBuilder::Stream_OUTPUT) |
45 | 0 | .AddCommand(ldConfigCommand); |
46 | 0 | auto process = builder.Start(); |
47 | 0 | if (!process.Valid() || process.GetStatus(0).SpawnResult != 0) { |
48 | 0 | this->Archive->SetError("Failed to start ldconfig process"); |
49 | 0 | return false; |
50 | 0 | } |
51 | | |
52 | 0 | std::string line; |
53 | 0 | static cmsys::RegularExpression const regex("^([^\t:]*):"); |
54 | 0 | cmUVIStream output(process.OutputStream()); |
55 | 0 | while (std::getline(output, line)) { |
56 | 0 | cmsys::RegularExpressionMatch match; |
57 | 0 | if (regex.find(line.c_str(), match)) { |
58 | 0 | paths.push_back(match.match(1)); |
59 | 0 | } |
60 | 0 | } |
61 | |
|
62 | 0 | if (!process.Wait()) { |
63 | 0 | this->Archive->SetError("Failed to wait on ldconfig process"); |
64 | 0 | return false; |
65 | 0 | } |
66 | 0 | if (process.GetStatus(0).ExitStatus != 0) { |
67 | 0 | this->Archive->SetError("Failed to run ldconfig"); |
68 | 0 | return false; |
69 | 0 | } |
70 | | |
71 | 0 | return true; |
72 | 0 | } |