Skip to content

scancode: fix SPDX check - only warning #13782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions tools/test/travis-ci/scancode-evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand All @@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe len(license_offenders) + len(spdx_offenders) ?



def parse_args():
Expand Down
12 changes: 6 additions & 6 deletions tools/test/travis-ci/scancode_evaluate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,18 @@ def test_various_combinations_permissive_license_with_spdx(self):
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