Index: pylib/gyp/msvs_emulation.py |
=================================================================== |
--- pylib/gyp/msvs_emulation.py (revision 0) |
+++ pylib/gyp/msvs_emulation.py (revision 0) |
@@ -0,0 +1,33 @@ |
+# Copyright (c) 2012 Google Inc. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
Nico
2012/02/20 23:17:49
Needs module docstring
scottmg
2012/02/21 00:14:44
Done.
|
+import re |
+ |
+windows_quoter_regex = re.compile(r'(\\*)"') |
+ |
+def QuoteCmdExeArgument(arg): |
Nico
2012/02/20 23:17:49
need function docstring
scottmg
2012/02/21 00:14:44
Done.
|
+ # See http://goo.gl/cuFbX and http://goo.gl/dhPnp including the comment |
Nico
2012/02/20 23:17:49
nit: I wouldn't use a URL shortener
scottmg
2012/02/21 00:14:44
The urls were longer than 80 so it looked yucky.
|
+ # threads. This is actually the quoting rules for CommandLineToArgvW, not |
+ # for the shell, because the shell doesn't do anything in Windows. This |
+ # works more or less because most programs (including the compiler, etc.) |
+ # use that function to handle command line arguments. |
+ # |
+ # For a literal quote, CommandLineToArgvW requires 2n+1 backslashes |
+ # preceding it, and results in n backslashes + the quote. So we substitute |
+ # in 2* what we match, +1 more, plus the quote. |
+ tmp = windows_quoter_regex.sub(lambda mo: 2 * mo.group(1) + '\\"', arg) |
+ |
+ # Now, we need to escape some things that are actually for the shell. %'s |
Nico
2012/02/20 23:17:49
The '%' handling happens further down, so I wouldn
scottmg
2012/02/21 00:14:44
Done.
|
+ # need to be doubled, and various other characters need to be ^ escaped. |
+ tmp = re.sub(r'([&|^])', r'^\1', tmp) |
+ |
+ # Also make sure to escape the % so that they're passed literally through |
+ # escaping so they can be singled to just the original %. Otherwise, trying |
+ # to pass the literal representation that looks like an environment variable |
+ # to the shell (e.g. %PATH%) would fail. |
+ tmp = tmp.replace('%', '^%^%') |
+ |
+ # Finally, wrap the whole thing in quotes so that the above quote rule |
+ # applies and whitespace isn't a word break. |
+ return '"' + tmp + '"' |
Nico
2012/02/20 23:17:49
I assume all this is covered by existing tests.
scottmg
2012/02/21 00:14:44
Yes, this change is just trying to get existing te
|
Property changes on: pylib\gyp\msvs_emulation.py |
___________________________________________________________________ |
Added: svn:eol-style |
+ LF |