Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 1 | #!/usr/bin/env python2 |
Kuang-che Wu | 6e4beca | 2018-06-27 17:45:02 +0800 | [diff] [blame] | 2 | # -*- coding: utf-8 -*- |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 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 | """ChromeOS bisector to bisect local build commits. |
| 7 | |
| 8 | Example: |
Kuang-che Wu | c95fc15 | 2018-06-28 18:13:22 +0800 | [diff] [blame^] | 9 | $ ./bisect_cros_repo.py init --old rev1 --new rev2 \ |
| 10 | --chromeos_root ~/chromiumos |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 11 | $ ./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 | |
| 15 | When running switcher and evaluator, following environment variables |
| 16 | will 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 Wu | c95fc15 | 2018-06-28 18:13:22 +0800 | [diff] [blame^] | 20 | CHROMEOS_ROOT (e.g. ~/chromiumos). |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 21 | """ |
| 22 | |
| 23 | from __future__ import print_function |
| 24 | import logging |
| 25 | |
| 26 | from bisect_kit import cli |
| 27 | from bisect_kit import cros_util |
| 28 | from bisect_kit import repo_util |
| 29 | from bisect_kit import configure |
| 30 | from bisect_kit import core |
| 31 | |
| 32 | logger = logging.getLogger(__name__) |
| 33 | |
| 34 | |
| 35 | class ChromeOSRepoDomain(core.BisectDomain): |
| 36 | """BisectDomain for ChromeOS code changes.""" |
| 37 | revtype = staticmethod(cros_util.argtype_cros_version) |
| 38 | help = globals()['__doc__'] |
| 39 | |
| 40 | @staticmethod |
| 41 | def add_init_arguments(parser): |
| 42 | parser.add_argument( |
| 43 | '--dut', |
| 44 | type=cli.argtype_notempty, |
| 45 | metavar='DUT', |
| 46 | default=configure.get('DUT', ''), |
| 47 | help='DUT address') |
| 48 | parser.add_argument( |
| 49 | '--board', |
| 50 | metavar='BOARD', |
| 51 | default=configure.get('BOARD', ''), |
| 52 | help='ChromeOS board name') |
| 53 | parser.add_argument( |
Kuang-che Wu | c95fc15 | 2018-06-28 18:13:22 +0800 | [diff] [blame^] | 54 | '--chromeos_root', |
| 55 | metavar='CHROMEOS_ROOT', |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 56 | type=cli.argtype_dir_path, |
| 57 | required=True, |
Kuang-che Wu | c95fc15 | 2018-06-28 18:13:22 +0800 | [diff] [blame^] | 58 | default=configure.get('CHROMEOS_ROOT'), |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 59 | help='ChromeOS tree root') |
| 60 | |
| 61 | @staticmethod |
| 62 | def init(opts): |
| 63 | if not opts.dut and not opts.board: |
| 64 | raise core.ExecutionFatalError('Neither --dut nor --board is specified') |
| 65 | |
| 66 | if opts.dut: |
| 67 | assert cros_util.is_dut(opts.dut) |
| 68 | else: |
| 69 | logger.info("Tips: unless you don't need to build, otherwise it's " |
| 70 | "recommended to specify --dut in bisector instead of " |
| 71 | "switcher and evaluator.") |
| 72 | |
| 73 | if not opts.board: |
| 74 | opts.board = cros_util.query_dut_board(opts.dut) |
| 75 | |
| 76 | if cros_util.is_cros_short_version(opts.old): |
| 77 | opts.old = cros_util.version_to_full(opts.board, opts.old) |
| 78 | if cros_util.is_cros_short_version(opts.new): |
| 79 | opts.new = cros_util.version_to_full(opts.board, opts.new) |
| 80 | |
| 81 | logger.info('Clean up previous result of "mark as stable"') |
Kuang-che Wu | c95fc15 | 2018-06-28 18:13:22 +0800 | [diff] [blame^] | 82 | repo_util.abandon(opts.chromeos_root, 'stabilizing_branch') |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 83 | |
Kuang-che Wu | c95fc15 | 2018-06-28 18:13:22 +0800 | [diff] [blame^] | 84 | config = dict( |
| 85 | dut=opts.dut, board=opts.board, chromeos_root=opts.chromeos_root) |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 86 | |
| 87 | manifest_manager = cros_util.ChromeOSManifestManager(config) |
Kuang-che Wu | c95fc15 | 2018-06-28 18:13:22 +0800 | [diff] [blame^] | 88 | dependency_manager = repo_util.DependencyManager(opts.chromeos_root, |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 89 | manifest_manager) |
| 90 | revlist = dependency_manager.get_revlist(opts.old, opts.new) |
| 91 | return config, revlist |
| 92 | |
| 93 | def __init__(self, config): |
| 94 | self.config = config |
| 95 | |
| 96 | def setenv(self, env, rev): |
| 97 | if self.config['dut']: |
| 98 | env['DUT'] = self.config['dut'] |
| 99 | if self.config['board']: |
| 100 | env['BOARD'] = self.config['board'] |
Kuang-che Wu | c95fc15 | 2018-06-28 18:13:22 +0800 | [diff] [blame^] | 101 | env['CHROMEOS_ROOT'] = self.config['chromeos_root'] |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 102 | env['INTRA_REV'] = rev |
| 103 | |
| 104 | def view(self, old, new): |
| 105 | print('old', old) |
| 106 | print('new', new) |
| 107 | |
| 108 | manifest_manager = cros_util.ChromeOSManifestManager(self.config) |
Kuang-che Wu | c95fc15 | 2018-06-28 18:13:22 +0800 | [diff] [blame^] | 109 | dependency_manager = repo_util.DependencyManager( |
| 110 | self.config['chromeos_root'], manifest_manager) |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 111 | dependency_manager.view_rev_diff(old, new) |
| 112 | |
| 113 | |
| 114 | if __name__ == '__main__': |
| 115 | cli.BisectorCommandLine(ChromeOSRepoDomain).main() |