Skip to content

Commit 11e5c2c

Browse files
authored
Merge pull request #15 from blackducksoftware/dev
v1.0.15 - Added support for Yocto-5, will run Detect on startup if de…
2 parents 37c10df + b197f41 commit 11e5c2c

File tree

7 files changed

+42
-22
lines changed

7 files changed

+42
-22
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Black Duck SCA Scan Yocto Script - bd_scan_yocto_via_sbom.py v1.0.14
1+
# Black Duck SCA Scan Yocto Script - bd_scan_yocto_via_sbom.py v1.0.15
22

33
# PROVISION OF THIS SCRIPT
44
This script is provided under the MIT license (see LICENSE file).
@@ -158,7 +158,7 @@ There are several additional options to modify the behaviour of this utility inc
158158
--detect_jar_path DETECT_JAR_PATH
159159
Detect jar path
160160
--detect_opts DETECT_OPTS
161-
Additional Detect options
161+
Additional Detect options (remove leading '--' from options)
162162
--api_timeout Specify API timeout in seconds (default 60) - will be used in
163163
Detect as --detect.timeout
164164
--sbom_create_custom_components

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "bd_scan_yocto_via_sbom"
7-
version = "1.0.14"
7+
version = "1.0.15"
88
authors = [
99
{ name="Matthew Brady", email="[email protected]" },
1010
]

yocto_import_sbom/BBClass.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -245,21 +245,24 @@ def check_files(conf):
245245
licman_dir = os.path.dirname(manpath)
246246

247247
if not conf.license_manifest:
248-
if not conf.target or not conf.machine:
249-
logging.error("Manifest file not specified and it could not be determined as Target not specified or "
250-
"machine not identified from environment")
251-
return False
252-
else:
253-
manpath = os.path.join(conf.deploy_dir, "licenses",
254-
f"{conf.target}-{machine}-*", "license.manifest")
248+
# if not conf.target or not conf.machine:
249+
# logging.error("Manifest file not specified and it could not be determined as Target not specified or "
250+
# "machine not identified from environment")
251+
# return False
252+
# else:
253+
# Pre Yocto-v5 path
254+
# manpath = os.path.join(conf.deploy_dir, "licenses",
255+
# f"{conf.target}-{machine}-*", "license.manifest")
256+
manpath = os.path.join(conf.deploy_dir, "licenses", "**", "license.manifest")
257+
logging.debug(f"License.manifest glob path is {manpath}")
255258
manifest = ""
256-
manlist = glob.glob(manpath)
259+
manlist = glob.glob(manpath, recursive=True)
257260
if len(manlist) > 0:
258261
# Get most recent file
259262
manifest = manlist[-1]
260263

261264
if not os.path.isfile(manifest):
262-
logging.error(f"Manifest file '{manifest}' could not be located")
265+
logging.error(f"Manifest file 'license.manifest' could not be located (Search path is '{manpath})")
263266
return False
264267
else:
265268
logging.info(f"Located license.manifest file {manifest}")

yocto_import_sbom/BOMClass.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def process_cve_file(self, cve_file, reclist):
228228
self.CVEPatchedVulnList = patched_vulns
229229
return
230230

231-
def run_detect_sigscan(self, conf, tdir):
231+
def run_detect_sigscan(self, conf, tdir, extra_opt=''):
232232
import shutil
233233

234234
cmd = self.get_detect(conf)
@@ -243,6 +243,8 @@ def run_detect_sigscan(self, conf, tdir):
243243
detect_cmd += "--detect.wait.for.results=true "
244244
if 'detect.timeout' not in conf.detect_opts:
245245
detect_cmd += f"--detect.timeout={conf.api_timeout} "
246+
if extra_opt != '':
247+
detect_cmd += f"{extra_opt} "
246248

247249
if conf.detect_opts:
248250
detect_cmd += conf.detect_opts

yocto_import_sbom/ConfigClass.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import sys
55
from .OEClass import OE
66

7+
script_version = "v1.0.15"
78

89
class Config:
910
def __init__(self):
@@ -80,7 +81,7 @@ def __init__(self):
8081
"from OE data are scanned by default)",
8182
action='store_true')
8283
parser.add_argument("--detect_jar_path", help="OPTIONAL Synopsys Detect jar path", default="")
83-
parser.add_argument("--detect_opts", help="OPTIONAL Additional Synopsys Detect options", default="")
84+
parser.add_argument("--detect_opts", help="OPTIONAL Additional Synopsys Detect options (remove leading '--')", default="")
8485
parser.add_argument("--api_timeout", help="OPTIONAL API and Detect timeout in seconds (default 60)",
8586
default="60")
8687
parser.add_argument("--sbom_create_custom_components",
@@ -122,7 +123,7 @@ def __init__(self):
122123
self.skip_sig_scan = False
123124
self.scan_all_packages = False
124125
self.detect_jar = ''
125-
self.detect_opts = args.detect_opts
126+
self.detect_opts = ''
126127
self.api_timeout = args.api_timeout
127128
self.sbom_custom_components = args.sbom_create_custom_components
128129
self.cve_check_dir = ''
@@ -144,7 +145,7 @@ def __init__(self):
144145
else:
145146
logging.basicConfig(level=loglevel)
146147

147-
logging.info("Black Duck Yocto scan via SBOM utility - v1.0.14")
148+
logging.info(f"Black Duck Yocto scan via SBOM utility - {script_version}")
148149
logging.info("SUPPLIED ARGUMENTS:")
149150
for arg in vars(args):
150151
logging.info(f"--{arg}={getattr(args, arg)}")
@@ -213,9 +214,9 @@ def __init__(self):
213214

214215
if args.target:
215216
self.target = args.target
216-
elif not self.license_manifest:
217-
logging.error(f"Target --target required if --license_manifest not specified")
218-
terminate = True
217+
# elif not self.license_manifest:
218+
# logging.error(f"Target --target required if --license_manifest not specified")
219+
# terminate = True
219220

220221
if args.bitbake_layers_file:
221222
if not os.path.exists(args.bitbake_layers_file):
@@ -286,6 +287,9 @@ def __init__(self):
286287
else:
287288
self.recipe_report = args.recipe_report
288289

290+
if args.detect_opts != '':
291+
self.detect_opts = args.detect_opts.replace('detect', '--detect')
292+
289293
if terminate:
290294
sys.exit(2)
291295
return

yocto_import_sbom/SBOMClass.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ def add_package(self, recipe):
8181
recipe_layer = recipe.layer
8282
recipe_name = recipe.name
8383
if recipe.epoch:
84-
recipe_version = f"{recipe.epoch}:{recipe.orig_version}"
84+
recipe_version = f"{recipe.epoch}:{recipe.version}"
8585
else:
86-
recipe_version = recipe.orig_version
86+
recipe_version = recipe.version
8787
recipe_pr = 'r0'
8888
else:
8989
recipe_layer = recipe.oe_layer['name']

yocto_import_sbom/main.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,23 @@
77
import logging
88
import sys
99

10+
import tempfile
11+
import os
12+
13+
empty_dir = tempfile.TemporaryDirectory()
14+
1015

1116
def main():
1217
conf = Config()
1318

1419
logging.info("")
1520
logging.info("--- PHASE 1 - PROCESS PROJECT --------------------------------------------")
21+
bom = BOM(conf)
22+
if conf.detect_opts != '':
23+
if not bom.run_detect_sigscan(conf, empty_dir.name, extra_opt='--detect.tools=DETECTOR'):
24+
logging.error("Unable to run Detect to initialise project")
25+
sys.exit(2)
26+
1627
reclist = RecipeList()
1728
bb = BB()
1829
if not bb.process(conf, reclist):
@@ -46,7 +57,7 @@ def main():
4657
logging.info("Done creating SBOM file")
4758
logging.info("")
4859
logging.info("--- PHASE 4 - UPLOAD SBOM ------------------------------------------------")
49-
bom = BOM(conf)
60+
# bom = BOM(conf)
5061

5162
if bom.upload_sbom(conf, bom, sbom):
5263
logging.info(f"Uploaded SBOM file '{sbom.file}' to create project "

0 commit comments

Comments
 (0)