File: cmExportBuildSbomGenerator.cxx

package info (click to toggle)
cmake 4.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 158,704 kB
  • sloc: ansic: 406,077; cpp: 309,512; sh: 4,233; python: 3,696; yacc: 3,109; lex: 1,279; f90: 538; asm: 471; lisp: 375; java: 310; cs: 270; fortran: 239; objc: 215; perl: 213; xml: 198; makefile: 110; javascript: 83; pascal: 63; tcl: 55; php: 25; ruby: 22; sed: 2
file content (89 lines) | stat: -rw-r--r-- 2,435 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file LICENSE.rst or https://cmake.org/licensing for details.  */
#include "cmExportBuildSbomGenerator.h"

#include <functional>
#include <utility>
#include <vector>

#include <cmext/string_view>

#include "cmGeneratorExpression.h"
#include "cmSbomArguments.h"
#include "cmSbomObject.h"
#include "cmSpdx.h"
#include "cmStringAlgorithms.h"

class cmGeneratorTarget;

cmExportBuildSbomGenerator::cmExportBuildSbomGenerator(cmSbomArguments args)
  : cmExportSbomGenerator(args)
{
  this->SetNamespace(cmStrCat(this->GetPackageName(), "::"_s));
}

bool cmExportBuildSbomGenerator::GenerateMainFile(std::ostream& os)
{
  if (!this->CollectExports([&](cmGeneratorTarget const*) {})) {
    return false;
  }

  cmSbomDocument doc;
  doc.Graph.reserve(256);

  cmSpdxCreationInfo const* ci =
    insert_back(doc.Graph, this->GenerateCreationInfo());
  cmSpdxDocument* project = insert_back(doc.Graph, this->GenerateSbom(ci));
  std::vector<TargetProperties> targets;

  for (auto const& exp : this->Exports) {
    cmGeneratorTarget const* target = exp.Target;

    ImportPropertyMap properties;
    this->PopulateInterfaceProperties(target, properties);
    this->PopulateInterfaceLinkLibrariesProperty(
      target, cmGeneratorExpression::BuildInterface, properties);
    this->PopulateLinkLibrariesProperty(
      target, cmGeneratorExpression::BuildInterface, properties);

    targets.push_back(
      TargetProperties{ insert_back(project->RootElements,
                                    this->GenerateImportTarget(ci, target)),
                        target, std::move(properties) });
  }

  for (auto const& target : targets) {
    this->GenerateProperties(doc, project, ci, target, targets);
  }

  this->WriteSbom(doc, os);
  return true;
}

void cmExportBuildSbomGenerator::HandleMissingTarget(
  std::string& /* link_libs */, cmGeneratorTarget const* /* depender */,
  cmGeneratorTarget* /* dependee */)
{
}

std::string cmExportBuildSbomGenerator::GetCxxModulesDirectory() const
{
  return {};
}

cm::string_view cmExportBuildSbomGenerator::GetImportPrefixWithSlash() const
{
  return "";
}

std::string cmExportBuildSbomGenerator::GetCxxModuleFile(
  std::string const& /*name*/) const
{
  return {};
}

void cmExportBuildSbomGenerator::GenerateCxxModuleConfigInformation(
  std::string const& /*name*/, std::ostream& /*os*/) const
{
  // TODO
}