blob: 896fe5e70cdd4e605443e3b250ae22c1b465e531 [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 Wuc95fc152018-06-28 18:13:22 +08009 $ ./bisect_cros_repo.py init --old rev1 --new rev2 \
10 --chromeos_root ~/chromiumos
Kuang-che Wubfc4a642018-04-19 11:54:08 +080011 $ ./bisect_cros_repo.py config switch ./switch_cros_localbuild.py
12 $ ./bisect_cros_repo.py config eval ./eval-manually.sh
13 $ ./bisect_cros_repo.py run
14
15When running switcher and evaluator, following environment variables
16will be set:
17 BOARD (e.g. samus),
18 DUT (e.g. samus-dut),
19 INTRA_REV (e.g. 9901.0.0,9902.0.0+3), and
Kuang-che Wuc95fc152018-06-28 18:13:22 +080020 CHROMEOS_ROOT (e.g. ~/chromiumos).
Kuang-che Wubfc4a642018-04-19 11:54:08 +080021"""
22
23from __future__ import print_function
24import logging
25
26from bisect_kit import cli
Kuang-che Wue4bae0b2018-07-19 12:10:14 +080027from bisect_kit import codechange
Kuang-che Wubfc4a642018-04-19 11:54:08 +080028from bisect_kit import configure
29from bisect_kit import core
Kuang-che Wue4bae0b2018-07-19 12:10:14 +080030from bisect_kit import cros_util
31from bisect_kit import repo_util
Kuang-che Wubfc4a642018-04-19 11:54:08 +080032
33logger = logging.getLogger(__name__)
34
35
36class ChromeOSRepoDomain(core.BisectDomain):
37 """BisectDomain for ChromeOS code changes."""
38 revtype = staticmethod(cros_util.argtype_cros_version)
39 help = globals()['__doc__']
40
41 @staticmethod
42 def add_init_arguments(parser):
43 parser.add_argument(
44 '--dut',
45 type=cli.argtype_notempty,
46 metavar='DUT',
Kuang-che Wue4bae0b2018-07-19 12:10:14 +080047 default=configure.get('DUT'),
Kuang-che Wubfc4a642018-04-19 11:54:08 +080048 help='DUT address')
49 parser.add_argument(
50 '--board',
51 metavar='BOARD',
52 default=configure.get('BOARD', ''),
53 help='ChromeOS board name')
54 parser.add_argument(
Kuang-che Wuc95fc152018-06-28 18:13:22 +080055 '--chromeos_root',
56 metavar='CHROMEOS_ROOT',
Kuang-che Wubfc4a642018-04-19 11:54:08 +080057 type=cli.argtype_dir_path,
58 required=True,
Kuang-che Wuc95fc152018-06-28 18:13:22 +080059 default=configure.get('CHROMEOS_ROOT'),
Kuang-che Wubfc4a642018-04-19 11:54:08 +080060 help='ChromeOS tree root')
Kuang-che Wue4bae0b2018-07-19 12:10:14 +080061 parser.add_argument(
62 '--chromeos_repo_mirror_dir',
63 type=cli.argtype_dir_path,
64 default=configure.get('CHROMEOS_REPO_MIRROR_DIR', ''),
65 help='ChromeOS repo mirror path')
Kuang-che Wubfc4a642018-04-19 11:54:08 +080066
67 @staticmethod
68 def init(opts):
69 if not opts.dut and not opts.board:
70 raise core.ExecutionFatalError('Neither --dut nor --board is specified')
71
72 if opts.dut:
73 assert cros_util.is_dut(opts.dut)
74 else:
75 logger.info("Tips: unless you don't need to build, otherwise it's "
76 "recommended to specify --dut in bisector instead of "
77 "switcher and evaluator.")
78
79 if not opts.board:
80 opts.board = cros_util.query_dut_board(opts.dut)
81
82 if cros_util.is_cros_short_version(opts.old):
83 opts.old = cros_util.version_to_full(opts.board, opts.old)
84 if cros_util.is_cros_short_version(opts.new):
85 opts.new = cros_util.version_to_full(opts.board, opts.new)
86
87 logger.info('Clean up previous result of "mark as stable"')
Kuang-che Wuc95fc152018-06-28 18:13:22 +080088 repo_util.abandon(opts.chromeos_root, 'stabilizing_branch')
Kuang-che Wubfc4a642018-04-19 11:54:08 +080089
Kuang-che Wuc95fc152018-06-28 18:13:22 +080090 config = dict(
Kuang-che Wue4bae0b2018-07-19 12:10:14 +080091 dut=opts.dut,
92 board=opts.board,
93 chromeos_root=opts.chromeos_root,
94 chromeos_repo_mirror_dir=opts.chromeos_repo_mirror_dir)
Kuang-che Wubfc4a642018-04-19 11:54:08 +080095
Kuang-che Wue4bae0b2018-07-19 12:10:14 +080096 spec_manager = cros_util.ChromeOSSpecManager(config)
97 cache = repo_util.RepoMirror(opts.chromeos_repo_mirror_dir)
98
99 # Make sure all repos in between are cached
100 float_specs = spec_manager.collect_float_spec(opts.old, opts.new)
101 for spec in reversed(float_specs):
102 spec_manager.parse_spec(spec)
103 if cache.are_spec_commits_available(spec):
104 continue
105 spec_manager.sync_disk_state(spec.name)
106
107 code_manager = codechange.CodeManager(opts.chromeos_root, spec_manager,
108 cache)
109 revlist = code_manager.build_revlist(opts.old, opts.new)
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800110 return config, revlist
111
112 def __init__(self, config):
113 self.config = config
114
115 def setenv(self, env, rev):
116 if self.config['dut']:
117 env['DUT'] = self.config['dut']
118 if self.config['board']:
119 env['BOARD'] = self.config['board']
Kuang-che Wuc95fc152018-06-28 18:13:22 +0800120 env['CHROMEOS_ROOT'] = self.config['chromeos_root']
Kuang-che Wue4bae0b2018-07-19 12:10:14 +0800121 env['CHROMEOS_REPO_MIRROR_DIR'] = self.config['chromeos_repo_mirror_dir']
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800122 env['INTRA_REV'] = rev
123
124 def view(self, old, new):
125 print('old', old)
126 print('new', new)
127
Kuang-che Wue4bae0b2018-07-19 12:10:14 +0800128 spec_manager = cros_util.ChromeOSSpecManager(self.config)
129 cache = repo_util.RepoMirror(self.config['chromeos_repo_mirror_dir'])
130 code_manager = codechange.CodeManager(self.config['chromeos_root'],
131 spec_manager, cache)
132 code_manager.view_rev_diff(old, new)
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800133
134
135if __name__ == '__main__':
136 cli.BisectorCommandLine(ChromeOSRepoDomain).main()