blob: 017e16791b04bcd1b1a9c2862a4846c79f2ff082 [file] [log] [blame]
Alex Klein34581082018-12-03 12:56:53 -07001# -*- 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
8The setup_board process includes the simple directory creations, installs
9several configuration files, sets up portage command wrappers and configs,
10and installs the toolchain and some core dependency packages (e.g. kernel
11headers, gcc-libs).
12"""
13
14from __future__ import print_function
15
Alex Klein07547042021-03-12 11:47:03 -070016import argparse
Mike Frysinger6a2b0f22020-02-20 13:34:07 -050017import sys
18
Alex Klein2960c752020-03-09 13:43:38 -060019from chromite.lib import build_target_lib
Alex Klein34581082018-12-03 12:56:53 -070020from chromite.lib import commandline
Alex Kleinda35fcf2019-03-07 16:01:15 -070021from chromite.lib import cros_build_lib
Mike Frysingerc14d9a02019-08-26 15:44:16 -040022from chromite.lib import portage_util
Alex Kleinda35fcf2019-03-07 16:01:15 -070023from chromite.service import sysroot
Alex Klein34581082018-12-03 12:56:53 -070024
25
Mike Frysinger6a2b0f22020-02-20 13:34:07 -050026assert sys.version_info >= (3, 6), 'This module requires Python 3.6+'
27
28
Alex Klein34581082018-12-03 12:56:53 -070029def GetParser():
30 """Build the argument parser."""
Alex Klein6893e712019-01-16 14:43:29 -070031 # TODO(crbug.com/922144) Remove underscore separated arguments and the
32 # deprecated message after 2019-06-01.
33 deprecated = 'Argument will be removed 2019-06-01. Use %s instead.'
Alex Klein34581082018-12-03 12:56:53 -070034 parser = commandline.ArgumentParser(description=__doc__)
35
Alex Klein3ac03882021-02-22 13:23:16 -070036 parser.add_argument('-b', '--board', '--build-target', required=True,
37 dest='board', help='The name of the board to set up.')
Alex Klein34581082018-12-03 12:56:53 -070038 parser.add_argument('--default', action='store_true', default=False,
39 help='Set the board to the default board in your chroot.')
40 parser.add_argument('--force', action='store_true', default=False,
41 help='Force re-creating the board root.')
42 # The positive and negative versions of the arguments are used.
43 # TODO(saklein) Simplify usages to a single version of the argument.
44 parser.add_argument('--usepkg', action='store_true', default=True,
45 dest='usepkg', help='Use binary packages to bootstrap.')
46 parser.add_argument('--nousepkg', action='store_false', default=True,
47 dest='usepkg', help='Use binary packages to bootstrap.')
48
49 advanced = parser.add_argument_group('Advanced Options')
Alex Klein6893e712019-01-16 14:43:29 -070050 advanced.add_argument('--accept-licenses',
Alex Klein34581082018-12-03 12:56:53 -070051 help='Licenses to append to the accept list.')
Alex Klein6893e712019-01-16 14:43:29 -070052 advanced.add_argument('--accept_licenses',
53 deprecated=deprecated % '--accept-licenses',
54 help='Deprecated form of --accept-licenses.')
Alex Klein34581082018-12-03 12:56:53 -070055
56 # Build target related arguments.
57 target = parser.add_argument_group('Advanced Build Target Options')
58 target.add_argument('--profile',
59 help='The portage configuration profile to use. Profile '
60 'must be located in overlay-board/profiles.')
61 target.add_argument('--variant', help='Board variant.')
Alex Klein6893e712019-01-16 14:43:29 -070062 target.add_argument('--board-root', type='path', help='Board root.')
63 target.add_argument('--board_root', type='path',
64 deprecated=deprecated % '--board-root',
65 help='Deprecated form of --board-root.')
Alex Klein34581082018-12-03 12:56:53 -070066
67 # Arguments related to the build itself.
68 build = parser.add_argument_group('Advanced Build Modification Options')
69 build.add_argument('--jobs', type=int,
70 help='Maximum number of packages to build in parallel.')
Alex Klein6893e712019-01-16 14:43:29 -070071 build.add_argument('--regen-configs', action='store_true', default=False,
Alex Klein34581082018-12-03 12:56:53 -070072 help='Regenerate all config files (useful for '
Alex Klein6893e712019-01-16 14:43:29 -070073 'modifying profiles without rebuild).')
74 build.add_argument('--regen_configs', action='store_true', default=False,
75 deprecated=deprecated % '--regen-configs',
76 help='Deprecated form of --regen-configs.')
Alex Klein34581082018-12-03 12:56:53 -070077 build.add_argument('--quiet', action='store_true', default=False,
78 help="Don't print warnings when board already exists.")
Alex Klein6893e712019-01-16 14:43:29 -070079 build.add_argument('--skip-toolchain-update', action='store_true',
80 default=False,
Alex Klein34581082018-12-03 12:56:53 -070081 help="Don't update toolchain automatically.")
Alex Klein6893e712019-01-16 14:43:29 -070082 build.add_argument('--skip_toolchain_update', action='store_true',
83 default=False,
84 deprecated=deprecated % '--skip-toolchain-update',
85 help='Deprecated form of --skip-toolchain-update.')
86 build.add_argument('--skip-chroot-upgrade', action='store_true',
87 default=False,
Alex Klein34581082018-12-03 12:56:53 -070088 help="Don't run the chroot upgrade automatically; "
89 'use with care.')
Alex Klein6893e712019-01-16 14:43:29 -070090 build.add_argument('--skip_chroot_upgrade', action='store_true',
91 default=False,
92 deprecated=deprecated % '--skip-chroot-upgrade',
93 help='Deprecated form of --skip-chroot-upgrade.')
94 build.add_argument('--skip-board-pkg-init', action='store_true',
95 default=False,
Alex Klein34581082018-12-03 12:56:53 -070096 help="Don't emerge any packages during setup_board into "
97 'the board root.')
Alex Klein6893e712019-01-16 14:43:29 -070098 build.add_argument('--skip_board_pkg_init', action='store_true',
99 default=False,
100 deprecated=deprecated % '--skip-board-pkg-init',
101 help='Deprecated form of --skip-board-pkg-init.')
102 build.add_argument('--reuse-pkgs-from-local-boards', dest='reuse_local',
103 action='store_true', default=False,
Alex Klein34581082018-12-03 12:56:53 -0700104 help='Bootstrap from local packages instead of remote '
105 'packages.')
Alex Klein6893e712019-01-16 14:43:29 -0700106 build.add_argument('--reuse_pkgs_from_local_boards', dest='reuse_local',
107 action='store_true', default=False,
108 deprecated=deprecated % '--reuse-pkgs-from-local-boards',
109 help='Deprecated form of --reuse-pkgs-from-local-boards.')
Alex Klein34581082018-12-03 12:56:53 -0700110
Alex Klein1b031e32021-03-08 15:28:30 -0700111 experimental = parser.add_argument_group('Experimental Options')
112 experimental.add_argument(
113 '--more-binhosts',
114 dest='expanded_binhost_inheritance',
Alex Klein07547042021-03-12 11:47:03 -0700115 default=True,
Alex Klein1b031e32021-03-08 15:28:30 -0700116 action='store_true',
Alex Klein07547042021-03-12 11:47:03 -0700117 help=argparse.SUPPRESS)
Alex Klein1b031e32021-03-08 15:28:30 -0700118 experimental.add_argument(
119 '--fewer-binhosts',
120 dest='expanded_binhost_inheritance',
Alex Klein07547042021-03-12 11:47:03 -0700121 default=True,
Alex Klein1b031e32021-03-08 15:28:30 -0700122 action='store_false',
123 help='Do not try to include any additional binhosts.')
124
Alex Klein34581082018-12-03 12:56:53 -0700125 return parser
126
127
128def _ParseArgs(args):
129 """Parse and validate arguments."""
130 parser = GetParser()
131 opts = parser.parse_args(args)
132
133 # Translate raw options to config objects.
Alex Kleinda35fcf2019-03-07 16:01:15 -0700134 name = '%s_%s' % (opts.board, opts.variant) if opts.variant else opts.board
Alex Klein2960c752020-03-09 13:43:38 -0600135 opts.build_target = build_target_lib.BuildTarget(name,
136 build_root=opts.board_root,
137 profile=opts.profile)
Alex Klein34581082018-12-03 12:56:53 -0700138
Alex Kleinda35fcf2019-03-07 16:01:15 -0700139 opts.run_config = sysroot.SetupBoardRunConfig(
Alex Klein1b031e32021-03-08 15:28:30 -0700140 set_default=opts.default,
141 force=opts.force,
142 usepkg=opts.usepkg,
143 jobs=opts.jobs,
144 regen_configs=opts.regen_configs,
145 quiet=opts.quiet,
Alex Klein34581082018-12-03 12:56:53 -0700146 update_toolchain=not opts.skip_toolchain_update,
147 upgrade_chroot=not opts.skip_chroot_upgrade,
148 init_board_pkgs=not opts.skip_board_pkg_init,
Alex Klein1b031e32021-03-08 15:28:30 -0700149 local_build=opts.reuse_local,
150 expanded_binhost_inheritance=opts.expanded_binhost_inheritance,
151 )
Alex Klein34581082018-12-03 12:56:53 -0700152
153 opts.Freeze()
154 return opts
155
156
157def main(argv):
158 opts = _ParseArgs(argv)
Alex Kleinda35fcf2019-03-07 16:01:15 -0700159 try:
160 sysroot.SetupBoard(opts.build_target, opts.accept_licenses, opts.run_config)
Mike Frysingerc14d9a02019-08-26 15:44:16 -0400161 except portage_util.MissingOverlayError as e:
162 # Add a bit more user friendly message as people can typo names easily.
163 cros_build_lib.Die(
164 '%s\n'
165 "Double check the --board setting and make sure you're syncing the "
166 'right manifest (internal-vs-external).', e)
Alex Kleinda35fcf2019-03-07 16:01:15 -0700167 except sysroot.Error as e:
Mike Frysinger6b5c3cd2019-08-27 16:51:00 -0400168 cros_build_lib.Die(e)