feat(provenance): emit deterministic SPDX and CycloneDX SBOMs
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 4s
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 4s
- New Provenance::Sbom module generating SPDX 2.3 / CycloneDX 1.5 from lockfile packages + BuildGraph outputs - Wire vbs build|test --sbom FILE --sbom-format spdx|cyclonedx - Register the module in CMake, build.cpp and the self-host recipe - Ed25519 signing requested upstream as Void/Library#36 (VL-014) - Verified in Docker GCC 16: 8/8 CTest suites; deterministic JSON unit test + CLI SBOM assertion
This commit is contained in:
1 parent
2970fbe25c
commit
55ea305528
13 files changed
+403
-8
No files matched your search
@@ -14,6 +14,7 @@
|
||||
#include <Void/Build/Package/Toml.hpp>
|
||||
#include <Void/Build/Platform/FileOps.hpp>
|
||||
#include <Void/Build/Platform/ProcessSupervisor.hpp>
|
||||
#include <Void/Build/Provenance/Sbom.hpp>
|
||||
#include <Void/Build/Provider/Provider.hpp>
|
||||
#include <Void/Build/Provider/Translator.hpp>
|
||||
#include <Void/Build/SelfHost/TestRegistryGen.hpp>
|
||||
@@ -507,6 +508,8 @@ struct BuildCmdOptions {
|
||||
std::optional<std::string> remote_cache_token_env;
|
||||
std::vector<std::string> members;
|
||||
std::optional<std::string> changed_since;
|
||||
std::optional<std::string> sbom_arg;
|
||||
std::optional<std::string> sbom_format_arg;
|
||||
std::optional<std::filesystem::path> lock_root;
|
||||
std::optional<std::filesystem::path> state_dir;
|
||||
bool publish_editor_selection{true};
|
||||
@@ -856,6 +859,78 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
|
||||
std::cout << "vbs: [" << prof_name << "] built (" << rep->executed_count << " executed, "
|
||||
<< rep->cached_count << " cached)\n";
|
||||
|
||||
if (opts.sbom_arg) {
|
||||
Provenance::SbomInput sbom;
|
||||
sbom.project_name = project_root.filename().string();
|
||||
sbom.tool_version = std::string{Bootstrap::version};
|
||||
sbom.created_epoch = ctx.reproducibility_epoch;
|
||||
const auto sbom_ctx_key = Package::make_lock_context_key(ctx, "target");
|
||||
if (pinned_lock && pinned_lock->has_value()) {
|
||||
const auto &document = (*pinned_lock)->document;
|
||||
if (const auto it = document.contexts.find(sbom_ctx_key);
|
||||
it != document.contexts.end()) {
|
||||
for (const auto &entry : it->second.entries) {
|
||||
if (entry.version.empty()) {
|
||||
continue;
|
||||
}
|
||||
Provenance::SbomPackage package;
|
||||
package.name =
|
||||
entry.package_name.empty() ? entry.alias : entry.package_name;
|
||||
package.version = entry.version;
|
||||
package.download_location = entry.registry_authority.empty()
|
||||
? entry.location
|
||||
: entry.registry_authority;
|
||||
package.sha256 = entry.sha256;
|
||||
package.purl = "pkg:generic/" + package.name + "@" + package.version;
|
||||
sbom.packages.push_back(std::move(package));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const auto &target : graph->targets) {
|
||||
for (const auto &output : target.primary_outputs) {
|
||||
auto digest = Util::sha256_file_hex(output);
|
||||
if (!digest) {
|
||||
continue;
|
||||
}
|
||||
Provenance::SbomFile file;
|
||||
file.path = Platform::path_is_within(project_root, output)
|
||||
? output.lexically_relative(project_root).generic_string()
|
||||
: output.filename().string();
|
||||
file.sha256 = std::move(*digest);
|
||||
sbom.files.push_back(std::move(file));
|
||||
}
|
||||
}
|
||||
try {
|
||||
const auto format = opts.sbom_format_arg
|
||||
? Provenance::parse_sbom_format(*opts.sbom_format_arg)
|
||||
: Provenance::SbomFormat::Spdx;
|
||||
auto generated = Provenance::generate_sbom(sbom, format);
|
||||
if (!generated) {
|
||||
std::cerr << "vbs: SBOM generation failed: " << generated.error().message()
|
||||
<< '\n';
|
||||
all_ok = false;
|
||||
continue;
|
||||
}
|
||||
std::filesystem::path sbom_path{*opts.sbom_arg};
|
||||
if (opts.profiles.size() > 1) {
|
||||
sbom_path =
|
||||
sbom_path.parent_path() / (sbom_path.stem().string() + "." + prof_name +
|
||||
sbom_path.extension().string());
|
||||
}
|
||||
if (auto wrote = Platform::atomic_write_file(sbom_path, *generated, true); !wrote) {
|
||||
std::cerr << "vbs: failed writing SBOM: " << wrote.error().message() << '\n';
|
||||
all_ok = false;
|
||||
continue;
|
||||
}
|
||||
Void::Log::info("Sbom", "[{}] Wrote {} SBOM to {}", prof_name,
|
||||
Provenance::sbom_format_name(format), sbom_path.string());
|
||||
} catch (const std::exception &ex) {
|
||||
std::cerr << "vbs: " << ex.what() << '\n';
|
||||
all_ok = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (run_tests) {
|
||||
for (const auto &t : graph->targets) {
|
||||
if (t.kind != TargetKind::Test || t.primary_outputs.empty()) {
|
||||
@@ -2131,6 +2206,9 @@ int main(int argc, char **argv) {
|
||||
.option_many("--member", "", "Workspace member to build/test", build_opts.members)
|
||||
.option("--changed-since", "", "Build/test workspace members changed since a git ref",
|
||||
build_opts.changed_since)
|
||||
.option("--sbom", "", "Write an SBOM after a successful build", build_opts.sbom_arg)
|
||||
.option("--sbom-format", "", "SBOM format: spdx (default) or cyclonedx",
|
||||
build_opts.sbom_format_arg)
|
||||
.option("--remote-cache", "", "Shared HTTP action cache URL (or VBS_REMOTE_CACHE)",
|
||||
build_opts.remote_cache_arg)
|
||||
.option("--remote-cache-token-env", "",
|
||||
|
||||
Reference in new issue
Block a user