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