OLD | NEW |
---|---|
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2013 The Chromium Authors. 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 """This module holds utilities which make writing recipes easier.""" | 5 """This module holds utilities which make writing recipes easier.""" |
6 | 6 |
7 import contextlib as _contextlib | |
7 import os as _os | 8 import os as _os |
8 | 9 |
9 # e.g. /b/build/slave/<slave-name>/build | 10 # e.g. /b/build/slave/<slave-name>/build |
10 SLAVE_BUILD_ROOT = _os.path.abspath(_os.getcwd()) | 11 SLAVE_BUILD_ROOT = _os.path.abspath(_os.getcwd()) |
11 # e.g. /b | 12 # e.g. /b |
12 ROOT = _os.path.abspath(_os.path.join(SLAVE_BUILD_ROOT, _os.pardir, _os.pardir, | 13 ROOT = _os.path.abspath(_os.path.join(SLAVE_BUILD_ROOT, _os.pardir, _os.pardir, |
13 _os.pardir, _os.pardir)) | 14 _os.pardir, _os.pardir)) |
14 # e.g. /b/build_internal | 15 # e.g. /b/build_internal |
15 BUILD_INTERNAL_ROOT = _os.path.join(ROOT, 'build_internal') | 16 BUILD_INTERNAL_ROOT = _os.path.join(ROOT, 'build_internal') |
16 # e.g. /b/build | 17 # e.g. /b/build |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 The actual checkout root is filled in by annotated_run after the recipe | 51 The actual checkout root is filled in by annotated_run after the recipe |
51 completes, and is dependent on the implementation of 'root()' in | 52 completes, and is dependent on the implementation of 'root()' in |
52 annotated_checkout for the checkout type that you've selected. | 53 annotated_checkout for the checkout type that you've selected. |
53 | 54 |
54 NOTE: In order for this function to work, your recipe MUST use the 'checkout' | 55 NOTE: In order for this function to work, your recipe MUST use the 'checkout' |
55 functionality provided by annotated_run. | 56 functionality provided by annotated_run. |
56 """ # pylint: disable=W0105 | 57 """ # pylint: disable=W0105 |
57 checkout_path = _path_method('checkout_path', "%(CheckoutRootPlaceholder)s") | 58 checkout_path = _path_method('checkout_path', "%(CheckoutRootPlaceholder)s") |
58 | 59 |
59 | 60 |
61 @_contextlib.contextmanager | |
62 def mock_paths(): | |
63 path_base_names = ['depot_tools', 'build_internal', 'build', 'slave_build', | |
64 'root'] | |
65 g = globals() | |
66 tokens = {} | |
67 path_funcs = {} | |
68 try: | |
69 for name in path_base_names: | |
70 token_name = (name+"_root").upper() | |
71 token_val = '[%s]' % token_name | |
72 path_func_name = (name+"_path") | |
Isaac (away)
2013/05/14 21:34:27
did pylint really pass on this? Maybe use gpylint
| |
73 | |
74 if token_name in g: | |
75 tokens[token_name] = g[token_name] | |
76 g[token_name] = token_val | |
77 | |
78 if path_func_name in g: | |
79 path_funcs[path_func_name] = g[path_func_name] | |
80 g[path_func_name] = _path_method(path_func_name, token_val) | |
81 yield | |
82 finally: | |
83 g.update(tokens) | |
84 g.update(path_funcs) | |
85 | |
86 | |
60 def deep_set(obj, key_vals): | 87 def deep_set(obj, key_vals): |
61 """Take an object (a dict or list), and a list of key/value pairs to set, | 88 """Take an object (a dict or list), and a list of key/value pairs to set, |
62 and transform it by replacing items in obj at the key locations with the | 89 and transform it by replacing items in obj at the key locations with the |
63 respective values. | 90 respective values. |
64 | 91 |
65 keys are strings in the form of: (str|int)[.(str|int)]* | 92 keys are strings in the form of: (str|int)[.(str|int)]* |
66 | 93 |
67 Example: | 94 Example: |
68 obj = {'some': {'deep': {'list': [1, 2, 3, 4, 5, 6]}}} | 95 obj = {'some': {'deep': {'list': [1, 2, 3, 4, 5, 6]}}} |
69 key_vals = [("some.deep.list.3", 'foobar')] | 96 key_vals = [("some.deep.list.3", 'foobar')] |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
248 '-e', 'commit-bot@chromium.org']) | 275 '-e', 'commit-bot@chromium.org']) |
249 | 276 |
250 def git_step(self, *args): | 277 def git_step(self, *args): |
251 name = 'git '+args[0] | 278 name = 'git '+args[0] |
252 # Distinguish 'git config' commands by the variable they are setting. | 279 # Distinguish 'git config' commands by the variable they are setting. |
253 if args[0] == 'config' and not args[1].startswith('-'): | 280 if args[0] == 'config' and not args[1].startswith('-'): |
254 name += " "+args[1] | 281 name += " "+args[1] |
255 return self.step(name, [ | 282 return self.step(name, [ |
256 'git', '--work-tree', checkout_path(), | 283 'git', '--work-tree', checkout_path(), |
257 '--git-dir', checkout_path('.git')]+list(args)) | 284 '--git-dir', checkout_path('.git')]+list(args)) |
OLD | NEW |