Andrew Geissler | 220dafd | 2023-10-04 10:18:08 -0500 | [diff] [blame] | 1 | # |
| 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
| 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
| 7 | import json |
| 8 | import os |
| 9 | from oeqa.selftest.case import OESelftestTestCase |
| 10 | from oeqa.utils.commands import bitbake, get_bb_var, runCmd |
| 11 | |
| 12 | class SPDXCheck(OESelftestTestCase): |
| 13 | |
| 14 | @classmethod |
| 15 | def setUpClass(cls): |
| 16 | super(SPDXCheck, cls).setUpClass() |
| 17 | bitbake("python3-spdx-tools-native") |
| 18 | bitbake("-c addto_recipe_sysroot python3-spdx-tools-native") |
| 19 | |
| 20 | def check_recipe_spdx(self, high_level_dir, spdx_file, target_name): |
| 21 | config = """ |
| 22 | INHERIT += "create-spdx" |
| 23 | """ |
| 24 | self.write_config(config) |
| 25 | |
| 26 | deploy_dir = get_bb_var("DEPLOY_DIR") |
| 27 | machine_var = get_bb_var("MACHINE") |
| 28 | # qemux86-64 creates the directory qemux86_64 |
| 29 | machine_dir = machine_var.replace("-", "_") |
| 30 | |
| 31 | full_file_path = os.path.join(deploy_dir, "spdx", machine_dir, high_level_dir, spdx_file) |
| 32 | |
| 33 | try: |
| 34 | os.remove(full_file_path) |
| 35 | except FileNotFoundError: |
| 36 | pass |
| 37 | |
| 38 | bitbake("%s -c create_spdx" % target_name) |
| 39 | |
| 40 | def check_spdx_json(filename): |
| 41 | with open(filename) as f: |
| 42 | report = json.load(f) |
| 43 | self.assertNotEqual(report, None) |
| 44 | self.assertNotEqual(report["SPDXID"], None) |
| 45 | |
| 46 | python = os.path.join(get_bb_var('STAGING_BINDIR', 'python3-spdx-tools-native'), 'nativepython3') |
| 47 | validator = os.path.join(get_bb_var('STAGING_BINDIR', 'python3-spdx-tools-native'), 'pyspdxtools') |
| 48 | result = runCmd("{} {} -i {}".format(python, validator, filename)) |
| 49 | |
| 50 | self.assertExists(full_file_path) |
| 51 | result = check_spdx_json(full_file_path) |
| 52 | |
| 53 | def test_spdx_base_files(self): |
| 54 | self.check_recipe_spdx("packages", "base-files.spdx.json", "base-files") |