aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2017-04-23 01:11:25 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2017-04-23 02:00:28 +0300
commit476c2639521b57184565d85f85e94862d0be7269 (patch)
tree767cd7c48cdec135ce2bbfa44f811916ee0bdca3
parentaa486f5bb2b962ee6f5f65cabe05bb33f92ebead (diff)
downloadmeson-476c2639521b57184565d85f85e94862d0be7269.zip
meson-476c2639521b57184565d85f85e94862d0be7269.tar.gz
meson-476c2639521b57184565d85f85e94862d0be7269.tar.bz2
Unset compiler envvars in unit tests.
-rw-r--r--mesonbuild/environment.py19
-rwxr-xr-xrun_unittests.py10
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)