Skip to content

Commit 9e9a3aa

Browse files
authored
Merge pull request easybuilders#4848 from bartoldeman/iteropts-expand-all
restore original value for non-list easyconfig parameter values that are considered for iterating over
2 parents 8182a62 + 64ca7d8 commit 9e9a3aa

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

easybuild/framework/easyblock.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2392,19 +2392,24 @@ def handle_iterate_opts(self):
23922392
# handle configure/build/install options that are specified as lists (+ perhaps builddependencies)
23932393
# set first element to be used, keep track of list in self.iter_opts
23942394
# only needs to be done during first iteration, since after that the options won't be lists anymore
2395-
if self.iter_idx == 0:
2395+
if self.iter_idx == 0 and self.cfg.iterate_options:
23962396
# keep track of list, supply first element as first option to handle
2397-
for opt in self.cfg.iterate_options:
2397+
for opt in ITERATE_OPTIONS:
23982398
self.iter_opts[opt] = self.cfg[opt] # copy
2399-
self.log.debug("Found list for %s: %s", opt, self.iter_opts[opt])
2399+
self.log.debug("Iterating opt %s: %s", opt, self.iter_opts[opt])
24002400

24012401
if self.iter_opts:
24022402
print_msg("starting iteration #%s ..." % self.iter_idx, log=self.log, silent=self.silent)
24032403
self.log.info("Current iteration index: %s", self.iter_idx)
24042404

24052405
# pop first element from all iterative easyconfig parameters as next value to use
24062406
for opt, value in self.iter_opts.items():
2407-
if len(value) > self.iter_idx:
2407+
if opt not in self.cfg.iterate_options:
2408+
# Use original value even for options that were specified as strings so don't change
2409+
# (ie. elements in ITERATE_OPTIONS but not in self.cfg.iterate_options), so they
2410+
# are restored after an easyblock such as CMakeMake changes them
2411+
self.cfg[opt] = value
2412+
elif len(value) > self.iter_idx:
24082413
self.cfg[opt] = value[self.iter_idx]
24092414
else:
24102415
self.cfg[opt] = '' # empty list => empty option as next value

test/framework/easyblock.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
from easybuild.base import fancylogger
4545
from easybuild.framework.easyblock import EasyBlock, get_easyblock_instance
4646
from easybuild.framework.easyconfig import CUSTOM
47-
from easybuild.framework.easyconfig.easyconfig import EasyConfig
47+
from easybuild.framework.easyconfig.easyconfig import EasyConfig, ITERATE_OPTIONS
4848
from easybuild.framework.easyconfig.tools import avail_easyblocks, process_easyconfig
4949
from easybuild.framework.extensioneasyblock import ExtensionEasyBlock
5050
from easybuild.tools import LooseVersion, config
@@ -1173,7 +1173,9 @@ def test_handle_iterate_opts(self):
11731173
self.assertEqual(eb.cfg.iterate_options, [])
11741174
self.assertEqual(eb.cfg['configopts'], ["--opt1 --anotheropt", "--opt2", "--opt3 --optbis"])
11751175

1176-
expected_iter_opts = {'configopts': ["--opt1 --anotheropt", "--opt2", "--opt3 --optbis"]}
1176+
expected_iter_opts = dict.fromkeys(ITERATE_OPTIONS, "")
1177+
expected_iter_opts['builddependencies'] = []
1178+
expected_iter_opts['configopts'] = ["--opt1 --anotheropt", "--opt2", "--opt3 --optbis"]
11771179

11781180
# once iteration mode is set, we're still in iteration #0
11791181
self.mock_stdout(True)
@@ -1185,6 +1187,8 @@ def test_handle_iterate_opts(self):
11851187
self.assertEqual(eb.cfg.iterating, True)
11861188
self.assertEqual(eb.cfg.iterate_options, ['configopts'])
11871189
self.assertEqual(eb.cfg['configopts'], "--opt1 --anotheropt")
1190+
# mimic easyblock that changes this in-place
1191+
eb.cfg['preconfigopts'] = "FOO=bar "
11881192
self.assertEqual(eb.iter_opts, expected_iter_opts)
11891193

11901194
# when next iteration is start, iteration index gets bumped
@@ -1196,6 +1200,8 @@ def test_handle_iterate_opts(self):
11961200
self.assertEqual(stdout, "== starting iteration #1 ...\n")
11971201
self.assertEqual(eb.cfg.iterating, True)
11981202
self.assertEqual(eb.cfg.iterate_options, ['configopts'])
1203+
# preconfigopts should have been restored (https://github.com/easybuilders/easybuild-framework/pull/4848)
1204+
self.assertEqual(eb.cfg['preconfigopts'], "")
11991205
self.assertEqual(eb.cfg['configopts'], "--opt2")
12001206
self.assertEqual(eb.iter_opts, expected_iter_opts)
12011207

0 commit comments

Comments
 (0)