utils/generate-cyclonedx: fix 'project' dependency
PATCH v2 1/4 utils/generate-cyclonedx: fix 'project' dependency
The definition of the project name & version is stored under the metadata:component CycloneDX property.
Since the introduction of the generate-cyclonedx script [1] a 'buildroot' dependency entry that depends on every components has been part of the generated SBOM.
Tools such as 'DependencyTrack' relies on such entry to create graph of the entire project.
With the commit [2] that introduced the option to pass a custom project name and version, this dependency reference was not updated to match the custom 'bom-ref'.
This patch fixes the reference to match the custom project name.
[1] dbab39e2d9 support/scripts/generate-cyclonedx.py: add script to generate CycloneDX-style SBOM
[2] 9cbbc47762 utils/generate-cyclonedx: add project name and version options
--- utils/generate-cyclonedx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
utils/generate-cyclonedx +1 -1
@@ -428,7 +428,7 @@ def main(): cyclonedx_component(name, comp) for name, comp in filtered_show_info_dict.items() ], "dependencies": [ - cyclonedx_dependency("buildroot", list(filtered_show_info_dict)), + cyclonedx_dependency(args.project_name, list(filtered_show_info_dict)), *[cyclonedx_dependency(ref, br2_parse_deps_recursively(ref, show_info_dict, args.virtual)) for ref in filtered_show_info_dict], ],
Signature · 6 lines
2.52.0 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH v2 2/4 utils/generate-cyclonedx: use direct dependencies
Since the introduction of the generate-cyclonedx script in [1] the dependencies were 'recursive'. This means that the dependencies of a package dependency were included.
The CycloneDX spec [2] states that only direct dependencies needs to be included.
This patch drop the recursive dependencies.
[1] dbab39e2d9 support/scripts/generate-cyclonedx.py: add script to generate CycloneDX-style SBOM
[2] https://cyclonedx.org/docs/1.6/json/#dependencies
--- utils/generate-cyclonedx | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-)
utils/generate-cyclonedx +8 -13
@@ -337,10 +337,9 @@ def cyclonedx_vulnerabilities(show_info_dict): } for cve, components in cves.items()] -def br2_parse_deps_recursively(ref, show_info_dict, virtual=False, deps=[]): - """Parse dependencies from the show-info output. This function will - recursively collect all dependencies, and return a list where each dependency - is stated at most once. +def br2_parse_deps(ref, show_info_dict, virtual=False): + """This function will collect all dependencies from the show-info output. + The dependency on virtual package will collect the final dependency without including the virtual one.
@@ -350,18 +349,14 @@ def br2_parse_deps_recursively(ref, show_info_dict, virtual=False, deps=[]): show_info_dict (dict): The JSON output of the show-info command, parsed into a Python dictionary. - Kwargs: - deps (list): A list, to which dependencies will be appended. If set to None, - a new empty list will be created. Defaults to None. - Returns: list: A list of dependencies of the 'ref' package. """ + deps = [] + for dep in show_info_dict.get(ref, {}).get("dependencies", []): - if dep not in deps: - if virtual or show_info_dict.get(dep, {}).get("virtual") is False: - deps.append(dep) - br2_parse_deps_recursively(dep, show_info_dict, virtual, deps) + if virtual or show_info_dict.get(dep, {}).get("virtual") is False: + deps.append(dep) return deps
@@ -429,7 +424,7 @@ def main(): ], "dependencies": [ cyclonedx_dependency(args.project_name, list(filtered_show_info_dict)), - *[cyclonedx_dependency(ref, br2_parse_deps_recursively(ref, show_info_dict, args.virtual)) + *[cyclonedx_dependency(ref, br2_parse_deps(ref, show_info_dict, args.virtual)) for ref in filtered_show_info_dict], ], "vulnerabilities": cyclonedx_vulnerabilities(show_info_dict),
Signature · 6 lines
2.52.0 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Re: [Buildroot] [PATCH v2 2/4] utils/generate-cyclonedx: use direct dependencies
Quoted 9 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Thomas" == Thomas Perale via buildroot <[email protected]> writes:
Since the introduction of the
generate-cyclonedxscript in [1] the dependencies were 'recursive'. This means that the dependencies of a package dependency were included.The CycloneDX spec [2] states that only direct dependencies needs to be included.
Quoted 7 lines
This patch drop the recursive dependencies.
[1]
dbab39e2d9support/scripts/generate-cyclonedx.py: add script to generate CycloneDX-style SBOM
[2] https://cyclonedx.org/docs/1.6/json/#dependenciesSigned-off-by Thomas Perale <[email protected]>
Committed, thanks.
Signature · 5 lines
Bye, Peter Korsgaard _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Thomas Perale via buildroot
AppliedRe: [Buildroot] [PATCH v2 2/4] utils/generate-cyclonedx: use direct dependencies
In reply to Thomas Perale via buildrootIn reply of:
Quoted 7 lines
Since the introduction of the
generate-cyclonedxscript in [1] the dependencies were 'recursive'. This means that the dependencies of a package dependency were included.The CycloneDX spec [2] states that only direct dependencies needs to be included.
Quoted 6 lines
This patch drop the recursive dependencies.
[1]
dbab39e2d9support/scripts/generate-cyclonedx.py: add script to generate CycloneDX-style SBOM
[2] https://cyclonedx.org/docs/1.6/json/#dependenciesSigned-off-by Thomas Perale <[email protected]>
Applied to 2025.02.x & 2025.11.x. Thanks
Quoted 61 lines
--- utils/generate-cyclonedx | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-)utils/generate-cyclonedx +8
-13@@ -337,10 +337,9 @@ def cyclonedx_vulnerabilities(show_info_dict): } for cve, components in cves.items()] -def br2_parse_deps_recursively(ref, show_info_dict, virtual=False, deps=[]): - """Parse dependencies from the show-info output. This function will - recursively collect all dependencies, and return a list where each dependency - is stated at most once. +def br2_parse_deps(ref, show_info_dict, virtual=False): + """This function will collect all dependencies from the show-info output. + The dependency on virtual package will collect the final dependency without including the virtual one.@@ -350,18 +349,14 @@ def br2_parse_deps_recursively(ref, show_info_dict, virtual=False, deps=[]): show_info_dict (dict): The JSON output of the show-info command, parsed into a Python dictionary. - Kwargs: - deps (list): A list, to which dependencies will be appended. If set to None, - a new empty list will be created. Defaults to None. - Returns: list: A list of dependencies of the 'ref' package. """ + deps = [] + for dep in show_info_dict.get(ref, {}).get("dependencies", []): - if dep not in deps: - if virtual or show_info_dict.get(dep, {}).get("virtual") is False: - deps.append(dep) - br2_parse_deps_recursively(dep, show_info_dict, virtual, deps) + if virtual or show_info_dict.get(dep, {}).get("virtual") is False: + deps.append(dep) return deps@@ -429,7 +424,7 @@ def main(): ], "dependencies": [ cyclonedx_dependency(args.project_name, list(filtered_show_info_dict)), - *[cyclonedx_dependency(ref, br2_parse_deps_recursively(ref, show_info_dict, args.virtual)) + *[cyclonedx_dependency(ref, br2_parse_deps(ref, show_info_dict, args.virtual)) for ref in filtered_show_info_dict], ], "vulnerabilities": cyclonedx_vulnerabilities(show_info_dict),Signature · 6 lines
2.52.0 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH v2 3/4 package/pkg-utils: add 'provides' to show-info
In reply to Thomas Perale via buildrootAdd the list of virtual packages a show-info entry provides to the output.
For more information on virtual packages infrastructure see [1]
[1] https://buildroot.org/downloads/manual/manual.html#_infrastructure_for_virtual_packages
--- package/pkg-utils.mk | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
package/pkg-utils.mk +8 -1
@@ -201,9 +201,16 @@ define _json-info-pkg-details $(foreach patch, \ $(call pkg-patches-list,$(1)), \ $(call mk-json-str,$(patsubst $(CONFIG_DIR)/%,%,$(patch)))$(comma) \ - ) ], + $(if $($(1)_PROVIDES), \ + "provides": [ \ + $(foreach provide, \ + $($(1)_PROVIDES), \ + $(call mk-json-str,$(provide))$(comma) \ + ) \ + ]$(comma) \ + ) endef define _json-info-fs
Signature · 6 lines
2.52.0 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Re: [Buildroot] [PATCH v2 3/4] package/pkg-utils: add 'provides' to show-info
Quoted 10 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Thomas" == Thomas Perale via buildroot <[email protected]> writes:
Add the list of virtual packages a show-info entry provides to the output.
For more information on virtual packages infrastructure see [1]
[1] https://buildroot.org/downloads/manual/manual.html#_infrastructure_for_virtual_packages
Signed-off-by Thomas Perale <[email protected]>
Committed, thanks.
Signature · 5 lines
Bye, Peter Korsgaard _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Thomas Perale via buildroot
AppliedRe: [Buildroot] [PATCH v2 3/4] package/pkg-utils: add 'provides' to show-info
In reply to Thomas Perale via buildrootIn reply of:
Quoted 8 lines
Add the list of virtual packages a show-info entry provides to the output.
For more information on virtual packages infrastructure see [1]
[1] https://buildroot.org/downloads/manual/manual.html#_infrastructure_for_virtual_packages
Signed-off-by Thomas Perale <[email protected]>
Applied to 2025.02.x & 2025.11.x. Thanks
Quoted 33 lines
--- package/pkg-utils.mk | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)package/pkg-utils.mk +8
-1@@ -201,9 +201,16 @@ define _json-info-pkg-details $(foreach patch, \ $(call pkg-patches-list,$(1)), \ $(call mk-json-str,$(patsubst $(CONFIG_DIR)/%,%,$(patch)))$(comma) \ - ) ], + $(if $($(1)_PROVIDES), \ + "provides": [ \ + $(foreach provide, \ + $($(1)_PROVIDES), \ + $(call mk-json-str,$(provide))$(comma) \ + ) \ + ]$(comma) \ + ) endef define _json-info-fsSignature · 6 lines
2.52.0 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH v2 4/4 utils/generate-cyclonedx: fix dependencies w/o virtual
In reply to Thomas Perale via buildrootSince its introduction in [1], by default the generate-cyclonedx script doesn't include buildroot's virtual packages in its 'components' list, unless using the --virtual argument.
References to virtual packages present in the 'show-info' output are filtered out in the resulting dependencies.
This patch fix the default CycloneDX dependencies generation without virtual packages to reference the packages that provide the virtual package instead of just dropping the virtual package itself.
If we use the package lbase64 that depends on the virtual package luainterpreter as an example. The 'dependency' entry looks like the following:
```
{
"ref": "lbase64",
"dependsOn": [
"host-skeleton",
"skeleton-init-common",
"skeleton-init-sysv",
"toolchain-external-bootlin"
]
}
```The luainterpreter dependency is missing.
After applying this patch, package that provides the luainterpreter is present:
```
{
"ref": "lbase64",
"dependsOn": [
"host-skeleton",
"lua",
"skeleton-custom",
"skeleton-init-sysv"
]
}
```In the case of a virtual package provided by multiple packages all those packages will be listed. This happens when generating an SBOM on the entire Buildroot packages.
[1] dbab39e2d9 support/scripts/generate-cyclonedx.py: add script to generate CycloneDX-style SBOM
---
v1 -> v2: use set to avoid duplication of dependencies
utils/generate-cyclonedx | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-)
utils/generate-cyclonedx +25 -5
@@ -337,7 +337,25 @@ def cyclonedx_vulnerabilities(show_info_dict): } for cve, components in cves.items()] -def br2_parse_deps(ref, show_info_dict, virtual=False): +def br2_virtual_is_provided_by(ref, show_info_dict) -> list: + """Retrieve the list of packages that provide a virtual package. + + Args: + ref (str): The identifier of the virtual package. + show_info_dict (dict): The JSON output of the show-info + command, parsed into a Python dictionary. + + Returns: + list: package list that provides the virtual package. + """ + return [ + name + for name, comp in show_info_dict.items() + if "provides" in comp and ref in comp["provides"] + ] + + +def br2_parse_deps(ref, show_info_dict, virtual=False) -> list: """This function will collect all dependencies from the show-info output. The dependency on virtual package will collect the final dependency without
@@ -352,13 +370,15 @@ def br2_parse_deps(ref, show_info_dict, virtual=False): Returns: list: A list of dependencies of the 'ref' package. """ - deps = [] + deps = set() for dep in show_info_dict.get(ref, {}).get("dependencies", []): - if virtual or show_info_dict.get(dep, {}).get("virtual") is False: - deps.append(dep) + if not virtual and show_info_dict.get(dep, {}).get("virtual"): + deps.update(br2_virtual_is_provided_by(dep, show_info_dict)) + else: + deps.add(dep) - return deps + return list(deps) def main():
Signature · 6 lines
2.52.0 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Re: [Buildroot] [PATCH v2 4/4] utils/generate-cyclonedx: fix dependencies w/o virtual
Quoted 50 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Thomas" == Thomas Perale via buildroot <[email protected]> writes:
Since its introduction in [1], by default the
generate-cyclonedxscript doesn't include buildroot's virtual packages in its 'components' list, unless using the--virtualargument.References to virtual packages present in the 'show-info' output are filtered out in the resulting dependencies.
This patch fix the default CycloneDX dependencies generation without virtual packages to reference the packages that provide the virtual package instead of just dropping the virtual package itself.
If we use the package
lbase64that depends on the virtual packageluainterpreteras an example. The 'dependency' entry looks like the following:``` { "ref": "lbase64", "dependsOn": [ "host-skeleton", "skeleton-init-common", "skeleton-init-sysv", "toolchain-external-bootlin" ] } ```The
luainterpreterdependency is missing.After applying this patch, package that provides the
luainterpreteris present:``` { "ref": "lbase64", "dependsOn": [ "host-skeleton", "lua", "skeleton-custom", "skeleton-init-sysv" ] } ```In the case of a virtual package provided by multiple packages all those packages will be listed. This happens when generating an SBOM on the entire Buildroot packages.
Quoted 5 lines
[1]
dbab39e2d9support/scripts/generate-cyclonedx.py: add script to generate CycloneDX-style SBOMSigned-off-by Thomas Perale <[email protected]>---
v1 -> v2: use set to avoid duplication of dependencies
Committed, thanks.
Maybe we should start adding some tests to generate-cyclonedx?
Signature · 5 lines
Bye, Peter Korsgaard _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Thomas Perale via buildroot
AppliedRe: [Buildroot] [PATCH v2 4/4] utils/generate-cyclonedx: fix dependencies w/o virtual
In reply to Thomas Perale via buildrootIn reply of:
Quoted 44 lines
Since its introduction in [1], by default the
generate-cyclonedxscript doesn't include buildroot's virtual packages in its 'components' list, unless using the--virtualargument.References to virtual packages present in the 'show-info' output are filtered out in the resulting dependencies.
This patch fix the default CycloneDX dependencies generation without virtual packages to reference the packages that provide the virtual package instead of just dropping the virtual package itself.
If we use the package
lbase64that depends on the virtual packageluainterpreteras an example. The 'dependency' entry looks like the following:``` { "ref": "lbase64", "dependsOn": [ "host-skeleton", "skeleton-init-common", "skeleton-init-sysv", "toolchain-external-bootlin" ] } ```The
luainterpreterdependency is missing.After applying this patch, package that provides the
luainterpreteris present:``` { "ref": "lbase64", "dependsOn": [ "host-skeleton", "lua", "skeleton-custom", "skeleton-init-sysv" ] } ```
Quoted 7 lines
In the case of a virtual package provided by multiple packages all those packages will be listed. This happens when generating an SBOM on the entire Buildroot packages.
[1]
dbab39e2d9support/scripts/generate-cyclonedx.py: add script to generate CycloneDX-style SBOMSigned-off-by Thomas Perale <[email protected]>
Applied to 2025.02.x & 2025.11.x. Thanks
Quoted 64 lines
---
v1 -> v2: use set to avoid duplication of dependenciesutils/generate-cyclonedx | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-)utils/generate-cyclonedx +25
-5@@ -337,7 +337,25 @@ def cyclonedx_vulnerabilities(show_info_dict): } for cve, components in cves.items()] -def br2_parse_deps(ref, show_info_dict, virtual=False): +def br2_virtual_is_provided_by(ref, show_info_dict) -> list: + """Retrieve the list of packages that provide a virtual package. + + Args: + ref (str): The identifier of the virtual package. + show_info_dict (dict): The JSON output of the show-info + command, parsed into a Python dictionary. + + Returns: + list: package list that provides the virtual package. + """ + return [ + name + for name, comp in show_info_dict.items() + if "provides" in comp and ref in comp["provides"] + ] + + +def br2_parse_deps(ref, show_info_dict, virtual=False) -> list: """This function will collect all dependencies from the show-info output. The dependency on virtual package will collect the final dependency without@@ -352,13 +370,15 @@ def br2_parse_deps(ref, show_info_dict, virtual=False): Returns: list: A list of dependencies of the 'ref' package. """ - deps = [] + deps = set() for dep in show_info_dict.get(ref, {}).get("dependencies", []): - if virtual or show_info_dict.get(dep, {}).get("virtual") is False: - deps.append(dep) + if not virtual and show_info_dict.get(dep, {}).get("virtual"): + deps.update(br2_virtual_is_provided_by(dep, show_info_dict)) + else: + deps.add(dep) - return deps + return list(deps) def main():Signature · 6 lines
2.52.0 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Quoted 15 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Thomas" == Thomas Perale via buildroot <[email protected]> writes:
The definition of the project name & version is stored under the
metadata:componentCycloneDX property.Since the introduction of the
generate-cyclonedxscript [1] a 'buildroot' dependency entry that depends on every components has been part of the generated SBOM.
Tools such as 'DependencyTrack' relies on such entry to create graph of the entire project.With the commit [2] that introduced the option to pass a custom project name and version, this dependency reference was not updated to match the custom 'bom-ref'.
Quoted 7 lines
This patch fixes the reference to match the custom project name.
[1]
dbab39e2d9support/scripts/generate-cyclonedx.py: add script to generate CycloneDX-style SBOM
[2]9cbbc47762utils/generate-cyclonedx: add project name and version optionsSigned-off-by Thomas Perale <[email protected]>
Committed, thanks.
Signature · 5 lines
Bye, Peter Korsgaard _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Thomas Perale via buildroot
AppliedIn reply of:
Quoted 13 lines
The definition of the project name & version is stored under the
metadata:componentCycloneDX property.Since the introduction of the
generate-cyclonedxscript [1] a 'buildroot' dependency entry that depends on every components has been part of the generated SBOM.
Tools such as 'DependencyTrack' relies on such entry to create graph of the entire project.With the commit [2] that introduced the option to pass a custom project name and version, this dependency reference was not updated to match the custom 'bom-ref'.
Quoted 6 lines
This patch fixes the reference to match the custom project name.
[1]
dbab39e2d9support/scripts/generate-cyclonedx.py: add script to generate CycloneDX-style SBOM
[2]9cbbc47762utils/generate-cyclonedx: add project name and version optionsSigned-off-by Thomas Perale <[email protected]>
Applied to 2025.02.x & 2025.11.x. Thanks
Quoted 24 lines
--- utils/generate-cyclonedx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)utils/generate-cyclonedx +1
-1@@ -428,7 +428,7 @@ def main(): cyclonedx_component(name, comp) for name, comp in filtered_show_info_dict.items() ], "dependencies": [ - cyclonedx_dependency("buildroot", list(filtered_show_info_dict)), + cyclonedx_dependency(args.project_name, list(filtered_show_info_dict)), *[cyclonedx_dependency(ref, br2_parse_deps_recursively(ref, show_info_dict, args.virtual)) for ref in filtered_show_info_dict], ],Signature · 6 lines
2.52.0 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot