Skip to content

Commit 3924049

Browse files
pdunajrlubos
authored andcommitted
scripts: sbom: Fix lookup for sysbuild case
When sysbuild is enabled, check each domain. Signed-off-by: Pawel Dunaj <[email protected]>
1 parent cbad6dd commit 3924049

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

scripts/west_commands/sbom/input_build.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from args import args
1717
from data_structure import Data, FileInfo
1818
from common import SbomException, command_execute
19+
import yaml
1920

2021

2122
DEFAULT_BUILD_DIR = 'build'
@@ -399,7 +400,13 @@ def test_tool(arg_name: str, cmake_var_name: str) -> str:
399400
return result
400401

401402
try:
402-
with open(build_dir / 'CMakeCache.txt', 'r') as fd:
403+
domains = yaml.safe_load(open(os.path.join(build_dir, 'domains.yaml'), 'r'))
404+
cmakecache = os.path.join(build_dir, domains['default'], 'CMakeCache.txt')
405+
except FileNotFoundError:
406+
cmakecache = os.path.join(build_dir, 'CMakeCache.txt')
407+
408+
try:
409+
with open(cmakecache, 'r') as fd:
403410
cmake_cache = fd.read()
404411
except FileNotFoundError as ex:
405412
raise SbomException('Cannot find "CMakeCache.txt".\n'
@@ -427,9 +434,16 @@ def generate_input(data: Data):
427434
log.wrn('Fetching input files from a build directory is experimental for now.')
428435
check_external_tools(Path(args.build_dir[0][0]))
429436
for build_dir, *targets in args.build_dir:
430-
if len(targets) == 0:
431-
targets = [DEFAULT_TARGET]
432-
log.dbg(f'INPUT: build directory: {build_dir}, targets: {targets}')
433-
b = InputBuild(data, build_dir)
434-
for target in targets:
435-
b.generate_from_target(target)
437+
try:
438+
domains = yaml.safe_load(open(os.path.join(build_dir, 'domains.yaml'), 'r'))
439+
domains = [d['name'] for d in domains['domains']]
440+
except FileNotFoundError:
441+
domains = ['.']
442+
for domain in domains:
443+
domain_build_dir = Path(os.path.join(build_dir, domain))
444+
if len(targets) == 0:
445+
targets = [DEFAULT_TARGET]
446+
log.dbg(f'INPUT: build directory: {domain_build_dir}, targets: {targets}')
447+
b = InputBuild(data, domain_build_dir)
448+
for target in targets:
449+
b.generate_from_target(target)

0 commit comments

Comments
 (0)