diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/build_environment.py | 15 | ||||
-rw-r--r-- | lib/spack/spack/test/flag_handlers.py | 14 |
2 files changed, 27 insertions, 2 deletions
diff --git a/lib/spack/spack/build_environment.py b/lib/spack/spack/build_environment.py index dcc6e46ec6..b2a7e1f6d6 100644 --- a/lib/spack/spack/build_environment.py +++ b/lib/spack/spack/build_environment.py @@ -57,6 +57,7 @@ import os import shutil import sys import traceback +import types from six import iteritems from six import StringIO @@ -165,7 +166,19 @@ def set_compiler_environment_variables(pkg, env): env_flags = {} build_system_flags = {} for flag in spack.spec.FlagMap.valid_compiler_flags(): - injf, envf, bsf = pkg.flag_handler(flag, pkg.spec.compiler_flags[flag]) + # Always convert flag_handler to function type. + # This avoids discrepencies in calling conventions between functions + # and methods, or between bound and unbound methods in python 2. + # We cannot effectively convert everything to a bound method, which + # would be the simpler solution. + if isinstance(pkg.flag_handler, types.FunctionType): + handler = pkg.flag_handler + else: + if sys.version_info >= (3, 0): + handler = pkg.flag_handler.__func__ + else: + handler = pkg.flag_handler.im_func + injf, envf, bsf = handler(pkg, flag, pkg.spec.compiler_flags[flag]) inject_flags[flag] = injf or [] env_flags[flag] = envf or [] build_system_flags[flag] = bsf or [] diff --git a/lib/spack/spack/test/flag_handlers.py b/lib/spack/spack/test/flag_handlers.py index 0b785a948f..80dad9c35e 100644 --- a/lib/spack/spack/test/flag_handlers.py +++ b/lib/spack/spack/test/flag_handlers.py @@ -36,7 +36,7 @@ def temp_env(): os.environ = old_env -def add_O3_to_build_system_cflags(name, flags): +def add_O3_to_build_system_cflags(pkg, name, flags): build_system_flags = [] if name == 'cflags': build_system_flags.append('-O3') @@ -61,6 +61,18 @@ class TestFlagHandlers(object): assert 'SPACK_CPPFLAGS' not in os.environ assert 'CPPFLAGS' not in os.environ + def test_unbound_method(self, temp_env): + # Other tests test flag_handlers set as bound methods and functions. + # This tests an unbound method in python2 (no change in python3). + s = spack.spec.Spec('mpileaks cppflags=-g') + s.concretize() + pkg = spack.repo.get(s) + pkg.flag_handler = pkg.__class__.inject_flags + spack.build_environment.setup_package(pkg, False) + + assert os.environ['SPACK_CPPFLAGS'] == '-g' + assert 'CPPFLAGS' not in os.environ + def test_inject_flags(self, temp_env): s = spack.spec.Spec('mpileaks cppflags=-g') s.concretize() |