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