blob: a5feee9495741a43977bbe8188afc9d29d456b36 [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
16from chromite.lib import commandline
Alex Kleinb7cdbe62019-02-22 11:41:32 -070017from chromite.service import setup_board
Alex Klein34581082018-12-03 12:56:53 -070018
19
20def GetParser():
21 """Build the argument parser."""
Alex Klein6893e712019-01-16 14:43:29 -070022 # TODO(crbug.com/922144) Remove underscore separated arguments and the
23 # deprecated message after 2019-06-01.
24 deprecated = 'Argument will be removed 2019-06-01. Use %s instead.'
Alex Klein34581082018-12-03 12:56:53 -070025 parser = commandline.ArgumentParser(description=__doc__)
26
27 parser.add_argument('--board', required=True,
28 help='The name of the board to set up.')
29 parser.add_argument('--default', action='store_true', default=False,
30 help='Set the board to the default board in your chroot.')
31 parser.add_argument('--force', action='store_true', default=False,
32 help='Force re-creating the board root.')
33 # The positive and negative versions of the arguments are used.
34 # TODO(saklein) Simplify usages to a single version of the argument.
35 parser.add_argument('--usepkg', action='store_true', default=True,
36 dest='usepkg', help='Use binary packages to bootstrap.')
37 parser.add_argument('--nousepkg', action='store_false', default=True,
38 dest='usepkg', help='Use binary packages to bootstrap.')
39
40 advanced = parser.add_argument_group('Advanced Options')
Alex Klein6893e712019-01-16 14:43:29 -070041 advanced.add_argument('--accept-licenses',
Alex Klein34581082018-12-03 12:56:53 -070042 help='Licenses to append to the accept list.')
Alex Klein6893e712019-01-16 14:43:29 -070043 advanced.add_argument('--accept_licenses',
44 deprecated=deprecated % '--accept-licenses',
45 help='Deprecated form of --accept-licenses.')
Alex Klein34581082018-12-03 12:56:53 -070046
47 # Build target related arguments.
48 target = parser.add_argument_group('Advanced Build Target Options')
49 target.add_argument('--profile',
50 help='The portage configuration profile to use. Profile '
51 'must be located in overlay-board/profiles.')
52 target.add_argument('--variant', help='Board variant.')
Alex Klein6893e712019-01-16 14:43:29 -070053 target.add_argument('--board-root', type='path', help='Board root.')
54 target.add_argument('--board_root', type='path',
55 deprecated=deprecated % '--board-root',
56 help='Deprecated form of --board-root.')
Alex Klein34581082018-12-03 12:56:53 -070057
58 # Arguments related to the build itself.
59 build = parser.add_argument_group('Advanced Build Modification Options')
60 build.add_argument('--jobs', type=int,
61 help='Maximum number of packages to build in parallel.')
Alex Klein6893e712019-01-16 14:43:29 -070062 build.add_argument('--regen-configs', action='store_true', default=False,
Alex Klein34581082018-12-03 12:56:53 -070063 help='Regenerate all config files (useful for '
Alex Klein6893e712019-01-16 14:43:29 -070064 'modifying profiles without rebuild).')
65 build.add_argument('--regen_configs', action='store_true', default=False,
66 deprecated=deprecated % '--regen-configs',
67 help='Deprecated form of --regen-configs.')
Alex Klein34581082018-12-03 12:56:53 -070068 build.add_argument('--quiet', action='store_true', default=False,
69 help="Don't print warnings when board already exists.")
Alex Klein6893e712019-01-16 14:43:29 -070070 build.add_argument('--skip-toolchain-update', action='store_true',
71 default=False,
Alex Klein34581082018-12-03 12:56:53 -070072 help="Don't update toolchain automatically.")
Alex Klein6893e712019-01-16 14:43:29 -070073 build.add_argument('--skip_toolchain_update', action='store_true',
74 default=False,
75 deprecated=deprecated % '--skip-toolchain-update',
76 help='Deprecated form of --skip-toolchain-update.')
77 build.add_argument('--skip-chroot-upgrade', action='store_true',
78 default=False,
Alex Klein34581082018-12-03 12:56:53 -070079 help="Don't run the chroot upgrade automatically; "
80 'use with care.')
Alex Klein6893e712019-01-16 14:43:29 -070081 build.add_argument('--skip_chroot_upgrade', action='store_true',
82 default=False,
83 deprecated=deprecated % '--skip-chroot-upgrade',
84 help='Deprecated form of --skip-chroot-upgrade.')
85 build.add_argument('--skip-board-pkg-init', action='store_true',
86 default=False,
Alex Klein34581082018-12-03 12:56:53 -070087 help="Don't emerge any packages during setup_board into "
88 'the board root.')
Alex Klein6893e712019-01-16 14:43:29 -070089 build.add_argument('--skip_board_pkg_init', action='store_true',
90 default=False,
91 deprecated=deprecated % '--skip-board-pkg-init',
92 help='Deprecated form of --skip-board-pkg-init.')
93 build.add_argument('--reuse-pkgs-from-local-boards', dest='reuse_local',
94 action='store_true', default=False,
Alex Klein34581082018-12-03 12:56:53 -070095 help='Bootstrap from local packages instead of remote '
96 'packages.')
Alex Klein6893e712019-01-16 14:43:29 -070097 build.add_argument('--reuse_pkgs_from_local_boards', dest='reuse_local',
98 action='store_true', default=False,
99 deprecated=deprecated % '--reuse-pkgs-from-local-boards',
100 help='Deprecated form of --reuse-pkgs-from-local-boards.')
Alex Klein34581082018-12-03 12:56:53 -0700101
102 return parser
103
104
105def _ParseArgs(args):
106 """Parse and validate arguments."""
107 parser = GetParser()
108 opts = parser.parse_args(args)
109
110 # Translate raw options to config objects.
111 opts.board_conf = setup_board.Board(board=opts.board, variant=opts.variant,
112 board_root=opts.board_root,
113 profile=opts.profile)
114
115 opts.run_config = setup_board.SetupBoardRunConfig(
116 set_default=opts.default, force=opts.force, usepkg=opts.usepkg,
117 jobs=opts.jobs, regen_configs=opts.regen_configs, quiet=opts.quiet,
118 update_toolchain=not opts.skip_toolchain_update,
119 upgrade_chroot=not opts.skip_chroot_upgrade,
120 init_board_pkgs=not opts.skip_board_pkg_init,
121 local_build=opts.reuse_local)
122
123 opts.Freeze()
124 return opts
125
126
127def main(argv):
128 opts = _ParseArgs(argv)
129 setup_board.SetupBoard(opts.board_conf, opts.accept_licenses, opts.run_config)