Skip to content

Commit 6ae9912

Browse files
committed
Add test to check for old and new optarch syntax. Add deprecation warning.
1 parent cbdcbbf commit 6ae9912

File tree

3 files changed

+48
-41
lines changed

3 files changed

+48
-41
lines changed

easybuild/tools/toolchain/compiler.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* Damian Alvarez (Forschungszentrum Juelich GmbH)
3434
"""
3535
from easybuild.tools import systemtools
36-
from easybuild.tools.build_log import EasyBuildError
36+
from easybuild.tools.build_log import EasyBuildError, print_warning
3737
from easybuild.tools.config import build_option
3838
from easybuild.tools.toolchain.constants import COMPILER_VARIABLES
3939
from easybuild.tools.toolchain.toolchain import Toolchain
@@ -356,6 +356,11 @@ def _set_optimal_architecture(self, default_optarch=None):
356356
optarch = self.COMPILER_OPTIMAL_ARCHITECTURE_OPTION[(self.arch, self.cpu_family)]
357357

358358
if optarch is not None:
359+
if not optarch.startswith('-'):
360+
print_warning(f'Specifying optarch "{optarch}" without initial dash is deprecated in EasyBuild 5.')
361+
# Add flags for backwards compatibility
362+
optarch = '-' + optarch
363+
359364
optarch_log_str = optarch or 'no flags'
360365
self.log.info("_set_optimal_architecture: using %s as optarch for %s/%s.",
361366
optarch_log_str, self.arch, self.cpu_family)

test/framework/toolchain.py

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,47 +2274,49 @@ def test_independence(self):
22742274
"""Test independency of toolchain instances."""
22752275

22762276
# tweaking --optarch is required for Cray toolchains (craypre-<optarch> module must be available)
2277-
init_config(build_options={'optarch': 'test', 'silent': True})
2278-
2279-
tc_cflags = {
2280-
'CrayCCE': "-O2 -g -homp -craype-verbose",
2281-
'CrayGNU': "-O2 -fno-math-errno -g -fopenmp -craype-verbose",
2282-
'CrayIntel': "-O2 -ftz -fp-speculation=safe -fp-model source -g -fopenmp -craype-verbose",
2283-
'GCC': "-O2 -ftree-vectorize -test -fno-math-errno -g -fopenmp",
2284-
'iccifort': "-O2 -test -ftz -fp-speculation=safe -fp-model source -g -fopenmp",
2285-
'intel-compilers': "-O2 -test -ftz -fp-speculation=safe -fp-model precise -g -qopenmp",
2286-
}
2277+
custom_optarchs = ['test', '-test'] # specifying without initial - is deprecated but should still work
2278+
for custom_optarch in custom_optarchs:
2279+
init_config(build_options={'optarch': custom_optarch, 'silent': True})
2280+
2281+
tc_cflags = {
2282+
'CrayCCE': "-O2 -g -homp -craype-verbose",
2283+
'CrayGNU': "-O2 -fno-math-errno -g -fopenmp -craype-verbose",
2284+
'CrayIntel': "-O2 -ftz -fp-speculation=safe -fp-model source -g -fopenmp -craype-verbose",
2285+
'GCC': "-O2 -ftree-vectorize -test -fno-math-errno -g -fopenmp",
2286+
'iccifort': "-O2 -test -ftz -fp-speculation=safe -fp-model source -g -fopenmp",
2287+
'intel-compilers': "-O2 -test -ftz -fp-speculation=safe -fp-model precise -g -qopenmp",
2288+
}
22872289

2288-
toolchains = [
2289-
('CrayCCE', '2015.06-XC'),
2290-
('CrayGNU', '2015.06-XC'),
2291-
('CrayIntel', '2015.06-XC'),
2292-
('GCC', '6.4.0-2.28'),
2293-
('iccifort', '2018.1.163'),
2294-
('intel-compilers', '2022.1.0'),
2295-
]
2290+
toolchains = [
2291+
('CrayCCE', '2015.06-XC'),
2292+
('CrayGNU', '2015.06-XC'),
2293+
('CrayIntel', '2015.06-XC'),
2294+
('GCC', '6.4.0-2.28'),
2295+
('iccifort', '2018.1.163'),
2296+
('intel-compilers', '2022.1.0'),
2297+
]
22962298

2297-
# purposely obtain toolchains several times in a row, value for $CFLAGS should not change
2298-
for _ in range(3):
2299-
for tcname, tcversion in toolchains:
2300-
# Cray* modules do not unload other Cray* modules thus loading a second Cray* module
2301-
# makes environment inconsistent which is not allowed by Environment Modules tool
2302-
if isinstance(self.modtool, EnvironmentModules):
2303-
self.modtool.purge()
2304-
tc = get_toolchain({'name': tcname, 'version': tcversion}, {},
2305-
mns=ActiveMNS(), modtool=self.modtool)
2306-
# also check whether correct compiler flag for OpenMP is used while we're at it
2307-
# and options for oneAPI compiler for Intel
2308-
if tcname == 'intel-compilers':
2309-
tc.set_options({'oneapi': True, 'openmp': True})
2310-
else:
2311-
tc.set_options({'openmp': True})
2312-
with self.mocked_stdout_stderr():
2313-
tc.prepare()
2314-
expected_cflags = tc_cflags[tcname]
2315-
msg = "Expected $CFLAGS found for toolchain %s: %s" % (tcname, expected_cflags)
2316-
self.assertEqual(str(tc.variables['CFLAGS']), expected_cflags, msg)
2317-
self.assertEqual(os.environ['CFLAGS'], expected_cflags, msg)
2299+
# purposely obtain toolchains several times in a row, value for $CFLAGS should not change
2300+
for _ in range(3):
2301+
for tcname, tcversion in toolchains:
2302+
# Cray* modules do not unload other Cray* modules thus loading a second Cray* module
2303+
# makes environment inconsistent which is not allowed by Environment Modules tool
2304+
if isinstance(self.modtool, EnvironmentModules):
2305+
self.modtool.purge()
2306+
tc = get_toolchain({'name': tcname, 'version': tcversion}, {},
2307+
mns=ActiveMNS(), modtool=self.modtool)
2308+
# also check whether correct compiler flag for OpenMP is used while we're at it
2309+
# and options for oneAPI compiler for Intel
2310+
if tcname == 'intel-compilers':
2311+
tc.set_options({'oneapi': True, 'openmp': True})
2312+
else:
2313+
tc.set_options({'openmp': True})
2314+
with self.mocked_stdout_stderr():
2315+
tc.prepare()
2316+
expected_cflags = tc_cflags[tcname]
2317+
msg = "Expected $CFLAGS found for toolchain %s: %s" % (tcname, expected_cflags)
2318+
self.assertEqual(str(tc.variables['CFLAGS']), expected_cflags, msg)
2319+
self.assertEqual(os.environ['CFLAGS'], expected_cflags, msg)
23182320

23192321
def test_pgi_toolchain(self):
23202322
"""Tests for PGI toolchain."""

test/framework/toolchainvariables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class TCV(ToolchainVariables):
159159

160160
tcv.nappend('MPICH_CC', 'icc', var_class=CommandFlagList)
161161
self.assertEqual(str(tcv['MPICH_CC']), "icc")
162-
tcv.nappend('MPICH_CC', 'test')
162+
tcv.nappend('MPICH_CC', '-test')
163163
self.assertEqual(str(tcv['MPICH_CC']), "icc -test")
164164

165165

0 commit comments

Comments
 (0)