/src/CMake/Source/cmBinUtilsWindowsPEDumpbinGetRuntimeDependenciesTool.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 "cmBinUtilsWindowsPEDumpbinGetRuntimeDependenciesTool.h" |
5 | | |
6 | | #include <istream> |
7 | | #include <vector> |
8 | | |
9 | | #include <cmsys/RegularExpression.hxx> |
10 | | |
11 | | #include "cmRuntimeDependencyArchive.h" |
12 | | #include "cmStringAlgorithms.h" |
13 | | #include "cmUVProcessChain.h" |
14 | | #include "cmUVStream.h" |
15 | | |
16 | | cmBinUtilsWindowsPEDumpbinGetRuntimeDependenciesTool:: |
17 | | cmBinUtilsWindowsPEDumpbinGetRuntimeDependenciesTool( |
18 | | cmRuntimeDependencyArchive* archive) |
19 | 0 | : cmBinUtilsWindowsPEGetRuntimeDependenciesTool(archive) |
20 | 0 | { |
21 | 0 | } |
22 | | |
23 | | bool cmBinUtilsWindowsPEDumpbinGetRuntimeDependenciesTool::GetFileInfo( |
24 | | std::string const& file, std::vector<std::string>& needed) |
25 | 0 | { |
26 | 0 | cmUVProcessChainBuilder builder; |
27 | 0 | builder.SetBuiltinStream(cmUVProcessChainBuilder::Stream_OUTPUT); |
28 | |
|
29 | 0 | std::vector<std::string> command; |
30 | 0 | if (!this->Archive->GetGetRuntimeDependenciesCommand("dumpbin", command)) { |
31 | 0 | this->SetError("Could not find dumpbin"); |
32 | 0 | return false; |
33 | 0 | } |
34 | 0 | command.emplace_back("/dependents"); |
35 | 0 | command.push_back(file); |
36 | 0 | builder.AddCommand(command); |
37 | |
|
38 | 0 | auto process = builder.Start(); |
39 | 0 | if (!process.Valid() || process.GetStatus(0).SpawnResult != 0) { |
40 | 0 | this->SetError(cmStrCat("Failed to start dumpbin process for:\n ", file)); |
41 | 0 | return false; |
42 | 0 | } |
43 | | |
44 | 0 | std::string line; |
45 | 0 | static cmsys::RegularExpression const regex( |
46 | 0 | "^ ([^\n]*\\.[Dd][Ll][Ll])\r?$"); |
47 | 0 | cmUVIStream output(process.OutputStream()); |
48 | 0 | while (std::getline(output, line)) { |
49 | 0 | cmsys::RegularExpressionMatch match; |
50 | 0 | if (regex.find(line.c_str(), match)) { |
51 | 0 | needed.push_back(match.match(1)); |
52 | 0 | } |
53 | 0 | } |
54 | |
|
55 | 0 | if (!process.Wait()) { |
56 | 0 | this->SetError( |
57 | 0 | cmStrCat("Failed to wait on dumpbin process for:\n ", file)); |
58 | 0 | return false; |
59 | 0 | } |
60 | 0 | if (process.GetStatus(0).ExitStatus != 0) { |
61 | 0 | this->SetError(cmStrCat("Failed to run dumpbin on:\n ", file)); |
62 | 0 | return false; |
63 | 0 | } |
64 | | |
65 | 0 | return true; |
66 | 0 | } |