Skip to content

Commit

Permalink
Merge branch 'release/2.12' into develop2
Browse files Browse the repository at this point in the history
  • Loading branch information
czoido committed Feb 12, 2025
2 parents 4decf5b + fca973c commit 0e07b09
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
24 changes: 22 additions & 2 deletions conan/tools/sbom/cyclonedx.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@


def cyclonedx_1_4(graph, name=None, add_build=False, add_tests=False, **kwargs):
def cyclonedx_1_4(conanfile, name=None, add_build=False, add_tests=False, **kwargs):
"""
(Experimental) Generate cyclone 1.4 sbom with json format
(Experimental) Generate cyclone 1.4 SBOM with JSON format
Creates a CycloneDX 1.4 Software Bill of Materials (SBOM) from a given dependency graph.
Parameters:
conanfile: The conanfile instance.
name (str, optional): Custom name for the metadata field.
add_build (bool, optional, default=False): Include build dependencies.
add_tests (bool, optional, default=False): Include test dependencies.
Returns:
The generated CycloneDX 1.4 document as a string.
Example usage:
```
cyclonedx(conanfile, name="custom_name", add_build=True, add_test=True, **kwargs)
```
"""
import uuid
import time
from datetime import datetime, timezone
graph = conanfile.subgraph

has_special_root_node = not (getattr(graph.root.ref, "name", False) and getattr(graph.root.ref, "version", False) and getattr(graph.root.ref, "revision", False))
special_id = str(uuid.uuid4())
Expand Down
4 changes: 2 additions & 2 deletions test/functional/sbom/test_cyclonedx.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from conan.tools.sbom import cyclonedx_1_4
def post_package(conanfile):
sbom_cyclonedx_1_4 = cyclonedx_1_4(conanfile.subgraph, add_build=%s, add_tests=%s)
sbom_cyclonedx_1_4 = cyclonedx_1_4(conanfile, add_build=%s, add_tests=%s)
metadata_folder = conanfile.package_metadata_folder
file_name = "sbom.cdx.json"
with open(os.path.join(metadata_folder, file_name), 'w') as f:
Expand Down Expand Up @@ -138,7 +138,7 @@ def test_sbom_generation_dependency_test_require(hook_setup_post_package_no_test
from conan.tools.sbom import cyclonedx_1_4
def post_generate(conanfile):
sbom_cyclonedx_1_4 = cyclonedx_1_4(conanfile.subgraph, name=%s)
sbom_cyclonedx_1_4 = cyclonedx_1_4(conanfile, name=%s)
generators_folder = conanfile.generators_folder
file_name = "sbom.cdx.json"
os.mkdir(os.path.join(generators_folder, "sbom"))
Expand Down

0 comments on commit 0e07b09

Please sign in to comment.