Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a --no-build-requires command line option to the sbom:cyclonedx extension command #159

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions extensions/commands/sbom/cmd_cyclonedx.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from conan.api.conan_api import ConanAPI
from conan.api.output import cli_out_write
from conan.api.subapi.graph import CONTEXT_BUILD
from conan.cli.args import common_graph_args, validate_common_graph_args
from conan.cli.command import conan_command
from conan.errors import ConanException
Expand Down Expand Up @@ -128,6 +129,8 @@ def me_as_tool() -> Tool:
# FIXME: Process the ``--build-require`` argument
parser.add_argument("--build-require", action='store_true', default=False,
help='Whether the provided path is a build-require')
parser.add_argument("--no-build-requires", action='store_true', default=False,
help='Omit the build requirements from the SBOM')
args = parser.parse_args(*args)
validate_common_graph_args(args)
cwd = os.getcwd()
Expand All @@ -151,12 +154,16 @@ def me_as_tool() -> Tool:
remotes, args.update)
# endregion COPY

components = {node: create_component(node) for node in deps_graph.nodes}
def filter_context(node): return not args.no_build_requires or node.context != CONTEXT_BUILD
memsharded marked this conversation as resolved.
Show resolved Hide resolved

components = {node: create_component(node) for node in deps_graph.nodes if filter_context(node)}
bom = Bom()
bom.metadata.component = components[deps_graph.root]
bom.metadata.tools.add(me_as_tool())
for node in deps_graph.nodes[1:]: # node 0 is the root
bom.components.add(components[node])
if filter_context(node):
bom.components.add(components[node])
for dep in deps_graph.nodes:
bom.register_dependency(components[dep], [components[dep_dep.dst] for dep_dep in dep.dependencies])
if filter_context(dep):
bom.register_dependency(components[dep], [components[dep_dep.dst] for dep_dep in dep.dependencies if filter_context(dep_dep.dst)])
return bom