blob: 6d5b5a32dec31d62fb4bf1f9ed9ea6ff6ee3ed61 [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 Wu67be74b2018-10-15 14:17:26 +0800114 manifest_path = 'default.xml'
115 manifest_full_path = os.path.join(manifest_dir, manifest_path)
116 # hack for chromeos symlink
117 if os.path.islink(manifest_full_path):
118 manifest_path = os.readlink(manifest_full_path)
119
120 parser = repo_util.ManifestParser(manifest_dir)
121 latest = None
122 removed = {}
123 for _, git_rev in reversed(
124 parser.enumerate_manifest_commits(last_sync_time, None, manifest_path)):
Kuang-che Wu7d0c7592019-09-16 09:59:28 +0800125 try:
126 root = parser.parse_xml_recursive(git_rev, manifest_path)
127 except xml.etree.ElementTree.ParseError:
128 logger.warning('%s %s@%s syntax error, skip', manifest_dir, manifest_path,
129 git_rev[:12])
130 continue
Kuang-che Wubfa64482018-10-16 11:49:49 +0800131 if (only_branch and root.find('default') is not None and
132 root.find('default').get('revision') != only_branch):
133 break
Kuang-che Wu67be74b2018-10-15 14:17:26 +0800134 entries = parser.process_parsed_result(root)
135 if latest is None:
136 assert entries is not None
137 latest = entries
138 continue
139
140 for path, path_spec in entries.items():
141 if path in latest:
142 continue
143 if path in removed:
144 continue
145 removed[path] = path_spec
146
147 return removed
148
149
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800150def setup_chromeos_repos(opts, path_factory):
151 chromeos_mirror = path_factory.get_chromeos_mirror()
152 chromeos_tree = path_factory.get_chromeos_tree()
153 subvolume_or_makedirs(opts, chromeos_mirror)
154 subvolume_or_makedirs(opts, chromeos_tree)
155
156 manifest_url = (
157 'https://chrome-internal.googlesource.com/chromeos/manifest-internal')
158 repo_url = 'https://chromium.googlesource.com/external/repo.git'
159
160 if os.path.exists(os.path.join(chromeos_mirror, '.repo', 'manifests')):
161 logger.warning(
162 '%s has already been initialized, assume it is setup properly',
163 chromeos_mirror)
164 else:
165 logger.info('repo init for chromeos mirror')
166 repo_util.init(
167 chromeos_mirror,
168 manifest_url=manifest_url,
169 repo_url=repo_url,
170 mirror=True)
171
172 local_manifest_dir = os.path.join(chromeos_mirror, '.repo',
173 'local_manifests')
174 os.mkdir(local_manifest_dir)
175 with open(os.path.join(local_manifest_dir, 'manifest-versions.xml'),
176 'w') as f:
Kuang-che Wuae6824b2019-08-27 22:20:01 +0800177 f.write("""<?xml version="1.0" encoding="UTF-8"?>
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800178 <manifest>
179 <project name="chromeos/manifest-versions" remote="cros-internal" />
180 </manifest>
Kuang-che Wuae6824b2019-08-27 22:20:01 +0800181 """)
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800182
183 logger.info('repo init for chromeos tree')
184 repo_util.init(
185 chromeos_tree,
186 manifest_url=manifest_url,
187 repo_url=repo_url,
188 reference=chromeos_mirror)
189
Kuang-che Wudc714412018-10-17 16:06:39 +0800190 with locking.lock_file(
191 os.path.join(chromeos_mirror, locking.LOCK_FILE_FOR_MIRROR_SYNC)):
192 logger.info('repo sync for chromeos mirror (this takes hours; be patient)')
193 repo_util.sync(chromeos_mirror)
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800194
195 logger.info('repo sync for chromeos tree')
196 repo_util.sync(chromeos_tree)
197
198
Kuang-che Wu67be74b2018-10-15 14:17:26 +0800199def read_last_sync_time(repo_dir):
200 timestamp_path = os.path.join(repo_dir, 'last_sync_time')
201 if os.path.exists(timestamp_path):
202 with open(timestamp_path) as f:
203 return int(f.read())
204 else:
205 # 4 months should be enough for most bisect cases.
206 return int(time.time()) - 86400 * 120
207
208
209def write_sync_time(repo_dir, sync_time):
210 timestamp_path = os.path.join(repo_dir, 'last_sync_time')
211 with open(timestamp_path, 'w') as f:
212 f.write('%d\n' % sync_time)
213
214
215def write_extra_manifest_to_mirror(repo_dir, removed):
216 local_manifest_dir = os.path.join(repo_dir, '.repo', 'local_manifests')
217 if not os.path.exists(local_manifest_dir):
218 os.mkdir(local_manifest_dir)
219 with open(os.path.join(local_manifest_dir, 'deleted-repos.xml'), 'w') as f:
Kuang-che Wuae6824b2019-08-27 22:20:01 +0800220 f.write("""<?xml version="1.0" encoding="UTF-8"?>\n<manifest>\n""")
Kuang-che Wu67be74b2018-10-15 14:17:26 +0800221 remotes = {}
222 for path_spec in removed.values():
223 scheme, netloc, remote_path = urlparse.urlsplit(path_spec.repo_url)[:3]
224 assert remote_path[0] == '/'
225 remote_path = remote_path[1:]
226 if (scheme, netloc) not in remotes:
227 remote_name = 'remote_for_deleted_repo_%s' % (scheme + netloc)
228 remotes[scheme, netloc] = remote_name
Kuang-che Wuae6824b2019-08-27 22:20:01 +0800229 f.write(""" <remote name="%s" fetch="%s" />\n""" %
Kuang-che Wu67be74b2018-10-15 14:17:26 +0800230 (remote_name, '%s://%s' % (scheme, netloc)))
Kuang-che Wubfa64482018-10-16 11:49:49 +0800231 f.write(
Kuang-che Wuae6824b2019-08-27 22:20:01 +0800232 """ <project name="%s" path="%s" remote="%s" revision="%s" />\n""" %
Kuang-che Wubfa64482018-10-16 11:49:49 +0800233 (remote_path, path_spec.path, remotes[scheme, netloc], path_spec.at))
Kuang-che Wuae6824b2019-08-27 22:20:01 +0800234 f.write("""</manifest>\n""")
Kuang-che Wu67be74b2018-10-15 14:17:26 +0800235
236
Kuang-che Wubfa64482018-10-16 11:49:49 +0800237def generate_extra_manifest_for_deleted_repo(repo_dir, only_branch=None):
238 last_sync_time = read_last_sync_time(repo_dir)
239 removed = collect_removed_manifest_repos(
240 repo_dir, last_sync_time, only_branch=only_branch)
241 write_extra_manifest_to_mirror(repo_dir, removed)
242 logger.info('since last sync, %d repo got removed', len(removed))
Kuang-che Wub76b7f62019-09-16 10:06:18 +0800243 return len(removed)
Kuang-che Wubfa64482018-10-16 11:49:49 +0800244
245
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800246def sync_chromeos_code(opts, path_factory):
247 del opts # unused
248
Kuang-che Wu67be74b2018-10-15 14:17:26 +0800249 start_sync_time = int(time.time())
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800250 chromeos_mirror = path_factory.get_chromeos_mirror()
Kuang-che Wu67be74b2018-10-15 14:17:26 +0800251
Kuang-che Wu67be74b2018-10-15 14:17:26 +0800252 logger.info('repo sync for chromeos mirror')
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800253 repo_util.sync(chromeos_mirror)
Kuang-che Wub76b7f62019-09-16 10:06:18 +0800254 # If there are repos deleted after last sync, generate custom manifest and
255 # sync again for those repos. So we can mirror commits just before the repo
256 # deletion.
257 if generate_extra_manifest_for_deleted_repo(chromeos_mirror) != 0:
258 logger.info('repo sync again')
259 repo_util.sync(chromeos_mirror)
Kuang-che Wu67be74b2018-10-15 14:17:26 +0800260 write_sync_time(chromeos_mirror, start_sync_time)
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800261
262 logger.info('repo sync for chromeos tree')
263 chromeos_tree = path_factory.get_chromeos_tree()
264 repo_util.sync(chromeos_tree)
265
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800266
267def query_chrome_latest_branch():
268 result = None
269 r = urllib2.urlopen('https://omahaproxy.appspot.com/all')
270 for row in csv.DictReader(r):
271 if row['true_branch'].isdigit():
272 result = max(result, int(row['true_branch']))
273 return result
274
275
276def setup_chrome_repos(opts, path_factory):
277 chrome_cache = path_factory.get_chrome_cache()
278 subvolume_or_makedirs(opts, chrome_cache)
279 chrome_tree = path_factory.get_chrome_tree()
280 subvolume_or_makedirs(opts, chrome_tree)
281
282 latest_branch = query_chrome_latest_branch()
283 logger.info('latest chrome branch is %d', latest_branch)
284 assert latest_branch
Kuang-che Wuae6824b2019-08-27 22:20:01 +0800285 spec = """
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800286solutions = [
287 { "name" : "buildspec",
288 "url" : "https://chrome-internal.googlesource.com/a/chrome/tools/buildspec.git",
289 "deps_file" : "branches/%d/DEPS",
290 "custom_deps" : {
291 },
292 "custom_vars": {'checkout_src_internal': True},
293 },
294]
295target_os = ['chromeos']
296cache_dir = %r
Kuang-che Wuae6824b2019-08-27 22:20:01 +0800297""" % (latest_branch, chrome_cache)
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800298
Kuang-che Wudc714412018-10-17 16:06:39 +0800299 with locking.lock_file(
300 os.path.join(chrome_cache, locking.LOCK_FILE_FOR_MIRROR_SYNC)):
301 logger.info('gclient config for chrome')
302 gclient_util.config(chrome_tree, spec=spec)
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800303
Kuang-che Wudc714412018-10-17 16:06:39 +0800304 is_first_sync = not os.listdir(chrome_cache)
305 if is_first_sync:
306 logger.info('gclient sync for chrome (this takes hours; be patient)')
307 else:
308 logger.info('gclient sync for chrome')
309 gclient_util.sync(
310 chrome_tree, with_branch_heads=True, with_tags=True, ignore_locks=True)
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800311
Kuang-che Wudc714412018-10-17 16:06:39 +0800312 # It's possible that some repos are removed from latest branch and thus
313 # their commit history is not fetched in recent gclient sync. So we call
314 # 'git fetch' for all existing git mirrors.
315 # TODO(kcwu): only sync repos not in DEPS files of latest branch
316 logger.info('additional sync for chrome mirror')
317 for git_repo_name in os.listdir(chrome_cache):
318 # another gclient is running or leftover of previous run; skip
319 if git_repo_name.startswith('_cache_tmp'):
320 continue
321 git_repo = os.path.join(chrome_cache, git_repo_name)
Kuang-che Wu08366542019-01-12 12:37:49 +0800322 if not git_util.is_git_bare_dir(git_repo):
Kuang-che Wudc714412018-10-17 16:06:39 +0800323 continue
Kuang-che Wu2b1286b2019-05-20 20:37:26 +0800324 git_util.fetch(git_repo)
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800325
Kuang-che Wu1e49f512018-12-06 15:27:42 +0800326 # Some repos were removed from the DEPS and won't be synced here. They will
327 # be synced during DEPS file processing because the necessary information
328 # requires full DEPS parsing. (crbug.com/902238)
329
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800330
331def sync_chrome_code(opts, path_factory):
332 # The sync step is identical to the initial gclient config step.
333 setup_chrome_repos(opts, path_factory)
334
335
336def setup_android_repos(opts, path_factory, branch):
337 android_mirror = path_factory.get_android_mirror(branch)
338 android_tree = path_factory.get_android_tree(branch)
339 subvolume_or_makedirs(opts, android_mirror)
340 subvolume_or_makedirs(opts, android_tree)
341
342 manifest_url = ('persistent-https://googleplex-android.git.corp.google.com'
343 '/platform/manifest')
344 repo_url = 'https://gerrit.googlesource.com/git-repo'
345
346 if os.path.exists(os.path.join(android_mirror, '.repo', 'manifests')):
347 logger.warning(
348 '%s has already been initialized, assume it is setup properly',
349 android_mirror)
350 else:
351 logger.info('repo init for android mirror branch=%s', branch)
352 repo_util.init(
353 android_mirror,
354 manifest_url=manifest_url,
355 repo_url=repo_url,
356 manifest_branch=branch,
357 mirror=True)
358
359 logger.info('repo init for android tree branch=%s', branch)
360 repo_util.init(
361 android_tree,
362 manifest_url=manifest_url,
363 repo_url=repo_url,
364 manifest_branch=branch,
365 reference=android_mirror)
366
367 logger.info('repo sync for android mirror (this takes hours; be patient)')
368 repo_util.sync(android_mirror, current_branch=True)
369
370 logger.info('repo sync for android tree branch=%s', branch)
371 repo_util.sync(android_tree, current_branch=True)
372
373
374def sync_android_code(opts, path_factory, branch):
375 del opts # unused
Kuang-che Wu67be74b2018-10-15 14:17:26 +0800376 start_sync_time = int(time.time())
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800377 android_mirror = path_factory.get_android_mirror(branch)
378 android_tree = path_factory.get_android_tree(branch)
379
Kuang-che Wudc714412018-10-17 16:06:39 +0800380 with locking.lock_file(
381 os.path.join(android_mirror, locking.LOCK_FILE_FOR_MIRROR_SYNC)):
382 logger.info('repo sync for android mirror branch=%s', branch)
Kuang-che Wub76b7f62019-09-16 10:06:18 +0800383 repo_util.sync(android_mirror, current_branch=True)
Kuang-che Wudc714412018-10-17 16:06:39 +0800384 # Android usually big jump between milestone releases and add/delete lots of
385 # repos when switch releases. Because it's infeasible to bisect between such
386 # big jump, the deleted repo is useless. In order to save disk, do not sync
387 # repos deleted in other branches.
Kuang-che Wub76b7f62019-09-16 10:06:18 +0800388 if generate_extra_manifest_for_deleted_repo(
389 android_mirror, only_branch=branch) != 0:
390 logger.info('repo sync again')
391 repo_util.sync(android_mirror, current_branch=True)
Kuang-che Wudc714412018-10-17 16:06:39 +0800392 write_sync_time(android_mirror, start_sync_time)
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800393
394 logger.info('repo sync for android tree branch=%s', branch)
395 repo_util.sync(android_tree, current_branch=True)
396
397
398def cmd_init(opts):
399 path_factory = DefaultProjectPathFactory(opts.mirror_base, opts.work_base,
400 CHECKOUT_TEMPLATE_NAME)
401
402 if opts.chromeos:
403 setup_chromeos_repos(opts, path_factory)
404 if opts.chrome:
405 setup_chrome_repos(opts, path_factory)
406 for branch in opts.android:
407 setup_android_repos(opts, path_factory, branch)
408
409
410def enumerate_android_branches_available(base):
411 branches = []
412 for name in os.listdir(base):
413 if name.startswith('android.'):
414 branches.append(name.partition('.')[2])
415 return branches
416
417
Kuang-che Wu22f207e2019-02-23 12:53:53 +0800418def do_sync(opts):
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800419 path_factory = DefaultProjectPathFactory(opts.mirror_base, opts.work_base,
420 CHECKOUT_TEMPLATE_NAME)
421
422 sync_all = False
423 if not opts.chromeos and not opts.chrome and not opts.android:
424 logger.info('sync trees for all')
425 sync_all = True
426
427 if sync_all or opts.chromeos:
428 sync_chromeos_code(opts, path_factory)
429 if sync_all or opts.chrome:
430 sync_chrome_code(opts, path_factory)
431
432 if sync_all:
433 android_branches = enumerate_android_branches_available(opts.mirror_base)
434 else:
435 android_branches = opts.android
436 for branch in android_branches:
437 sync_android_code(opts, path_factory, branch)
438
439
Kuang-che Wu22f207e2019-02-23 12:53:53 +0800440def cmd_sync(opts):
441 try:
442 do_sync(opts)
443 except subprocess.CalledProcessError:
444 # Sync may fail due to network or server issues.
445 logger.exception('do_sync failed, will retry one minute later')
446 time.sleep(60)
447 do_sync(opts)
448
449
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800450def cmd_new(opts):
451 work_dir = os.path.join(opts.work_base, opts.session)
452 if not os.path.exists(work_dir):
453 os.makedirs(work_dir)
454
455 template_factory = DefaultProjectPathFactory(opts.mirror_base, opts.work_base,
456 CHECKOUT_TEMPLATE_NAME)
457 path_factory = DefaultProjectPathFactory(opts.mirror_base, opts.work_base,
458 opts.session)
459
460 prepare_all = False
461 if not opts.chromeos and not opts.chrome and not opts.android:
462 logger.info('prepare trees for all')
463 prepare_all = True
464
465 chromeos_template = template_factory.get_chromeos_tree()
466 if (prepare_all and os.path.exists(chromeos_template)) or opts.chromeos:
467 logger.info('prepare tree for chromeos, %s',
468 path_factory.get_chromeos_tree())
469 snapshot_or_copytree(chromeos_template, path_factory.get_chromeos_tree())
470
471 chrome_template = template_factory.get_chrome_tree()
472 if (prepare_all and os.path.exists(chrome_template)) or opts.chrome:
473 logger.info('prepare tree for chrome, %s', path_factory.get_chrome_tree())
474 snapshot_or_copytree(chrome_template, path_factory.get_chrome_tree())
475
476 if prepare_all:
477 android_branches = enumerate_android_branches_available(opts.mirror_base)
478 else:
479 android_branches = opts.android
480 for branch in android_branches:
481 logger.info('prepare tree for android branch=%s, %s', branch,
482 path_factory.get_android_tree(branch))
483 snapshot_or_copytree(
484 template_factory.get_android_tree(branch),
485 path_factory.get_android_tree(branch))
486
487
488def delete_tree(path):
489 if is_btrfs_subvolume(path):
Kuang-che Wu9d3ccde2019-01-03 17:06:09 +0800490 # btrfs should be mounted with 'user_subvol_rm_allowed' option and thus
491 # normal user permission is enough.
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800492 util.check_call('btrfs', 'subvolume', 'delete', path)
493 else:
Kuang-che Wu9d3ccde2019-01-03 17:06:09 +0800494 util.check_call('sudo', 'rm', '-rf', path)
Kuang-che Wu41e8b592018-09-25 17:01:30 +0800495
496
497def cmd_list(opts):
498 print('%-20s %s' % ('Session', 'Path'))
499 for name in os.listdir(opts.work_base):
500 if name == CHECKOUT_TEMPLATE_NAME:
501 continue
502 path = os.path.join(opts.work_base, name)
503 print('%-20s %s' % (name, path))
504
505
506def cmd_delete(opts):
507 assert opts.session
508 path_factory = DefaultProjectPathFactory(opts.mirror_base, opts.work_base,
509 opts.session)
510
511 chromeos_tree = path_factory.get_chromeos_tree()
512 if os.path.exists(chromeos_tree):
513 if os.path.exists(os.path.join(chromeos_tree, 'chromite')):
514 # ignore error
515 util.call('cros_sdk', '--unmount', cwd=chromeos_tree)
516 delete_tree(chromeos_tree)
517
518 chrome_tree = path_factory.get_chrome_tree()
519 if os.path.exists(chrome_tree):
520 delete_tree(chrome_tree)
521
522 android_branches = enumerate_android_branches_available(opts.mirror_base)
523 for branch in android_branches:
524 android_tree = path_factory.get_android_tree(branch)
525 if os.path.exists(android_tree):
526 delete_tree(android_tree)
527
528 os.rmdir(os.path.join(opts.work_base, opts.session))
529
530
531def create_parser():
532 parser = argparse.ArgumentParser(
533 formatter_class=argparse.RawDescriptionHelpFormatter, description=__doc__)
534 parser.add_argument(
535 '--mirror_base',
536 metavar='MIRROR_BASE',
537 default=configure.get('MIRROR_BASE', DEFAULT_MIRROR_BASE),
538 help='Directory for mirrors (default: %(default)s)')
539 parser.add_argument(
540 '--work_base',
541 metavar='WORK_BASE',
542 default=configure.get('WORK_BASE', DEFAULT_WORK_BASE),
543 help='Directory for bisection working directories (default: %(default)s)')
544 common.add_common_arguments(parser)
545 subparsers = parser.add_subparsers(
546 dest='command', title='commands', metavar='<command>')
547
548 parser_init = subparsers.add_parser(
549 'init', help='Mirror source trees and create template checkout')
550 parser_init.add_argument(
551 '--chrome', action='store_true', help='init chrome mirror and tree')
552 parser_init.add_argument(
553 '--chromeos', action='store_true', help='init chromeos mirror and tree')
554 parser_init.add_argument(
555 '--android',
556 metavar='BRANCH',
557 action='append',
558 default=[],
559 help='init android mirror and tree of BRANCH')
560 parser_init.add_argument(
561 '--btrfs',
562 action='store_true',
563 help='create btrfs subvolume for source tree')
564 parser_init.set_defaults(func=cmd_init)
565
566 parser_sync = subparsers.add_parser(
567 'sync',
568 help='Sync source trees',
569 description='Sync all if no projects are specified '
570 '(--chrome, --chromeos, or --android)')
571 parser_sync.add_argument(
572 '--chrome', action='store_true', help='sync chrome mirror and tree')
573 parser_sync.add_argument(
574 '--chromeos', action='store_true', help='sync chromeos mirror and tree')
575 parser_sync.add_argument(
576 '--android',
577 metavar='BRANCH',
578 action='append',
579 default=[],
580 help='sync android mirror and tree of BRANCH')
581 parser_sync.set_defaults(func=cmd_sync)
582
583 parser_new = subparsers.add_parser(
584 'new',
585 help='Create new source checkout for bisect',
586 description='Create for all if no projects are specified '
587 '(--chrome, --chromeos, or --android)')
588 parser_new.add_argument('--session', required=True)
589 parser_new.add_argument(
590 '--chrome', action='store_true', help='create chrome checkout')
591 parser_new.add_argument(
592 '--chromeos', action='store_true', help='create chromeos checkout')
593 parser_new.add_argument(
594 '--android',
595 metavar='BRANCH',
596 action='append',
597 default=[],
598 help='create android checkout of BRANCH')
599 parser_new.set_defaults(func=cmd_new)
600
601 parser_list = subparsers.add_parser(
602 'list', help='List existing sessions with source checkout')
603 parser_list.set_defaults(func=cmd_list)
604
605 parser_delete = subparsers.add_parser('delete', help='Delete source checkout')
606 parser_delete.add_argument('--session', required=True)
607 parser_delete.set_defaults(func=cmd_delete)
608
609 return parser
610
611
612def main():
613 common.init()
614 parser = create_parser()
615 opts = parser.parse_args()
616 common.config_logging(opts)
617
618 opts.func(opts)
619
620
621if __name__ == '__main__':
622 main()