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"
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");
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) {
39 e
<< "Failed to start dumpbin process for:\n " << file
;
40 this->SetError(e
.str());
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()) {
57 e
<< "Failed to wait on dumpbin process for:\n " << file
;
58 this->SetError(e
.str());
61 if (process
.GetStatus(0).ExitStatus
!= 0) {
63 e
<< "Failed to run dumpbin on:\n " << file
;
64 this->SetError(e
.str());