|
1 | 1 | # Hooks to customize how EasyBuild installs software in EESSI |
2 | 2 | # see https://docs.easybuild.io/en/latest/Hooks.html |
| 3 | +import datetime |
3 | 4 | import glob |
4 | 5 | import os |
5 | 6 | import re |
6 | 7 |
|
7 | 8 | import easybuild.tools.environment as env |
8 | 9 | from easybuild.easyblocks.generic.configuremake import obtain_config_guess |
9 | 10 | from easybuild.framework.easyconfig.constants import EASYCONFIG_CONSTANTS |
| 11 | +from easybuild.tools import config |
10 | 12 | from easybuild.tools.build_log import EasyBuildError, print_msg |
11 | | -from easybuild.tools.config import build_option, update_build_option |
12 | | -from easybuild.tools.filetools import apply_regex_substitutions, copy_file, remove_file, symlink, which |
| 13 | +from easybuild.tools.config import build_option, install_path, update_build_option |
| 14 | +from easybuild.tools.filetools import apply_regex_substitutions, copy_dir, copy_file, remove_file, symlink, which |
13 | 15 | from easybuild.tools.run import run_cmd |
14 | 16 | from easybuild.tools.systemtools import AARCH64, POWER, X86_64, get_cpu_architecture, get_cpu_features |
15 | 17 | from easybuild.tools.toolchain.compiler import OPTARCH_GENERIC |
|
46 | 48 | # Make sure a single environment variable name is used for this throughout the hooks |
47 | 49 | EESSI_IGNORE_ZEN4_GCC1220_ENVVAR="EESSI_IGNORE_LMOD_ERROR_ZEN4_GCC1220" |
48 | 50 |
|
| 51 | +STACK_REPROD_SUBDIR = 'reprod' |
| 52 | + |
| 53 | + |
49 | 54 | def is_gcccore_1220_based(**kwargs): |
50 | 55 | # ecname, ecversion, tcname, tcversion): |
51 | 56 | """ |
@@ -516,6 +521,20 @@ def post_module_hook_zen4_gcccore1220(self, *args, **kwargs): |
516 | 521 | del self.initial_environ[EESSI_IGNORE_ZEN4_GCC1220_ENVVAR] |
517 | 522 |
|
518 | 523 |
|
| 524 | +def post_easyblock_hook_copy_easybuild_subdir(self, *args, **kwargs): |
| 525 | + """ |
| 526 | + Post easyblock hook that copies the easybuild subdirectory of every installed application |
| 527 | + to a central and timestamped location in the root of the software stack, e.g.: |
| 528 | + /path/to/stack/reprod/MyApp/1.2-foss-2025a/20250102T12:34:56Z |
| 529 | + """ |
| 530 | + |
| 531 | + stack_reprod_dir = os.path.join(os.path.dirname(install_path()), STACK_REPROD_SUBDIR) |
| 532 | + now_utc_timestamp = datetime.datetime.now(datetime.UTC).strftime('%Y%m%d_%H%M%S%Z') |
| 533 | + app_easybuild_dir = os.path.join(self.installdir, config.log_path(ec=self.cfg)) |
| 534 | + app_reprod_dir = os.path.join(stack_reprod_dir, self.install_subdir, now_utc_timestamp, 'easybuild') |
| 535 | + copy_dir(app_easybuild_dir, app_reprod_dir) |
| 536 | + |
| 537 | + |
519 | 538 | # Modules for dependencies are loaded in the prepare step. Thus, that's where we need this variable to be set |
520 | 539 | # so that the modules can be succesfully loaded without printing the error (so that we can create a module |
521 | 540 | # _with_ the warning for the current software being installed) |
@@ -1297,6 +1316,24 @@ def post_module_hook(self, *args, **kwargs): |
1297 | 1316 | post_module_hook_zen4_gcccore1220(self, *args, **kwargs) |
1298 | 1317 |
|
1299 | 1318 |
|
| 1319 | +# The post_easyblock_hook was introduced in EasyBuild 5.1.1. |
| 1320 | +# Older versions would fail if the function is defined anyway, as EasyBuild performs some checks on function names in hooks files. |
| 1321 | +if EASYBUILD_VERSION >= '5.1.1': |
| 1322 | + def post_easyblock_hook(self, *args, **kwargs): |
| 1323 | + """Main post easyblock hook: trigger custom functions based on software name.""" |
| 1324 | + if self.name in POST_EASYBLOCK_HOOKS: |
| 1325 | + POST_EASYBLOCK_HOOKS[self.name](self, *args, **kwargs) |
| 1326 | + |
| 1327 | + # Always trigger this one for EESSI CVMFS/site installations and version 2025.06 or newer, regardless of self.name |
| 1328 | + if os.getenv('EESSI_CVMFS_INSTALL') or os.getenv('EESSI_SITE_INSTALL'): |
| 1329 | + if os.getenv('EESSI_VERSION') and LooseVersion(os.getenv('EESSI_VERSION')) >= '2025.06': |
| 1330 | + post_easyblock_hook_copy_easybuild_subdir(self, *args, **kwargs) |
| 1331 | + else: |
| 1332 | + self.log.debug("No CVMFS/site installation requested, not running post_easyblock_hook_copy_easybuild_subdir.") |
| 1333 | +else: |
| 1334 | + print_msg(f"Not enabling the post_easybuild_hook, as it requires EasyBuild 5.1.1 or newer.") |
| 1335 | + |
| 1336 | + |
1300 | 1337 | PARSE_HOOKS = { |
1301 | 1338 | 'casacore': parse_hook_casacore_disable_vectorize, |
1302 | 1339 | 'CGAL': parse_hook_cgal_toolchainopts_precise, |
@@ -1365,6 +1402,8 @@ def post_module_hook(self, *args, **kwargs): |
1365 | 1402 |
|
1366 | 1403 | POST_MODULE_HOOKS = {} |
1367 | 1404 |
|
| 1405 | +POST_EASYBLOCK_HOOKS = {} |
| 1406 | + |
1368 | 1407 | # Define parallelism limit operations |
1369 | 1408 | def divide_by_factor(parallel, factor): |
1370 | 1409 | """Divide parallelism by given factor""" |
|
0 commit comments