Skip to content

Commit 476c263

Browse files
committed
Unset compiler envvars in unit tests.
1 parent aa486f5 commit 476c263

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

mesonbuild/environment.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@
2424

2525
build_filename = 'meson.build'
2626

27+
# Environment variables that each lang uses.
28+
cflags_mapping = {'c': 'CFLAGS',
29+
'cpp': 'CXXFLAGS',
30+
'objc': 'OBJCFLAGS',
31+
'objcpp': 'OBJCXXFLAGS',
32+
'fortran': 'FFLAGS',
33+
'd': 'DFLAGS',
34+
'vala': 'VALAFLAGS'}
35+
36+
2737
def find_coverage_tools():
2838
gcovr_exe = 'gcovr'
2939
lcov_exe = 'lcov'
@@ -809,15 +819,6 @@ def log_var(var, val):
809819
if hasattr(compiler, 'get_linker_exelist'):
810820
compiler_is_linker = (compiler.get_exelist() == compiler.get_linker_exelist())
811821

812-
# Compile flags
813-
cflags_mapping = {'c': 'CFLAGS',
814-
'cpp': 'CXXFLAGS',
815-
'objc': 'OBJCFLAGS',
816-
'objcpp': 'OBJCXXFLAGS',
817-
'fortran': 'FFLAGS',
818-
'd': 'DFLAGS',
819-
'vala': 'VALAFLAGS'}
820-
821822
if lang not in cflags_mapping.keys():
822823
return [], [], []
823824

run_unittests.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,5 +1556,15 @@ def test_subdir(self):
15561556
self.assertEqual(s2, self.read_contents('sub2/meson.build'))
15571557

15581558

1559+
def unset_envs():
1560+
# For unit tests we must fully control all commend lines
1561+
# so that there are no unexpected changes coming from the
1562+
# environment, for example when doing a package build.
1563+
varnames = ['CPPFLAGS', 'LDFLAGS'] + list(mesonbuild.environment.cflags_mapping.values())
1564+
for v in varnames:
1565+
if v in os.environ:
1566+
del os.environ[v]
1567+
15591568
if __name__ == '__main__':
1569+
unset_envs()
15601570
unittest.main(buffer=True)

0 commit comments

Comments
 (0)