Skip to content

Commit 5c695af

Browse files
authored
Merge pull request #3560 from boegel/test_cudaver_toolchain
avoid initializing Toolchain instance when taking into account toolchain dependencies for templates
2 parents dd1794c + 6b119a6 commit 5c695af

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

easybuild/framework/easyconfig/templates.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ def template_constant_dict(config, ignore=None, skip_lower=None, toolchain=None)
233233
# a cyclic import...);
234234
# we need to know to determine whether we're iterating over a list of build dependencies
235235
is_easyconfig = hasattr(config, 'iterating') and hasattr(config, 'iterate_options')
236-
237236
if is_easyconfig:
238237
# if we're iterating over different lists of build dependencies,
239238
# only consider build dependencies when we're actually in iterative mode!
@@ -243,9 +242,11 @@ def template_constant_dict(config, ignore=None, skip_lower=None, toolchain=None)
243242
else:
244243
deps.extend(config.get('builddependencies', []))
245244

246-
# Include all toolchain deps (e.g. CUDAcore template in fosscuda)
247-
if config.toolchain.tcdeps is not None:
248-
deps.extend(config.toolchain.tcdeps)
245+
# include all toolchain deps (e.g. CUDAcore component in fosscuda);
246+
# access Toolchain instance via _toolchain to avoid triggering initialization of the toolchain!
247+
if config._toolchain is not None:
248+
if config._toolchain.tcdeps is not None:
249+
deps.extend(config._toolchain.tcdeps)
249250

250251
for dep in deps:
251252
if isinstance(dep, dict):

test/framework/easyconfig.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,51 @@ def test_templating(self):
10501050
ec = EasyConfig(test_ec)
10511051
self.assertEqual(ec['sanity_check_commands'], ['mpiexec -np 1 -- toy'])
10521052

1053+
def test_templating_cuda_toolchain(self):
1054+
"""Test templates via toolchain component, like setting %(cudaver)s with fosscuda toolchain."""
1055+
1056+
build_options = {'robot_path': [self.test_prefix]}
1057+
init_config(build_options=build_options)
1058+
1059+
# create fake easyconfig files, good enough to test with
1060+
cuda_ec = os.path.join(self.test_prefix, 'CUDA-10.1.243')
1061+
cuda_ec_txt = '\n'.join([
1062+
"easyblock = 'Toolchain'",
1063+
"name = 'CUDA'",
1064+
"version = '10.1.243'",
1065+
"homepage = 'https://example.com'",
1066+
"description = 'CUDA'",
1067+
"toolchain = SYSTEM",
1068+
])
1069+
write_file(cuda_ec, cuda_ec_txt)
1070+
1071+
fosscuda_ec = os.path.join(self.test_prefix, 'fosscuda-2021.02.eb')
1072+
fosscuda_ec_txt = '\n'.join([
1073+
"easyblock = 'Toolchain'",
1074+
"name = 'fosscuda'",
1075+
"version = '2021.02'",
1076+
"homepage = 'https://example.com'",
1077+
"description = 'fosscuda toolchain'",
1078+
"toolchain = SYSTEM",
1079+
"dependencies = [('CUDA', '10.1.243')]",
1080+
])
1081+
write_file(fosscuda_ec, fosscuda_ec_txt)
1082+
1083+
test_ec = os.path.join(self.test_prefix, 'test.eb')
1084+
test_ec_txt = '\n'.join([
1085+
"easyblock = 'Toolchain'",
1086+
"name = 'test'",
1087+
"version = '1.0'",
1088+
"homepage = 'https://example.com'",
1089+
"description = 'just a test'",
1090+
"toolchain = {'name': 'fosscuda', 'version': '2021.02'}",
1091+
])
1092+
write_file(test_ec, test_ec_txt)
1093+
ec = EasyConfig(test_ec)
1094+
self.assertEqual(ec.template_values['cudaver'], '10.1.243')
1095+
self.assertEqual(ec.template_values['cudamajver'], '10')
1096+
self.assertEqual(ec.template_values['cudashortver'], '10.1')
1097+
10531098
def test_java_wrapper_templating(self):
10541099
"""test templating when the Java wrapper is a dep"""
10551100
self.contents = '\n'.join([

test/framework/robot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ def test_resolve_dependencies_minimal(self):
436436
" ('SQLite', '3.8.10.2'),",
437437
"]",
438438
# toolchain as list line, for easy modification later;
439-
"toolchain = {'name': 'foss', 'version': '2018a'}",
439+
"toolchain = {'name': 'foss', 'version': '%(version_minor)s018a'}",
440440
]
441441
write_file(barec, '\n'.join(barec_lines))
442442
bar = process_easyconfig(barec)[0]

0 commit comments

Comments
 (0)