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

Side by Side Diff: scripts/master/factory/chromeos_factory.py

Issue 8669004: Add arm/tegra2 CQ builders and major cleanup of dead code in chromeos_factory. (Closed) Base URL: svn://chrome-svn/chrome/trunk/tools/build
Patch Set: Created 9 years 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/master/chromeos_revision_source.py ('k') | no next file » | 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) 2011 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2011 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 """Set of utilities to build the chromium master.""" 5 """Set of utilities to build the chromium master."""
6 6
7 import os 7 import os
8 import re
9 8
10 from buildbot.steps import trigger, shell 9 from buildbot.steps import trigger, shell
11 from buildbot.process.properties import WithProperties 10 from buildbot.process.properties import WithProperties
12 11
13 from master import chromeos_revision_source
14 from master import chromium_step 12 from master import chromium_step
15 from master.factory import build_factory 13 from master.factory import build_factory
16 from master.factory import chromeos_build_factory 14 from master.factory import chromeos_build_factory
17 15
18 class CbuildbotFactory(object): 16 class CbuildbotFactory(object):
19 """ 17 """
20 Create a cbuildbot build factory. 18 Create a cbuildbot build factory.
21 19
22 This is designed mainly to utilize build scripts directly hosted in 20 This is designed mainly to utilize build scripts directly hosted in
23 chromite.git. 21 chromite.git.
24 22
25 Attributes: 23 Attributes:
26 type: The type of cbuildbot setup to produce. If none is specified you
27 just get the boiler plate code in your factory and you can add
28 whatever steps you want to that factory.
29 board: What board to build (x86-generic x86-agz etc).
30 buildroot: --buildroot to pass to cbuild. 24 buildroot: --buildroot to pass to cbuild.
31 triagelog: Path to a log file to run triagelog, if it is not defined
32 triagelog will not run.
33 variant: board variant to pass on to cbuild build type
34 params: string of parameters to pass to the cbuildbot type 25 params: string of parameters to pass to the cbuildbot type
35 timeout: Timeout in seconds for the main command 26 timeout: Timeout in seconds for the main command
36 (i.e. the type command). Default 9000 seconds. 27 (i.e. the type command). Default 9000 seconds.
37 crostools_repo: git repo for crostools toolset. 28 crostools_repo: git repo for crostools toolset.
38 chromite_repo: git repo for chromite toolset. 29 chromite_repo: git repo for chromite toolset.
30 trigger_name: Name of the trigger to fire after starting.
39 dry_run: Means cbuildbot --debug, or don't push anything (cbuildbot only) 31 dry_run: Means cbuildbot --debug, or don't push anything (cbuildbot only)
40 factory: a factory with pre-existing steps to extend rather than start 32 factory: a factory with pre-existing steps to extend rather than start
41 fresh. Allows composing. 33 fresh. Allows composing.
34 pass_revision: to pass the chrome revision desired into the build.
42 chromite_patch: a url and ref pair (dict) to patch the checked out 35 chromite_patch: a url and ref pair (dict) to patch the checked out
43 chromite. Fits well with a single change from a codereview, to use 36 chromite. Fits well with a single change from a codereview, to use
44 on one or more builders for realistic testing, or experiments. 37 on one or more builders for realistic testing, or experiments.
45 """ 38 """
46 _default_git_base = 'http://git.chromium.org/chromiumos' 39 _default_git_base = 'http://git.chromium.org/chromiumos'
47 _default_crostools = 'ssh://gerrit-int.chromium.org:29419/chromeos/crostools' 40 _default_crostools = 'ssh://gerrit-int.chromium.org:29419/chromeos/crostools'
48 _default_chromite = _default_git_base + '/chromite.git' 41 _default_chromite = _default_git_base + '/chromite.git'
49 42
50 DEFAULT_CBUILDBOT_TYPE = 'cbuildbot' 43 def __init__(self,
scottz 2011/11/23 01:50:16 Nit: generally you either put as many arguments ar
51 CHROME_CBUILDBOT_TYPE = 'cbuildbot_chrome' 44 buildroot='/b/cbuild', params='', timeout=9000,
Peter Mayo 2011/11/23 14:28:10 suggest: params='' is a default that doesn't work
52 45 trigger_name=None, branch='master',
53 # Redefining built-in 'type'
54 # pylint: disable=W0622
55 def __init__(self, type=DEFAULT_CBUILDBOT_TYPE, board='x86-generic',
56 buildroot='/b/cbuild', triagelog=None, params='', timeout=9000,
57 variant=None, is_master=False, branch='master', old_style=False,
58 crostools_repo=_default_crostools, 46 crostools_repo=_default_crostools,
59 chromite_repo=_default_chromite, 47 chromite_repo=_default_chromite,
60 dry_run=False, chrome_root=None, factory=None, 48 dry_run=False, chrome_root=None, factory=None,
49 pass_revision=False,
61 slave_manager=True, chromite_patch=None, trybot=False): 50 slave_manager=True, chromite_patch=None, trybot=False):
62 self.buildroot = buildroot 51 self.buildroot = buildroot
63 self.crostools_repo = crostools_repo 52 self.crostools_repo = crostools_repo
64 self.chromite_repo = chromite_repo 53 self.chromite_repo = chromite_repo
65 self.chromite_patch = chromite_patch 54 self.chromite_patch = chromite_patch
66 if chromite_patch: 55 if chromite_patch:
67 assert ('url' in chromite_patch and 'ref' in chromite_patch) 56 assert ('url' in chromite_patch and 'ref' in chromite_patch)
57
68 self.timeout = timeout 58 self.timeout = timeout
69 self.variant = variant
70 self.board = board
71 self.branch = branch 59 self.branch = branch
72 self.type = type 60 self.trigger_name = trigger_name
73 self.is_master = is_master
74 self.dry_run = dry_run 61 self.dry_run = dry_run
75 self.chrome_root = chrome_root 62 self.chrome_root = chrome_root
76 self.slave_manager = slave_manager 63 self.slave_manager = slave_manager
77 self.trybot = trybot 64 self.trybot = trybot
78 65
79 if factory: 66 if factory:
80 self.f_cbuild = factory 67 self.f_cbuild = factory
68 elif pass_revision:
69 self.f_cbuild = build_factory.BuildFactory()
81 else: 70 else:
82 self.f_cbuild = chromeos_build_factory.BuildFactory() 71 self.f_cbuild = chromeos_build_factory.BuildFactory()
83 self.add_boiler_plate_steps()
84 72
85 if type == 'cbuildbot': 73 self.add_bootstrap_steps()
86 description_suffix = '' 74 self.add_cbuildbot_step(params, pass_revision)
87 if self.is_master:
88 description_suffix = 'master'
89
90 self.cbuildbot_type(params, description_suffix=description_suffix)
91 elif type == 'cbuild':
92 self.cbuild_type(params)
93 elif type == 'oneoff':
94 self.oneoff_type()
95
96 if triagelog:
97 self.add_triagelog_step(triagelog)
98
99
100 def _branchAtOrAbove(self, version):
101 """See if the current branch is at or above some cutoff point.
102
103 This is intended to help with backwards compatibility with older
104 branches.
105
106 '0.12.123.456' > '0.12'
107 '0.11.123.456' < '0.12'
108
109 Note that this method can break with some version strings out there:
110 '0.11.241.B'. In this case, if you don't specify enough detail
111 reach the 'B' it's fine. If that's a problem, the method will
112 have to be improved.
113 """
114
115 # Master is assumed to be past the cut off point.
116 if self.branch == 'master':
117 return True
118
119 if not re.match('\d+\.\d+\.\d+\.(\d+|B)', self.branch):
120 return True
121
122 # '0.12.123.456' -> ['0', '12', '123', '456']
123 branch_parts = self.branch.split('.')
124 version_parts = version.split('.')
125
126 # The first different section tells which is newer
127 for b, v in zip(branch_parts, version_parts):
128 if int(b) > int(v):
129 return True
130
131 if int(b) < int(v):
132 return False
133
134 # If all sections matched, see if zip truncated a difference
135 return len(branch_parts) >= len(version_parts)
136 75
137 def _git_clear_and_checkout(self, repo, patch=None): 76 def _git_clear_and_checkout(self, repo, patch=None):
138 """ 77 """rm -rf and clone the basename of the repo passed without .git
139 rm -rf and clone the basename of the repo passed without .git
140 78
141 Args: 79 Args:
142 repo: ssh: uri for the repo to be checked out 80 repo: ssh: uri for the repo to be checked out
143 patch: object with url and ref to patch on top 81 patch: object with url and ref to patch on top
144 """ 82 """
145 git_bin = '/usr/bin/git' 83 git_bin = '/usr/bin/git'
146 git_checkout_dir = os.path.basename(repo).replace('.git', '') 84 git_checkout_dir = os.path.basename(repo).replace('.git', '')
147 clear_and_clone_cmd = 'rm -rf %s ; sleep 10 ;' % git_checkout_dir 85 clear_and_clone_cmd = 'rm -rf %s ; sleep 10 ;' % git_checkout_dir
148 clear_and_clone_cmd += '%s clone %s;cd %s;' % (git_bin, repo, 86 clear_and_clone_cmd += '%s clone %s;cd %s;' % (git_bin, repo,
149 git_checkout_dir) 87 git_checkout_dir)
150 #It's possible that branch can be coming from WithProperites set 88 # It's possible that branch can be coming from WithProperites set
151 #If the branch is master, then even if the branch is empty, it amounts 89 # If the branch is master, then even if the branch is empty, it amounts
152 #to the same 'git checkout' or 'git checkout master' 90 # to the same 'git checkout' or 'git checkout master'
153 #If self.branch is set to something otherthan master, that means, branch 91 # If self.branch is set to something otherthan master, that means, branch
154 #has been passed in and we want to honor the explicitly passed in branch 92 # has been passed in and we want to honor the explicitly passed in branch
155
156 clear_and_clone_cmd += '%s checkout ' % git_bin 93 clear_and_clone_cmd += '%s checkout ' % git_bin
157
158 if self.branch == 'master': 94 if self.branch == 'master':
159 # Whitelist top of tree chrome PFQ builds to always use master 95 clear_and_clone_cmd += '%(branch)s'
160 # as the branch checkout, this avoids us trying to clone a SVN
161 # revision that is passed to the builder. We are doing this in this
162 # fashion to avoid having to write a script that wraps our git call
163 # to confirm the hash we are passed. While technically we have access to
164 # branch/revision unfortunately the only way it is available is via
165 # WithProperties which is only transferred to something usable in a shell
166 # step.
167 if self.type and (self.CHROME_CBUILDBOT_TYPE == self.type):
168 clear_and_clone_cmd += 'master'
169 else:
170 # If branch is passed by the change source and we are not chrome pfq use
171 # use it.
172 clear_and_clone_cmd += '%(branch)s'
173 else: 96 else:
174 clear_and_clone_cmd += self.branch 97 clear_and_clone_cmd += self.branch
175 98
176 msg = 'Clear and Clone %s' % git_checkout_dir 99 msg = 'Clear and Clone %s' % git_checkout_dir
177 if patch: 100 if patch:
178 clear_and_clone_cmd += ('; %s pull %s %s' % 101 clear_and_clone_cmd += ('; %s pull %s %s' %
179 (git_bin, patch['url'], patch['ref'])) 102 (git_bin, patch['url'], patch['ref']))
180 msg = 'Clear, Clone and Patch %s' % git_checkout_dir 103 msg = 'Clear, Clone and Patch %s' % git_checkout_dir
181 104
182 self.f_cbuild.addStep(shell.ShellCommand, 105 self.f_cbuild.addStep(shell.ShellCommand,
183 command=WithProperties(clear_and_clone_cmd), 106 command=WithProperties(clear_and_clone_cmd),
Peter Mayo 2011/11/23 14:28:10 suggest: move the WithProperties to where the prop
184 name=msg, 107 name=msg,
185 description=msg) 108 description=msg)
186 109
187 def add_boiler_plate_steps(self): 110 def add_bootstrap_steps(self):
188 """ 111 """Bootstraps Chromium OS Build by syncing pre-requisite repositories.
189 Add the following boiler plate steps to the factory.
190 112
191 * gclient sync of /b 113 * gclient sync of /b
192 * clearing of chromite[& crostools] 114 * clearing of chromite[& crostools]
193 * clean checkout of chromite[& crostools] 115 * clean checkout of chromite[& crostools]
194 """ 116 """
195 if self.slave_manager: 117 if self.slave_manager:
196 build_slave_sync = ['gclient', 'sync'] 118 build_slave_sync = ['gclient', 'sync']
197 self.f_cbuild.addStep(shell.ShellCommand, 119 self.f_cbuild.addStep(shell.ShellCommand,
198 command=build_slave_sync, 120 command=build_slave_sync,
199 name='update_scripts', 121 name='update_scripts',
200 description='Sync buildbot slave files', 122 description='Sync buildbot slave files',
201 workdir='/b', 123 workdir='/b',
202 timeout=300) 124 timeout=300)
203 125
204 self._git_clear_and_checkout(self.chromite_repo, self.chromite_patch) 126 self._git_clear_and_checkout(self.chromite_repo, self.chromite_patch)
205 if self.crostools_repo: 127 if self.crostools_repo:
206 self._git_clear_and_checkout(self.crostools_repo) 128 self._git_clear_and_checkout(self.crostools_repo)
207 129
208 def cbuildbot_type(self, params, description_suffix='', haltOnFailure=True, 130 def add_cbuildbot_step(self, params, pass_revision=False):
209 pass_revision=False): 131 """Adds cbuildbot step for Chromium OS builds.
210 """Adds cbuildbot steps for pre flight queue builders.
211 132
212 Cbuildbot includes the steps for syncing and building pre flight queue 133 Cbuildbot includes all steps for building any Chromium OS config.
213 builders. This includes both chrome and standard pfq builders.
214 134
215 Args: 135 Args:
216 params: Extra parameters for cbuildbot. 136 params: Extra parameters for cbuildbot.
217 description_suffix: Optional suffix to add to description that shows up
218 on dashboard.
219 pass_revision: To pass the chrome revision desired into the build. 137 pass_revision: To pass the chrome revision desired into the build.
220 haltOnFailure: To halt build because of failure of cbuildbot step. Useful
221 for setting to False for case of Chrome pfq where multiple cbuildbot
222 steps are invoked.
223 """ 138 """
224 # Gathers queued commits and drops them for cbuildbot to pick up. 139 cmd = ['chromite/buildbot/cbuildbot',
225 self.f_cbuild.addStep(chromeos_revision_source.GitRevisionDropper, 140 shell.WithProperties("--buildnumber=%(buildnumber)s"),
scottz 2011/11/23 01:50:16 Nit: Pick either ' or "
226 timeout=self.timeout) 141 '--buildroot=%s' % self.buildroot]
227
228 # Triggered cbuildbots (pfq slaves) have this property set.
229 if self.is_master:
230 if self.type == self.CHROME_CBUILDBOT_TYPE:
231 self.f_cbuild.addStep(
232 trigger.Trigger(schedulerNames=['chrome_pre_flight_queue_slaves'],
233 waitForFinish=False))
234 else:
235 self.f_cbuild.addStep(
236 trigger.Trigger(schedulerNames=['pre_flight_queue_slaves'],
237 waitForFinish=False))
238
239 cbuild_cmd = ['chromite/buildbot/cbuildbot',
240 shell.WithProperties("--buildnumber=%(buildnumber)s")]
241 if pass_revision:
242 cbuild_cmd.append(shell.WithProperties('--chrome_version=%(revision)s'))
243
244 if self._branchAtOrAbove('0.12') and not self.trybot:
245 cbuild_cmd += ['--buildbot']
246 142
247 if self.dry_run: 143 if self.dry_run:
248 cbuild_cmd += ['--debug'] 144 cmd += ['--debug']
249
250 cbuild_cmd += ['--buildroot=%s' % self.buildroot]
251 cbuild_cmd += [('--revisionfile=%s' %
252 chromeos_revision_source.PFQ_REVISION_FILE)]
253 # Below, WithProperties is appended to cbuild_cmd and rendered into a string
254 # for each specific build at build-time. When clobber is None, it renders
255 # to an empty string. When clobber is not None, it renders to the string
256 # --clobber. Note: the :+ after clobber controls this behavior and is not
257 # a typo.
258 cbuild_cmd.append(WithProperties('%s', 'clobber:+--clobber'))
259 145
260 if self.trybot: 146 if self.trybot:
261 cbuild_cmd.append(WithProperties("--gerrit-patches='%(issue)s'")) 147 cmd.append(WithProperties("--gerrit-patches='%(issue)s'"))
262
263 name = self.type
264 if description_suffix:
265 description = '%s_%s' % (name, description_suffix)
266 else: 148 else:
267 description = name 149 cmd += ['--buildbot']
268 150
269 if self.chrome_root: 151 if self.chrome_root:
270 cbuild_cmd.append('--chrome_root=%s' % self.chrome_root) 152 cmd.append('--chrome_root=%s' % self.chrome_root)
271 153
272 cbuild_cmd += params.split() 154 # Add properties from buildbot as necessary.
155 cmd.append(WithProperties('%s', 'clobber:+--clobber'))
156 if pass_revision:
157 cmd.append(shell.WithProperties('--chrome_version=%(revision)s'))
158
159 # Add additional parameters.
160 cmd += params.split()
161
162 # Trigger other slaves that should be run along with this builder.
163 if self.trigger_name:
164 self.f_cbuild.addStep(trigger.Trigger(schedulerNames=[self.trigger_name],
165 waitForFinish=False))
166 description = 'cbuildbot_master'
167 else:
168 description = 'master'
169
273 self.f_cbuild.addStep(chromium_step.AnnotatedCommand, 170 self.f_cbuild.addStep(chromium_step.AnnotatedCommand,
274 command=cbuild_cmd, 171 command=cmd,
275 timeout=self.timeout, 172 timeout=self.timeout,
276 name=name, 173 name='cbuildbot',
277 description=description, 174 description=description,
278 haltOnFailure=haltOnFailure,
279 usePTY=False) 175 usePTY=False)
280 176
281 def oneoff_type(self):
282 """
283 Add a step to run /home/chrome-bot/buildbot-oneoff --buildnumber=XXX.
284 """
285 cmd = ['/home/chrome-bot/buildbot-oneoff',
286 shell.WithProperties("--buildnumber=%(buildnumber)s"),
287 shell.WithProperties('%(branch)s)')]
288 self.f_cbuild.addStep(shell.ShellCommand,
289 command=cmd,
290 timeout=self.timeout,
291 name='one off chromebot',
292 description='one off chromebot')
293
294 def cbuild_type(self, params):
295 cbuild_cmd = ['crostools/cbuild',
296 shell.WithProperties("--buildnumber=%(buildnumber)s")]
297 cbuild_cmd += ['--board=%s' % self.board,
298 '--buildroot=%s' % self.buildroot]
299 # Below, WithProperties is appended to cbuild_cmd and rendered into a string
300 # for each specific build at build-time. When clobber is None, it renders
301 # to an empty string. When clobber is not None, it renders to the string
302 # --clobber. Note: the :+ after clobber controls this behavior and is not
303 # a typo.
304 cbuild_cmd.append(WithProperties('%s', 'clobber:+--clobber'))
305 cbuild_cmd.append(WithProperties('%(branch)s'))
306 if self.variant:
307 cbuild_cmd.append('--variant=%s' % self.variant)
308 cbuild_cmd += params.split()
309 self.f_cbuild.addStep(shell.ShellCommand,
310 command=cbuild_cmd,
311 timeout=self.timeout,
312 name='cbuild',
313 description='cbuild')
314
315 logfile = os.path.join(self.buildroot, 'logs/cbuild.log')
316 self.add_triagelog_step(logfile)
317
318 def add_triagelog_step(self, logfile):
319 """
320 Add a step to the boiler plate to run triage log with the
321 specified log
322
323 Args:
324 logfile: path to the file to run triage log on.
325 """
326 triagelog_cmd = ['crostools/triagelog', '--nohighlighting', logfile]
327 self.f_cbuild.addStep(shell.ShellCommand,
328 command=triagelog_cmd,
329 timeout=900,
330 name='triagelog',
331 description='triagelog')
332
333 def get_factory(self): 177 def get_factory(self):
334 """ 178 """Returns the produced factory."""
335 Return the produced factory.
336
337 Returns:
338 a buildbot factory object
339 """
340 return self.f_cbuild 179 return self.f_cbuild
341
342
343 class ChromeCbuildbotFactory(CbuildbotFactory):
344 """
345 Create a cbuildbot build factory for chrome.
346
347 Attributes:
348 board: What board to build (x86-generic x86-agz etc).
349 buildroot: --buildroot to pass to cbuild.
350 params: string of parameters to pass to the cbuildbot type
351 timeout: Timeout in seconds for the main command
352 (i.e. the type command). Default 9000 seconds.
353 is_master: Whether or not this pfq manages others.
354 chrome_rev_stages: Array of strings designating chrome rev steps to run
355 in cbuildbot tot, latest_release, etc.
356 crostools_repo: git repo for crostools toolset.
357 chromite_repo: git repo for chromite toolset.
358 dry_run: Means cbuildbot --debug, or don't push anything (cbuildbot only)
359 chrome_root: directory to use for chrome.
360 pass_revision: to pass the chrome revision desired into the build.
361 factory: a factory with pre-existing steps to extend rather than start
362 fresh. Allows composing.
363 """
364 def __init__(self, buildroot='/b/cbuild', params='', timeout=9000,
365 is_master=False, branch='master', chrome_rev_stages=None,
366 crostools_repo=CbuildbotFactory._default_crostools,
367 chromite_repo=CbuildbotFactory._default_chromite,
368 dry_run=False, chrome_root=None, factory=None,
369 slave_manager=True, chromite_patch=None, pass_revision=False):
370 # We don't inherit ChromeOS behavior for revisions.
371 if not factory:
372 factory = build_factory.BuildFactory()
373
374 CbuildbotFactory.__init__(self, type=CbuildbotFactory.CHROME_CBUILDBOT_TYPE,
375 board=None,
376 buildroot=buildroot, is_master=is_master,
377 crostools_repo=crostools_repo,
378 chromite_repo=chromite_repo,
379 dry_run=dry_run,
380 chrome_root=chrome_root,
381 factory=factory,
382 slave_manager=slave_manager,
383 chromite_patch=chromite_patch)
384 # TODO(sosa): Remove legacy support.
385 if chrome_rev_stages:
386 for chrome_rev in chrome_rev_stages:
387 bot_params = '--chrome_rev=%s %s' % (chrome_rev, params)
388 self.cbuildbot_type(bot_params, description_suffix=chrome_rev,
389 pass_revision=pass_revision, haltOnFailure=False)
390 else:
391 self.cbuildbot_type(params, haltOnFailure=False,
392 pass_revision=pass_revision)
OLDNEW
« no previous file with comments | « scripts/master/chromeos_revision_source.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698