aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2023-01-08 15:29:46 -0500
committerNirbheek Chauhan <nirbheek@centricular.com>2023-02-06 23:37:24 +0530
commitae83c72b705ee1d1cdfd97936ca4de3adcf22eb3 (patch)
tree161b847f1de4e8583e09035e527ffcd9b2f4a143
parent9492672598b71ca1c1dec0581c90e5bbdb3c83de (diff)
downloadmeson-ae83c72b705ee1d1cdfd97936ca4de3adcf22eb3.zip
meson-ae83c72b705ee1d1cdfd97936ca4de3adcf22eb3.tar.gz
meson-ae83c72b705ee1d1cdfd97936ca4de3adcf22eb3.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
-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()