Merge topic 'curl-tls-verify'
[kiteware-cmake.git] / Source / cmBinUtilsWindowsPEDumpbinGetRuntimeDependenciesTool.cxx
blobcd211400f4327db9365460f8c9b294065ec83cbd
1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
4 #include "cmBinUtilsWindowsPEDumpbinGetRuntimeDependenciesTool.h"
6 #include <sstream>
8 #include <cmsys/RegularExpression.hxx>
10 #include "cmRuntimeDependencyArchive.h"
11 #include "cmUVProcessChain.h"
12 #include "cmUVStream.h"
14 cmBinUtilsWindowsPEDumpbinGetRuntimeDependenciesTool::
15 cmBinUtilsWindowsPEDumpbinGetRuntimeDependenciesTool(
16 cmRuntimeDependencyArchive* archive)
17 : cmBinUtilsWindowsPEGetRuntimeDependenciesTool(archive)
21 bool cmBinUtilsWindowsPEDumpbinGetRuntimeDependenciesTool::GetFileInfo(
22 const std::string& file, std::vector<std::string>& needed)
24 cmUVProcessChainBuilder builder;
25 builder.SetBuiltinStream(cmUVProcessChainBuilder::Stream_OUTPUT);
27 std::vector<std::string> command;
28 if (!this->Archive->GetGetRuntimeDependenciesCommand("dumpbin", command)) {
29 this->SetError("Could not find dumpbin");
30 return false;
32 command.emplace_back("/dependents");
33 command.push_back(file);
34 builder.AddCommand(command);
36 auto process = builder.Start();
37 if (!process.Valid() || process.GetStatus(0).SpawnResult != 0) {
38 std::ostringstream e;
39 e << "Failed to start dumpbin process for:\n " << file;
40 this->SetError(e.str());
41 return false;
44 std::string line;
45 static const cmsys::RegularExpression regex(
46 "^ ([^\n]*\\.[Dd][Ll][Ll])\r$");
47 cmUVPipeIStream output(process.GetLoop(), process.OutputStream());
48 while (std::getline(output, line)) {
49 cmsys::RegularExpressionMatch match;
50 if (regex.find(line.c_str(), match)) {
51 needed.push_back(match.match(1));
55 if (!process.Wait()) {
56 std::ostringstream e;
57 e << "Failed to wait on dumpbin process for:\n " << file;
58 this->SetError(e.str());
59 return false;
61 if (process.GetStatus(0).ExitStatus != 0) {
62 std::ostringstream e;
63 e << "Failed to run dumpbin on:\n " << file;
64 this->SetError(e.str());
65 return false;
68 return true;