OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Utilities for formatting and writing DEPS files.""" | 6 """Utilities for formatting and writing DEPS files.""" |
7 | 7 |
8 import errno | 8 import errno |
9 import os | 9 import os |
10 import shutil | 10 import shutil |
11 import subprocess | 11 import subprocess |
12 import sys | 12 import sys |
13 import time | 13 import time |
14 | 14 |
15 | 15 |
16 class VarImpl(object): | 16 class VarImpl(object): |
17 """Implement the Var function used within the DEPS file.""" | 17 """Implement the Var function used within the DEPS file.""" |
18 | 18 |
19 def __init__(self, local_scope): | 19 def __init__(self, local_scope, var_overrides=None): |
20 self._local_scope = local_scope | 20 self._local_scope = local_scope |
| 21 self._var_overrides = var_overrides or {} |
21 | 22 |
22 def Lookup(self, var_name): | 23 def Lookup(self, var_name): |
23 """Implements the Var syntax.""" | 24 """Implements the Var syntax.""" |
| 25 if var_name in self._var_overrides: |
| 26 return self._var_overrides[var_name] |
24 if var_name in self._local_scope.get('vars', {}): | 27 if var_name in self._local_scope.get('vars', {}): |
25 return self._local_scope['vars'][var_name] | 28 return self._local_scope['vars'][var_name] |
26 raise Exception('Var is not defined: %s' % var_name) | 29 raise Exception('Var is not defined: %s' % var_name) |
27 | 30 |
28 | 31 |
29 def GetDepsContent(deps_path): | 32 def GetDepsContent(deps_path, var_overrides=None): |
30 """Read a DEPS file and return all the sections.""" | 33 """Read a DEPS file and return all the sections.""" |
31 deps_file = open(deps_path, 'rU') | 34 deps_file = open(deps_path, 'rU') |
| 35 var_overrides = var_overrides or {} |
32 content = deps_file.read() | 36 content = deps_file.read() |
33 local_scope = {} | 37 local_scope = {} |
34 var = VarImpl(local_scope) | 38 var = VarImpl(local_scope, var_overrides) |
35 global_scope = { | 39 global_scope = { |
36 'Var': var.Lookup, | 40 'Var': var.Lookup, |
37 'deps': {}, | 41 'deps': {}, |
38 'deps_os': {}, | 42 'deps_os': {}, |
39 'include_rules': [], | 43 'include_rules': [], |
40 'skip_child_includes': [], | 44 'skip_child_includes': [], |
41 'hooks': [], | 45 'hooks': [], |
42 'vars': {}, | 46 'vars': {}, |
43 } | 47 } |
44 exec(content, global_scope, local_scope) | 48 exec(content, global_scope, local_scope) |
45 local_scope.setdefault('deps', {}) | 49 local_scope.setdefault('deps', {}) |
46 local_scope.setdefault('deps_os', {}) | 50 local_scope.setdefault('deps_os', {}) |
47 local_scope.setdefault('include_rules', []) | 51 local_scope.setdefault('include_rules', []) |
48 local_scope.setdefault('skip_child_includes', []) | 52 local_scope.setdefault('skip_child_includes', []) |
49 local_scope.setdefault('hooks', []) | 53 local_scope.setdefault('hooks', []) |
50 local_scope.setdefault('vars', {}) | 54 local_scope.setdefault('vars', {}) |
| 55 local_scope['vars'].update(var_overrides) |
51 | 56 |
52 return (local_scope['deps'], local_scope['deps_os'], | 57 return (local_scope['deps'], local_scope['deps_os'], |
53 local_scope['include_rules'], local_scope['skip_child_includes'], | 58 local_scope['include_rules'], local_scope['skip_child_includes'], |
54 local_scope['hooks'], local_scope['vars']) | 59 local_scope['hooks'], local_scope['vars']) |
55 | 60 |
56 | 61 |
57 def PrettyDeps(deps, indent=0): | 62 def PrettyDeps(deps, indent=0): |
58 """Stringify a deps dictionary in a pretty way.""" | 63 """Stringify a deps dictionary in a pretty way.""" |
59 pretty = ' ' * indent | 64 pretty = ' ' * indent |
60 pretty += '{\n' | 65 pretty += '{\n' |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 # For POSIX: making the directory writable guarantees removability. | 212 # For POSIX: making the directory writable guarantees removability. |
208 # Windows will ignore the non-read-only bits in the chmod value. | 213 # Windows will ignore the non-read-only bits in the chmod value. |
209 os.chmod(root, 0770) | 214 os.chmod(root, 0770) |
210 for name in files: | 215 for name in files: |
211 remove_with_retry(os.remove, os.path.join(root, name)) | 216 remove_with_retry(os.remove, os.path.join(root, name)) |
212 for name in dirs: | 217 for name in dirs: |
213 remove_with_retry(lambda p: shutil.rmtree(p, onerror=RmTreeOnError), | 218 remove_with_retry(lambda p: shutil.rmtree(p, onerror=RmTreeOnError), |
214 os.path.join(root, name)) | 219 os.path.join(root, name)) |
215 | 220 |
216 remove_with_retry(os.rmdir, file_path) | 221 remove_with_retry(os.rmdir, file_path) |
OLD | NEW |