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

Side by Side Diff: scripts/slave/recipe_modules/chromite/api.py

Issue 2325913002: recipe_modules/chromite: Use "build_type". (Closed)
Patch Set: Keep variant API in for downstream compatibility. Created 4 years, 3 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 | scripts/slave/recipe_modules/chromite/config.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 2013 The Chromium Authors. All rights reserved. 1 # Copyright 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 import cgi 5 import cgi
6 import re 6 import re
7 7
8 from recipe_engine import recipe_api 8 from recipe_engine import recipe_api
9 9
10 10
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 if 'buildnumber' in self.m.properties: 70 if 'buildnumber' in self.m.properties:
71 defaults['CBB_BUILD_NUMBER'] = int(self.m.properties['buildnumber']) 71 defaults['CBB_BUILD_NUMBER'] = int(self.m.properties['buildnumber'])
72 72
73 buildbucket_props = self.m.buildbucket.properties 73 buildbucket_props = self.m.buildbucket.properties
74 if buildbucket_props: 74 if buildbucket_props:
75 defaults['CBB_BUILDBUCKET_ID'] = buildbucket_props['build']['id'] 75 defaults['CBB_BUILDBUCKET_ID'] = buildbucket_props['build']['id']
76 76
77 return defaults 77 return defaults
78 78
79 def _load_config_dump(self): 79 def _load_config_dump(self):
80 if self.using_old_chromite_layout or self.c.cbb.config_repo:
81 # Our method of loading the configuration from the JSON dump will not
82 # work on old Chromite layout repositories.
83 #
84 # We also don't support loading our configuration from an external config
85 # repo. If we wanted to support this in the future, we would need to
86 # check out that other config repo at the correct revision and load
87 # "config_dump.json" from its root.
88 return {}
89
80 if not self._cached_config: 90 if not self._cached_config:
81 config_path = self.m.path.join(self.chromite_path, 91 config_path = self.m.path.join(self.chromite_path,
82 'cbuildbot', 'config_dump.json') 92 'cbuildbot', 'config_dump.json')
83 step_result = self.m.json.read('read chromite config', config_path, 93 step_result = self.m.json.read('read chromite config', config_path,
84 add_json_log=False) 94 add_json_log=False)
85 self._cached_config = step_result.json.output 95 self._cached_config = step_result.json.output
86 return self._cached_config 96 return self._cached_config
87 97
88 def load_config(self, name): 98 def load_config(self, name):
89 c = self._load_config_dump() 99 c = self._load_config_dump()
100 assert c is not None, 'Unable to load config dump'
101
90 conf = c.get(name) 102 conf = c.get(name)
91 if conf is None: 103 if conf is None:
92 return None 104 return None
93 105
94 layers = [conf] 106 layers = [conf]
95 template = conf.get('_template') 107 template = conf.get('_template')
96 if template: 108 if template:
97 layers.append(c['_templates'][template]) 109 layers.append(c['_templates'][template])
98 default = c.get('_default') 110 default = c.get('_default')
99 if default: 111 if default:
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 master = properties['mastername'] 257 master = properties['mastername']
246 variant = properties.get('cbb_variant') 258 variant = properties.get('cbb_variant')
247 259
248 # Set the master's base configuration. 260 # Set the master's base configuration.
249 config_map = config_map.get(master, {}) 261 config_map = config_map.get(master, {})
250 master_config = config_map.get('master_config') 262 master_config = config_map.get('master_config')
251 assert master_config, ( 263 assert master_config, (
252 "No 'master_config' configuration for '%s'" % (master,)) 264 "No 'master_config' configuration for '%s'" % (master,))
253 self.set_config(master_config) 265 self.set_config(master_config)
254 266
267 # If we have any specialized build type configurations for this master,
268 # load them.
269 self.c.build_type_configs = config_map.get('build_type_configs', {})
270
255 # Apply any variant configurations. 271 # Apply any variant configurations.
272 # TODO(dnj): Deprecate variants in favor of build types once all recipes
273 # using them have moved off of them.
256 if variant: 274 if variant:
257 for config_name in config_map.get('variants', {}).get(variant, ()): 275 for config_name in config_map.get('variants', {}).get(variant, ()):
258 self.apply_config(config_name) 276 self.apply_config(config_name)
259 277
260 278
261 # If a config repo was specified, use it. 279 def run_cbuildbot(self, args=[]):
262 if 'config_repo' in properties: 280 """Performs a Chromite repository checkout, then runs cbuildbot.
263 self.c.cbb.config_repo = self.m.properties['config_repo']
264 281
265 def run_cbuildbot(self, args=[]): 282 Args:
283 args (list): Additional arguments to pass to `cbuildbot` invocation.
284 """
266 self.checkout_chromite() 285 self.checkout_chromite()
267 self.run(args=args) 286 self.run(args=args)
268 287
269 def checkout_chromite(self): 288 def checkout_chromite(self):
270 """Checks out the configured Chromite branch. 289 """Checks out the configured Chromite branch.
271 """ 290 """
272 self.m.bot_update.ensure_checkout( 291 self.m.bot_update.ensure_checkout(
273 gclient_config=self.gclient_config(), 292 gclient_config=self.gclient_config(),
274 update_presentation=False) 293 update_presentation=False)
275 294
276 if self.c.chromite_branch and self.c.cbb.disable_bootstrap: 295 if self.c.chromite_branch and self.c.cbb.disable_bootstrap:
277 # Chromite auto-detects which branch to build for based on its current 296 # Chromite auto-detects which branch to build for based on its current
278 # checkout. "bot_update" checks out remote branches, but Chromite requires 297 # checkout. "bot_update" checks out remote branches, but Chromite requires
279 # a local branch. 298 # a local branch.
280 # 299 #
281 # Normally we'd bootstrap, but if we're disabling bootstrapping, we have 300 # Normally we'd bootstrap, but if we're disabling bootstrapping, we have
282 # to checkout the local branch to let Chromite know which branch to build. 301 # to checkout the local branch to let Chromite know which branch to build.
283 self.m.git('checkout', self.c.chromite_branch, 302 self.m.git('checkout', self.c.chromite_branch,
284 name=str('checkout chromite branch [%s]' % (self.c.chromite_branch))) 303 name=str('checkout chromite branch [%s]' % (self.c.chromite_branch)))
285 self.m.git('pull', 304 self.m.git('pull',
286 name=str('sync chromite branch [%s]' % (self.c.chromite_branch))) 305 name=str('sync chromite branch [%s]' % (self.c.chromite_branch)))
287 self._set_chromite_path(self.m.path['checkout']) 306 self._set_chromite_path(self.m.path['checkout'])
307
308 # If we are configured with build type configurations, we will need to load
309 # the Chromite configuration for this configuration target.
310 self._apply_build_type_config()
311
288 return self.chromite_path 312 return self.chromite_path
289 313
314 def _apply_build_type_config(self):
315 """Identify the "build_type" field for this config, and apply any additional
316 recipe configurations based on that value.
317
318 This is used to specialize builders based on the type of builder that they
319 are.
320
321 If no build type config is defined for this configuration's build type, or
322 if this configuration's build type could not be loaded, no additional
323 configuration will be applied.
324 """
325 if not self.c.build_type_configs:
326 # If no build type configs are defined, then there's no point doing the
327 # work of loading the configuration.
328 return
329
330 # Load our build type from the configuration JSON, if one is not already
331 # provided.
332 if not self.c.build_type:
333 assert self.c.cbb.config, 'No build configuration installed.'
334 config = self.load_config(self.c.cbb.config)
335 self.c.build_type = (config or {}).get('build_type')
336
337 # If we have a build type, and it has a configuration associated with it,
338 # apply that configuration.
339 if self.c.build_type and self.c.build_type in self.c.build_type_configs:
340 self.apply_config(self.c.build_type_configs[self.c.build_type])
341
290 def run(self, args=[]): 342 def run(self, args=[]):
291 """Runs the configured 'cbuildbot' build. 343 """Runs the configured 'cbuildbot' build.
292 344
293 This workflow uses the registered configuration dictionary to make master- 345 This workflow uses the registered configuration dictionary to make master-
294 and builder-specific changes to the standard workflow. 346 and builder-specific changes to the standard workflow.
295 347
296 The specific workflow paths that are taken are also influenced by several 348 The specific workflow paths that are taken are also influenced by several
297 build properties. 349 build properties.
298 350
299 TODO(dnj): When CrOS migrates away from BuildBot, replace property 351 TODO(dnj): When CrOS migrates away from BuildBot, replace property
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 cbb_args.extend(['--master-build-id', self.c.cbb.build_id]) 414 cbb_args.extend(['--master-build-id', self.c.cbb.build_id])
363 415
364 # Add custom args, if there are any. 416 # Add custom args, if there are any.
365 cbb_args.extend(args) 417 cbb_args.extend(args)
366 418
367 # Run cbuildbot. 419 # Run cbuildbot.
368 return self.cbuildbot(str('cbuildbot [%s]' % (self.c.cbb.config,)), 420 return self.cbuildbot(str('cbuildbot [%s]' % (self.c.cbb.config,)),
369 self.c.cbb.config, 421 self.c.cbb.config,
370 args=cbb_args, 422 args=cbb_args,
371 cwd=self.m.path['slave_build']) 423 cwd=self.m.path['slave_build'])
OLDNEW
« no previous file with comments | « no previous file | scripts/slave/recipe_modules/chromite/config.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698