Repository navigation
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Shared staging directories can cause parallel SBOM targets to delete each other’s files, while conflicting checksum options and colliding validation paths can fail generation or delete generated output.
3 open issues
What changed in this PR
This PR moves installed-artifact staging and SPDX validation into the shared CMake SBOM helper, reducing logic that products need to maintain themselves.
Changes:
- Adds
STAGE_TARGETto hash installed artifacts using isolatedDESTDIRstaging. - Adds
VALIDATEand tag-value output installation, with missing-tool errors deferred until build time. - Adds integration tests and updates vendoring documentation.
| File | Description |
|---|---|
tests/test_sbom_cmake_install.py |
Tests staging, validation, installation, cleanup, and missing tools. |
share/README.md |
Clarifies vendoring instructions and documents new helper options. |
share/build/sbom.cmake |
Wires staging, validation, and build-time prerequisite failures. |
share/build/sbom-with-sde.cmake |
Stages installed artifacts and cleans up after generation. |
share/build/sbom-validate.cmake |
Validates SPDX and writes tag-value output. |
share/build/sbom-paths.cmake |
Derives the tag-value output path for validation. |
share/build/sbom-fail.cmake |
Reports missing prerequisites when the target runs. |
Review effort: Balanced
| endif() | ||
|
|
||
| if(SB_STAGE_TARGET) | ||
| set(_stage_dir "${CMAKE_CURRENT_BINARY_DIR}/_sbom_staging") |
There was a problem hiding this comment.
Reproduced: two STAGE_TARGET calls in one directory built with -j2 failed 5 of 15 runs with "SBOM staging install failed".
| if(_tv STREQUAL "" AND WOLFSSL_COMPLIANCE_TOOLING_SBOM_TV_FROM_SPDX) | ||
| string(REGEX REPLACE "\\.json$" "" _tv "${_spdx}") | ||
| endif() |
There was a problem hiding this comment.
Reproduced: SPDX_OUT b.spdx with VALIDATE left b.spdx holding the tag-value output instead of the SPDX JSON.
| if(SB_LIB) | ||
| message(FATAL_ERROR | ||
| "wolfssl_compliance_tooling_add_sbom: STAGE_TARGET names the " | ||
| "hashed file. Do not pass LIB.") |
The products wrote the same CMake code around the helper, with the same bugs. The helper now does that work. - STAGE_TARGET <t> installs the project with DESTDIR into a private staging directory and hashes the installed file of <t>. The prefix stays the real one, so the bytes match a real install. A DESTDIR in the environment does not move the staging, and an absolute install directory stays inside it. The staging directory is removed after the driver runs, also when it fails. - VALIDATE runs pyspdxtools on the SPDX file and writes the tag-value file in the same target. install-sbom depends on that target, so it validates and installs the tag-value file too. - A missing python3, or a missing pyspdxtools with VALIDATE, no longer fails configure. The target fails with the reason when it is built. - share/README.md had the title "share/" and pointed at a sync tool that a product does not have. It now names the toolkit and says where the sync tool is.
368113e to
f9fe302
Compare
Frauschi
left a comment
There was a problem hiding this comment.
Ran the new tests locally and the staging hashes the installed copy; three issues inline.
| endforeach() | ||
| list(REMOVE_DUPLICATES _srcs) | ||
|
|
||
| set(_sbom_error "") |


What
Frauschi's review of wolfSSL/wolfssl#11701 found bugs in the CMake code that wolfSSL and wolfTPM write around
wolfssl_compliance_tooling_add_sbom(). The code is generic, so the helper now does that work, and the products can remove their copies.STAGE_TARGET <t>: hash the installed copy of<t>, asmake sbomdoes. When the target runs, the project is installed withDESTDIRinto_sbom_stagingin the build tree. The prefix stays the real one, so the staged file has the same bytes (RPATH, install name) as a real install. This fixes two bugs ofcmake --install --prefix:DESTDIRin the environment moved the staged files, and the driver did not find the library. The staging now sets its ownDESTDIRand restores the caller's after the install.CMAKE_INSTALL_LIBDIRinstalled into the real directory. WithDESTDIR, it stays inside the staging tree.The file is the target's file name in
CMAKE_INSTALL_FULL_LIBDIR, or inCMAKE_INSTALL_FULL_BINDIRfor a program or a Windows DLL. The staging directory is removed after the driver runs, also when it fails.VALIDATE: runpyspdxtoolson the SPDX file and write the tag-value file (TV_OUT, or the SPDX path without.json) in the same target.install-sbomdepends on that target, so it now validates the SPDX file and installs the.spdxfile. Before, wolfSSL'sinstall-sbomdepended on the generation target only, so it skippedpyspdxtoolsand did not install the.spdxfile.Missing tools: a missing
python3, or a missingpyspdxtoolswithVALIDATE, no longer fails configure (-DCMAKE_DISABLE_FIND_PACKAGE_Python3=ONreproduced the failure). The target fails with the reason when someone builds it (sbom-fail.cmake).share/README.md: the title was# share/, and it pointed at a sync tool that a product does not have. It now names the toolkit, and it says that the sync tool is in a toolkit checkout. It also lists the CMake scripts and the new options.Tests
New
HelperBuildTestsintests/test_sbom_cmake_install.py. Each test builds a small shared library:test_stage_validate_and_install: absoluteCMAKE_INSTALL_LIBDIRandDESTDIRset forinstall-sbom. The library is not installed to the absolute directory. No_sbom_stagingstays. The CycloneDX, SPDX and tag-value files are installed underDESTDIR. The CycloneDX hash is the SHA-256 of a real installed copy.test_failed_validation_fails_the_target: a failedpyspdxtoolsfailsinstall-sbom, writes no tag-value file and leaves no staging directory.test_staging_without_a_build_fails_and_cleans_up: a failed staging install gives a clear error and leaves no staging directory.test_missing_python_fails_at_build_timeandtest_validate_without_pyspdxtools_fails_at_build_time: configure succeeds, and the build fails with the reason.The tests use a stub
pyspdxtools, so CI does not needspdx-tools.This branch merges cleanly with #51. #49 and #50 already conflict with master in
share/build/sbom.mk(from #52). This PR does not change that file.