blob: 2c129003dd3d040b666b795aaaa280a8489a9b66 [file] [log] [blame]
Kuang-che Wu708310b2018-03-28 17:24:34 +08001#!/usr/bin/env python2
Kuang-che Wu6e4beca2018-06-27 17:45:02 +08002# -*- coding: utf-8 -*-
Kuang-che Wu708310b2018-03-28 17:24:34 +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"""Android bisector to bisect a range of android build id.
7
8Example:
9 $ ./bisect_android_build_id.py init --old rev1 --new rev2 --dut DUT
10 $ ./bisect_android_build_id.py config switch ./switch_arc_prebuilt.py
11 $ ./bisect_android_build_id.py config eval ./eval-manually.sh
12 $ ./bisect_android_build_id.py run
13
14When running switcher and evaluator, following environment variables
15will be set:
16 ANDROID_BRANCH (e.g. git_mnc-dr-arc-dev),
17 ANDROID_FLAVOR (e.g. cheets_x86-user),
18 ANDROID_BUILD_ID (e.g. 9876543),
Kuang-che Wu708310b2018-03-28 17:24:34 +080019 DUT (e.g. samus-dut, if available).
20"""
21
22from __future__ import print_function
23import logging
24
25from bisect_kit import android_util
26from bisect_kit import arc_util
Kuang-che Wu2526a672019-09-10 16:23:59 +080027from bisect_kit import bisector_cli
Kuang-che Wu708310b2018-03-28 17:24:34 +080028from bisect_kit import cli
29from bisect_kit import configure
30from bisect_kit import core
31from bisect_kit import cros_util
32
33logger = logging.getLogger(__name__)
34
35
36class AndroidBuildIDDomain(core.BisectDomain):
37 """BisectDomain for Android build IDs."""
38 revtype = staticmethod(android_util.argtype_android_build_id)
39 help = globals()['__doc__']
40
41 @staticmethod
42 def add_init_arguments(parser):
43 parser.add_argument(
44 '--branch',
45 metavar='ANDROID_BRANCH',
46 default=configure.get('ANDROID_BRANCH'),
47 help='git branch like "git_mnc-dr-arc-dev"')
48 parser.add_argument(
49 '--flavor',
50 metavar='ANDROID_FLAVOR',
51 default=configure.get('ANDROID_FLAVOR'),
52 help='example: cheets_x86-user')
53 parser.add_argument(
54 '--only_good_build',
55 action='store_true',
56 help='Bisect only good builds. '
57 'This flag is only needed if weird builds blocked bisection')
58
59 # Only used for Android on ChromeOS.
60 parser.add_argument(
61 '--dut',
62 type=cli.argtype_notempty,
63 metavar='DUT',
64 default=configure.get('DUT'),
65 help='For ChromeOS, address of DUT (Device Under Test)')
Kuang-che Wu708310b2018-03-28 17:24:34 +080066
67 @staticmethod
68 def init(opts):
69 if opts.dut:
70 assert cros_util.is_dut(opts.dut)
71
72 if not opts.flavor:
73 assert opts.dut
74 opts.flavor = arc_util.query_flavor(opts.dut)
75
76 if not opts.branch:
77 assert opts.dut
78 board = cros_util.query_dut_board(opts.dut)
79 version = cros_util.query_dut_short_version(opts.dut)
80 opts.branch = cros_util.query_android_branch(board, version)
81 assert opts.branch
82
Kuang-che Wu94ef56e2019-01-15 21:17:42 +080083 config = dict(branch=opts.branch, flavor=opts.flavor)
Kuang-che Wu708310b2018-03-28 17:24:34 +080084 if opts.dut:
85 config['dut'] = opts.dut
86
Kuang-che Wu0a902f42019-01-21 18:58:32 +080087 revlist = android_util.get_build_ids_between(opts.branch, opts.flavor,
88 opts.old, opts.new)
Kuang-che Wu708310b2018-03-28 17:24:34 +080089
90 if opts.only_good_build:
91 revlist = [
92 bid for bid in revlist
93 if android_util.is_good_build(opts.branch, opts.flavor, bid)
94 ]
95
96 return config, revlist
97
98 def __init__(self, config):
99 self.config = config
100
101 def setenv(self, env, rev):
102 env['ANDROID_BRANCH'] = self.config['branch']
103 env['ANDROID_FLAVOR'] = self.config['flavor']
104 env['ANDROID_BUILD_ID'] = rev
105 if self.config.get('dut'):
106 env['DUT'] = self.config['dut']
Kuang-che Wu708310b2018-03-28 17:24:34 +0800107
Kuang-che Wue80bb872018-11-15 19:45:25 +0800108 def fill_candidate_summary(self, summary, interesting_indexes):
Kuang-che Wue80bb872018-11-15 19:45:25 +0800109 url_template = ('https://android-build.googleplex.com/'
110 'builds/{new}/branches/%s/targets/%s/cls?end={old}') % (
111 self.config['branch'], self.config['flavor'])
Kuang-che Wu948a79c2019-06-19 19:13:56 +0800112 if 'current_range' in summary:
113 old, new = summary['current_range']
114 summary['links'] = [
115 {
116 'name': 'change_list',
117 'url': url_template.format(old=old, new=new),
Kuang-che Wu948a79c2019-06-19 19:13:56 +0800118 },
119 ]
Kuang-che Wue80bb872018-11-15 19:45:25 +0800120
121 for i in interesting_indexes:
122 if i == 0:
123 continue
124 rev_info = summary['rev_info'][i]
125 rev_info.update({
126 'actions': [{
127 'link':
128 url_template.format(
129 old=summary['rev_info'][i - 1]['rev'],
130 new=rev_info['rev']),
131 }],
132 })
Kuang-che Wu708310b2018-03-28 17:24:34 +0800133
134
135if __name__ == '__main__':
Kuang-che Wu2526a672019-09-10 16:23:59 +0800136 bisector_cli.BisectorCommandLine(AndroidBuildIDDomain).main()