From ae83c72b705ee1d1cdfd97936ca4de3adcf22eb3 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Sun, 8 Jan 2023 15:29:46 -0500 Subject: 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 --- mesonbuild/backend/ninjabackend.py | 5 +++-- 1 file 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 @@ -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() -- cgit v1.1