Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: scripts/slave/recipe_util.py

Issue 14988009: First cut of testing infrastructure for recipes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: nitfixen Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « scripts/slave/annotated_run.py ('k') | scripts/slave/recipes/gatekeeper.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 """Used by unittest/recipes_test.py to temporarily override the paths
64 generated by the various path functions in this module.
65
66 This is necessary to give equivalent output when running the tests on any
67 checkout configuration. Instead of real paths, recipes which use these
68 functions will get paths like '[DEPOT_TOOLS_ROOT]'.
69 """
70 path_base_names = ['depot_tools', 'build_internal', 'build', 'slave_build',
71 'root']
72 g = globals()
73 tokens = {}
74 path_funcs = {}
75 try:
76 for name in path_base_names:
77 token_name = (name+"_root").upper()
78 token_val = '[%s]' % token_name
79 path_func_name = (name+"_path")
80
81 if token_name in g:
82 tokens[token_name] = g[token_name]
83 g[token_name] = token_val
84
85 if path_func_name in g:
86 path_funcs[path_func_name] = g[path_func_name]
87 g[path_func_name] = _path_method(path_func_name, token_val)
88 yield
89 finally:
90 g.update(tokens)
91 g.update(path_funcs)
92
93
60 def deep_set(obj, key_vals): 94 def deep_set(obj, key_vals):
61 """Take an object (a dict or list), and a list of key/value pairs to set, 95 """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 96 and transform it by replacing items in obj at the key locations with the
63 respective values. 97 respective values.
64 98
65 keys are strings in the form of: (str|int)[.(str|int)]* 99 keys are strings in the form of: (str|int)[.(str|int)]*
66 100
67 Example: 101 Example:
68 obj = {'some': {'deep': {'list': [1, 2, 3, 4, 5, 6]}}} 102 obj = {'some': {'deep': {'list': [1, 2, 3, 4, 5, 6]}}}
69 key_vals = [("some.deep.list.3", 'foobar')] 103 key_vals = [("some.deep.list.3", 'foobar')]
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 '-e', 'commit-bot@chromium.org']) 282 '-e', 'commit-bot@chromium.org'])
249 283
250 def git_step(self, *args): 284 def git_step(self, *args):
251 name = 'git '+args[0] 285 name = 'git '+args[0]
252 # Distinguish 'git config' commands by the variable they are setting. 286 # Distinguish 'git config' commands by the variable they are setting.
253 if args[0] == 'config' and not args[1].startswith('-'): 287 if args[0] == 'config' and not args[1].startswith('-'):
254 name += " "+args[1] 288 name += " "+args[1]
255 return self.step(name, [ 289 return self.step(name, [
256 'git', '--work-tree', checkout_path(), 290 'git', '--work-tree', checkout_path(),
257 '--git-dir', checkout_path('.git')]+list(args)) 291 '--git-dir', checkout_path('.git')]+list(args))
OLDNEW
« no previous file with comments | « scripts/slave/annotated_run.py ('k') | scripts/slave/recipes/gatekeeper.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698