Skip to content

Commit bbfd3a7

Browse files
authored
Merge pull request #4359 from xinan1911/sysroottem
Add sysroot template value
2 parents 2dc4707 + a410526 commit bbfd3a7

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

easybuild/framework/easyconfig/templates.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@
9090
# template values which are only generated dynamically
9191
TEMPLATE_NAMES_DYNAMIC = [
9292
('arch', "System architecture (e.g. x86_64, aarch64, ppc64le, ...)"),
93+
('sysroot', "Location root directory of system, prefix for standard paths like /usr/lib and /usr/include"
94+
"as specify by the --sysroot configuration option"),
9395
('mpi_cmd_prefix', "Prefix command for running MPI programs (with default number of ranks)"),
9496
('cuda_compute_capabilities', "Comma-separated list of CUDA compute capabilities, as specified via "
9597
"--cuda-compute-capabilities configuration option or via cuda_compute_capabilities easyconfig parameter"),
@@ -201,6 +203,9 @@ def template_constant_dict(config, ignore=None, skip_lower=None, toolchain=None)
201203
# set 'arch' for system architecture based on 'machine' (4th) element of platform.uname() return value
202204
template_values['arch'] = platform.uname()[4]
203205

206+
# set 'sysroot' template based on 'sysroot' configuration option, using empty string as fallback
207+
template_values['sysroot'] = build_option('sysroot') or ''
208+
204209
# step 1: add TEMPLATE_NAMES_EASYCONFIG
205210
for name in TEMPLATE_NAMES_EASYCONFIG:
206211
if name in ignore:

test/framework/easyconfig.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,6 +1346,34 @@ def test_start_dir_template(self):
13461346
self.assertIn('start_dir in extension configure is %s &&' % ext_start_dir, logtxt)
13471347
self.assertIn('start_dir in extension build is %s &&' % ext_start_dir, logtxt)
13481348

1349+
def test_sysroot_template(self):
1350+
"""Test the %(sysroot)s template"""
1351+
1352+
test_easyconfigs = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'easyconfigs', 'test_ecs')
1353+
toy_ec = os.path.join(test_easyconfigs, 't', 'toy', 'toy-0.0.eb')
1354+
1355+
test_ec = os.path.join(self.test_prefix, 'test.eb')
1356+
test_ec_txt = read_file(toy_ec)
1357+
test_ec_txt += '\nconfigopts = "--some-opt=%(sysroot)s/"'
1358+
test_ec_txt += '\nbuildopts = "--some-opt=%(sysroot)s/"'
1359+
test_ec_txt += '\ninstallopts = "--some-opt=%(sysroot)s/"'
1360+
write_file(test_ec, test_ec_txt)
1361+
1362+
# Validate the value of the sysroot template if sysroot is unset (i.e. the build option is None)
1363+
ec = EasyConfig(test_ec)
1364+
self.assertEqual(ec['configopts'], "--some-opt=/")
1365+
self.assertEqual(ec['buildopts'], "--some-opt=/")
1366+
self.assertEqual(ec['installopts'], "--some-opt=/")
1367+
1368+
# Validate the value of the sysroot template if sysroot is unset (i.e. the build option is None)
1369+
# As a test, we'll set the sysroot to self.test_prefix, as it has to be a directory that is guaranteed to exist
1370+
update_build_option('sysroot', self.test_prefix)
1371+
1372+
ec = EasyConfig(test_ec)
1373+
self.assertEqual(ec['configopts'], "--some-opt=%s/" % self.test_prefix)
1374+
self.assertEqual(ec['buildopts'], "--some-opt=%s/" % self.test_prefix)
1375+
self.assertEqual(ec['installopts'], "--some-opt=%s/" % self.test_prefix)
1376+
13491377
def test_constant_doc(self):
13501378
"""test constant documentation"""
13511379
doc = avail_easyconfig_constants()
@@ -3234,6 +3262,7 @@ def test_template_constant_dict(self):
32343262
'nameletter': 'g',
32353263
'nameletterlower': 'g',
32363264
'parallel': None,
3265+
'sysroot': '',
32373266
'toolchain_name': 'foss',
32383267
'toolchain_version': '2018a',
32393268
'version': '1.5',
@@ -3315,6 +3344,7 @@ def test_template_constant_dict(self):
33153344
'pyminver': '7',
33163345
'pyshortver': '3.7',
33173346
'pyver': '3.7.2',
3347+
'sysroot': '',
33183348
'version': '0.01',
33193349
'version_major': '0',
33203350
'version_major_minor': '0.01',
@@ -3379,6 +3409,7 @@ def test_template_constant_dict(self):
33793409
'namelower': 'foo',
33803410
'nameletter': 'f',
33813411
'nameletterlower': 'f',
3412+
'sysroot': '',
33823413
'version': '1.2.3',
33833414
'version_major': '1',
33843415
'version_major_minor': '1.2',

0 commit comments

Comments
 (0)