mirror of https://github.com/ARMmbed/mbed-os.git
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.pull/13782/head
parent
e439ad9993
commit
61d88dd617
|
|
@ -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():
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue