blob: 549ddcb111dc7afd72eada7e72e67675c7b1ade2 [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 \\
11 --chromeos_repo_mirror_dir $CHROMEOS_REPO_MIRROR_DIR
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
32from bisect_kit import repo_util
Kuang-che Wubfc4a642018-04-19 11:54:08 +080033
34logger = logging.getLogger(__name__)
35
36
37class ChromeOSRepoDomain(core.BisectDomain):
38 """BisectDomain for ChromeOS code changes."""
39 revtype = staticmethod(cros_util.argtype_cros_version)
40 help = globals()['__doc__']
41
42 @staticmethod
43 def add_init_arguments(parser):
44 parser.add_argument(
45 '--dut',
46 type=cli.argtype_notempty,
47 metavar='DUT',
Kuang-che Wue4bae0b2018-07-19 12:10:14 +080048 default=configure.get('DUT'),
Kuang-che Wubfc4a642018-04-19 11:54:08 +080049 help='DUT address')
50 parser.add_argument(
51 '--board',
52 metavar='BOARD',
53 default=configure.get('BOARD', ''),
54 help='ChromeOS board name')
55 parser.add_argument(
Kuang-che Wuc95fc152018-06-28 18:13:22 +080056 '--chromeos_root',
57 metavar='CHROMEOS_ROOT',
Kuang-che Wubfc4a642018-04-19 11:54:08 +080058 type=cli.argtype_dir_path,
59 required=True,
Kuang-che Wuc95fc152018-06-28 18:13:22 +080060 default=configure.get('CHROMEOS_ROOT'),
Kuang-che Wubfc4a642018-04-19 11:54:08 +080061 help='ChromeOS tree root')
Kuang-che Wue4bae0b2018-07-19 12:10:14 +080062 parser.add_argument(
63 '--chromeos_repo_mirror_dir',
64 type=cli.argtype_dir_path,
65 default=configure.get('CHROMEOS_REPO_MIRROR_DIR', ''),
66 help='ChromeOS repo mirror path')
Kuang-che Wubfc4a642018-04-19 11:54:08 +080067
68 @staticmethod
69 def init(opts):
70 if not opts.dut and not opts.board:
71 raise core.ExecutionFatalError('Neither --dut nor --board is specified')
72
73 if opts.dut:
74 assert cros_util.is_dut(opts.dut)
75 else:
76 logger.info("Tips: unless you don't need to build, otherwise it's "
77 "recommended to specify --dut in bisector instead of "
78 "switcher and evaluator.")
79
80 if not opts.board:
81 opts.board = cros_util.query_dut_board(opts.dut)
82
83 if cros_util.is_cros_short_version(opts.old):
84 opts.old = cros_util.version_to_full(opts.board, opts.old)
85 if cros_util.is_cros_short_version(opts.new):
86 opts.new = cros_util.version_to_full(opts.board, opts.new)
87
88 logger.info('Clean up previous result of "mark as stable"')
Kuang-che Wuc95fc152018-06-28 18:13:22 +080089 repo_util.abandon(opts.chromeos_root, 'stabilizing_branch')
Kuang-che Wubfc4a642018-04-19 11:54:08 +080090
Kuang-che Wuc95fc152018-06-28 18:13:22 +080091 config = dict(
Kuang-che Wue4bae0b2018-07-19 12:10:14 +080092 dut=opts.dut,
93 board=opts.board,
94 chromeos_root=opts.chromeos_root,
95 chromeos_repo_mirror_dir=opts.chromeos_repo_mirror_dir)
Kuang-che Wubfc4a642018-04-19 11:54:08 +080096
Kuang-che Wue4bae0b2018-07-19 12:10:14 +080097 spec_manager = cros_util.ChromeOSSpecManager(config)
98 cache = repo_util.RepoMirror(opts.chromeos_repo_mirror_dir)
99
100 # Make sure all repos in between are cached
101 float_specs = spec_manager.collect_float_spec(opts.old, opts.new)
102 for spec in reversed(float_specs):
103 spec_manager.parse_spec(spec)
104 if cache.are_spec_commits_available(spec):
105 continue
106 spec_manager.sync_disk_state(spec.name)
107
108 code_manager = codechange.CodeManager(opts.chromeos_root, spec_manager,
109 cache)
110 revlist = code_manager.build_revlist(opts.old, opts.new)
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800111 return config, revlist
112
113 def __init__(self, config):
114 self.config = config
115
116 def setenv(self, env, rev):
117 if self.config['dut']:
118 env['DUT'] = self.config['dut']
119 if self.config['board']:
120 env['BOARD'] = self.config['board']
Kuang-che Wuc95fc152018-06-28 18:13:22 +0800121 env['CHROMEOS_ROOT'] = self.config['chromeos_root']
Kuang-che Wue4bae0b2018-07-19 12:10:14 +0800122 env['CHROMEOS_REPO_MIRROR_DIR'] = self.config['chromeos_repo_mirror_dir']
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800123 env['INTRA_REV'] = rev
124
125 def view(self, old, new):
126 print('old', old)
127 print('new', new)
128
Kuang-che Wue4bae0b2018-07-19 12:10:14 +0800129 spec_manager = cros_util.ChromeOSSpecManager(self.config)
130 cache = repo_util.RepoMirror(self.config['chromeos_repo_mirror_dir'])
131 code_manager = codechange.CodeManager(self.config['chromeos_root'],
132 spec_manager, cache)
133 code_manager.view_rev_diff(old, new)
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800134
135
136if __name__ == '__main__':
137 cli.BisectorCommandLine(ChromeOSRepoDomain).main()