From 630d7a517593dece863d9134401c73d7b461c32d Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Wed, 12 Apr 2017 23:00:28 +0300 Subject: [PATCH] Process VS dependency string as raw bytes. --- mesonbuild/backend/ninjabackend.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index bce46f6f9..dfb56006c 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -166,14 +166,20 @@ class NinjaBackend(backends.Backend): int dummy; ''') - pc, stdo = Popen_safe(['cl', '/showIncludes', '/c', 'incdetect.c'], - cwd=self.environment.get_scratch_dir())[0:2] - - for line in stdo.split('\n'): - if line.endswith('stdio.h'): - matchstr = ':'.join(line.split(':')[0:2]) + ':' - with open(tempfilename, 'a') as binfile: - binfile.write('msvc_deps_prefix = ' + matchstr + '\n') + # The output of cl dependency information is language + # and locale dependent. Any attempt at converting it to + # Python strings leads to failure. We _must_ do this detection + # in raw byte mode and write the result in raw bytes. + pc = subprocess.Popen(['cl', '/showIncludes', '/c', 'incdetect.c'], + cwd=self.environment.get_scratch_dir(), + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + (stdo, _) = pc.communicate() + + for line in stdo.split(b'\r\n'): + if line.endswith(b'stdio.h'): + matchstr = b':'.join(line.split(b':')[0:2]) + b':' + with open(tempfilename, 'ab') as binfile: + binfile.write(b'msvc_deps_prefix = ' + matchstr + b'\n') return open(tempfilename, 'a') raise MesonException('Could not determine vs dep dependency prefix string.')