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"
8 #include <cmsys/RegularExpression.hxx>
10 #include "cmRuntimeDependencyArchive.h"
11 #include "cmUVProcessChain.h"
13 cmBinUtilsWindowsPEDumpbinGetRuntimeDependenciesTool::
14 cmBinUtilsWindowsPEDumpbinGetRuntimeDependenciesTool(
15 cmRuntimeDependencyArchive* archive)
16 : cmBinUtilsWindowsPEGetRuntimeDependenciesTool(archive)
20 bool cmBinUtilsWindowsPEDumpbinGetRuntimeDependenciesTool::GetFileInfo(
21 const std::string& file, std::vector<std::string>& needed)
23 cmUVProcessChainBuilder builder;
24 builder.SetBuiltinStream(cmUVProcessChainBuilder::Stream_OUTPUT);
26 std::vector<std::string> command;
27 if (!this->Archive->GetGetRuntimeDependenciesCommand("dumpbin", command)) {
28 this->SetError("Could not find dumpbin");
31 command.emplace_back("/dependents");
32 command.push_back(file);
33 builder.AddCommand(command);
35 auto process = builder.Start();
36 if (!process.Valid()) {
38 e << "Failed to start dumpbin process for:\n " << file;
39 this->SetError(e.str());
44 static const cmsys::RegularExpression regex(
45 "^ ([^\n]*\\.[Dd][Ll][Ll])\r$");
46 while (std::getline(*process.OutputStream(), line)) {
47 cmsys::RegularExpressionMatch match;
48 if (regex.find(line.c_str(), match)) {
49 needed.push_back(match.match(1));
53 if (!process.Wait()) {
55 e << "Failed to wait on dumpbin process for:\n " << file;
56 this->SetError(e.str());
59 auto status = process.GetStatus();
60 if (!status[0] || status[0]->ExitStatus != 0) {
62 e << "Failed to run dumpbin on:\n " << file;
63 this->SetError(e.str());