diff --git a/easybuild/tools/toolchain/compiler.py b/easybuild/tools/toolchain/compiler.py index 68d224fc7c..faa5294fe2 100644 --- a/easybuild/tools/toolchain/compiler.py +++ b/easybuild/tools/toolchain/compiler.py @@ -349,6 +349,11 @@ def _set_optimal_architecture(self, default_optarch=None): optarch = self.COMPILER_OPTIMAL_ARCHITECTURE_OPTION[(self.arch, self.cpu_family)] if optarch is not None: + # In EB 5.0 flags should include the initial "-", but for backwards compatiblity we add it if the flag is missing. + if not optarch.startswith('-'): + print_warning(f'Specifying optarch "{optarch}" without initial dash is deprecated in EasyBuild 5.') + optarch = '-' + optarch + optarch_log_str = optarch or 'no flags' self.log.info("_set_optimal_architecture: using %s as optarch for %s/%s.", optarch_log_str, self.arch, self.cpu_family) diff --git a/test/framework/toolchain.py b/test/framework/toolchain.py index 83eca9eab1..ec3fd140fe 100644 --- a/test/framework/toolchain.py +++ b/test/framework/toolchain.py @@ -2189,47 +2189,50 @@ def test_independence(self): """Test independency of toolchain instances.""" # tweaking --optarch is required for Cray toolchains (craypre- module must be available) - init_config(build_options={'optarch': 'test', 'silent': True}) + custom_optarchs = ['test', '-test'] # specifying without initial - is deprecated but should still work + for custom_optarch in custom_optarchs: + init_config(build_options={'optarch': custom_optarch, 'silent': True}) + + tc_cflags = { + 'CrayCCE': "-O2 -homp -craype-verbose", + 'CrayGNU': "-O2 -fno-math-errno -fopenmp -craype-verbose", + 'CrayIntel': "-O2 -ftz -fp-speculation=safe -fp-model source -fopenmp -craype-verbose", + 'GCC': "-O2 -ftree-vectorize -test -fno-math-errno -fopenmp", + 'iccifort': "-O2 -test -ftz -fp-speculation=safe -fp-model source -fopenmp", + 'intel-compilers': "-O2 -test -ftz -fp-speculation=safe -fp-model precise -qopenmp", + } - tc_cflags = { - 'CrayCCE': "-O2 -homp -craype-verbose", - 'CrayGNU': "-O2 -fno-math-errno -fopenmp -craype-verbose", - 'CrayIntel': "-O2 -ftz -fp-speculation=safe -fp-model source -fopenmp -craype-verbose", - 'GCC': "-O2 -ftree-vectorize -test -fno-math-errno -fopenmp", - 'iccifort': "-O2 -test -ftz -fp-speculation=safe -fp-model source -fopenmp", - 'intel-compilers': "-O2 -test -ftz -fp-speculation=safe -fp-model precise -qopenmp", - } + toolchains = [ + ('CrayCCE', '2015.06-XC'), + ('CrayGNU', '2015.06-XC'), + ('CrayIntel', '2015.06-XC'), + ('GCC', '6.4.0-2.28'), + ('iccifort', '2018.1.163'), + ('intel-compilers', '2022.1.0'), + ] - toolchains = [ - ('CrayCCE', '2015.06-XC'), - ('CrayGNU', '2015.06-XC'), - ('CrayIntel', '2015.06-XC'), - ('GCC', '6.4.0-2.28'), - ('iccifort', '2018.1.163'), - ('intel-compilers', '2022.1.0'), - ] + # purposely obtain toolchains several times in a row, value for $CFLAGS should not change + for _ in range(3): + for tcname, tcversion in toolchains: + # Cray* modules do not unload other Cray* modules thus loading a second Cray* module + # makes environment inconsistent which is not allowed by Environment Modules tool + if isinstance(self.modtool, EnvironmentModules): + self.modtool.purge() + tc = get_toolchain({'name': tcname, 'version': tcversion}, {}, + mns=ActiveMNS(), modtool=self.modtool) + # also check whether correct compiler flag for OpenMP is used while we're at it + # and options for oneAPI compiler for Intel + if tcname == 'intel-compilers': + tc.set_options({'oneapi': True, 'openmp': True}) + else: + tc.set_options({'openmp': True}) + with self.mocked_stdout_stderr(): + tc.prepare() + expected_cflags = tc_cflags[tcname] + msg = "Expected $CFLAGS found for toolchain %s: %s" % (tcname, expected_cflags) + self.assertEqual(str(tc.variables['CFLAGS']), expected_cflags, msg) + self.assertEqual(os.environ['CFLAGS'], expected_cflags, msg) - # purposely obtain toolchains several times in a row, value for $CFLAGS should not change - for _ in range(3): - for tcname, tcversion in toolchains: - # Cray* modules do not unload other Cray* modules thus loading a second Cray* module - # makes environment inconsistent which is not allowed by Environment Modules tool - if isinstance(self.modtool, EnvironmentModules): - self.modtool.purge() - tc = get_toolchain({'name': tcname, 'version': tcversion}, {}, - mns=ActiveMNS(), modtool=self.modtool) - # also check whether correct compiler flag for OpenMP is used while we're at it - # and options for oneAPI compiler for Intel - if tcname == 'intel-compilers': - tc.set_options({'oneapi': True, 'openmp': True}) - else: - tc.set_options({'openmp': True}) - with self.mocked_stdout_stderr(): - tc.prepare() - expected_cflags = tc_cflags[tcname] - msg = "Expected $CFLAGS found for toolchain %s: %s" % (tcname, expected_cflags) - self.assertEqual(str(tc.variables['CFLAGS']), expected_cflags, msg) - self.assertEqual(os.environ['CFLAGS'], expected_cflags, msg) def test_pgi_toolchain(self): """Tests for PGI toolchain.""" diff --git a/test/framework/toolchainvariables.py b/test/framework/toolchainvariables.py index 63f81dfba2..f8b478e27d 100644 --- a/test/framework/toolchainvariables.py +++ b/test/framework/toolchainvariables.py @@ -159,7 +159,7 @@ class TCV(ToolchainVariables): tcv.nappend('MPICH_CC', 'icc', var_class=CommandFlagList) self.assertEqual(str(tcv['MPICH_CC']), "icc") - tcv.nappend('MPICH_CC', 'test') + tcv.nappend('MPICH_CC', '-test') self.assertEqual(str(tcv['MPICH_CC']), "icc -test")