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

Side by Side Diff: recipe_modules/bot_update/api.py

Issue 1815863002: Make the config -> pythonish conversion a gclient module function. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « no previous file | recipe_modules/gclient/api.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 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 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 5
6 """Recipe module to ensure a checkout is consistant on a bot.""" 6 """Recipe module to ensure a checkout is consistant on a bot."""
7 7
8 from recipe_engine import recipe_api 8 from recipe_engine import recipe_api
9 9
10 10
11 # This is just for testing, to indicate if a master is using a Git scheduler 11 # This is just for testing, to indicate if a master is using a Git scheduler
12 # or not. 12 # or not.
13 SVN_MASTERS = ( 13 SVN_MASTERS = (
14 'experimental.svn', 14 'experimental.svn',
15 ) 15 )
16 16
17 17
18 def jsonish_to_python(spec, is_top=False):
19 """Turn a json spec into a python parsable object.
20
21 This exists because Gclient specs, while resembling json, is actually
22 ingested using a python "eval()". Therefore a bit of plumming is required
23 to turn our newly constructed Gclient spec into a gclient-readable spec.
24 """
25 ret = ''
26 if is_top: # We're the 'top' level, so treat this dict as a suite.
27 ret = '\n'.join(
28 '%s = %s' % (k, jsonish_to_python(spec[k])) for k in sorted(spec)
29 )
30 else:
31 if isinstance(spec, dict):
32 ret += '{'
33 ret += ', '.join(
34 "%s: %s" % (repr(str(k)), jsonish_to_python(spec[k]))
35 for k in sorted(spec)
36 )
37 ret += '}'
38 elif isinstance(spec, list):
39 ret += '['
40 ret += ', '.join(jsonish_to_python(x) for x in spec)
41 ret += ']'
42 elif isinstance(spec, basestring):
43 ret = repr(str(spec))
44 else:
45 ret = repr(spec)
46 return ret
47
48
49 class BotUpdateApi(recipe_api.RecipeApi): 18 class BotUpdateApi(recipe_api.RecipeApi):
50 19
51 def __init__(self, mastername, buildername, slavename, issue, patchset, 20 def __init__(self, mastername, buildername, slavename, issue, patchset,
52 patch_url, repository, gerrit_ref, rietveld, revision, 21 patch_url, repository, gerrit_ref, rietveld, revision,
53 parent_got_revision, deps_revision_overrides, fail_patch, 22 parent_got_revision, deps_revision_overrides, fail_patch,
54 *args, **kwargs): 23 *args, **kwargs):
55 self._mastername = mastername 24 self._mastername = mastername
56 self._buildername = buildername 25 self._buildername = buildername
57 self._slavename = slavename 26 self._slavename = slavename
58 self._issue = issue 27 self._issue = issue
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 the 'rietveld' property. 69 the 'rietveld' property.
101 issue: The rietveld issue number to use. If omitted, will infer from 70 issue: The rietveld issue number to use. If omitted, will infer from
102 the 'issue' property. 71 the 'issue' property.
103 patchset: The rietveld issue patchset to use. If omitted, will infer from 72 patchset: The rietveld issue patchset to use. If omitted, will infer from
104 the 'patchset' property. 73 the 'patchset' property.
105 """ 74 """
106 refs = refs or [] 75 refs = refs or []
107 # We can re-use the gclient spec from the gclient module, since all the 76 # We can re-use the gclient spec from the gclient module, since all the
108 # data bot_update needs is already configured into the gclient spec. 77 # data bot_update needs is already configured into the gclient spec.
109 cfg = gclient_config or self.m.gclient.c 78 cfg = gclient_config or self.m.gclient.c
110 spec_string = jsonish_to_python(cfg.as_jsonish(), True)
111 79
112 # Used by bot_update to determine if we want to run or not. 80 # Used by bot_update to determine if we want to run or not.
113 master = self._mastername 81 master = self._mastername
114 builder = self._buildername 82 builder = self._buildername
115 slave = self._slavename 83 slave = self._slavename
116 84
117 # Construct our bot_update command. This basically be inclusive of 85 # Construct our bot_update command. This basically be inclusive of
118 # everything required for bot_update to know: 86 # everything required for bot_update to know:
119 root = patch_root 87 root = patch_root
120 if root is None: 88 if root is None:
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 130
163 rev_map = cfg.got_revision_mapping.as_jsonish() 131 rev_map = cfg.got_revision_mapping.as_jsonish()
164 132
165 flags = [ 133 flags = [
166 # 1. Do we want to run? (master/builder/slave). 134 # 1. Do we want to run? (master/builder/slave).
167 ['--master', master], 135 ['--master', master],
168 ['--builder', builder], 136 ['--builder', builder],
169 ['--slave', slave], 137 ['--slave', slave],
170 138
171 # 2. What do we want to check out (spec/root/rev/rev_map). 139 # 2. What do we want to check out (spec/root/rev/rev_map).
172 ['--spec', spec_string], 140 ['--spec', self.m.gclient.config_to_pythonish(cfg)],
173 ['--root', root], 141 ['--root', root],
174 ['--revision_mapping_file', self.m.json.input(rev_map)], 142 ['--revision_mapping_file', self.m.json.input(rev_map)],
175 ['--git-cache-dir', cfg.cache_dir], 143 ['--git-cache-dir', cfg.cache_dir],
176 144
177 # 3. How to find the patch, if any (issue/patchset/patch_url). 145 # 3. How to find the patch, if any (issue/patchset/patch_url).
178 ['--issue', issue], 146 ['--issue', issue],
179 ['--patchset', patchset], 147 ['--patchset', patchset],
180 ['--patch_url', patch_url], 148 ['--patch_url', patch_url],
181 ['--rietveld_server', rietveld or self._rietveld], 149 ['--rietveld_server', rietveld or self._rietveld],
182 ['--gerrit_repo', gerrit_repo], 150 ['--gerrit_repo', gerrit_repo],
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 268
301 # bot_update actually just sets root to be the folder name of the 269 # bot_update actually just sets root to be the folder name of the
302 # first solution. 270 # first solution.
303 if step_result.json.output['did_run']: 271 if step_result.json.output['did_run']:
304 co_root = step_result.json.output['root'] 272 co_root = step_result.json.output['root']
305 cwd = kwargs.get('cwd', self.m.path['slave_build']) 273 cwd = kwargs.get('cwd', self.m.path['slave_build'])
306 if 'checkout' not in self.m.path: 274 if 'checkout' not in self.m.path:
307 self.m.path['checkout'] = cwd.join(*co_root.split(self.m.path.sep)) 275 self.m.path['checkout'] = cwd.join(*co_root.split(self.m.path.sep))
308 276
309 return step_result 277 return step_result
OLDNEW
« no previous file with comments | « no previous file | recipe_modules/gclient/api.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698