Build SBOM and reproducible builds¶
The build writes three software bills of materials next to the library and
embeds the SHA-256 of its primary CycloneDX document in libgpridge. The
in-tree generator records Meson’s resolved build dependencies.
What eb-stack already covers¶
eb-stack package inspect reads the Spack package.py, a conda
recipe.yaml, and an EasyBuild .eb file. It writes package.sbom.cdx.json
(CycloneDX 1.5, no timestamp), package.spdx.json (SPDX 2.3), and
package.spdx3.json (SPDX 3.0). Component identity is a package URL. A
64-hex source digest is SHA-256. scripts/gen_recipe_sbom.py runs that
command for the recipes in this repository. There is no checked-in
easyconfig; the EasyBuild document is produced after
easybuild/generate_easyconfig.py writes one.
python scripts/gen_recipe_sbom.py --eb-stack eb-stack \
--source packaging/spack/packages/gpridge/package.py \
--output gpridge.recipe.cdx.json --sha gpridge.recipe.sbom.sha256
What the build inventory adds¶
The in-tree generator reads meson-info dependency, project, build-option,
and compiler records. It emits the primary CycloneDX 1.5 SBOM and records
resolved component versions, configure options, compiler identities, and the
exact git commit (or the tarball version).
The build uses scripts/gen_in_tree_sbom.py and Meson introspection:
installs
gpridge.cdx.json,gpridge.spdx.json,gpridge.spdx3.json, andgpridge.sbom.sha256atshare/gpridge/sbom/;copies those files into the
gpridgepackage so a wheel carries them;writes
gpr_sbom_digest.h, which the library compiles in.
The digest is the SHA-256 of the exact gpridge.cdx.json bytes. SPDX 2.3 and
SPDX 3.0 carry the same packages, artifact files, checksums, and relationships,
but they are not part of the embedded digest.
GPR_SBOM_SHA256 and GPR_SOURCE_DATE_EPOCH are compiled into the library as
a string marker and into gpridge._core.build_info. Neither adds a C ABI
entry. _core.build_info returns those two strings and the library version.
gpridge.build_info.read_build_info returns the same digest when the
installed CycloneDX file matches, with digest_verified set. A stale
GPRIDGE_SBOM_DIR is skipped in favor of a later copy; if nothing else
matches, it raises SbomLookupError and names that variable. The search list
is the directory next to the module and <prefix>/share/gpridge/sbom, so a
library installed without a copy inside the Python package is still found. A
wheel carries only the copy inside the package.
read_build_info()["dependencies"] is always the CycloneDX build inventory
and source is build-sbom. runtime_components is the separate list from
gpridge.provenance.component_registry(), which describes what the running
process loaded, or None when the extension is not importable. A library
built with -Dsbom=disabled embeds an empty digest: source is then
sbom-disabled, the inventory is empty, and no directory is searched, so
another installation’s SBOM is never reported for this build.
The source-tree digest is SHA-256 over the tracked source tree (git ls-files)
together with its untracked and ignored build inputs, sorted by path, when
the source root has its own .git. A build input is a file Meson, the
compilers, Cargo or the Python build read: C, C++, Fortran, CUDA and Rust
sources and headers, Python, .in templates, TOML, wraps, Cap’n Proto
schemas, linker scripts, patches, meson.build, meson_options.txt and
Cargo.lock. Build directories, environment prefixes, __pycache__, the
wrap checkouts under subprojects/ and a wrap Meson promoted from one of
them are not inputs of the tree; each subproject is its own component. It is this
generator’s own encoding, not the checksum of any file or archive, so no
format records it as a package hash: CycloneDX carries it in the root
property gpridge:source-tree-sha256, SPDX 2.3 in an OTHER annotation on
the root package, and SPDX 3.0.1 in an Annotation whose subject is the root
package. Both annotations begin gpridge:source-tree-sha256=<hex>. Each path
contributes its work-tree kind (100644, 100755, 120000 symlink, 160000
submodule, or absent), the path, and its content (a symlink’s target, a
submodule’s commit), each field prefixed by its length. A source root
without its own .git, such as an unpacked source archive, hashes every file
under it the same way, minus build directories, environment prefixes and
__pycache__. gpridge:source-digest-scope is tracked-tree or
source-tree accordingly. gpridge:git-dirty is true when a tracked file
differs from HEAD, when an untracked or ignored build input is present, or
when the repository has no commit. A directory inside some other repository
does not inherit that repository’s commit. A .git that git cannot read
stops generation; it is never reported as a clean tree.
Each dependency is hashed from the library that matches its name, or from the
first -l argument when the name does not match. That library is the only
file the package CONTAINS. Every other resolved library is its own SPDX
file and a link dependency: the package DEPENDS_ON the component whose
artifact it is (gtest_main on gtest), else on the file (hdf5 on
libsz). The root depends on the Meson dependencies, in-tree libraries,
subprojects and Python bindings directly; a crate compiled into an in-tree
Cargo archive is a dependency of that archive’s component, and robin-map of
nanobind, which vendors it. CycloneDX dependencies carries the same
component edges. A package that contains its artifact has
filesAnalyzed true and the SPDX 2.3 packageVerificationCode over the
files it contains; every other package, the root included, has
filesAnalyzed false. SPDX 2.3 files carry SHA-1, which the specification
requires, beside SHA-256. Every SPDX 2.3 package and file writes its
license and copyright fields (licenseConcluded, licenseInfoInFiles or
licenseInfoFromFiles, copyrightText), NOASSERTION when unknown: SPDX
2.3 reads an absent field that way, but SPDX 2.2 requires them. Only the
root’s copyrightText is known; it is the copyright notice lines of
the project’s license file. A header-only dependency is recorded with no
file hash. A library this build produces and links into libgpridge is
hashed from that file; meson.build lists these in
sbom-in-tree-libraries.json, which is a generator input. Other configured
subprojects are listed without a file hash. The SBOM target depends on those
library targets.
If the file is missing, generation stops and names the dependency. It does
not hash a system library of the same name, and it does not leave the hash
out. A library Meson resolved as an external system library may be hashed
from the system path. gpridge:artifact-origin is in-tree or system.
SPDX 2.3 fileName values are relative paths. In SPDX 3, createdBy
identifies the SoftwareAgent for the gpridge-sbom generator within
the same document.
A system library is found the way GNU ld finds it. Every -L directory is
searched first, then the directories the compiler that links reports with
-print-search-dirs. In each directory -l<name> opens lib<name>.so
before lib<name>.a, and only the archive after -Bstatic until the next
-Bdynamic. Those two modes apply inside one comma-joined group as well, so
-Wl,-Bstatic,-lfoo,-Bdynamic,-lbar links the archive of foo and the
shared object of bar. -l:<file> names the file exactly. A name the model
cannot find is listed in gpridge:unresolved-link-names; it is not dropped.
Meson reports dl and threads without a version; the C library provides
both, so they take the glibc release printed in the libc.so.6 that the
recorded compiler links (-print-file-name=libc.so.6), with
gpridge:version-source glibc-release. Any other dependency without a
version, and those two under another C library, is kept with
gpridge:version-unknown-reason: SPDX 2.3 versionInfo is NOASSERTION,
and CycloneDX and SPDX 3.0.1 leave the optional version out. No document
writes the version unknown.
Where versions and licenses come from¶
Every subproject the build configured is a component: the list is
intro-projectinfo.json’s subprojects, which covers in-tree subprojects,
wraps, and fallbacks. A wrap’s checkout directory comes from the directory
key of its .wrap file. The SBOM target in meson.build passes no license
and only meson.project_version(): the root package takes the version and
the license of this project’s project() call, the latter from
intro-projectinfo.json (--license overrides it). Every other component’s
version and license come from its own metadata, and
gpridge:version-source and gpridge:license-source name which.
Value |
Source |
Read from |
|---|---|---|
version |
|
the crate’s entry in the subproject’s |
version |
|
the version marker in a vendored single-file source (vesin) |
version |
|
the subproject’s |
version |
|
the |
license |
|
the crate’s |
license |
|
the |
license |
|
an |
license |
|
|
license |
|
a license recorded on the Meson dependency itself |
license |
|
a table for code that ships no license metadata of its own |
Every source except curated is what the package itself states, so SPDX 2.3
writes it as licenseDeclared and leaves licenseConcluded as NOASSERTION:
the generator does not analyse the code. A curated license is this
project’s conclusion for code that declares none, so it is licenseConcluded
and licenseDeclared is NOASSERTION. The root package’s license is the one
the project declares. SPDX 3.0.1 links a declared license through
hasDeclaredLicense and a curated one through hasConcludedLicense to a
simplelicensing_LicenseExpression element. A license nothing declares is
NOASSERTION in both SPDX 2.3 fields, has no license relationship in SPDX
3.0.1 (which reads as NoAssertion), and is left out of CycloneDX, where
NOASSERTION is not a license expression. CycloneDX 1.5 carries the
expression and names its origin in gpridge:license-source.
Every license, the root’s --license included, is parsed with the
license-expression package against the SPDX expression grammar, and each
identifier as written has to be a current SPDX license list identifier or
exception. An alias (GPL), a deprecated identifier (GPL-2.0+), a
LicenseRef- the document does not define, or a malformed expression stops
generation with the component and the expression named; it is never
written. The generator runs in the Python that builds the extension when
with_python is set, and otherwise in the python3 that Meson finds; that
interpreter needs license-expression. Without it -Dsbom=enabled stops
configure, and -Dsbom=auto configures the build as disabled with a
Meson message naming the missing package.
Several SPDX-License-Identifier headers, or a Meson license list, combine
with AND. An operand that is a disjunction keeps its parentheses, so
MIT OR Apache-2.0 and BSD-3-Clause become
(MIT OR Apache-2.0) AND BSD-3-Clause.
meson dist runs scripts/dist_sbom.py. It reads the same in-tree library
manifest and subproject metadata as the build, so the source distribution
lists the same components with the same versions and licenses. It does not
hash host-compiled files, so its components carry no file hashes.
Turning it on¶
The Meson option -Dsbom is auto by default. Both -Dsbom=auto and
-Dsbom=enabled write
the primary build SBOM with the in-tree generator; neither requires
eb-stack. auto falls back to disabled when license-expression is
missing, which enabled refuses. disabled still compiles the library, with an empty digest.
When a compatible eb-stack is on PATH, it additionally writes a
recipe-level CycloneDX companion with package inspect --source --sbom-out.
CycloneDX has no timestamp. SPDX created is the UTC rendering of
SOURCE_DATE_EPOCH, which defaults to the Unix epoch when unset. The generated
header records the same integer. Set the same value for every build that must
match byte for byte. The SPDX 2.3 documentNamespace and every SPDX 3.0.1
spdxId are derived from the CycloneDX digest and the document’s own
content, created included, so builds that differ in any input or in
SOURCE_DATE_EPOCH get distinct identities and identical inputs get the same
ones.
Reproducible builds¶
scripts/repro_build.sh configures two build directories for the same source
tree and SOURCE_DATE_EPOCH, generates the SBOM in each, and compares all
five outputs byte for byte. Source, build, and home paths are scrubbed from
the introspected properties before serialization, including a path glued to
-I, -L or -isystem and a path joined by a comma in -Wl,-rpath, or
-Wl,-rpath-link,. They become /source, /build and /home/<user>.
Any other absolute path in a build option, a compiler record, or an artifact
path is kept only under /usr, /lib*, /bin or /sbin; elsewhere it
becomes <path-DIGEST>/name, where the digest is of its directory.
gpridge:build-options carries only the options in the generator’s
allowlist: the options of meson_options.txt and the Meson options that
shape the binaries (build type, optimization, compiler standards and
arguments, base options, install directories). A name that suggests a
secret (token, key, password, secret, credential) is never
published, and a NAME=value argument with such a name keeps only
NAME=<redacted>. gpridge:build-options-withheld lists the names of the
other options, subproject options included, without their values.
SPDX 2.3 and 3.0.1 have no fields for this build provenance (git commit and dirty state, compilers, options, inventory kind, library search directories). The root package carries a second annotation whose statement is =gpridge build provenance: = followed by a JSON object of the same CycloneDX property names and values, without the source-tree digest and its scope, which the first annotation states.
The integration test validates the generated CycloneDX 1.5, SPDX 2.3, and SPDX 3.0.1 documents against the official JSON schemas stored beside the test. It also checks artifact hashes and verifies that a second run is byte-identical.
Checking a prefix¶
sha256sum share/gpridge/sbom/gpridge.cdx.json
# This value is gpridge.sbom.sha256 and the digest embedded in the library.
python -c "import gpridge.build_info; print(gpridge.build_info.read_build_info()['sbom_sha256'])"
An empty sha256 means this build was configured with =sbom=disabled.