Skip to content
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
49 changes: 25 additions & 24 deletions easybuild/framework/easyblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2375,33 +2375,34 @@ def check_checksums_for(self, ent, sub='', source_cnt=None):
checksum_issues.append(msg)

for fn, checksum in zip(sources + patches, checksums):

# a checksum may be specified as a dictionary which maps filename to actual checksum
# for example when different source files are used for different CPU architectures
if isinstance(checksum, dict):
# sources entry may be a dictionary rather than just a string value with filename
if isinstance(fn, dict):
filename = fn['filename']
else:
filename = fn
checksum = checksum.get(filename)

# take into account that we may encounter a tuple of valid SHA256 checksums
# (see https://github.com/easybuilders/easybuild-framework/pull/2958)
if isinstance(checksum, tuple):
# 1st tuple item may indicate checksum type, must be SHA256 or else it's blatently ignored here
if len(checksum) == 2 and checksum[0] == CHECKSUM_TYPE_SHA256:
valid_checksums = (checksum[1],)
else:
valid_checksums = checksum
checksums_to_check = checksum.values()
else:
valid_checksums = (checksum,)

non_sha256_checksums = [c for c in valid_checksums if not is_sha256_checksum(c)]
if non_sha256_checksums:
if all(c is None for c in non_sha256_checksums):
print_warning("Found %d None checksum value(s), please make sure this is intended!" %
len(non_sha256_checksums))
checksums_to_check = [checksum]

for checksum in checksums_to_check:
# take into account that we may encounter a tuple of valid SHA256 checksums
# (see https://github.com/easybuilders/easybuild-framework/pull/2958)
if isinstance(checksum, tuple):
# 1st tuple item may indicate checksum type, must be SHA256 or else it's blatently ignored here
if len(checksum) == 2 and checksum[0] == CHECKSUM_TYPE_SHA256:
valid_checksums = (checksum[1],)
else:
valid_checksums = checksum
else:
msg = "Non-SHA256 checksum(s) found for %s: %s" % (fn, valid_checksums)
checksum_issues.append(msg)
valid_checksums = (checksum,)

non_sha256_checksums = [c for c in valid_checksums if not is_sha256_checksum(c)]
if non_sha256_checksums:
if all(c is None for c in non_sha256_checksums):
print_warning("Found %d None checksum value(s), please make sure this is intended!" %
len(non_sha256_checksums))
else:
msg = "Non-SHA256 checksum(s) found for %s: %s" % (fn, valid_checksums)
checksum_issues.append(msg)

return checksum_issues

Expand Down
18 changes: 18 additions & 0 deletions test/framework/easyconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -3750,6 +3750,24 @@ def test_check_sha256_checksums(self):
# multiple checksums listed for source tarball, while exactly one (SHA256) checksum is expected
self.assertTrue(res[1].startswith("Non-SHA256 checksum(s) found for toy-0.0.tar.gz: "))

checksums_dict = textwrap.dedent("""checksums = [{
'toy-0.0-aarch64.tar.gz': 'not_really_a_sha256_checksum',
'toy-0.0-x86_64.tar.gz': '%s',
}]""" % toy_sha256)

test_ec_txt = checksums_regex.sub(checksums_dict, toy_ec_txt)
test_ec_txt = re.sub(r'patches = \[(.|\n)*\]', '', test_ec_txt)

test_ec = os.path.join(self.test_prefix, 'toy-checksums-dict.eb')
write_file(test_ec, test_ec_txt)
ecs, _ = parse_easyconfigs([(test_ec, False)])
ecs = [ec['ec'] for ec in ecs]

res = check_sha256_checksums(ecs)
self.assertTrue(len(res) == 1)
regex = re.compile(r"Non-SHA256 checksum\(s\) found for toy-0.0.tar.gz:.*not_really_a_sha256_checksum")
self.assertTrue(regex.match(res[0]), "Pattern '%s' found in: %s" % (regex.pattern, res[0]))

def test_deprecated(self):
"""Test use of 'deprecated' easyconfig parameter."""
topdir = os.path.dirname(os.path.abspath(__file__))
Expand Down