aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/backend/ninjabackend.py
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2023-01-08 15:29:46 -0500
committerXavier Claessens <xclaesse@gmail.com>2023-01-08 18:02:37 -0500
commit9f12f6e1586b91e10ec950d0e334b3d1159d00b7 (patch)
treee3404692f4240ab1ce85798ae4ab9aa757060103 /mesonbuild/backend/ninjabackend.py
parent25e73b6c9e9599e852fba1f153497de1eccd862b (diff)
downloadmeson-9f12f6e1586b91e10ec950d0e334b3d1159d00b7.zip
meson-9f12f6e1586b91e10ec950d0e334b3d1159d00b7.tar.gz
meson-9f12f6e1586b91e10ec950d0e334b3d1159d00b7.tar.bz2
msvc: handle filename extensions for incdetect based on the compiler language
It is possible, albeit possibly inadvisable, for the exact combination of MSVC and "$CXX has C++ specific flags in it" to occur. When this happens, and cl.exe is given a filename ending in .c, it complains that you cannot compile a .c file with that option. Instead, pick the first filename matching that language and use that as the temporary filename. This more or less matches what we do in compiler-time checks. And it's the proper thing to do, rather than assume that cl.exe, when detected as the current C++ compiler, can *also* compile C because it's *also* a C compiler. Fixes #11257
Diffstat (limited to 'mesonbuild/backend/ninjabackend.py')
-rw-r--r--mesonbuild/backend/ninjabackend.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index c583024..3e3c770 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -523,8 +523,9 @@ class NinjaBackend(backends.Backend):
else:
# None of our compilers are MSVC, we're done.
return open(tempfilename, 'a', encoding='utf-8')
+ filebase = 'incdetect.' + compilers.lang_suffixes[compiler.language][0]
filename = os.path.join(self.environment.get_scratch_dir(),
- 'incdetect.c')
+ filebase)
with open(filename, 'w', encoding='utf-8') as f:
f.write(dedent('''\
#include<stdio.h>
@@ -536,7 +537,7 @@ class NinjaBackend(backends.Backend):
# Python strings leads to failure. We _must_ do this detection
# in raw byte mode and write the result in raw bytes.
pc = subprocess.Popen(compiler.get_exelist() +
- ['/showIncludes', '/c', 'incdetect.c'],
+ ['/showIncludes', '/c', filebase],
cwd=self.environment.get_scratch_dir(),
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdout, stderr) = pc.communicate()