From 476c2639521b57184565d85f85e94862d0be7269 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sun, 23 Apr 2017 01:11:25 +0300 Subject: Unset compiler envvars in unit tests. --- mesonbuild/environment.py | 19 ++++++++++--------- run_unittests.py | 10 ++++++++++ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index 61425a4..3152d5d 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -24,6 +24,16 @@ import shutil build_filename = 'meson.build' +# Environment variables that each lang uses. +cflags_mapping = {'c': 'CFLAGS', + 'cpp': 'CXXFLAGS', + 'objc': 'OBJCFLAGS', + 'objcpp': 'OBJCXXFLAGS', + 'fortran': 'FFLAGS', + 'd': 'DFLAGS', + 'vala': 'VALAFLAGS'} + + def find_coverage_tools(): gcovr_exe = 'gcovr' lcov_exe = 'lcov' @@ -809,15 +819,6 @@ def get_args_from_envvars(compiler): if hasattr(compiler, 'get_linker_exelist'): compiler_is_linker = (compiler.get_exelist() == compiler.get_linker_exelist()) - # Compile flags - cflags_mapping = {'c': 'CFLAGS', - 'cpp': 'CXXFLAGS', - 'objc': 'OBJCFLAGS', - 'objcpp': 'OBJCXXFLAGS', - 'fortran': 'FFLAGS', - 'd': 'DFLAGS', - 'vala': 'VALAFLAGS'} - if lang not in cflags_mapping.keys(): return [], [], [] diff --git a/run_unittests.py b/run_unittests.py index 20464e0..1d80aac 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -1556,5 +1556,15 @@ class RewriterTests(unittest.TestCase): self.assertEqual(s2, self.read_contents('sub2/meson.build')) +def unset_envs(): + # For unit tests we must fully control all commend lines + # so that there are no unexpected changes coming from the + # environment, for example when doing a package build. + varnames = ['CPPFLAGS', 'LDFLAGS'] + list(mesonbuild.environment.cflags_mapping.values()) + for v in varnames: + if v in os.environ: + del os.environ[v] + if __name__ == '__main__': + unset_envs() unittest.main(buffer=True) -- cgit v1.1