From 61d88dd617cd30c67c43a51f36a3510b401a043f Mon Sep 17 00:00:00 2001 From: Martin Kojtal Date: Mon, 19 Oct 2020 09:27:20 +0100 Subject: [PATCH] scancode: fix SPDX check - only warning SPDX are not yet done in our codebase. We suggest them to be present but 3rd party drivers have not yet been updated. The check as it was causes problems when updating 3rd party drivers (red flags in the PR). Proper fix will be to clean up SPDX id in the codebase. --- tools/test/travis-ci/scancode-evaluate.py | 19 ++++++++++++------- .../test/travis-ci/scancode_evaluate_test.py | 12 ++++++------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/tools/test/travis-ci/scancode-evaluate.py b/tools/test/travis-ci/scancode-evaluate.py index 0156c200fd..c487ae5e71 100644 --- a/tools/test/travis-ci/scancode-evaluate.py +++ b/tools/test/travis-ci/scancode-evaluate.py @@ -89,7 +89,8 @@ def license_check(scancode_output_path): ReturnCode.ERROR.value if any error in file licenses found """ - offenders = [] + license_offenders = [] + spdx_offenders = [] try: with open(scancode_output_path, 'r') as read_file: scancode_output_data = json.load(read_file) @@ -107,13 +108,13 @@ def license_check(scancode_output_path): if not scancode_output_data_file['licenses']: scancode_output_data_file['fail_reason'] = MISSING_LICENSE_TEXT - offenders.append(scancode_output_data_file) + license_offenders.append(scancode_output_data_file) # check the next file in the scancode output continue if not has_permissive_text_in_scancode_output(scancode_output_data_file['licenses']): scancode_output_data_file['fail_reason'] = MISSING_PERMISSIVE_LICENSE_TEXT - offenders.append(scancode_output_data_file) + license_offenders.append(scancode_output_data_file) if not has_spdx_text_in_scancode_output(scancode_output_data_file['licenses']): # Scancode does not recognize license notice in Python file headers. @@ -131,13 +132,17 @@ def license_check(scancode_output_path): if not has_spdx_text_in_analysed_file(scanned_file_content): scancode_output_data_file['fail_reason'] = MISSING_SPDX_TEXT - offenders.append(scancode_output_data_file) + spdx_offenders.append(scancode_output_data_file) - if offenders: + if license_offenders: userlog.warning("Found files with missing license details, please review and fix") - for offender in offenders: + for offender in license_offenders: userlog.warning("File: %s reason: %s" % (path_leaf(offender['path']), offender['fail_reason'])) - return len(offenders) + if spdx_offenders: + userlog.warning("Found files with missing SPDX identifier, please review and fix") + for offender in spdx_offenders: + userlog.warning("File: %s reason: %s" % (path_leaf(offender['path']), offender['fail_reason'])) + return len(license_offenders) def parse_args(): diff --git a/tools/test/travis-ci/scancode_evaluate_test.py b/tools/test/travis-ci/scancode_evaluate_test.py index 19d527f678..fc2e068e6c 100644 --- a/tools/test/travis-ci/scancode_evaluate_test.py +++ b/tools/test/travis-ci/scancode_evaluate_test.py @@ -78,18 +78,18 @@ class TestScancodeEvaluate: def test_missing_license_permissive_license_and_spdx(self, create_scanned_files): """ Test four files scanned with various issues. test.h: Missing license text (error count += 1) - test3.h: Missing `Permissive` license text and `spdx` in match.identifier and not in file tested by ScanCode (error count += 2) + test3.h: Missing `Permissive` license text and `spdx` in match.identifier and not in file tested by ScanCode (error count += 1) test4.h: Missing `Permissive` license text and `spdx` in match.identifier but found in file tested by ScanCode (error count += 1) test5.h: Missing `spdx` in match.identifier but found in file tested by ScanCode. (error count += 0) @inputs scancode_test/scancode_test_2.json - @output 4 + @output 3 """ - assert license_check(os.path.join(STUBS_PATH, "scancode_test_3.json")) == 4 + assert license_check(os.path.join(STUBS_PATH, "scancode_test_3.json")) == 3 def test_permissive_license_no_spdx(self, create_scanned_files): """ Multiple `Permissive` licenses in one file but none with `spdx` in - match.identifier and not in file tested by ScanCode (error count += 1) + match.identifier and not in file tested by ScanCode (error count += 0) @inputs scancode_test/scancode_test_2.json - @outputs 1 + @outputs 0 """ - assert license_check(os.path.join(STUBS_PATH, "scancode_test_4.json")) == 1 + assert license_check(os.path.join(STUBS_PATH, "scancode_test_4.json")) == 0