diff options
author | Jon Turney <jon.turney@dronecode.org.uk> | 2019-04-30 18:52:44 +0100 |
---|---|---|
committer | Dan Kegel <dank@kegel.com> | 2020-06-05 14:15:32 -0700 |
commit | eb60c041f9d2ae8554045b50080bbfc7b439af01 (patch) | |
tree | 57a7688bbb00c02cae5ba8c76a80e38bff0d1b45 | |
parent | fbacf87af525f7b69e4f1a310f6ef38c5853406c (diff) | |
download | meson-eb60c041f9d2ae8554045b50080bbfc7b439af01.zip meson-eb60c041f9d2ae8554045b50080bbfc7b439af01.tar.gz meson-eb60c041f9d2ae8554045b50080bbfc7b439af01.tar.bz2 |
ninja: Implement Windows-style command line quoting
We avoided having to get this right previously, as we'd always use a
response file if possible.
But this is so insane, I can't imagine it's right.
See also: subprocess.list2cmdline() internal method
-rw-r--r-- | mesonbuild/backend/ninjabackend.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 5743d48..fb150a3 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -53,8 +53,17 @@ FORTRAN_SUBMOD_PAT = r"^\s*\bsubmodule\b\s*\((\w+:?\w+)\)\s*(\w+)" FORTRAN_USE_PAT = r"^\s*use,?\s*(?:non_intrinsic)?\s*(?:::)?\s*(\w+)" def cmd_quote(s): - # XXX: this needs to understand how to escape any existing double quotes(") - return '"{}"'.format(s) + # see: https://docs.microsoft.com/en-us/windows/desktop/api/shellapi/nf-shellapi-commandlinetoargvw#remarks + + # backslash escape any existing double quotes + # any existing backslashes preceding a quote are doubled + s = re.sub(r'(\\*)"', lambda m: '\\' * (len(m.group(1)) * 2 + 1) + '"', s) + # any terminal backslashes likewise need doubling + s = re.sub(r'(\\*)$', lambda m: '\\' * (len(m.group(1)) * 2), s) + # and double quote + s = '"{}"'.format(s) + + return s # How ninja executes command lines differs between Unix and Windows # (see https://ninja-build.org/manual.html#ref_rule_command) @@ -340,8 +349,6 @@ class NinjaBuildElement: else: quoter = lambda x: ninja_quote(qf(x)) i = i.replace('\\', '\\\\') - if qf('') == '""': - i = i.replace('"', '\\"') newelems.append(quoter(i)) line += ' '.join(newelems) line += '\n' |