blob: 54b315b21c9f27685f241d66d914f2a9d4a30f8c [file] [log] [blame]
Kuang-che Wubfc4a642018-04-19 11:54:08 +08001#!/usr/bin/env python2
Kuang-che Wu6e4beca2018-06-27 17:45:02 +08002# -*- coding: utf-8 -*-
Kuang-che Wubfc4a642018-04-19 11:54:08 +08003# 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"""ChromeOS bisector to bisect local build commits.
7
8Example:
Kuang-che Wu94f48e52018-07-25 15:28:31 +08009 $ ./bisect_cros_repo.py init --old rev1 --new rev2 \\
10 --chromeos_root ~/chromiumos \\
Kuang-che Wud8fc9572018-10-03 21:00:41 +080011 --chromeos_mirror $CHROMEOS_MIRROR
Kuang-che Wubfc4a642018-04-19 11:54:08 +080012 $ ./bisect_cros_repo.py config switch ./switch_cros_localbuild.py
13 $ ./bisect_cros_repo.py config eval ./eval-manually.sh
14 $ ./bisect_cros_repo.py run
15
16When running switcher and evaluator, following environment variables
17will be set:
18 BOARD (e.g. samus),
19 DUT (e.g. samus-dut),
20 INTRA_REV (e.g. 9901.0.0,9902.0.0+3), and
Kuang-che Wuc95fc152018-06-28 18:13:22 +080021 CHROMEOS_ROOT (e.g. ~/chromiumos).
Kuang-che Wubfc4a642018-04-19 11:54:08 +080022"""
23
24from __future__ import print_function
25import logging
26
27from bisect_kit import cli
Kuang-che Wue4bae0b2018-07-19 12:10:14 +080028from bisect_kit import codechange
Kuang-che Wubfc4a642018-04-19 11:54:08 +080029from bisect_kit import configure
30from bisect_kit import core
Kuang-che Wue4bae0b2018-07-19 12:10:14 +080031from bisect_kit import cros_util
Kuang-che Wue121fae2018-11-09 16:18:39 +080032from bisect_kit import errors
Kuang-che Wue4bae0b2018-07-19 12:10:14 +080033from bisect_kit import repo_util
Kuang-che Wubfc4a642018-04-19 11:54:08 +080034
35logger = logging.getLogger(__name__)
36
37
38class ChromeOSRepoDomain(core.BisectDomain):
39 """BisectDomain for ChromeOS code changes."""
40 revtype = staticmethod(cros_util.argtype_cros_version)
Kuang-che Wu752228c2018-09-05 13:54:22 +080041 intra_revtype = staticmethod(
42 codechange.argtype_intra_rev(cros_util.argtype_cros_version))
Kuang-che Wubfc4a642018-04-19 11:54:08 +080043 help = globals()['__doc__']
44
45 @staticmethod
46 def add_init_arguments(parser):
47 parser.add_argument(
48 '--dut',
49 type=cli.argtype_notempty,
50 metavar='DUT',
Kuang-che Wue4bae0b2018-07-19 12:10:14 +080051 default=configure.get('DUT'),
Kuang-che Wubfc4a642018-04-19 11:54:08 +080052 help='DUT address')
53 parser.add_argument(
54 '--board',
55 metavar='BOARD',
56 default=configure.get('BOARD', ''),
57 help='ChromeOS board name')
58 parser.add_argument(
Kuang-che Wuc95fc152018-06-28 18:13:22 +080059 '--chromeos_root',
60 metavar='CHROMEOS_ROOT',
Kuang-che Wubfc4a642018-04-19 11:54:08 +080061 type=cli.argtype_dir_path,
62 required=True,
Kuang-che Wuc95fc152018-06-28 18:13:22 +080063 default=configure.get('CHROMEOS_ROOT'),
Kuang-che Wubfc4a642018-04-19 11:54:08 +080064 help='ChromeOS tree root')
Kuang-che Wue4bae0b2018-07-19 12:10:14 +080065 parser.add_argument(
Kuang-che Wud8fc9572018-10-03 21:00:41 +080066 '--chromeos_mirror',
Kuang-che Wue4bae0b2018-07-19 12:10:14 +080067 type=cli.argtype_dir_path,
Kuang-che Wud8fc9572018-10-03 21:00:41 +080068 default=configure.get('CHROMEOS_MIRROR', ''),
Kuang-che Wue4bae0b2018-07-19 12:10:14 +080069 help='ChromeOS repo mirror path')
Kuang-che Wubfc4a642018-04-19 11:54:08 +080070
71 @staticmethod
72 def init(opts):
73 if not opts.dut and not opts.board:
Kuang-che Wue121fae2018-11-09 16:18:39 +080074 raise errors.ArgumentError('--dut and --board', 'Neither is specified')
Kuang-che Wubfc4a642018-04-19 11:54:08 +080075
76 if opts.dut:
77 assert cros_util.is_dut(opts.dut)
78 else:
79 logger.info("Tips: unless you don't need to build, otherwise it's "
80 "recommended to specify --dut in bisector instead of "
81 "switcher and evaluator.")
82
83 if not opts.board:
84 opts.board = cros_util.query_dut_board(opts.dut)
85
86 if cros_util.is_cros_short_version(opts.old):
87 opts.old = cros_util.version_to_full(opts.board, opts.old)
88 if cros_util.is_cros_short_version(opts.new):
89 opts.new = cros_util.version_to_full(opts.board, opts.new)
90
91 logger.info('Clean up previous result of "mark as stable"')
Kuang-che Wuc95fc152018-06-28 18:13:22 +080092 repo_util.abandon(opts.chromeos_root, 'stabilizing_branch')
Kuang-che Wubfc4a642018-04-19 11:54:08 +080093
Kuang-che Wuc95fc152018-06-28 18:13:22 +080094 config = dict(
Kuang-che Wue4bae0b2018-07-19 12:10:14 +080095 dut=opts.dut,
96 board=opts.board,
97 chromeos_root=opts.chromeos_root,
Kuang-che Wud8fc9572018-10-03 21:00:41 +080098 chromeos_mirror=opts.chromeos_mirror)
Kuang-che Wubfc4a642018-04-19 11:54:08 +080099
Kuang-che Wue4bae0b2018-07-19 12:10:14 +0800100 spec_manager = cros_util.ChromeOSSpecManager(config)
Kuang-che Wud8fc9572018-10-03 21:00:41 +0800101 cache = repo_util.RepoMirror(opts.chromeos_mirror)
Kuang-che Wue4bae0b2018-07-19 12:10:14 +0800102
103 # Make sure all repos in between are cached
104 float_specs = spec_manager.collect_float_spec(opts.old, opts.new)
105 for spec in reversed(float_specs):
106 spec_manager.parse_spec(spec)
107 if cache.are_spec_commits_available(spec):
108 continue
109 spec_manager.sync_disk_state(spec.name)
110
111 code_manager = codechange.CodeManager(opts.chromeos_root, spec_manager,
112 cache)
113 revlist = code_manager.build_revlist(opts.old, opts.new)
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800114 return config, revlist
115
116 def __init__(self, config):
117 self.config = config
118
119 def setenv(self, env, rev):
120 if self.config['dut']:
121 env['DUT'] = self.config['dut']
122 if self.config['board']:
123 env['BOARD'] = self.config['board']
Kuang-che Wuc95fc152018-06-28 18:13:22 +0800124 env['CHROMEOS_ROOT'] = self.config['chromeos_root']
Kuang-che Wud8fc9572018-10-03 21:00:41 +0800125 env['CHROMEOS_MIRROR'] = self.config['chromeos_mirror']
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800126 env['INTRA_REV'] = rev
127
Kuang-che Wu81aecc02018-10-31 19:37:32 +0800128 def view(self, revlist, old, new):
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800129 print('old', old)
130 print('new', new)
131
Kuang-che Wue4bae0b2018-07-19 12:10:14 +0800132 spec_manager = cros_util.ChromeOSSpecManager(self.config)
Kuang-che Wud8fc9572018-10-03 21:00:41 +0800133 cache = repo_util.RepoMirror(self.config['chromeos_mirror'])
Kuang-che Wue4bae0b2018-07-19 12:10:14 +0800134 code_manager = codechange.CodeManager(self.config['chromeos_root'],
135 spec_manager, cache)
Kuang-che Wu81aecc02018-10-31 19:37:32 +0800136 code_manager.view_rev_diff(revlist, old, new)
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800137
138
139if __name__ == '__main__':
140 cli.BisectorCommandLine(ChromeOSRepoDomain).main()