Coverage Report

Created: 2026-03-12 06:35

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