Skip to content

Commit

Permalink
Make vs dependency detector work on non-english locales.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpakkane committed Dec 18, 2015
1 parent 015688f commit c86ee81
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
30 changes: 29 additions & 1 deletion ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from build import InvalidArguments
from coredata import MesonException
import os, sys, pickle, re
import subprocess
import subprocess, shutil

if mesonlib.is_windows():
quote_char = '"'
Expand Down Expand Up @@ -130,6 +130,33 @@ def check_outputs(self, elem):
raise MesonException('Multiple producers for Ninja target "%s". Please rename your targets.' % n)
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):
self.interpreter = interp
outfilename = os.path.join(self.environment.get_build_dir(), self.ninja_filename)
Expand All @@ -140,6 +167,7 @@ def generate(self, interp):
outfile.write('# It is autogenerated by the Meson build system.\n')
outfile.write('# Do not edit by hand.\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_phony(outfile)
outfile.write('# Build rules for targets\n\n')
Expand Down
20 changes: 12 additions & 8 deletions run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,11 @@ def run_configure_inprocess(commandlist):
sys.stdout = mystdout = StringIO()
old_stderr = sys.stderr
sys.stderr = mystderr = StringIO()
returncode = meson.run(commandlist)
sys.stdout = old_stdout
sys.stderr = old_stderr
try:
returncode = meson.run(commandlist)
finally:
sys.stdout = old_stdout
sys.stderr = old_stderr
return (returncode, mystdout.getvalue(), mystderr.getvalue())

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


Expand Down

0 comments on commit c86ee81

Please sign in to comment.