Skip to content

feat(sbom): add --macro-prefix to record only a product's own macros - #49

Open
Frauschi wants to merge 1 commit into
masterfrom
feat/macro-prefix-filter
Open

Frauschi wants to merge 1 commit into
masterfrom
feat/macro-prefix-filter

Conversation

@Frauschi

Copy link
Copy Markdown
Member

What

gen-sbom --macro-prefix PREFIX (repeatable) records only the captured build macros whose name starts with one of the prefixes. It is meant for a product that shares one user_settings.h with wolfSSL, such as wolfCert, whose SBOM today records every wolfSSL macro as the product's own configuration.

  • Applies to --options-h and --user-settings alike. --crypto-only auto still reads the full capture.
  • The scope is recorded in the document (wolfssl:sbom:macro-prefix property in CycloneDX, annotation in SPDX) and folded into the config identity only when set, so existing SBOMs keep their serialNumber.
  • Each prefix that matches nothing warns, and so does a prefix given when nothing was captured. An empty prefix, one with surrounding whitespace, or one containing a comma is an error.
  • With --crypto-only auto, wolfssl-subset-basis=captured can rest on a macro the prefix filtered out of the document (for example WOLFCRYPT_ONLY); that is intended, and the docstring says so.
  • Wired through the build fragments: driver (forwarded only when gen-sbom advertises it, with a note when dropped), CMake MACRO_PREFIX, sbom.mk and sbom.am SBOM_MACRO_PREFIX.
  • sbom.am also gains SBOM_USER_SETTINGS / SBOM_USER_SETTINGS_INCLUDES / SBOM_USER_SETTINGS_DEFINES, matching the CMake and Make paths.
  • Not covered yet: the compdb and IAR frontends have no --macro-prefix option.

Tests

  • TestMacroPrefix in test_gen_sbom.py (12 tests), identity coverage in test_sbom_identity.py, end-to-end generate plus driver forwarding in test_sbom.py.
  • Fragment wiring: CMake MACRO_PREFIX in test_sbom_cmake_install.py, sbom.mk in test_sbom.py, and sbom.am (SBOM_MACRO_PREFIX plus the three SBOM_USER_SETTINGS errors) in test_sbom_autotools.py. The SBOM_USER_SETTINGS capture itself needs pcpp and runs in CI.
  • Independent of the other two open follow-ups (driver input checks, CMake helper scope); all three merge cleanly in any order and pass together.

A product that shares one user_settings.h with wolfSSL, such as wolfCert,
captures every wolfSSL macro along with its own, so its SBOM recorded
wolfSSL's configuration as the product's build properties. gen-sbom now
takes --macro-prefix PREFIX (repeatable) and records only the captured
macros whose name starts with one of the prefixes. It applies to
--options-h and --user-settings alike. --crypto-only auto still reads the
full capture, since that decision depends on wolfSSL's macros, so the
recorded subset basis can rest on a macro the document filtered out.

The prefixes are recorded in the document (a wolfssl:sbom:macro-prefix
property in CycloneDX, an annotation in SPDX) and folded into the
configuration identity only when set, so an unscoped SBOM keeps its
serialNumber. A prefix that matches none of the captured macros, or a
prefix given when nothing was captured, prints a warning. An empty
prefix, one with surrounding whitespace, or one holding a comma is an
error, since the recorded value is a comma-joined list.

The driver forwards --macro-prefix only when gen-sbom advertises it and
prints a note when it has to drop it, as sbom.am does. The CMake helper
takes MACRO_PREFIX, sbom.mk and sbom.am take SBOM_MACRO_PREFIX. sbom.am
also gains SBOM_USER_SETTINGS (with SBOM_USER_SETTINGS_INCLUDES and
SBOM_USER_SETTINGS_DEFINES), so an autotools product configured by a
user_settings.h can use the same capture as the CMake and Make paths.

Tests cover the filter and its warnings in test_gen_sbom.py, the identity
fold, the driver forwarding, and the wiring in each build fragment: CMake
and sbom.mk through their generated driver command, sbom.am through the
autotools fixture.
Copilot AI balanced review requested due to automatic review settings October 22, 2026 17:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The scoped filtering, backward-compatible identity handling, and build integrations are consistent with the stated behavior, with no unresolved blocking findings.

No open issues 🎉

What changed in this PR

Adds macro-prefix filtering to the shared SBOM generator so products can record their own configuration macros from a header shared with wolfSSL.

Changes:

  • Filters recorded macros while preserving full-capture crypto-only detection and unchanged document identities when no prefix is set.
  • Forwards prefixes through the driver, CMake, Make, and Autotools; adds Autotools user-settings inputs.
  • Adds tests for filtering, validation, identity, and build integration, plus usage documentation.
File Description
tests/​test_sbom.py Tests driver forwarding, fallback notes, and Make integration.
tests/​test_sbom_identity.py Tests prefix-sensitive identity and default compatibility.
tests/​test_sbom_cmake_install.py Tests CMake prefix forwarding.
tests/​test_sbom_autotools.py Tests prefix filtering and user-settings input checks.
tests/​test_gen_sbom.py Tests filtering, metadata, warnings, and validation.
share/​sbom.am Adds prefix forwarding and user-settings capture inputs.
share/​sbom-driver.py Forwards prefixes when supported by the generator.
share/​README.md Documents filtering and Autotools configuration.
share/​gen-sbom Implements filtering, scope metadata, and identity handling.
share/​build/​sbom.mk Forwards SBOM_MACRO_PREFIX to the driver.
share/​build/​sbom.cmake Adds the MACRO_PREFIX argument.
README.md Documents the Autotools user-settings option.

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants