From 0143b5cd0aa44d2b7ee9a48b0d39c1cba96dfeef Mon Sep 17 00:00:00 2001 From: Simon Branford <4967+branfosj@users.noreply.github.com> Date: Wed, 9 Aug 2023 16:39:03 +0100 Subject: [PATCH 1/5] enhance `get_flag` to handle lists --- easybuild/tools/toolchain/toolchain.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/easybuild/tools/toolchain/toolchain.py b/easybuild/tools/toolchain/toolchain.py index 308678a555..38d2f139d3 100644 --- a/easybuild/tools/toolchain/toolchain.py +++ b/easybuild/tools/toolchain/toolchain.py @@ -1129,8 +1129,14 @@ def _setenv_variables(self, donotset=None, verbose=True): setvar("EBVAR%s" % key, val, verbose=False) def get_flag(self, name): - """Get compiler flag for a certain option.""" - return "-%s" % self.options.option(name) + """Get compiler flag(s) for a certain option.""" + if isinstance(self.options.option(name), str): + return "-%s" % self.options.option(name) + elif isinstance(self.options.option(name), list): + return " ".join("-%s" % x for x in self.options.option(name)) + else: + msg = "Do not know how to convert toolchain flag %s, of type %s, for use" + raise EasyBuildError(msg % (name, type(self.options.option(name)))) def toolchain_family(self): """Return toolchain family for this toolchain.""" From f2ec534da2a3caf5b98fe5a2dbd2f00cb50e8e7e Mon Sep 17 00:00:00 2001 From: Simon Branford <4967+branfosj@users.noreply.github.com> Date: Wed, 9 Aug 2023 16:59:18 +0100 Subject: [PATCH 2/5] maintain existing behaviour unless it is a list --- easybuild/tools/toolchain/toolchain.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/easybuild/tools/toolchain/toolchain.py b/easybuild/tools/toolchain/toolchain.py index 38d2f139d3..4ada51995b 100644 --- a/easybuild/tools/toolchain/toolchain.py +++ b/easybuild/tools/toolchain/toolchain.py @@ -1130,13 +1130,10 @@ def _setenv_variables(self, donotset=None, verbose=True): def get_flag(self, name): """Get compiler flag(s) for a certain option.""" - if isinstance(self.options.option(name), str): - return "-%s" % self.options.option(name) - elif isinstance(self.options.option(name), list): + if isinstance(self.options.option(name), list): return " ".join("-%s" % x for x in self.options.option(name)) else: - msg = "Do not know how to convert toolchain flag %s, of type %s, for use" - raise EasyBuildError(msg % (name, type(self.options.option(name)))) + return "-%s" % self.options.option(name) def toolchain_family(self): """Return toolchain family for this toolchain.""" From 3052696ca49b3ed062d68e3e900758b8b3bbe454 Mon Sep 17 00:00:00 2001 From: Simon Branford Date: Wed, 9 Aug 2023 17:31:20 +0100 Subject: [PATCH 3/5] also accept tuple --- easybuild/tools/toolchain/toolchain.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/easybuild/tools/toolchain/toolchain.py b/easybuild/tools/toolchain/toolchain.py index 4ada51995b..b9d489852e 100644 --- a/easybuild/tools/toolchain/toolchain.py +++ b/easybuild/tools/toolchain/toolchain.py @@ -1130,7 +1130,7 @@ def _setenv_variables(self, donotset=None, verbose=True): def get_flag(self, name): """Get compiler flag(s) for a certain option.""" - if isinstance(self.options.option(name), list): + if isinstance(self.options.option(name), list) or isinstance(self.options.option(name), tuple): return " ".join("-%s" % x for x in self.options.option(name)) else: return "-%s" % self.options.option(name) From 2646f7584a1d0253a9afea4cdd0f766f6f53e26d Mon Sep 17 00:00:00 2001 From: Simon Branford Date: Wed, 9 Aug 2023 18:24:58 +0100 Subject: [PATCH 4/5] add tests --- easybuild/tools/toolchain/toolchain.py | 4 ++-- test/framework/toolchain.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/easybuild/tools/toolchain/toolchain.py b/easybuild/tools/toolchain/toolchain.py index b9d489852e..a16fe35dc0 100644 --- a/easybuild/tools/toolchain/toolchain.py +++ b/easybuild/tools/toolchain/toolchain.py @@ -1130,8 +1130,8 @@ def _setenv_variables(self, donotset=None, verbose=True): def get_flag(self, name): """Get compiler flag(s) for a certain option.""" - if isinstance(self.options.option(name), list) or isinstance(self.options.option(name), tuple): - return " ".join("-%s" % x for x in self.options.option(name)) + if isinstance(self.options.option(name), list): + return " ".join("-%s" % x for x in list(self.options.option(name))) else: return "-%s" % self.options.option(name) diff --git a/test/framework/toolchain.py b/test/framework/toolchain.py index 1c36431c45..cf0369764c 100644 --- a/test/framework/toolchain.py +++ b/test/framework/toolchain.py @@ -2950,6 +2950,20 @@ def test_env_vars_external_module(self): expected = {} self.assertEqual(res, expected) + def test_get_flag(self): + """Test get_flag function""" + tc = self.get_toolchain('gompi', version='2018a') + + checks = { + '-a': 'a', + '-openmp': 'openmp', + '-foo': ['foo'], + '-foo -bar': ['foo', 'bar'], + } + + for flagstring, flags in checks.items(): + tc.options.options_map['openmp'] = flags + self.assertEqual(tc.get_flag('openmp'), flagstring) def suite(): """ return all the tests""" From 587f64d893529c1b12b65de8e45a2741b5358f8c Mon Sep 17 00:00:00 2001 From: Simon Branford Date: Wed, 9 Aug 2023 18:27:03 +0100 Subject: [PATCH 5/5] f8 --- test/framework/toolchain.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/framework/toolchain.py b/test/framework/toolchain.py index cf0369764c..d80d41c788 100644 --- a/test/framework/toolchain.py +++ b/test/framework/toolchain.py @@ -2965,6 +2965,7 @@ def test_get_flag(self): tc.options.options_map['openmp'] = flags self.assertEqual(tc.get_flag('openmp'), flagstring) + def suite(): """ return all the tests""" return TestLoaderFiltered().loadTestsFromTestCase(ToolchainTest, sys.argv[1:])