Merge pull request #13782 from 0xc0170/fix_travis_scancode_spdx

scancode: fix SPDX check - only warning
pull/13787/head
Martin Kojtal 2020-10-19 13:17:43 +01:00 committed by GitHub
commit a9c77a95d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 13 deletions

View File

@ -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():

View File

@ -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