blob: 857434b7797ab1f98e0dd48f066767902ba136c4 [file] [log] [blame]
Kuang-che Wu41e8b592018-09-25 17:01:30 +08001#!/usr/bin/env python2
2# -*- coding: utf-8 -*-
3# Copyright 2018 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6"""Helper script to prepare source trees for ChromeOS bisection.
7
8Typical usage:
9
10 Initial setup:
11 $ %(prog)s init --chromeos
12 $ %(prog)s init --chrome
13 $ %(prog)s init --android=pi-arc-dev
14
15 Sync code if necessary:
16 $ %(prog)s sync
17
18 Create source trees for bisection
19 $ %(prog)s new --session=12345
20
21 After bisection finished, delete trees
22 $ %(prog)s delete --session=12345
23"""
24from __future__ import print_function
25import argparse
26import csv
27import logging
28import os
Kuang-che Wu22f207e2019-02-23 12:53:53 +080029import subprocess
Kuang-che Wu67be74b2018-10-15 14:17:26 +080030import time
Kuang-che Wu41e8b592018-09-25 17:01:30 +080031import urllib2
Kuang-che Wu67be74b2018-10-15 14:17:26 +080032import urlparse
Kuang-che Wu7d0c7592019-09-16 09:59:28 +080033import xml.etree.ElementTree
Kuang-che Wu41e8b592018-09-25 17:01:30 +080034
35from bisect_kit import common
36from bisect_kit import configure
37from bisect_kit import gclient_util
38from bisect_kit import git_util
Kuang-che Wudc714412018-10-17 16:06:39 +080039from bisect_kit import locking
Kuang-che Wu41e8b592018-09-25 17:01:30 +080040from bisect_kit import repo_util
41from bisect_kit import util
42
43DEFAULT_MIRROR_BASE = os.path.expanduser('~/git-mirrors')
44DEFAULT_WORK_BASE = os.path.expanduser('~/bisect-workdir')
45CHECKOUT_TEMPLATE_NAME = 'template'
46
47logger = logging.getLogger(__name__)
48
49
50class DefaultProjectPathFactory(object):
51 """Factory for chromeos/chrome/android source tree paths."""
52
53 def __init__(self, mirror_base, work_base, session):
54 self.mirror_base = mirror_base
55 self.work_base = work_base
56 self.session = session
57
58 def get_chromeos_mirror(self):
59 return os.path.join(self.mirror_base, 'chromeos')
60
61 def get_chromeos_tree(self):
62 return os.path.join(self.work_base, self.session, 'chromeos')
63
64 def get_android_mirror(self, branch):
65 return os.path.join(self.mirror_base, 'android.%s' % branch)
66
67 def get_android_tree(self, branch):
68 return os.path.join(self.work_base, self.session, 'android.%s' % branch)
69
70 def get_chrome_cache(self):
71 return os.path.join(self.mirror_base, 'chrome')
72
73 def get_chrome_tree(self):
74 return os.path.join(self.work_base, self.session, 'chrome')
75
76
77def subvolume_or_makedirs(opts, path):
78 if os.path.exists(path):
79 return
80
81 path = os.path.abspath(path)
82 if opts.btrfs:
83 dirname, basename = os.path.split(path)
84 if not os.path.exists(dirname):
85 os.makedirs(dirname)
86 util.check_call('btrfs', 'subvolume', 'create', basename, cwd=dirname)
87 else:
88 os.makedirs(path)
89
90
91def is_btrfs_subvolume(path):
92 if util.check_output('stat', '-f', '--format=%T', path).strip() != 'btrfs':
93 return False
94 return util.check_output('stat', '--format=%i', path).strip() == '256'
95
96
97def snapshot_or_copytree(src, dst):
98 assert os.path.isdir(src), '%s does not exist' % src
99 assert os.path.isdir(os.path.dirname(dst))
100
101 # Make sure dst do not exist, otherwise it becomes "dst/name" (one extra
102 # depth) instead of "dst".
103 assert not os.path.exists(dst)
104
105 if is_btrfs_subvolume(src):
106 util.check_call('btrfs', 'subvolume', 'snapshot', src, dst)
107 else:
108 # -a for recursion and preserve all attributes.
109 util.check_call('cp', '-a', src, dst)
110
111
Kuang-che Wubfa64482018-10-16 11:49:49 +0800112def collect_removed_manifest_repos(repo_dir, last_sync_time, only_branch=None):
Kuang-che Wu67be74b2018-10-15 14:17:26 +0800113 manifest_dir = os.path.join(repo_dir, '.repo', 'manifests')
Kuang-che Wu2b1286b2019-05-20 20:37:26 +0800114 git_util.fetch(manifest_dir)
Kuang-che Wu67be74b2018-10-15 14:17:26 +0800115
116 manifest_path = 'default.xml'
117 manifest_full_path = os.path.join(manifest_dir, manifest_path)
118 # hack for chromeos symlink
119 if os.path.islink(manifest_full_path):
120 manifest_path = os.readlink(manifest_full_path)
121
122 parser = repo_util.ManifestParser(manifest_dir)
123 latest = None
124 removed = {}
125 for _, git_rev in reversed(
126 parser.enumerate_manifest_commits(last_sync_time, None, manifest_path)):
Kuang-che Wu7d0c7592019-09-16 09:59:28 +0800127 try:
128 root = parser.parse_xml_recursive(git_rev, manifest_path)
129 except xml.etree.ElementTree.ParseError:
130 logger.warning('%s %s@%s syntax error, skip', manifest_dir, manifest_path,
131 git_rev[:12])
132 continue
Kuang-che Wubfa64482018-10-16 11:49:49 +0800133 if (only_branch and root.find('default') is not None and
134 root.find('default').get('revision') != only_branch):
135 break
Kuang-che Wu67be74b2018-10-15 14:17:26 +0800136 entries = parser.process_parsed_result(root)
137 if latest is None:
138 assert entries is not None
139 latest = entries
140 continue
141
142 for path, path_spec in entries.items():
143 if path in latest:
144 continue
145 if path in removed:
146 continue
147 removed[path] = path_spec
148
149 return removed
150
151
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800152def setup_chromeos_repos(opts, path_factory):
153 chromeos_mirror = path_factory.get_chromeos_mirror()
154 chromeos_tree = path_factory.get_chromeos_tree()
155 subvolume_or_makedirs(opts, chromeos_mirror)
156 subvolume_or_makedirs(opts, chromeos_tree)
157
158 manifest_url = (
159 'https://chrome-internal.googlesource.com/chromeos/manifest-internal')
160 repo_url = 'https://chromium.googlesource.com/external/repo.git'
161
162 if os.path.exists(os.path.join(chromeos_mirror, '.repo', 'manifests')):
163 logger.warning(
164 '%s has already been initialized, assume it is setup properly',
165 chromeos_mirror)
166 else:
167 logger.info('repo init for chromeos mirror')
168 repo_util.init(
169 chromeos_mirror,
170 manifest_url=manifest_url,
171 repo_url=repo_url,
172 mirror=True)
173
174 local_manifest_dir = os.path.join(chromeos_mirror, '.repo',
175 'local_manifests')
176 os.mkdir(local_manifest_dir)
177 with open(os.path.join(local_manifest_dir, 'manifest-versions.xml'),
178 'w') as f:
Kuang-che Wuae6824b2019-08-27 22:20:01 +0800179 f.write("""<?xml version="1.0" encoding="UTF-8"?>
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800180 <manifest>
181 <project name="chromeos/manifest-versions" remote="cros-internal" />
182 </manifest>
Kuang-che Wuae6824b2019-08-27 22:20:01 +0800183 """)
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800184
185 logger.info('repo init for chromeos tree')
186 repo_util.init(
187 chromeos_tree,
188 manifest_url=manifest_url,
189 repo_url=repo_url,
190 reference=chromeos_mirror)
191
Kuang-che Wudc714412018-10-17 16:06:39 +0800192 with locking.lock_file(
193 os.path.join(chromeos_mirror, locking.LOCK_FILE_FOR_MIRROR_SYNC)):
194 logger.info('repo sync for chromeos mirror (this takes hours; be patient)')
195 repo_util.sync(chromeos_mirror)
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800196
197 logger.info('repo sync for chromeos tree')
198 repo_util.sync(chromeos_tree)
199
200
Kuang-che Wu67be74b2018-10-15 14:17:26 +0800201def read_last_sync_time(repo_dir):
202 timestamp_path = os.path.join(repo_dir, 'last_sync_time')
203 if os.path.exists(timestamp_path):
204 with open(timestamp_path) as f:
205 return int(f.read())
206 else:
207 # 4 months should be enough for most bisect cases.
208 return int(time.time()) - 86400 * 120
209
210
211def write_sync_time(repo_dir, sync_time):
212 timestamp_path = os.path.join(repo_dir, 'last_sync_time')
213 with open(timestamp_path, 'w') as f:
214 f.write('%d\n' % sync_time)
215
216
217def write_extra_manifest_to_mirror(repo_dir, removed):
218 local_manifest_dir = os.path.join(repo_dir, '.repo', 'local_manifests')
219 if not os.path.exists(local_manifest_dir):
220 os.mkdir(local_manifest_dir)
221 with open(os.path.join(local_manifest_dir, 'deleted-repos.xml'), 'w') as f:
Kuang-che Wuae6824b2019-08-27 22:20:01 +0800222 f.write("""<?xml version="1.0" encoding="UTF-8"?>\n<manifest>\n""")
Kuang-che Wu67be74b2018-10-15 14:17:26 +0800223 remotes = {}
224 for path_spec in removed.values():
225 scheme, netloc, remote_path = urlparse.urlsplit(path_spec.repo_url)[:3]
226 assert remote_path[0] == '/'
227 remote_path = remote_path[1:]
228 if (scheme, netloc) not in remotes:
229 remote_name = 'remote_for_deleted_repo_%s' % (scheme + netloc)
230 remotes[scheme, netloc] = remote_name
Kuang-che Wuae6824b2019-08-27 22:20:01 +0800231 f.write(""" <remote name="%s" fetch="%s" />\n""" %
Kuang-che Wu67be74b2018-10-15 14:17:26 +0800232 (remote_name, '%s://%s' % (scheme, netloc)))
Kuang-che Wubfa64482018-10-16 11:49:49 +0800233 f.write(
Kuang-che Wuae6824b2019-08-27 22:20:01 +0800234 """ <project name="%s" path="%s" remote="%s" revision="%s" />\n""" %
Kuang-che Wubfa64482018-10-16 11:49:49 +0800235 (remote_path, path_spec.path, remotes[scheme, netloc], path_spec.at))
Kuang-che Wuae6824b2019-08-27 22:20:01 +0800236 f.write("""</manifest>\n""")
Kuang-che Wu67be74b2018-10-15 14:17:26 +0800237
238
Kuang-che Wubfa64482018-10-16 11:49:49 +0800239def generate_extra_manifest_for_deleted_repo(repo_dir, only_branch=None):
240 last_sync_time = read_last_sync_time(repo_dir)
241 removed = collect_removed_manifest_repos(
242 repo_dir, last_sync_time, only_branch=only_branch)
243 write_extra_manifest_to_mirror(repo_dir, removed)
244 logger.info('since last sync, %d repo got removed', len(removed))
245
246
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800247def sync_chromeos_code(opts, path_factory):
248 del opts # unused
249
Kuang-che Wu67be74b2018-10-15 14:17:26 +0800250 start_sync_time = int(time.time())
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800251 chromeos_mirror = path_factory.get_chromeos_mirror()
Kuang-che Wu67be74b2018-10-15 14:17:26 +0800252
Kuang-che Wu67be74b2018-10-15 14:17:26 +0800253 logger.info('repo sync for chromeos mirror')
Kuang-che Wubfa64482018-10-16 11:49:49 +0800254 generate_extra_manifest_for_deleted_repo(chromeos_mirror)
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800255 repo_util.sync(chromeos_mirror)
Kuang-che Wu67be74b2018-10-15 14:17:26 +0800256 write_sync_time(chromeos_mirror, start_sync_time)
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800257
258 logger.info('repo sync for chromeos tree')
259 chromeos_tree = path_factory.get_chromeos_tree()
260 repo_util.sync(chromeos_tree)
261
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800262
263def query_chrome_latest_branch():
264 result = None
265 r = urllib2.urlopen('https://omahaproxy.appspot.com/all')
266 for row in csv.DictReader(r):
267 if row['true_branch'].isdigit():
268 result = max(result, int(row['true_branch']))
269 return result
270
271
272def setup_chrome_repos(opts, path_factory):
273 chrome_cache = path_factory.get_chrome_cache()
274 subvolume_or_makedirs(opts, chrome_cache)
275 chrome_tree = path_factory.get_chrome_tree()
276 subvolume_or_makedirs(opts, chrome_tree)
277
278 latest_branch = query_chrome_latest_branch()
279 logger.info('latest chrome branch is %d', latest_branch)
280 assert latest_branch
Kuang-che Wuae6824b2019-08-27 22:20:01 +0800281 spec = """
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800282solutions = [
283 { "name" : "buildspec",
284 "url" : "https://chrome-internal.googlesource.com/a/chrome/tools/buildspec.git",
285 "deps_file" : "branches/%d/DEPS",
286 "custom_deps" : {
287 },
288 "custom_vars": {'checkout_src_internal': True},
289 },
290]
291target_os = ['chromeos']
292cache_dir = %r
Kuang-che Wuae6824b2019-08-27 22:20:01 +0800293""" % (latest_branch, chrome_cache)
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800294
Kuang-che Wudc714412018-10-17 16:06:39 +0800295 with locking.lock_file(
296 os.path.join(chrome_cache, locking.LOCK_FILE_FOR_MIRROR_SYNC)):
297 logger.info('gclient config for chrome')
298 gclient_util.config(chrome_tree, spec=spec)
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800299
Kuang-che Wudc714412018-10-17 16:06:39 +0800300 is_first_sync = not os.listdir(chrome_cache)
301 if is_first_sync:
302 logger.info('gclient sync for chrome (this takes hours; be patient)')
303 else:
304 logger.info('gclient sync for chrome')
305 gclient_util.sync(
306 chrome_tree, with_branch_heads=True, with_tags=True, ignore_locks=True)
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800307
Kuang-che Wudc714412018-10-17 16:06:39 +0800308 # It's possible that some repos are removed from latest branch and thus
309 # their commit history is not fetched in recent gclient sync. So we call
310 # 'git fetch' for all existing git mirrors.
311 # TODO(kcwu): only sync repos not in DEPS files of latest branch
312 logger.info('additional sync for chrome mirror')
313 for git_repo_name in os.listdir(chrome_cache):
314 # another gclient is running or leftover of previous run; skip
315 if git_repo_name.startswith('_cache_tmp'):
316 continue
317 git_repo = os.path.join(chrome_cache, git_repo_name)
Kuang-che Wu08366542019-01-12 12:37:49 +0800318 if not git_util.is_git_bare_dir(git_repo):
Kuang-che Wudc714412018-10-17 16:06:39 +0800319 continue
Kuang-che Wu2b1286b2019-05-20 20:37:26 +0800320 git_util.fetch(git_repo)
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800321
Kuang-che Wu1e49f512018-12-06 15:27:42 +0800322 # Some repos were removed from the DEPS and won't be synced here. They will
323 # be synced during DEPS file processing because the necessary information
324 # requires full DEPS parsing. (crbug.com/902238)
325
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800326
327def sync_chrome_code(opts, path_factory):
328 # The sync step is identical to the initial gclient config step.
329 setup_chrome_repos(opts, path_factory)
330
331
332def setup_android_repos(opts, path_factory, branch):
333 android_mirror = path_factory.get_android_mirror(branch)
334 android_tree = path_factory.get_android_tree(branch)
335 subvolume_or_makedirs(opts, android_mirror)
336 subvolume_or_makedirs(opts, android_tree)
337
338 manifest_url = ('persistent-https://googleplex-android.git.corp.google.com'
339 '/platform/manifest')
340 repo_url = 'https://gerrit.googlesource.com/git-repo'
341
342 if os.path.exists(os.path.join(android_mirror, '.repo', 'manifests')):
343 logger.warning(
344 '%s has already been initialized, assume it is setup properly',
345 android_mirror)
346 else:
347 logger.info('repo init for android mirror branch=%s', branch)
348 repo_util.init(
349 android_mirror,
350 manifest_url=manifest_url,
351 repo_url=repo_url,
352 manifest_branch=branch,
353 mirror=True)
354
355 logger.info('repo init for android tree branch=%s', branch)
356 repo_util.init(
357 android_tree,
358 manifest_url=manifest_url,
359 repo_url=repo_url,
360 manifest_branch=branch,
361 reference=android_mirror)
362
363 logger.info('repo sync for android mirror (this takes hours; be patient)')
364 repo_util.sync(android_mirror, current_branch=True)
365
366 logger.info('repo sync for android tree branch=%s', branch)
367 repo_util.sync(android_tree, current_branch=True)
368
369
370def sync_android_code(opts, path_factory, branch):
371 del opts # unused
Kuang-che Wu67be74b2018-10-15 14:17:26 +0800372 start_sync_time = int(time.time())
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800373 android_mirror = path_factory.get_android_mirror(branch)
374 android_tree = path_factory.get_android_tree(branch)
375
Kuang-che Wudc714412018-10-17 16:06:39 +0800376 with locking.lock_file(
377 os.path.join(android_mirror, locking.LOCK_FILE_FOR_MIRROR_SYNC)):
378 logger.info('repo sync for android mirror branch=%s', branch)
379 # Android usually big jump between milestone releases and add/delete lots of
380 # repos when switch releases. Because it's infeasible to bisect between such
381 # big jump, the deleted repo is useless. In order to save disk, do not sync
382 # repos deleted in other branches.
383 generate_extra_manifest_for_deleted_repo(android_mirror, only_branch=branch)
384 repo_util.sync(android_mirror, current_branch=True)
385 write_sync_time(android_mirror, start_sync_time)
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800386
387 logger.info('repo sync for android tree branch=%s', branch)
388 repo_util.sync(android_tree, current_branch=True)
389
390
391def cmd_init(opts):
392 path_factory = DefaultProjectPathFactory(opts.mirror_base, opts.work_base,
393 CHECKOUT_TEMPLATE_NAME)
394
395 if opts.chromeos:
396 setup_chromeos_repos(opts, path_factory)
397 if opts.chrome:
398 setup_chrome_repos(opts, path_factory)
399 for branch in opts.android:
400 setup_android_repos(opts, path_factory, branch)
401
402
403def enumerate_android_branches_available(base):
404 branches = []
405 for name in os.listdir(base):
406 if name.startswith('android.'):
407 branches.append(name.partition('.')[2])
408 return branches
409
410
Kuang-che Wu22f207e2019-02-23 12:53:53 +0800411def do_sync(opts):
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800412 path_factory = DefaultProjectPathFactory(opts.mirror_base, opts.work_base,
413 CHECKOUT_TEMPLATE_NAME)
414
415 sync_all = False
416 if not opts.chromeos and not opts.chrome and not opts.android:
417 logger.info('sync trees for all')
418 sync_all = True
419
420 if sync_all or opts.chromeos:
421 sync_chromeos_code(opts, path_factory)
422 if sync_all or opts.chrome:
423 sync_chrome_code(opts, path_factory)
424
425 if sync_all:
426 android_branches = enumerate_android_branches_available(opts.mirror_base)
427 else:
428 android_branches = opts.android
429 for branch in android_branches:
430 sync_android_code(opts, path_factory, branch)
431
432
Kuang-che Wu22f207e2019-02-23 12:53:53 +0800433def cmd_sync(opts):
434 try:
435 do_sync(opts)
436 except subprocess.CalledProcessError:
437 # Sync may fail due to network or server issues.
438 logger.exception('do_sync failed, will retry one minute later')
439 time.sleep(60)
440 do_sync(opts)
441
442
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800443def cmd_new(opts):
444 work_dir = os.path.join(opts.work_base, opts.session)
445 if not os.path.exists(work_dir):
446 os.makedirs(work_dir)
447
448 template_factory = DefaultProjectPathFactory(opts.mirror_base, opts.work_base,
449 CHECKOUT_TEMPLATE_NAME)
450 path_factory = DefaultProjectPathFactory(opts.mirror_base, opts.work_base,
451 opts.session)
452
453 prepare_all = False
454 if not opts.chromeos and not opts.chrome and not opts.android:
455 logger.info('prepare trees for all')
456 prepare_all = True
457
458 chromeos_template = template_factory.get_chromeos_tree()
459 if (prepare_all and os.path.exists(chromeos_template)) or opts.chromeos:
460 logger.info('prepare tree for chromeos, %s',
461 path_factory.get_chromeos_tree())
462 snapshot_or_copytree(chromeos_template, path_factory.get_chromeos_tree())
463
464 chrome_template = template_factory.get_chrome_tree()
465 if (prepare_all and os.path.exists(chrome_template)) or opts.chrome:
466 logger.info('prepare tree for chrome, %s', path_factory.get_chrome_tree())
467 snapshot_or_copytree(chrome_template, path_factory.get_chrome_tree())
468
469 if prepare_all:
470 android_branches = enumerate_android_branches_available(opts.mirror_base)
471 else:
472 android_branches = opts.android
473 for branch in android_branches:
474 logger.info('prepare tree for android branch=%s, %s', branch,
475 path_factory.get_android_tree(branch))
476 snapshot_or_copytree(
477 template_factory.get_android_tree(branch),
478 path_factory.get_android_tree(branch))
479
480
481def delete_tree(path):
482 if is_btrfs_subvolume(path):
Kuang-che Wu9d3ccde2019-01-03 17:06:09 +0800483 # btrfs should be mounted with 'user_subvol_rm_allowed' option and thus
484 # normal user permission is enough.
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800485 util.check_call('btrfs', 'subvolume', 'delete', path)
486 else:
Kuang-che Wu9d3ccde2019-01-03 17:06:09 +0800487 util.check_call('sudo', 'rm', '-rf', path)
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800488
489
490def cmd_list(opts):
491 print('%-20s %s' % ('Session', 'Path'))
492 for name in os.listdir(opts.work_base):
493 if name == CHECKOUT_TEMPLATE_NAME:
494 continue
495 path = os.path.join(opts.work_base, name)
496 print('%-20s %s' % (name, path))
497
498
499def cmd_delete(opts):
500 assert opts.session
501 path_factory = DefaultProjectPathFactory(opts.mirror_base, opts.work_base,
502 opts.session)
503
504 chromeos_tree = path_factory.get_chromeos_tree()
505 if os.path.exists(chromeos_tree):
506 if os.path.exists(os.path.join(chromeos_tree, 'chromite')):
507 # ignore error
508 util.call('cros_sdk', '--unmount', cwd=chromeos_tree)
509 delete_tree(chromeos_tree)
510
511 chrome_tree = path_factory.get_chrome_tree()
512 if os.path.exists(chrome_tree):
513 delete_tree(chrome_tree)
514
515 android_branches = enumerate_android_branches_available(opts.mirror_base)
516 for branch in android_branches:
517 android_tree = path_factory.get_android_tree(branch)
518 if os.path.exists(android_tree):
519 delete_tree(android_tree)
520
521 os.rmdir(os.path.join(opts.work_base, opts.session))
522
523
524def create_parser():
525 parser = argparse.ArgumentParser(
526 formatter_class=argparse.RawDescriptionHelpFormatter, description=__doc__)
527 parser.add_argument(
528 '--mirror_base',
529 metavar='MIRROR_BASE',
530 default=configure.get('MIRROR_BASE', DEFAULT_MIRROR_BASE),
531 help='Directory for mirrors (default: %(default)s)')
532 parser.add_argument(
533 '--work_base',
534 metavar='WORK_BASE',
535 default=configure.get('WORK_BASE', DEFAULT_WORK_BASE),
536 help='Directory for bisection working directories (default: %(default)s)')
537 common.add_common_arguments(parser)
538 subparsers = parser.add_subparsers(
539 dest='command', title='commands', metavar='<command>')
540
541 parser_init = subparsers.add_parser(
542 'init', help='Mirror source trees and create template checkout')
543 parser_init.add_argument(
544 '--chrome', action='store_true', help='init chrome mirror and tree')
545 parser_init.add_argument(
546 '--chromeos', action='store_true', help='init chromeos mirror and tree')
547 parser_init.add_argument(
548 '--android',
549 metavar='BRANCH',
550 action='append',
551 default=[],
552 help='init android mirror and tree of BRANCH')
553 parser_init.add_argument(
554 '--btrfs',
555 action='store_true',
556 help='create btrfs subvolume for source tree')
557 parser_init.set_defaults(func=cmd_init)
558
559 parser_sync = subparsers.add_parser(
560 'sync',
561 help='Sync source trees',
562 description='Sync all if no projects are specified '
563 '(--chrome, --chromeos, or --android)')
564 parser_sync.add_argument(
565 '--chrome', action='store_true', help='sync chrome mirror and tree')
566 parser_sync.add_argument(
567 '--chromeos', action='store_true', help='sync chromeos mirror and tree')
568 parser_sync.add_argument(
569 '--android',
570 metavar='BRANCH',
571 action='append',
572 default=[],
573 help='sync android mirror and tree of BRANCH')
574 parser_sync.set_defaults(func=cmd_sync)
575
576 parser_new = subparsers.add_parser(
577 'new',
578 help='Create new source checkout for bisect',
579 description='Create for all if no projects are specified '
580 '(--chrome, --chromeos, or --android)')
581 parser_new.add_argument('--session', required=True)
582 parser_new.add_argument(
583 '--chrome', action='store_true', help='create chrome checkout')
584 parser_new.add_argument(
585 '--chromeos', action='store_true', help='create chromeos checkout')
586 parser_new.add_argument(
587 '--android',
588 metavar='BRANCH',
589 action='append',
590 default=[],
591 help='create android checkout of BRANCH')
592 parser_new.set_defaults(func=cmd_new)
593
594 parser_list = subparsers.add_parser(
595 'list', help='List existing sessions with source checkout')
596 parser_list.set_defaults(func=cmd_list)
597
598 parser_delete = subparsers.add_parser('delete', help='Delete source checkout')
599 parser_delete.add_argument('--session', required=True)
600 parser_delete.set_defaults(func=cmd_delete)
601
602 return parser
603
604
605def main():
606 common.init()
607 parser = create_parser()
608 opts = parser.parse_args()
609 common.config_logging(opts)
610
611 opts.func(opts)
612
613
614if __name__ == '__main__':
615 main()