Kuang-che Wu | 875c89a | 2020-01-08 14:30:55 +0800 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Kuang-che Wu | 6e4beca | 2018-06-27 17:45:02 +0800 | [diff] [blame] | 2 | # -*- coding: utf-8 -*- |
Kuang-che Wu | acb6efd | 2018-04-25 18:52:58 +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 | """Switcher for Android container localbuild for ChromeOS bisecting.""" |
| 7 | |
| 8 | from __future__ import print_function |
| 9 | import argparse |
| 10 | import logging |
| 11 | |
| 12 | from bisect_kit import android_util |
Kuang-che Wu | acb6efd | 2018-04-25 18:52:58 +0800 | [diff] [blame] | 13 | from bisect_kit import arc_util |
Kuang-che Wu | e4bae0b | 2018-07-19 12:10:14 +0800 | [diff] [blame] | 14 | from bisect_kit import cli |
| 15 | from bisect_kit import codechange |
Kuang-che Wu | acb6efd | 2018-04-25 18:52:58 +0800 | [diff] [blame] | 16 | from bisect_kit import common |
| 17 | from bisect_kit import configure |
Kuang-che Wu | 0ebbf7c | 2019-08-28 18:19:19 +0800 | [diff] [blame] | 18 | from bisect_kit import errors |
Kuang-che Wu | fb55310 | 2018-10-02 18:14:29 +0800 | [diff] [blame] | 19 | from bisect_kit import locking |
Kuang-che Wu | e4bae0b | 2018-07-19 12:10:14 +0800 | [diff] [blame] | 20 | from bisect_kit import repo_util |
Kuang-che Wu | acb6efd | 2018-04-25 18:52:58 +0800 | [diff] [blame] | 21 | |
| 22 | logger = logging.getLogger(__name__) |
| 23 | |
| 24 | |
| 25 | def create_argument_parser(): |
Kuang-che Wu | d2d6e41 | 2021-01-28 16:26:41 +0800 | [diff] [blame] | 26 | parents = [common.common_argument_parser, common.session_optional_parser] |
| 27 | parser = argparse.ArgumentParser(parents=parents) |
Kuang-che Wu | fe1e88a | 2019-09-10 21:52:25 +0800 | [diff] [blame] | 28 | cli.patching_argparser_exit(parser) |
Kuang-che Wu | acb6efd | 2018-04-25 18:52:58 +0800 | [diff] [blame] | 29 | parser.add_argument( |
Kuang-che Wu | 0ebbf7c | 2019-08-28 18:19:19 +0800 | [diff] [blame] | 30 | '--dut', |
Kuang-che Wu | acb6efd | 2018-04-25 18:52:58 +0800 | [diff] [blame] | 31 | type=cli.argtype_notempty, |
| 32 | metavar='DUT', |
Kuang-che Wu | 0ebbf7c | 2019-08-28 18:19:19 +0800 | [diff] [blame] | 33 | default=configure.get('DUT'), |
Kuang-che Wu | acb6efd | 2018-04-25 18:52:58 +0800 | [diff] [blame] | 34 | help='DUT address') |
| 35 | parser.add_argument( |
| 36 | 'rev', |
| 37 | nargs='?', |
| 38 | type=cli.argtype_notempty, |
| 39 | metavar='INTRA_REV', |
| 40 | default=configure.get('INTRA_REV', ''), |
| 41 | help='Android build id, or bisecting intra version number') |
| 42 | parser.add_argument( |
| 43 | '--android_root', |
Kuang-che Wu | d1d45b4 | 2018-07-05 00:46:45 +0800 | [diff] [blame] | 44 | type=cli.argtype_dir_path, |
Kuang-che Wu | acb6efd | 2018-04-25 18:52:58 +0800 | [diff] [blame] | 45 | metavar='ANDROID_ROOT', |
| 46 | default=configure.get('ANDROID_ROOT', ''), |
| 47 | help='Android tree root') |
| 48 | parser.add_argument( |
Kuang-che Wu | d8fc957 | 2018-10-03 21:00:41 +0800 | [diff] [blame] | 49 | '--android_mirror', |
Kuang-che Wu | d1d45b4 | 2018-07-05 00:46:45 +0800 | [diff] [blame] | 50 | type=cli.argtype_dir_path, |
Kuang-che Wu | d8fc957 | 2018-10-03 21:00:41 +0800 | [diff] [blame] | 51 | default=configure.get('ANDROID_MIRROR', ''), |
Kuang-che Wu | d1d45b4 | 2018-07-05 00:46:45 +0800 | [diff] [blame] | 52 | help='Android repo mirror path') |
| 53 | parser.add_argument( |
Kuang-che Wu | acb6efd | 2018-04-25 18:52:58 +0800 | [diff] [blame] | 54 | '--flavor', |
| 55 | metavar='ANDROID_FLAVOR', |
| 56 | default=configure.get('ANDROID_FLAVOR'), |
| 57 | help='example: cheets_x86-user') |
| 58 | parser.add_argument( |
Kuang-che Wu | a2fe988 | 2018-09-05 17:16:31 +0800 | [diff] [blame] | 59 | '--nobuild', |
| 60 | action='store_true', |
| 61 | help='Sync source code only; do not build; imply --nodeploy') |
| 62 | parser.add_argument( |
| 63 | '--nodeploy', action='store_true', help='Do not deploy after build') |
Kuang-che Wu | acb6efd | 2018-04-25 18:52:58 +0800 | [diff] [blame] | 64 | return parser |
| 65 | |
| 66 | |
| 67 | def switch(opts): |
Kuang-che Wu | d1d45b4 | 2018-07-05 00:46:45 +0800 | [diff] [blame] | 68 | config = dict( |
| 69 | android_root=opts.android_root, |
| 70 | flavor=opts.flavor, |
Kuang-che Wu | d8fc957 | 2018-10-03 21:00:41 +0800 | [diff] [blame] | 71 | android_mirror=opts.android_mirror) |
Kuang-che Wu | d1d45b4 | 2018-07-05 00:46:45 +0800 | [diff] [blame] | 72 | spec_manager = android_util.AndroidSpecManager(config) |
Kuang-che Wu | d8fc957 | 2018-10-03 21:00:41 +0800 | [diff] [blame] | 73 | cache = repo_util.RepoMirror(opts.android_mirror) |
Kuang-che Wu | d1d45b4 | 2018-07-05 00:46:45 +0800 | [diff] [blame] | 74 | code_manager = codechange.CodeManager(opts.android_root, spec_manager, cache) |
| 75 | |
| 76 | logger.info('switch source code') |
| 77 | code_manager.switch(opts.rev) |
Kuang-che Wu | acb6efd | 2018-04-25 18:52:58 +0800 | [diff] [blame] | 78 | |
Kuang-che Wu | a2fe988 | 2018-09-05 17:16:31 +0800 | [diff] [blame] | 79 | if opts.nobuild: |
| 80 | return |
| 81 | |
Kuang-che Wu | acb6efd | 2018-04-25 18:52:58 +0800 | [diff] [blame] | 82 | logger.info('build') |
| 83 | # TODO(kcwu): use lower job count for non distributed compilation. |
Kuang-che Wu | fb55310 | 2018-10-02 18:14:29 +0800 | [diff] [blame] | 84 | with locking.lock_file(locking.LOCK_FILE_FOR_BUILD): |
| 85 | android_util.lunch(opts.android_root, opts.flavor, 'm', '-j1000') |
Kuang-che Wu | acb6efd | 2018-04-25 18:52:58 +0800 | [diff] [blame] | 86 | |
| 87 | if not opts.nodeploy: |
| 88 | logger.info('deploy') |
| 89 | arc_util.push_localbuild_to_device(opts.android_root, opts.dut, opts.flavor) |
| 90 | |
| 91 | |
Kuang-che Wu | fe1e88a | 2019-09-10 21:52:25 +0800 | [diff] [blame] | 92 | @cli.fatal_error_handler |
Kuang-che Wu | acb6efd | 2018-04-25 18:52:58 +0800 | [diff] [blame] | 93 | def main(args=None): |
| 94 | common.init() |
| 95 | parser = create_argument_parser() |
| 96 | opts = parser.parse_args(args) |
| 97 | common.config_logging(opts) |
| 98 | |
Kuang-che Wu | 0ebbf7c | 2019-08-28 18:19:19 +0800 | [diff] [blame] | 99 | if not opts.dut: |
| 100 | if not opts.nodeploy: |
| 101 | raise errors.ArgumentError('--dut', |
| 102 | 'DUT can be omitted only if --nodeploy') |
| 103 | if not opts.flavor: |
| 104 | raise errors.ArgumentError('--flavor', |
| 105 | 'flavor must be specified if no --dut') |
| 106 | |
Kuang-che Wu | acb6efd | 2018-04-25 18:52:58 +0800 | [diff] [blame] | 107 | if not opts.flavor: |
Kuang-che Wu | acb6efd | 2018-04-25 18:52:58 +0800 | [diff] [blame] | 108 | opts.flavor = arc_util.query_flavor(opts.dut) |
| 109 | assert opts.flavor |
| 110 | logger.info('use flavor=%s', opts.flavor) |
| 111 | |
| 112 | switch(opts) |
| 113 | |
| 114 | |
| 115 | if __name__ == '__main__': |
| 116 | main() |