aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/backend/ninjabackend.py
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2017-05-06 12:06:35 +0200
committerGitHub <noreply@github.com>2017-05-06 12:06:35 +0200
commit69c5931a8d5c714f2cbc717e372c5170531d879e (patch)
tree1d5f9a119df143858e0a3a2e5bfccaf9bb019a27 /mesonbuild/backend/ninjabackend.py
parent08d05bd82dfea8c58847a71c6f2362274aadd812 (diff)
parentf9708cf1ba01b4240f391fdb61a77fa22b8b037f (diff)
downloadmeson-69c5931a8d5c714f2cbc717e372c5170531d879e.zip
meson-69c5931a8d5c714f2cbc717e372c5170531d879e.tar.gz
meson-69c5931a8d5c714f2cbc717e372c5170531d879e.tar.bz2
Merge pull request #1657 from QuLogic/ninja-escape
ninja: Fix quoting newlines and $
Diffstat (limited to 'mesonbuild/backend/ninjabackend.py')
-rw-r--r--mesonbuild/backend/ninjabackend.py24
1 files changed, 17 insertions, 7 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index eaf4cac..dad752b 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -38,7 +38,12 @@ else:
rmfile_prefix = 'rm -f {} &&'
def ninja_quote(text):
- return text.replace(' ', '$ ').replace(':', '$:')
+ for char in ('$', ' ', ':'):
+ text = text.replace(char, '$' + char)
+ if '\n' in text:
+ raise MesonException('Ninja does not support newlines in rules. '
+ 'Please report this error with a test case to the Meson bug tracker.')
+ return text
class NinjaBuildElement:
@@ -480,12 +485,16 @@ int dummy;
# If the target requires capturing stdout, then use the serialized
# executable wrapper to capture that output and save it to a file.
#
+ # If the command line requires a newline, also use the wrapper, as
+ # ninja does not support them in its build rule syntax.
+ #
# Windows doesn't have -rpath, so for EXEs that need DLLs built within
# the project, we need to set PATH so the DLLs are found. We use
# a serialized executable wrapper for that and check if the
# CustomTarget command needs extra paths first.
- if target.capture or ((mesonlib.is_windows() or mesonlib.is_cygwin()) and
- self.determine_windows_extra_paths(target.command[0])):
+ if (target.capture or any('\n' in c for c in cmd) or
+ ((mesonlib.is_windows() or mesonlib.is_cygwin()) and
+ self.determine_windows_extra_paths(target.command[0]))):
exe_data = self.serialize_executable(target.command[0], cmd[1:],
# All targets are built from the build dir
self.environment.get_build_dir(),
@@ -1448,12 +1457,13 @@ int dummy;
def generate_swift_compile_rules(self, compiler, outfile):
rule = 'rule %s_COMPILER\n' % compiler.get_language()
- full_exe = [sys.executable,
- self.environment.get_build_command(),
+ full_exe = [ninja_quote(sys.executable),
+ ninja_quote(self.environment.get_build_command()),
'--internal',
'dirchanger',
- '$RUNDIR'] + compiler.get_exelist()
- invoc = ' '.join([ninja_quote(i) for i in full_exe])
+ '$RUNDIR']
+ invoc = (' '.join(full_exe) + ' ' +
+ ' '.join(ninja_quote(i) for i in compiler.get_exelist()))
command = ' command = %s $ARGS $in\n' % invoc
description = ' description = Compiling Swift source $in.\n'
outfile.write(rule)