Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 1 | # Copyright 2018 The Chromium OS Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """setup_board builds the sysroot for a board. |
| 6 | |
| 7 | The setup_board process includes the simple directory creations, installs |
| 8 | several configuration files, sets up portage command wrappers and configs, |
| 9 | and installs the toolchain and some core dependency packages (e.g. kernel |
| 10 | headers, gcc-libs). |
| 11 | """ |
| 12 | |
Alex Klein | 0754704 | 2021-03-12 11:47:03 -0700 | [diff] [blame] | 13 | import argparse |
Mike Frysinger | 6a2b0f2 | 2020-02-20 13:34:07 -0500 | [diff] [blame] | 14 | |
Alex Klein | 2960c75 | 2020-03-09 13:43:38 -0600 | [diff] [blame] | 15 | from chromite.lib import build_target_lib |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 16 | from chromite.lib import commandline |
Alex Klein | da35fcf | 2019-03-07 16:01:15 -0700 | [diff] [blame] | 17 | from chromite.lib import cros_build_lib |
Mike Frysinger | c14d9a0 | 2019-08-26 15:44:16 -0400 | [diff] [blame] | 18 | from chromite.lib import portage_util |
Alex Klein | da35fcf | 2019-03-07 16:01:15 -0700 | [diff] [blame] | 19 | from chromite.service import sysroot |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 20 | |
| 21 | |
| 22 | def GetParser(): |
| 23 | """Build the argument parser.""" |
Alex Klein | 6893e71 | 2019-01-16 14:43:29 -0700 | [diff] [blame] | 24 | # TODO(crbug.com/922144) Remove underscore separated arguments and the |
| 25 | # deprecated message after 2019-06-01. |
| 26 | deprecated = 'Argument will be removed 2019-06-01. Use %s instead.' |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 27 | parser = commandline.ArgumentParser(description=__doc__) |
| 28 | |
Alex Klein | 3ac0388 | 2021-02-22 13:23:16 -0700 | [diff] [blame] | 29 | parser.add_argument('-b', '--board', '--build-target', required=True, |
| 30 | dest='board', help='The name of the board to set up.') |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 31 | parser.add_argument('--default', action='store_true', default=False, |
| 32 | help='Set the board to the default board in your chroot.') |
| 33 | parser.add_argument('--force', action='store_true', default=False, |
| 34 | help='Force re-creating the board root.') |
| 35 | # The positive and negative versions of the arguments are used. |
| 36 | # TODO(saklein) Simplify usages to a single version of the argument. |
| 37 | parser.add_argument('--usepkg', action='store_true', default=True, |
| 38 | dest='usepkg', help='Use binary packages to bootstrap.') |
| 39 | parser.add_argument('--nousepkg', action='store_false', default=True, |
| 40 | dest='usepkg', help='Use binary packages to bootstrap.') |
| 41 | |
| 42 | advanced = parser.add_argument_group('Advanced Options') |
Alex Klein | 6893e71 | 2019-01-16 14:43:29 -0700 | [diff] [blame] | 43 | advanced.add_argument('--accept-licenses', |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 44 | help='Licenses to append to the accept list.') |
Alex Klein | 6893e71 | 2019-01-16 14:43:29 -0700 | [diff] [blame] | 45 | advanced.add_argument('--accept_licenses', |
| 46 | deprecated=deprecated % '--accept-licenses', |
| 47 | help='Deprecated form of --accept-licenses.') |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 48 | |
| 49 | # Build target related arguments. |
| 50 | target = parser.add_argument_group('Advanced Build Target Options') |
| 51 | target.add_argument('--profile', |
| 52 | help='The portage configuration profile to use. Profile ' |
| 53 | 'must be located in overlay-board/profiles.') |
| 54 | target.add_argument('--variant', help='Board variant.') |
Alex Klein | 6893e71 | 2019-01-16 14:43:29 -0700 | [diff] [blame] | 55 | target.add_argument('--board-root', type='path', help='Board root.') |
| 56 | target.add_argument('--board_root', type='path', |
| 57 | deprecated=deprecated % '--board-root', |
| 58 | help='Deprecated form of --board-root.') |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 59 | |
| 60 | # Arguments related to the build itself. |
| 61 | build = parser.add_argument_group('Advanced Build Modification Options') |
| 62 | build.add_argument('--jobs', type=int, |
| 63 | help='Maximum number of packages to build in parallel.') |
Alex Klein | 6893e71 | 2019-01-16 14:43:29 -0700 | [diff] [blame] | 64 | build.add_argument('--regen-configs', action='store_true', default=False, |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 65 | help='Regenerate all config files (useful for ' |
Alex Klein | 6893e71 | 2019-01-16 14:43:29 -0700 | [diff] [blame] | 66 | 'modifying profiles without rebuild).') |
| 67 | build.add_argument('--regen_configs', action='store_true', default=False, |
| 68 | deprecated=deprecated % '--regen-configs', |
| 69 | help='Deprecated form of --regen-configs.') |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 70 | build.add_argument('--quiet', action='store_true', default=False, |
| 71 | help="Don't print warnings when board already exists.") |
Alex Klein | 6893e71 | 2019-01-16 14:43:29 -0700 | [diff] [blame] | 72 | build.add_argument('--skip-toolchain-update', action='store_true', |
| 73 | default=False, |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 74 | help="Don't update toolchain automatically.") |
Alex Klein | 6893e71 | 2019-01-16 14:43:29 -0700 | [diff] [blame] | 75 | build.add_argument('--skip_toolchain_update', action='store_true', |
| 76 | default=False, |
| 77 | deprecated=deprecated % '--skip-toolchain-update', |
| 78 | help='Deprecated form of --skip-toolchain-update.') |
| 79 | build.add_argument('--skip-chroot-upgrade', action='store_true', |
| 80 | default=False, |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 81 | help="Don't run the chroot upgrade automatically; " |
| 82 | 'use with care.') |
Alex Klein | 6893e71 | 2019-01-16 14:43:29 -0700 | [diff] [blame] | 83 | build.add_argument('--skip_chroot_upgrade', action='store_true', |
| 84 | default=False, |
| 85 | deprecated=deprecated % '--skip-chroot-upgrade', |
| 86 | help='Deprecated form of --skip-chroot-upgrade.') |
| 87 | build.add_argument('--skip-board-pkg-init', action='store_true', |
| 88 | default=False, |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 89 | help="Don't emerge any packages during setup_board into " |
| 90 | 'the board root.') |
Alex Klein | 6893e71 | 2019-01-16 14:43:29 -0700 | [diff] [blame] | 91 | build.add_argument('--skip_board_pkg_init', action='store_true', |
| 92 | default=False, |
| 93 | deprecated=deprecated % '--skip-board-pkg-init', |
| 94 | help='Deprecated form of --skip-board-pkg-init.') |
| 95 | build.add_argument('--reuse-pkgs-from-local-boards', dest='reuse_local', |
| 96 | action='store_true', default=False, |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 97 | help='Bootstrap from local packages instead of remote ' |
| 98 | 'packages.') |
Alex Klein | 6893e71 | 2019-01-16 14:43:29 -0700 | [diff] [blame] | 99 | build.add_argument('--reuse_pkgs_from_local_boards', dest='reuse_local', |
| 100 | action='store_true', default=False, |
| 101 | deprecated=deprecated % '--reuse-pkgs-from-local-boards', |
| 102 | help='Deprecated form of --reuse-pkgs-from-local-boards.') |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 103 | |
Alex Klein | 1b031e3 | 2021-03-08 15:28:30 -0700 | [diff] [blame] | 104 | experimental = parser.add_argument_group('Experimental Options') |
| 105 | experimental.add_argument( |
| 106 | '--more-binhosts', |
| 107 | dest='expanded_binhost_inheritance', |
Alex Klein | 0754704 | 2021-03-12 11:47:03 -0700 | [diff] [blame] | 108 | default=True, |
Alex Klein | 1b031e3 | 2021-03-08 15:28:30 -0700 | [diff] [blame] | 109 | action='store_true', |
Alex Klein | 0754704 | 2021-03-12 11:47:03 -0700 | [diff] [blame] | 110 | help=argparse.SUPPRESS) |
Alex Klein | 1b031e3 | 2021-03-08 15:28:30 -0700 | [diff] [blame] | 111 | experimental.add_argument( |
| 112 | '--fewer-binhosts', |
| 113 | dest='expanded_binhost_inheritance', |
Alex Klein | 0754704 | 2021-03-12 11:47:03 -0700 | [diff] [blame] | 114 | default=True, |
Alex Klein | 1b031e3 | 2021-03-08 15:28:30 -0700 | [diff] [blame] | 115 | action='store_false', |
| 116 | help='Do not try to include any additional binhosts.') |
| 117 | |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 118 | return parser |
| 119 | |
| 120 | |
| 121 | def _ParseArgs(args): |
| 122 | """Parse and validate arguments.""" |
| 123 | parser = GetParser() |
| 124 | opts = parser.parse_args(args) |
| 125 | |
| 126 | # Translate raw options to config objects. |
Alex Klein | da35fcf | 2019-03-07 16:01:15 -0700 | [diff] [blame] | 127 | name = '%s_%s' % (opts.board, opts.variant) if opts.variant else opts.board |
Alex Klein | 2960c75 | 2020-03-09 13:43:38 -0600 | [diff] [blame] | 128 | opts.build_target = build_target_lib.BuildTarget(name, |
| 129 | build_root=opts.board_root, |
| 130 | profile=opts.profile) |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 131 | |
Alex Klein | da35fcf | 2019-03-07 16:01:15 -0700 | [diff] [blame] | 132 | opts.run_config = sysroot.SetupBoardRunConfig( |
Alex Klein | 1b031e3 | 2021-03-08 15:28:30 -0700 | [diff] [blame] | 133 | set_default=opts.default, |
| 134 | force=opts.force, |
| 135 | usepkg=opts.usepkg, |
| 136 | jobs=opts.jobs, |
| 137 | regen_configs=opts.regen_configs, |
| 138 | quiet=opts.quiet, |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 139 | update_toolchain=not opts.skip_toolchain_update, |
| 140 | upgrade_chroot=not opts.skip_chroot_upgrade, |
| 141 | init_board_pkgs=not opts.skip_board_pkg_init, |
Alex Klein | 1b031e3 | 2021-03-08 15:28:30 -0700 | [diff] [blame] | 142 | local_build=opts.reuse_local, |
| 143 | expanded_binhost_inheritance=opts.expanded_binhost_inheritance, |
| 144 | ) |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 145 | |
| 146 | opts.Freeze() |
| 147 | return opts |
| 148 | |
| 149 | |
| 150 | def main(argv): |
| 151 | opts = _ParseArgs(argv) |
Alex Klein | da35fcf | 2019-03-07 16:01:15 -0700 | [diff] [blame] | 152 | try: |
| 153 | sysroot.SetupBoard(opts.build_target, opts.accept_licenses, opts.run_config) |
Mike Frysinger | c14d9a0 | 2019-08-26 15:44:16 -0400 | [diff] [blame] | 154 | except portage_util.MissingOverlayError as e: |
| 155 | # Add a bit more user friendly message as people can typo names easily. |
| 156 | cros_build_lib.Die( |
| 157 | '%s\n' |
| 158 | "Double check the --board setting and make sure you're syncing the " |
| 159 | 'right manifest (internal-vs-external).', e) |
Alex Klein | da35fcf | 2019-03-07 16:01:15 -0700 | [diff] [blame] | 160 | except sysroot.Error as e: |
Mike Frysinger | 6b5c3cd | 2019-08-27 16:51:00 -0400 | [diff] [blame] | 161 | cros_build_lib.Die(e) |