Skip to content

Commit 541a645

Browse files
authored
Merge pull request #4076 from boegel/fix_check_sha256_checksums_dict
make check_sha256_checksums verify all checksums if they're specified as a dict value
2 parents 582a433 + 4ca4a3f commit 541a645

File tree

2 files changed

+43
-24
lines changed

2 files changed

+43
-24
lines changed

easybuild/framework/easyblock.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2375,33 +2375,34 @@ def check_checksums_for(self, ent, sub='', source_cnt=None):
23752375
checksum_issues.append(msg)
23762376

23772377
for fn, checksum in zip(sources + patches, checksums):
2378+
2379+
# a checksum may be specified as a dictionary which maps filename to actual checksum
2380+
# for example when different source files are used for different CPU architectures
23782381
if isinstance(checksum, dict):
2379-
# sources entry may be a dictionary rather than just a string value with filename
2380-
if isinstance(fn, dict):
2381-
filename = fn['filename']
2382-
else:
2383-
filename = fn
2384-
checksum = checksum.get(filename)
2385-
2386-
# take into account that we may encounter a tuple of valid SHA256 checksums
2387-
# (see https://github.com/easybuilders/easybuild-framework/pull/2958)
2388-
if isinstance(checksum, tuple):
2389-
# 1st tuple item may indicate checksum type, must be SHA256 or else it's blatently ignored here
2390-
if len(checksum) == 2 and checksum[0] == CHECKSUM_TYPE_SHA256:
2391-
valid_checksums = (checksum[1],)
2392-
else:
2393-
valid_checksums = checksum
2382+
checksums_to_check = checksum.values()
23942383
else:
2395-
valid_checksums = (checksum,)
2396-
2397-
non_sha256_checksums = [c for c in valid_checksums if not is_sha256_checksum(c)]
2398-
if non_sha256_checksums:
2399-
if all(c is None for c in non_sha256_checksums):
2400-
print_warning("Found %d None checksum value(s), please make sure this is intended!" %
2401-
len(non_sha256_checksums))
2384+
checksums_to_check = [checksum]
2385+
2386+
for checksum in checksums_to_check:
2387+
# take into account that we may encounter a tuple of valid SHA256 checksums
2388+
# (see https://github.com/easybuilders/easybuild-framework/pull/2958)
2389+
if isinstance(checksum, tuple):
2390+
# 1st tuple item may indicate checksum type, must be SHA256 or else it's blatently ignored here
2391+
if len(checksum) == 2 and checksum[0] == CHECKSUM_TYPE_SHA256:
2392+
valid_checksums = (checksum[1],)
2393+
else:
2394+
valid_checksums = checksum
24022395
else:
2403-
msg = "Non-SHA256 checksum(s) found for %s: %s" % (fn, valid_checksums)
2404-
checksum_issues.append(msg)
2396+
valid_checksums = (checksum,)
2397+
2398+
non_sha256_checksums = [c for c in valid_checksums if not is_sha256_checksum(c)]
2399+
if non_sha256_checksums:
2400+
if all(c is None for c in non_sha256_checksums):
2401+
print_warning("Found %d None checksum value(s), please make sure this is intended!" %
2402+
len(non_sha256_checksums))
2403+
else:
2404+
msg = "Non-SHA256 checksum(s) found for %s: %s" % (fn, valid_checksums)
2405+
checksum_issues.append(msg)
24052406

24062407
return checksum_issues
24072408

test/framework/easyconfig.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3750,6 +3750,24 @@ def test_check_sha256_checksums(self):
37503750
# multiple checksums listed for source tarball, while exactly one (SHA256) checksum is expected
37513751
self.assertTrue(res[1].startswith("Non-SHA256 checksum(s) found for toy-0.0.tar.gz: "))
37523752

3753+
checksums_dict = textwrap.dedent("""checksums = [{
3754+
'toy-0.0-aarch64.tar.gz': 'not_really_a_sha256_checksum',
3755+
'toy-0.0-x86_64.tar.gz': '%s',
3756+
}]""" % toy_sha256)
3757+
3758+
test_ec_txt = checksums_regex.sub(checksums_dict, toy_ec_txt)
3759+
test_ec_txt = re.sub(r'patches = \[(.|\n)*\]', '', test_ec_txt)
3760+
3761+
test_ec = os.path.join(self.test_prefix, 'toy-checksums-dict.eb')
3762+
write_file(test_ec, test_ec_txt)
3763+
ecs, _ = parse_easyconfigs([(test_ec, False)])
3764+
ecs = [ec['ec'] for ec in ecs]
3765+
3766+
res = check_sha256_checksums(ecs)
3767+
self.assertTrue(len(res) == 1)
3768+
regex = re.compile(r"Non-SHA256 checksum\(s\) found for toy-0.0.tar.gz:.*not_really_a_sha256_checksum")
3769+
self.assertTrue(regex.match(res[0]), "Pattern '%s' found in: %s" % (regex.pattern, res[0]))
3770+
37533771
def test_deprecated(self):
37543772
"""Test use of 'deprecated' easyconfig parameter."""
37553773
topdir = os.path.dirname(os.path.abspath(__file__))

0 commit comments

Comments
 (0)