Skip to content

Commit ed04e07

Browse files
authored
Merge pull request #3974 from boegel/post_install_patches
add support for post-install patches
2 parents 1ea947d + 9896bbb commit ed04e07

File tree

4 files changed

+49
-4
lines changed

4 files changed

+49
-4
lines changed

easybuild/framework/easyblock.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,13 +454,17 @@ def fetch_patches(self, patch_specs=None, extension=False, checksums=None):
454454
Add a list of patches.
455455
All patches will be checked if a file exists (or can be located)
456456
"""
457+
post_install_patches = []
457458
if patch_specs is None:
458-
patch_specs = self.cfg['patches']
459+
# if no patch_specs are specified, use all pre-install and post-install patches
460+
post_install_patches = self.cfg['postinstallpatches']
461+
patch_specs = self.cfg['patches'] + post_install_patches
459462

460463
patches = []
461464
for index, patch_spec in enumerate(patch_specs):
462465

463466
patch_info = create_patch_info(patch_spec)
467+
patch_info['postinstall'] = patch_spec in post_install_patches
464468

465469
force_download = build_option('force_download') in [FORCE_DOWNLOAD_ALL, FORCE_DOWNLOAD_PATCHES]
466470
path = self.obtain_file(patch_info['name'], extension=extension, force_download=force_download)
@@ -2230,7 +2234,7 @@ def fetch_step(self, skip_checksums=False):
22302234
self.dry_run_msg("\nList of patches:")
22312235

22322236
# fetch patches
2233-
if self.cfg['patches']:
2237+
if self.cfg['patches'] + self.cfg['postinstallpatches']:
22342238
if isinstance(self.cfg['checksums'], (list, tuple)):
22352239
# if checksums are provided as a list, first entries are assumed to be for sources
22362240
patches_checksums = self.cfg['checksums'][len(self.cfg['sources']):]
@@ -2402,11 +2406,15 @@ def extract_step(self):
24022406
else:
24032407
raise EasyBuildError("Unpacking source %s failed", src['name'])
24042408

2405-
def patch_step(self, beginpath=None):
2409+
def patch_step(self, beginpath=None, patches=None):
24062410
"""
24072411
Apply the patches
24082412
"""
2409-
for patch in self.patches:
2413+
if patches is None:
2414+
# if no patches are specified, use all non-post-install patches
2415+
patches = [p for p in self.patches if not p['postinstall']]
2416+
2417+
for patch in patches:
24102418
self.log.info("Applying patch %s" % patch['name'])
24112419
trace_msg("applying patch %s" % patch['name'])
24122420

@@ -2821,13 +2829,25 @@ def run_post_install_commands(self, commands=None):
28212829
raise EasyBuildError("Invalid element in 'postinstallcmds', not a string: %s", cmd)
28222830
run_cmd(cmd, simple=True, log_ok=True, log_all=True)
28232831

2832+
def apply_post_install_patches(self, patches=None):
2833+
"""
2834+
Apply post-install patch files that are specified via the 'postinstallpatches' easyconfig parameter.
2835+
"""
2836+
if patches is None:
2837+
patches = [p for p in self.patches if p['postinstall']]
2838+
2839+
self.log.debug("Post-install patches to apply: %s", patches)
2840+
if patches:
2841+
self.patch_step(beginpath=self.installdir, patches=patches)
2842+
28242843
def post_install_step(self):
28252844
"""
28262845
Do some postprocessing
28272846
- run post install commands if any were specified
28282847
"""
28292848

28302849
self.run_post_install_commands()
2850+
self.apply_post_install_patches()
28312851

28322852
self.fix_shebang()
28332853

easybuild/framework/easyconfig/default.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
'preinstallopts': ['', 'Extra prefix options for installation.', BUILD],
115115
'pretestopts': ['', 'Extra prefix options for test.', BUILD],
116116
'postinstallcmds': [[], 'Commands to run after the install step.', BUILD],
117+
'postinstallpatches': [[], 'Patch files to apply after running the install step.', BUILD],
117118
'required_linked_shared_libs': [[], "List of shared libraries (names, file names, or paths) which must be "
118119
"linked in all installed binaries/libraries", BUILD],
119120
'runtest': [None, ('Indicates if a test should be run after make; should specify argument '
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
--- README.old 2022-03-01 14:28:43.000000000 +0100
2+
+++ README 2022-03-01 14:29:01.000000000 +0100
3+
@@ -1 +1 @@
4+
-TOY
5+
+toy 0.0, a toy test program

test/framework/toy_build.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3721,6 +3721,25 @@ def test_toy_ignore_test_failure(self):
37213721
self.assertTrue("Build succeeded (with --ignore-test-failure) for 1 out of 1" in stdout)
37223722
self.assertFalse(stderr)
37233723

3724+
def test_toy_post_install_patches(self):
3725+
"""
3726+
Test use of post-install patches
3727+
"""
3728+
test_ecs = os.path.join(os.path.dirname(__file__), 'easyconfigs', 'test_ecs')
3729+
toy_ec = os.path.join(test_ecs, 't', 'toy', 'toy-0.0.eb')
3730+
3731+
test_ec_txt = read_file(toy_ec)
3732+
test_ec_txt += "\npostinstallpatches = ['toy-0.0_fix-README.patch']"
3733+
test_ec = os.path.join(self.test_prefix, 'test.eb')
3734+
write_file(test_ec, test_ec_txt)
3735+
3736+
self.test_toy_build(ec_file=test_ec)
3737+
3738+
toy_installdir = os.path.join(self.test_installpath, 'software', 'toy', '0.0')
3739+
toy_readme_txt = read_file(os.path.join(toy_installdir, 'README'))
3740+
# verify whether patch indeed got applied
3741+
self.assertEqual(toy_readme_txt, "toy 0.0, a toy test program\n")
3742+
37243743

37253744
def suite():
37263745
""" return all the tests in this file """

0 commit comments

Comments
 (0)