diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2016-07-29 19:50:36 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2016-07-29 19:51:11 +0530 |
commit | bfa25fc1d344950751c8b0302ef289de9a23a749 (patch) | |
tree | b9dc74c7d90f17d67da7176c6d70f20e7fb3ae4f /mesonbuild/backend/backends.py | |
parent | 2d05008956dedbfb4b6c8b690c4f025451aea587 (diff) | |
download | meson-bfa25fc1d344950751c8b0302ef289de9a23a749.zip meson-bfa25fc1d344950751c8b0302ef289de9a23a749.tar.gz meson-bfa25fc1d344950751c8b0302ef289de9a23a749.tar.bz2 |
ninja: Add escaping for backslash in -D arguments
This is only needed for defines. Other arguments such as -I and /Fa that
also take arguments with spaces and backslashes don't need it at all.
Diffstat (limited to 'mesonbuild/backend/backends.py')
-rw-r--r-- | mesonbuild/backend/backends.py | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index d2693b2..1f1c3ca 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -296,6 +296,33 @@ class Backend(): args = includeargs + args return args + @staticmethod + def escape_extra_args(compiler, args): + # No extra escaping/quoting needed when not running on Windows + if not mesonlib.is_windows(): + return args + extra_args = [] + # Compiler-specific escaping is needed for -D args but not for any others + if compiler.get_id() == 'msvc': + # MSVC needs escaping when a -D argument ends in \ or \" + for arg in args: + if arg.startswith('-D') or arg.startswith('/D'): + # Without extra escaping for these two, the next character + # gets eaten + if arg.endswith('\\'): + arg += '\\' + elif arg.endswith('\\"'): + arg = arg[:-2] + '\\\\"' + extra_args.append(arg) + else: + # MinGW GCC needs all backslashes in defines to be doubly-escaped + # FIXME: Not sure about Cygwin or Clang + for arg in args: + if arg.startswith('-D') or arg.startswith('/D'): + arg = arg.replace('\\', '\\\\') + extra_args.append(arg) + return extra_args + def generate_basic_compiler_args(self, target, compiler): commands = [] commands += self.get_cross_stdlib_args(target, compiler) @@ -304,7 +331,7 @@ class Backend(): commands += compiler.get_option_compile_args(self.environment.coredata.compiler_options) commands += self.build.get_global_args(compiler) commands += self.environment.coredata.external_args[compiler.get_language()] - commands += target.get_extra_args(compiler.get_language()) + commands += self.escape_extra_args(compiler, target.get_extra_args(compiler.get_language())) commands += compiler.get_buildtype_args(self.environment.coredata.get_builtin_option('buildtype')) if self.environment.coredata.get_builtin_option('werror'): commands += compiler.get_werror_args() |