| OLD | NEW |
| 1 # Copyright (c) 2012 Google Inc. All rights reserved. | 1 # Copyright (c) 2012 Google Inc. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """ | 5 """ |
| 6 This module helps emulate Visual Studio 2008 behavior on top of other | 6 This module helps emulate Visual Studio 2008 behavior on top of other |
| 7 build systems, primarily ninja. | 7 build systems, primarily ninja. |
| 8 """ | 8 """ |
| 9 | 9 |
| 10 import os | 10 import os |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 # These commands are used in rsp files, so no escaping for the shell (via ^) | 46 # These commands are used in rsp files, so no escaping for the shell (via ^) |
| 47 # is necessary. | 47 # is necessary. |
| 48 | 48 |
| 49 # Finally, wrap the whole thing in quotes so that the above quote rule | 49 # Finally, wrap the whole thing in quotes so that the above quote rule |
| 50 # applies and whitespace isn't a word break. | 50 # applies and whitespace isn't a word break. |
| 51 return '"' + arg + '"' | 51 return '"' + arg + '"' |
| 52 | 52 |
| 53 | 53 |
| 54 def EncodeRspFileList(args): | 54 def EncodeRspFileList(args): |
| 55 """Process a list of arguments using QuoteCmdExeArgument.""" | 55 """Process a list of arguments using QuoteCmdExeArgument.""" |
| 56 return ' '.join(QuoteForRspFile(arg) for arg in args) | 56 # Note that the first argument is assumed to be the command. We take extra |
| 57 # steps to make sure that calls to .bat files are handled correctly, and |
| 58 # that paths are normalized and quoted as necessary. |
| 59 if not args: return '' |
| 60 program = args[0] |
| 61 if program.startswith('call '): |
| 62 call, batch = program.split(' ', 1) |
| 63 program = 'call ' + QuoteForRspFile(os.path.normpath(batch)) |
| 64 else: |
| 65 program = os.path.normpath(program) |
| 66 # Don't add quotes around things without spaces so that 'call', 'echo', |
| 67 # etc. will work if they're specified as individual arguments. |
| 68 if ' ' in program: |
| 69 program = QuoteForRspFile(program) |
| 70 return program + ' ' + ' '.join(QuoteForRspFile(arg) for arg in args[1:]) |
| 57 | 71 |
| 58 | 72 |
| 59 def _GenericRetrieve(root, default, path): | 73 def _GenericRetrieve(root, default, path): |
| 60 """Given a list of dictionary keys |path| and a tree of dicts |root|, find | 74 """Given a list of dictionary keys |path| and a tree of dicts |root|, find |
| 61 value at path, or return |default| if any of the path doesn't exist.""" | 75 value at path, or return |default| if any of the path doesn't exist.""" |
| 62 if not root: | 76 if not root: |
| 63 return default | 77 return default |
| 64 if not path: | 78 if not path: |
| 65 return root | 79 return root |
| 66 return _GenericRetrieve(root.get(path[0]), default, path[1:]) | 80 return _GenericRetrieve(root.get(path[0]), default, path[1:]) |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 vs.Path(), r'Common7\Tools\vsvars32.bat')) | 484 vs.Path(), r'Common7\Tools\vsvars32.bat')) |
| 471 | 485 |
| 472 def ExpandMacros(string, expansions): | 486 def ExpandMacros(string, expansions): |
| 473 """Expand $(Variable) per expansions dict. See MsvsSettings.GetVSMacroEnv | 487 """Expand $(Variable) per expansions dict. See MsvsSettings.GetVSMacroEnv |
| 474 for the canonical way to retrieve a suitable dict.""" | 488 for the canonical way to retrieve a suitable dict.""" |
| 475 if '$' in string: | 489 if '$' in string: |
| 476 for old, new in expansions.iteritems(): | 490 for old, new in expansions.iteritems(): |
| 477 assert '$(' not in new, new | 491 assert '$(' not in new, new |
| 478 string = string.replace(old, new) | 492 string = string.replace(old, new) |
| 479 return string | 493 return string |
| OLD | NEW |