Skip to content

Commit 752ce42

Browse files
authored
Merge pull request #3067 from akesandgren/handle_patches_in_extensions_better
Handle patches in extensions more like normal patches.
2 parents 71fa3f9 + 9ea74ff commit 752ce42

File tree

4 files changed

+39
-10
lines changed

4 files changed

+39
-10
lines changed

easybuild/framework/easyblock.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,8 @@ def fetch_patches(self, patch_specs=None, extension=False, checksums=None):
453453
raise EasyBuildError('No file found for patch %s', patch_spec)
454454

455455
if extension:
456-
self.log.info("Fetched extension patches: %s" % patches)
457-
return [patch['path'] for patch in patches]
456+
self.log.info("Fetched extension patches: %s", patches)
457+
return patches
458458
else:
459459
self.log.info("Added patches: %s" % self.patches)
460460

@@ -544,6 +544,7 @@ def fetch_extension_sources(self, skip_checksums=False):
544544

545545
if not skip_checksums:
546546
for patch in ext_patches:
547+
patch = patch['path']
547548
# report both MD5 and SHA256 checksums,
548549
# since both are valid default checksum types
549550
for checksum_type in (CHECKSUM_TYPE_MD5, CHECKSUM_TYPE_SHA256):
@@ -553,6 +554,7 @@ def fetch_extension_sources(self, skip_checksums=False):
553554
# verify checksum (if provided)
554555
self.log.debug('Verifying checksums for extension patches...')
555556
for idx, patch in enumerate(ext_patches):
557+
patch = patch['path']
556558
checksum = self.get_checksum_for(checksums[1:], filename=patch, index=idx)
557559
if verify_checksum(patch, checksum):
558560
self.log.info('Checksum for extension patch %s verified', patch)
@@ -3484,8 +3486,8 @@ def make_checksum_lines(checksums, indent_level):
34843486
print_msg(" * %s: %s" % (src_fn, checksum), log=_log)
34853487
ext_checksums.append((src_fn, checksum))
34863488
for ext_patch in ext.get('patches', []):
3487-
patch_fn = os.path.basename(ext_patch)
3488-
checksum = compute_checksum(ext_patch, checksum_type)
3489+
patch_fn = os.path.basename(ext_patch['path'])
3490+
checksum = compute_checksum(ext_patch['path'], checksum_type)
34893491
print_msg(" * %s: %s" % (patch_fn, checksum), log=_log)
34903492
ext_checksums.append((patch_fn, checksum))
34913493

easybuild/framework/extensioneasyblock.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from easybuild.framework.easyconfig import CUSTOM
3333
from easybuild.framework.extension import Extension
3434
from easybuild.tools.build_log import EasyBuildError
35-
from easybuild.tools.filetools import apply_patch, change_dir, extract_file
35+
from easybuild.tools.filetools import change_dir, extract_file
3636
from easybuild.tools.utilities import remove_unwanted_chars, trace_msg
3737

3838

@@ -110,10 +110,7 @@ def run(self, unpack_src=False):
110110
change_dir(self.start_dir)
111111

112112
# patch if needed
113-
if self.patches:
114-
for patchfile in self.patches:
115-
if not apply_patch(patchfile, self.ext_dir):
116-
raise EasyBuildError("Applying patch %s failed", patchfile)
113+
EasyBlock.patch_step(self, beginpath=self.ext_dir)
117114

118115
def sanity_check_step(self, exts_filter=None, custom_paths=None, custom_commands=None):
119116
"""

test/framework/easyconfig.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,10 @@ def test_extensions_templates(self):
463463
# check whether template values were resolved correctly in Extension instances that were created/used
464464
toy_ext = eb.ext_instances[0]
465465
self.assertEqual(os.path.basename(toy_ext.src), 'toy-0.0-py3-test.tar.gz')
466-
self.assertEqual(toy_ext.patches, [os.path.join(self.test_prefix, toy_patch_fn)])
466+
patches = []
467+
for patch in toy_ext.patches:
468+
patches.append(patch['path'])
469+
self.assertEqual(patches, [os.path.join(self.test_prefix, toy_patch_fn)])
467470
expected = {
468471
'patches': ['toy-0.0_fix-silly-typo-in-printf-statement.patch'],
469472
'prebuildopts': 'gcc -O2 toy.c -o toy-0.0 && mv toy-0.0 toy #',

test/framework/toy_build.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,33 @@ def test_toy_patches(self):
11321132
archived_patch_file = os.path.join(repositorypath, 'toy', 'toy-0.0_fix-silly-typo-in-printf-statement.patch')
11331133
self.assertTrue(os.path.isfile(archived_patch_file))
11341134

1135+
def test_toy_extension_patches(self):
1136+
"""Test install toy that includes extensions with patches."""
1137+
test_ecs = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'easyconfigs', 'test_ecs')
1138+
toy_ec = os.path.join(test_ecs, 't', 'toy', 'toy-0.0.eb')
1139+
toy_ec_txt = read_file(toy_ec)
1140+
1141+
# create file that we'll copy via 'patches'
1142+
write_file(os.path.join(self.test_prefix, 'test.txt'), 'test123')
1143+
1144+
test_ec = os.path.join(self.test_prefix, 'test.eb')
1145+
test_ec_txt = '\n'.join([
1146+
toy_ec_txt,
1147+
'exts_list = [',
1148+
' ("bar", "0.0", {',
1149+
' "buildopts": " && ls -l test.txt",',
1150+
' "patches": [',
1151+
' "bar-0.0_fix-silly-typo-in-printf-statement.patch",', # normal patch
1152+
' ("bar-0.0_fix-very-silly-typo-in-printf-statement.patch", 0),', # patch with patch level
1153+
' ("test.txt", "."),', # file to copy to build dir (not a real patch file)
1154+
' ],',
1155+
' }),',
1156+
']',
1157+
])
1158+
write_file(test_ec, test_ec_txt)
1159+
1160+
self.test_toy_build(ec_file=test_ec)
1161+
11351162
def test_toy_module_fulltxt(self):
11361163
"""Strict text comparison of generated module file."""
11371164
self.test_toy_tweaked()

0 commit comments

Comments
 (0)