Make vs dependency detector work on non-english locales.

This commit is contained in:
Jussi Pakkanen 2015-12-18 17:30:30 +02:00
parent 015688f506
commit c86ee8158a
2 changed files with 41 additions and 9 deletions

View File

@ -22,7 +22,7 @@ from meson_install import InstallData
from build import InvalidArguments from build import InvalidArguments
from coredata import MesonException from coredata import MesonException
import os, sys, pickle, re import os, sys, pickle, re
import subprocess import subprocess, shutil
if mesonlib.is_windows(): if mesonlib.is_windows():
quote_char = '"' quote_char = '"'
@ -130,6 +130,33 @@ class NinjaBackend(backends.Backend):
raise MesonException('Multiple producers for Ninja target "%s". Please rename your targets.' % n) raise MesonException('Multiple producers for Ninja target "%s". Please rename your targets.' % n)
self.all_outputs[n] = True self.all_outputs[n] = True
def detect_vs_dep_prefix(self, outfile, tempfilename):
'''VS writes its dependency in a locale dependent format.
Detect the search prefix to use.'''
if shutil.which('cl') is None:
return outfile
outfile.close()
open(os.path.join(self.environment.get_scratch_dir(), 'incdetect.c'),
'w').write('''#include<stdio.h>
int dummy;
''')
pc = subprocess.Popen(['cl', '/showIncludes', '/c', 'incdetect.c'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=self.environment.get_scratch_dir())
(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':'
binfile = open(tempfilename, 'ab')
binfile.write(b'msvc_deps_prefix = ' + matchstr + b'\r\n')
binfile.close()
return open(tempfilename, 'a')
raise MesonException('Could not determine vs dep dependency prefix string.')
def generate(self, interp): def generate(self, interp):
self.interpreter = interp self.interpreter = interp
outfilename = os.path.join(self.environment.get_build_dir(), self.ninja_filename) outfilename = os.path.join(self.environment.get_build_dir(), self.ninja_filename)
@ -140,6 +167,7 @@ class NinjaBackend(backends.Backend):
outfile.write('# It is autogenerated by the Meson build system.\n') outfile.write('# It is autogenerated by the Meson build system.\n')
outfile.write('# Do not edit by hand.\n\n') outfile.write('# Do not edit by hand.\n\n')
outfile.write('ninja_required_version = 1.5.1\n\n') outfile.write('ninja_required_version = 1.5.1\n\n')
outfile = self.detect_vs_dep_prefix(outfile, tempfilename)
self.generate_rules(outfile) self.generate_rules(outfile)
self.generate_phony(outfile) self.generate_phony(outfile)
outfile.write('# Build rules for targets\n\n') outfile.write('# Build rules for targets\n\n')

View File

@ -153,9 +153,11 @@ def run_configure_inprocess(commandlist):
sys.stdout = mystdout = StringIO() sys.stdout = mystdout = StringIO()
old_stderr = sys.stderr old_stderr = sys.stderr
sys.stderr = mystderr = StringIO() sys.stderr = mystderr = StringIO()
returncode = meson.run(commandlist) try:
sys.stdout = old_stdout returncode = meson.run(commandlist)
sys.stderr = old_stderr finally:
sys.stdout = old_stdout
sys.stderr = old_stderr
return (returncode, mystdout.getvalue(), mystderr.getvalue()) return (returncode, mystdout.getvalue(), mystderr.getvalue())
def run_test_inprocess(testdir): def run_test_inprocess(testdir):
@ -165,11 +167,13 @@ def run_test_inprocess(testdir):
sys.stderr = mystderr = StringIO() sys.stderr = mystderr = StringIO()
old_cwd = os.getcwd() old_cwd = os.getcwd()
os.chdir(testdir) os.chdir(testdir)
returncode_test = meson_test.run(['meson-private/meson_test_setup.dat']) try:
returncode_benchmark = meson_benchmark.run(['meson-private/meson_benchmark_setup.dat']) returncode_test = meson_test.run(['meson-private/meson_test_setup.dat'])
sys.stdout = old_stdout returncode_benchmark = meson_benchmark.run(['meson-private/meson_benchmark_setup.dat'])
sys.stderr = old_stderr finally:
os.chdir(old_cwd) sys.stdout = old_stdout
sys.stderr = old_stderr
os.chdir(old_cwd)
return (max(returncode_test, returncode_benchmark), mystdout.getvalue(), mystderr.getvalue()) return (max(returncode_test, returncode_benchmark), mystdout.getvalue(), mystderr.getvalue())