mirror of
https://github.com/Kitware/CMake.git
synced 2026-11-06 05:16:58 +00:00
install(SBOM) could crash for dependencies outside an export set and mishandle private dependencies expressed through LINK_ONLY. Resolve link expressions before target lookup, traverse unexported dependencies transitively, and isolate document state per configuration. Preserve target license precedence and align document metadata inheritance with CPS. Add regression coverage for these cases. Fixes: #28141 Fixes: #28210
65 lines
1.8 KiB
C++
65 lines
1.8 KiB
C++
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
file LICENSE.rst or https://cmake.org/licensing for details. */
|
|
#pragma once
|
|
|
|
#include <iosfwd>
|
|
#include <string>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
#include <cm/memory>
|
|
|
|
#include "cmBuildSbomBuilder.h"
|
|
|
|
class cmExportSet;
|
|
class cmGeneratorTarget;
|
|
class cmLocalGenerator;
|
|
class cmSbomArguments;
|
|
|
|
/** \class cmBuildSbomGenerator
|
|
* \brief Generate build-tree SBOM files, one document per configuration.
|
|
*
|
|
* Stored on cmMakefile at configure time. At generate time,
|
|
* ComputeBuildFileGenerators() calls Compute(lg) to resolve export set
|
|
* targets for peer SBOM lookups before any documents are generated.
|
|
*/
|
|
class cmBuildSbomGenerator
|
|
{
|
|
public:
|
|
cmBuildSbomGenerator(cmSbomArguments const& args,
|
|
std::vector<cmExportSet*> const& exportSets,
|
|
std::string outputFile)
|
|
: OutputFile(std::move(outputFile))
|
|
, Builder(cm::make_unique<cmBuildSbomBuilder>(args, exportSets))
|
|
{
|
|
}
|
|
|
|
void Compute(cmLocalGenerator* lg);
|
|
|
|
std::string const& GetOutputFile() const { return this->OutputFile; }
|
|
|
|
/** True if this SBOM directly describes `target`. Used by peer SBOMs to
|
|
* attribute cross-references when install(export) provenance is absent. */
|
|
bool CoversTarget(cmGeneratorTarget const* target) const
|
|
{
|
|
return this->Builder->CoversTarget(target);
|
|
}
|
|
|
|
bool GenerateForBuild(std::ostream& os, std::string const& config)
|
|
{
|
|
return this->Builder->Generate(os, config);
|
|
}
|
|
|
|
std::string const& GetPackageName() const
|
|
{
|
|
return this->Builder->GetPackageName();
|
|
}
|
|
|
|
/** Open the output file and write the SBOM document to it. */
|
|
bool GenerateForBuild(std::string const& config);
|
|
|
|
private:
|
|
std::string const OutputFile;
|
|
std::unique_ptr<cmBuildSbomBuilder> Builder;
|
|
};
|