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