Skip to content

Commit bd3e854

Browse files
committed
ninjabackend: msvc: make detect_vs_dep_prefix independent of stdlib
this function does not pass enough args from the compiler object to find windows sdk without relying on environment variables. including a file from the same directory removes the dependency on stdlib.
1 parent 929100c commit bd3e854

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

mesonbuild/backend/ninjabackend.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -548,9 +548,13 @@ def detect_vs_dep_prefix(self, tempfilename: str) -> T.TextIO:
548548
filebase)
549549
with open(filename, 'w', encoding='utf-8') as f:
550550
f.write(dedent('''\
551-
#include<stdio.h>
551+
#include"incdetect2"
552552
int dummy;
553553
'''))
554+
filename_inc = os.path.join(self.environment.get_scratch_dir(),
555+
'incdetect2')
556+
with open(filename_inc, 'w', encoding='utf-8') as f:
557+
pass
554558

555559
# The output of cl dependency information is language
556560
# and locale dependent. Any attempt at converting it to
@@ -562,18 +566,18 @@ def detect_vs_dep_prefix(self, tempfilename: str) -> T.TextIO:
562566
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
563567
(stdout, stderr) = pc.communicate()
564568

565-
# We want to match 'Note: including file: ' in the line
566-
# 'Note: including file: d:\MyDir\include\stdio.h', however
569+
# 'Note: including file: d:\build\meson-private\incdetect2', however
567570
# different locales have different messages with a different
568-
# number of colons. Match up to the drive name 'd:\'.
571+
# number of colons. Match up to the drive name 'd:\' or
572+
# a relative path '.\'.
569573
# When used in cross compilation, the path separator is a
570574
# forward slash rather than a backslash so handle both; i.e.
571-
# the path is /MyDir/include/stdio.h.
575+
# the path is /build/meson-private/incdetect or ./incdetect2.
572576
# With certain cross compilation wrappings of MSVC, the paths
573577
# use backslashes, but without the leading drive name, so
574578
# allow the path to start with any path separator, i.e.
575-
# \MyDir\include\stdio.h.
576-
matchre = re.compile(rb"^(.*\s)([a-zA-Z]:[\\/]|[\\\/]).*stdio.h$")
579+
# \build\meson-private\incdetect2
580+
matchre = re.compile(rb"^(.*\s)([a-zA-Z]:[\\/]|\.?[\\/]).*incdetect2$")
577581

578582
def detect_prefix(out: bytes) -> T.TextIO:
579583
for line in re.split(rb'\r?\n', out):

0 commit comments

Comments
 (0)