blob: f7414da6dd69883c3989b7ec3b3b48c5bac77afe [file] [log] [blame]
Alex Klein34581082018-12-03 12:56:53 -07001# 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
7The setup_board process includes the simple directory creations, installs
8several configuration files, sets up portage command wrappers and configs,
9and installs the toolchain and some core dependency packages (e.g. kernel
10headers, gcc-libs).
11"""
12
Alex Klein07547042021-03-12 11:47:03 -070013import argparse
Mike Frysinger6a2b0f22020-02-20 13:34:07 -050014
Alex Klein2960c752020-03-09 13:43:38 -060015from chromite.lib import build_target_lib
Alex Klein34581082018-12-03 12:56:53 -070016from chromite.lib import commandline
Alex Kleinda35fcf2019-03-07 16:01:15 -070017from chromite.lib import cros_build_lib
Mike Frysingerc14d9a02019-08-26 15:44:16 -040018from chromite.lib import portage_util
Alex Kleinda35fcf2019-03-07 16:01:15 -070019from chromite.service import sysroot
Alex Klein34581082018-12-03 12:56:53 -070020
21
22def GetParser():
23 """Build the argument parser."""
Alex Klein6893e712019-01-16 14:43:29 -070024 # 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 Klein34581082018-12-03 12:56:53 -070027 parser = commandline.ArgumentParser(description=__doc__)
28
Alex Klein3ac03882021-02-22 13:23:16 -070029 parser.add_argument('-b', '--board', '--build-target', required=True,
30 dest='board', help='The name of the board to set up.')
Alex Klein34581082018-12-03 12:56:53 -070031 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,
George Burgess IV5f9732d2022-06-02 00:35:43 -070040 dest='usepkg',
41 help='Do not use binary packages to bootstrap.')
Alex Klein34581082018-12-03 12:56:53 -070042
43 advanced = parser.add_argument_group('Advanced Options')
Alex Klein6893e712019-01-16 14:43:29 -070044 advanced.add_argument('--accept-licenses',
Alex Klein34581082018-12-03 12:56:53 -070045 help='Licenses to append to the accept list.')
Alex Klein6893e712019-01-16 14:43:29 -070046 advanced.add_argument('--accept_licenses',
47 deprecated=deprecated % '--accept-licenses',
48 help='Deprecated form of --accept-licenses.')
Alex Klein34581082018-12-03 12:56:53 -070049
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 Klein6893e712019-01-16 14:43:29 -070056 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 Klein34581082018-12-03 12:56:53 -070060
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 Klein6893e712019-01-16 14:43:29 -070065 build.add_argument('--regen-configs', action='store_true', default=False,
Alex Klein34581082018-12-03 12:56:53 -070066 help='Regenerate all config files (useful for '
Alex Klein6893e712019-01-16 14:43:29 -070067 '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 Klein34581082018-12-03 12:56:53 -070071 build.add_argument('--quiet', action='store_true', default=False,
72 help="Don't print warnings when board already exists.")
Alex Klein6893e712019-01-16 14:43:29 -070073 build.add_argument('--skip-toolchain-update', action='store_true',
74 default=False,
Alex Klein34581082018-12-03 12:56:53 -070075 help="Don't update toolchain automatically.")
Alex Klein6893e712019-01-16 14:43:29 -070076 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 Klein34581082018-12-03 12:56:53 -070082 help="Don't run the chroot upgrade automatically; "
83 'use with care.')
Alex Klein6893e712019-01-16 14:43:29 -070084 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 Klein34581082018-12-03 12:56:53 -070090 help="Don't emerge any packages during setup_board into "
91 'the board root.')
Alex Klein6893e712019-01-16 14:43:29 -070092 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 Klein34581082018-12-03 12:56:53 -070098 help='Bootstrap from local packages instead of remote '
99 'packages.')
Alex Klein6893e712019-01-16 14:43:29 -0700100 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 Klein062d7282022-07-28 09:03:26 -0600104 build.add_argument(
105 '--backtrack',
106 type=int,
107 default=sysroot.BACKTRACK_DEFAULT,
108 help='See emerge --backtrack.')
Alex Klein34581082018-12-03 12:56:53 -0700109
Alex Kleinb45ad262021-03-12 12:23:58 -0700110 parser.add_argument(
Alex Klein1b031e32021-03-08 15:28:30 -0700111 '--fewer-binhosts',
112 dest='expanded_binhost_inheritance',
Alex Klein07547042021-03-12 11:47:03 -0700113 default=True,
Alex Klein1b031e32021-03-08 15:28:30 -0700114 action='store_false',
Alex Kleinb45ad262021-03-12 12:23:58 -0700115 help=argparse.SUPPRESS)
Alex Klein1b031e32021-03-08 15:28:30 -0700116
Alex Klein34581082018-12-03 12:56:53 -0700117 return parser
118
119
120def _ParseArgs(args):
121 """Parse and validate arguments."""
122 parser = GetParser()
123 opts = parser.parse_args(args)
124
125 # Translate raw options to config objects.
Alex Kleinda35fcf2019-03-07 16:01:15 -0700126 name = '%s_%s' % (opts.board, opts.variant) if opts.variant else opts.board
Alex Klein2960c752020-03-09 13:43:38 -0600127 opts.build_target = build_target_lib.BuildTarget(name,
128 build_root=opts.board_root,
129 profile=opts.profile)
Alex Klein34581082018-12-03 12:56:53 -0700130
Alex Kleinda35fcf2019-03-07 16:01:15 -0700131 opts.run_config = sysroot.SetupBoardRunConfig(
Alex Klein1b031e32021-03-08 15:28:30 -0700132 set_default=opts.default,
133 force=opts.force,
134 usepkg=opts.usepkg,
135 jobs=opts.jobs,
136 regen_configs=opts.regen_configs,
137 quiet=opts.quiet,
Alex Klein34581082018-12-03 12:56:53 -0700138 update_toolchain=not opts.skip_toolchain_update,
139 upgrade_chroot=not opts.skip_chroot_upgrade,
140 init_board_pkgs=not opts.skip_board_pkg_init,
Alex Klein1b031e32021-03-08 15:28:30 -0700141 local_build=opts.reuse_local,
142 expanded_binhost_inheritance=opts.expanded_binhost_inheritance,
Alex Klein062d7282022-07-28 09:03:26 -0600143 backtrack=opts.backtrack,
Alex Klein1b031e32021-03-08 15:28:30 -0700144 )
Alex Klein34581082018-12-03 12:56:53 -0700145
146 opts.Freeze()
147 return opts
148
149
150def main(argv):
151 opts = _ParseArgs(argv)
Alex Kleinda35fcf2019-03-07 16:01:15 -0700152 try:
153 sysroot.SetupBoard(opts.build_target, opts.accept_licenses, opts.run_config)
Mike Frysingerc14d9a02019-08-26 15:44:16 -0400154 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 Kleinda35fcf2019-03-07 16:01:15 -0700160 except sysroot.Error as e:
Mike Frysinger6b5c3cd2019-08-27 16:51:00 -0400161 cros_build_lib.Die(e)