Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 2 | # Copyright (c) 2013 The Chromium OS Authors. |
| 3 | # |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 4 | |
Simon Glass | c1e1e1d | 2023-07-19 17:48:30 -0600 | [diff] [blame] | 5 | """Control module for buildman |
| 6 | |
| 7 | This holds the main control logic for buildman, when not running tests. |
| 8 | """ |
| 9 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 10 | import multiprocessing |
| 11 | import os |
Simon Glass | a10ebe1 | 2014-09-05 19:00:18 -0600 | [diff] [blame] | 12 | import shutil |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 13 | import sys |
| 14 | |
Simon Glass | 20751d6 | 2022-07-11 19:04:03 -0600 | [diff] [blame] | 15 | from buildman import boards |
Simon Glass | f0d9c10 | 2020-04-17 18:09:02 -0600 | [diff] [blame] | 16 | from buildman import bsettings |
Simon Glass | e5650a8 | 2022-01-22 05:07:33 -0700 | [diff] [blame] | 17 | from buildman import cfgutil |
Simon Glass | f0d9c10 | 2020-04-17 18:09:02 -0600 | [diff] [blame] | 18 | from buildman import toolchain |
| 19 | from buildman.builder import Builder |
Simon Glass | a997ea5 | 2020-04-17 18:09:04 -0600 | [diff] [blame] | 20 | from patman import gitutil |
| 21 | from patman import patchstream |
Simon Glass | 131444f | 2023-02-23 18:18:04 -0700 | [diff] [blame] | 22 | from u_boot_pylib import command |
| 23 | from u_boot_pylib import terminal |
Simon Glass | 131444f | 2023-02-23 18:18:04 -0700 | [diff] [blame] | 24 | from u_boot_pylib.terminal import tprint |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 25 | |
Simon Glass | af0e29f | 2023-07-19 17:48:31 -0600 | [diff] [blame] | 26 | TEST_BUILDER = None |
| 27 | |
Simon Glass | c1e1e1d | 2023-07-19 17:48:30 -0600 | [diff] [blame] | 28 | def get_plural(count): |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 29 | """Returns a plural 's' if count is not 1""" |
| 30 | return 's' if count != 1 else '' |
| 31 | |
Simon Glass | c1e1e1d | 2023-07-19 17:48:30 -0600 | [diff] [blame] | 32 | def get_action_summary(is_summary, commits, selected, options): |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 33 | """Return a string summarising the intended action. |
| 34 | |
| 35 | Returns: |
| 36 | Summary string. |
| 37 | """ |
Simon Glass | d326ad7 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 38 | if commits: |
| 39 | count = len(commits) |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 40 | count = (count + options.step - 1) // options.step |
Simon Glass | af0e29f | 2023-07-19 17:48:31 -0600 | [diff] [blame] | 41 | commit_str = f'{count} commit{get_plural(count)}' |
Simon Glass | d326ad7 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 42 | else: |
| 43 | commit_str = 'current source' |
Simon Glass | af0e29f | 2023-07-19 17:48:31 -0600 | [diff] [blame] | 44 | msg = (f"{'Summary of' if is_summary else 'Building'} " |
| 45 | f'{commit_str} for {len(selected)} boards') |
| 46 | msg += (f' ({options.threads} thread{get_plural(options.threads)}, ' |
| 47 | f'{options.jobs} job{get_plural(options.jobs)} per thread)') |
| 48 | return msg |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 49 | |
Simon Glass | af0e29f | 2023-07-19 17:48:31 -0600 | [diff] [blame] | 50 | # pylint: disable=R0913 |
Simon Glass | f83559c | 2023-07-19 17:48:36 -0600 | [diff] [blame] | 51 | def show_actions(series, why_selected, boards_selected, output_dir, options, |
Simon Glass | c1e1e1d | 2023-07-19 17:48:30 -0600 | [diff] [blame] | 52 | board_warnings): |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 53 | """Display a list of actions that we would take, if not a dry run. |
| 54 | |
| 55 | Args: |
| 56 | series: Series object |
| 57 | why_selected: Dictionary where each key is a buildman argument |
Simon Glass | 6af145f | 2017-01-23 05:38:56 -0700 | [diff] [blame] | 58 | provided by the user, and the value is the list of boards |
| 59 | brought in by that argument. For example, 'arm' might bring |
| 60 | in 400 boards, so in this case the key would be 'arm' and |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 61 | the value would be a list of board names. |
| 62 | boards_selected: Dict of selected boards, key is target name, |
| 63 | value is Board object |
Simon Glass | f83559c | 2023-07-19 17:48:36 -0600 | [diff] [blame] | 64 | output_dir (str): Output directory for builder |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 65 | options: Command line options object |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 66 | board_warnings: List of warnings obtained from board selected |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 67 | """ |
| 68 | col = terminal.Color() |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 69 | print('Dry run, so not doing much. But I would do this:') |
| 70 | print() |
Simon Glass | d326ad7 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 71 | if series: |
| 72 | commits = series.commits |
| 73 | else: |
| 74 | commits = None |
Simon Glass | c1e1e1d | 2023-07-19 17:48:30 -0600 | [diff] [blame] | 75 | print(get_action_summary(False, commits, boards_selected, |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 76 | options)) |
Simon Glass | f83559c | 2023-07-19 17:48:36 -0600 | [diff] [blame] | 77 | print(f'Build directory: {output_dir}') |
Simon Glass | d326ad7 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 78 | if commits: |
| 79 | for upto in range(0, len(series.commits), options.step): |
| 80 | commit = series.commits[upto] |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 81 | print(' ', col.build(col.YELLOW, commit.hash[:8], bright=False), end=' ') |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 82 | print(commit.subject) |
| 83 | print() |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 84 | for arg in why_selected: |
| 85 | if arg != 'all': |
Simon Glass | af0e29f | 2023-07-19 17:48:31 -0600 | [diff] [blame] | 86 | print(arg, f': {len(why_selected[arg])} boards') |
Simon Glass | 6af145f | 2017-01-23 05:38:56 -0700 | [diff] [blame] | 87 | if options.verbose: |
Simon Glass | af0e29f | 2023-07-19 17:48:31 -0600 | [diff] [blame] | 88 | print(f" {' '.join(why_selected[arg])}") |
| 89 | print('Total boards to build for each ' |
| 90 | f"commit: {len(why_selected['all'])}\n") |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 91 | if board_warnings: |
| 92 | for warning in board_warnings: |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 93 | print(col.build(col.YELLOW, warning)) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 94 | |
Simon Glass | c1e1e1d | 2023-07-19 17:48:30 -0600 | [diff] [blame] | 95 | def show_toolchain_prefix(brds, toolchains): |
Simon Glass | 48ac42e | 2019-12-05 15:59:14 -0700 | [diff] [blame] | 96 | """Show information about a the tool chain used by one or more boards |
| 97 | |
Simon Glass | 2df44be | 2020-03-18 09:42:47 -0600 | [diff] [blame] | 98 | The function checks that all boards use the same toolchain, then prints |
| 99 | the correct value for CROSS_COMPILE. |
Simon Glass | 48ac42e | 2019-12-05 15:59:14 -0700 | [diff] [blame] | 100 | |
| 101 | Args: |
| 102 | boards: Boards object containing selected boards |
| 103 | toolchains: Toolchains object containing available toolchains |
Simon Glass | 48ac42e | 2019-12-05 15:59:14 -0700 | [diff] [blame] | 104 | |
| 105 | Return: |
| 106 | None on success, string error message otherwise |
| 107 | """ |
Simon Glass | 127a239 | 2022-07-11 19:04:02 -0600 | [diff] [blame] | 108 | board_selected = brds.get_selected_dict() |
Simon Glass | 48ac42e | 2019-12-05 15:59:14 -0700 | [diff] [blame] | 109 | tc_set = set() |
Simon Glass | 5df4522 | 2022-07-11 19:04:00 -0600 | [diff] [blame] | 110 | for brd in board_selected.values(): |
Simon Glass | 48ac42e | 2019-12-05 15:59:14 -0700 | [diff] [blame] | 111 | tc_set.add(toolchains.Select(brd.arch)) |
| 112 | if len(tc_set) != 1: |
| 113 | return 'Supplied boards must share one toolchain' |
Simon Glass | af0e29f | 2023-07-19 17:48:31 -0600 | [diff] [blame] | 114 | tchain = tc_set.pop() |
| 115 | print(tchain.GetEnvArgs(toolchain.VAR_CROSS_COMPILE)) |
Simon Glass | 48ac42e | 2019-12-05 15:59:14 -0700 | [diff] [blame] | 116 | return None |
| 117 | |
Tom Rini | 93ebd46 | 2022-11-09 19:14:53 -0700 | [diff] [blame] | 118 | def get_allow_missing(opt_allow, opt_no_allow, num_selected, has_branch): |
Simon Glass | af0e29f | 2023-07-19 17:48:31 -0600 | [diff] [blame] | 119 | """Figure out whether to allow external blobs |
| 120 | |
| 121 | Uses the allow-missing setting and the provided arguments to decide whether |
| 122 | missing external blobs should be allowed |
| 123 | |
| 124 | Args: |
| 125 | opt_allow (bool): True if --allow-missing flag is set |
| 126 | opt_no_allow (bool): True if --no-allow-missing flag is set |
| 127 | num_selected (int): Number of selected board |
| 128 | has_branch (bool): True if a git branch (to build) has been provided |
| 129 | |
| 130 | Returns: |
| 131 | bool: True to allow missing external blobs, False to produce an error if |
| 132 | external blobs are used |
| 133 | """ |
Tom Rini | 93ebd46 | 2022-11-09 19:14:53 -0700 | [diff] [blame] | 134 | allow_missing = False |
| 135 | am_setting = bsettings.GetGlobalItemValue('allow-missing') |
| 136 | if am_setting: |
| 137 | if am_setting == 'always': |
| 138 | allow_missing = True |
| 139 | if 'multiple' in am_setting and num_selected > 1: |
| 140 | allow_missing = True |
| 141 | if 'branch' in am_setting and has_branch: |
| 142 | allow_missing = True |
| 143 | |
| 144 | if opt_allow: |
| 145 | allow_missing = True |
| 146 | if opt_no_allow: |
| 147 | allow_missing = False |
| 148 | return allow_missing |
| 149 | |
Simon Glass | 2183b84 | 2023-07-19 17:48:33 -0600 | [diff] [blame] | 150 | |
| 151 | def determine_series(count, has_range, branch, git_dir): |
| 152 | """Determine the series which is to be built, if any |
| 153 | |
| 154 | Args: |
| 155 | count (int): Number of commits in branch |
| 156 | has_range (bool): True if a range of commits ('xx..yy') is being built |
| 157 | branch (str): Name of branch to build, or None if none |
| 158 | git_dir (str): Git directory to use, e.g. './.git' |
| 159 | |
| 160 | Returns: |
| 161 | Series: Series to build, or None for none |
| 162 | |
| 163 | Read the metadata from the commits. First look at the upstream commit, |
| 164 | then the ones in the branch. We would like to do something like |
| 165 | upstream/master~..branch but that isn't possible if upstream/master is |
| 166 | a merge commit (it will list all the commits that form part of the |
| 167 | merge) |
| 168 | |
| 169 | Conflicting tags are not a problem for buildman, since it does not use |
| 170 | them. For example, Series-version is not useful for buildman. On the |
| 171 | other hand conflicting tags will cause an error. So allow later tags |
| 172 | to overwrite earlier ones by setting allow_overwrite=True |
| 173 | """ |
| 174 | if branch: |
| 175 | if count == -1: |
| 176 | if has_range: |
| 177 | range_expr = branch |
| 178 | else: |
| 179 | range_expr = gitutil.get_range_in_branch(git_dir, branch) |
| 180 | upstream_commit = gitutil.get_upstream(git_dir, branch) |
| 181 | series = patchstream.get_metadata_for_list(upstream_commit, |
| 182 | git_dir, 1, series=None, allow_overwrite=True) |
| 183 | |
| 184 | series = patchstream.get_metadata_for_list(range_expr, |
| 185 | git_dir, None, series, allow_overwrite=True) |
| 186 | else: |
| 187 | # Honour the count |
| 188 | series = patchstream.get_metadata_for_list(branch, |
| 189 | git_dir, count, series=None, allow_overwrite=True) |
| 190 | else: |
| 191 | series = None |
| 192 | return series |
| 193 | |
| 194 | |
Simon Glass | 6c4beca | 2023-07-19 17:48:34 -0600 | [diff] [blame] | 195 | def do_fetch_arch(toolchains, col, fetch_arch): |
| 196 | """Handle the --fetch-arch option |
| 197 | |
| 198 | Args: |
| 199 | toolchains (Toolchains): Tool chains to use |
| 200 | col (terminal.Color): Color object to build |
| 201 | fetch_arch (str): Argument passed to the --fetch-arch option |
| 202 | |
| 203 | Returns: |
| 204 | int: Return code for buildman |
| 205 | """ |
| 206 | if fetch_arch == 'list': |
| 207 | sorted_list = toolchains.ListArchs() |
| 208 | print(col.build( |
| 209 | col.BLUE, |
| 210 | f"Available architectures: {' '.join(sorted_list)}\n")) |
| 211 | return 0 |
| 212 | |
| 213 | if fetch_arch == 'all': |
| 214 | fetch_arch = ','.join(toolchains.ListArchs()) |
| 215 | print(col.build(col.CYAN, |
| 216 | f'\nDownloading toolchains: {fetch_arch}')) |
| 217 | for arch in fetch_arch.split(','): |
| 218 | print() |
| 219 | ret = toolchains.FetchAndInstall(arch) |
| 220 | if ret: |
| 221 | return ret |
| 222 | return 0 |
| 223 | |
| 224 | |
Simon Glass | c1e1e1d | 2023-07-19 17:48:30 -0600 | [diff] [blame] | 225 | def do_buildman(options, args, toolchains=None, make_func=None, brds=None, |
| 226 | clean_dir=False, test_thread_exceptions=False): |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 227 | """The main control code for buildman |
| 228 | |
| 229 | Args: |
| 230 | options: Command line options object |
| 231 | args: Command line arguments (list of strings) |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 232 | toolchains: Toolchains to use - this should be a Toolchains() |
| 233 | object. If None, then it will be created and scanned |
| 234 | make_func: Make function to use for the builder. This is called |
| 235 | to execute 'make'. If this is None, the normal function |
| 236 | will be used, which calls the 'make' tool with suitable |
| 237 | arguments. This setting is useful for tests. |
Simon Glass | 5df4522 | 2022-07-11 19:04:00 -0600 | [diff] [blame] | 238 | brds: Boards() object to use, containing a list of available |
Simon Glass | cbd3658 | 2014-09-05 19:00:16 -0600 | [diff] [blame] | 239 | boards. If this is None it will be created and scanned. |
Simon Glass | a29b3ea | 2021-04-11 16:27:25 +1200 | [diff] [blame] | 240 | clean_dir: Used for tests only, indicates that the existing output_dir |
| 241 | should be removed before starting the build |
Simon Glass | 9bf9a72 | 2021-04-11 16:27:27 +1200 | [diff] [blame] | 242 | test_thread_exceptions: Uses for tests only, True to make the threads |
| 243 | raise an exception instead of reporting their result. This simulates |
| 244 | a failure in the code somewhere |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 245 | """ |
Simon Glass | af0e29f | 2023-07-19 17:48:31 -0600 | [diff] [blame] | 246 | # Used so testing can obtain the builder: pylint: disable=W0603 |
| 247 | global TEST_BUILDER |
Simon Glass | a10ebe1 | 2014-09-05 19:00:18 -0600 | [diff] [blame] | 248 | |
Simon Glass | 761648b | 2022-01-29 14:14:11 -0700 | [diff] [blame] | 249 | gitutil.setup() |
Simon Glass | 9f1ba0f | 2016-07-27 20:33:02 -0600 | [diff] [blame] | 250 | col = terminal.Color() |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 251 | |
Simon Glass | 2183b84 | 2023-07-19 17:48:33 -0600 | [diff] [blame] | 252 | git_dir = os.path.join(options.git, '.git') |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 253 | |
Simon Glass | a3d9b4f | 2016-07-27 20:33:04 -0600 | [diff] [blame] | 254 | no_toolchains = toolchains is None |
| 255 | if no_toolchains: |
Simon Glass | f77ca5b | 2019-01-07 16:44:20 -0700 | [diff] [blame] | 256 | toolchains = toolchain.Toolchains(options.override_toolchain) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 257 | |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 258 | if options.fetch_arch: |
Simon Glass | 6c4beca | 2023-07-19 17:48:34 -0600 | [diff] [blame] | 259 | return do_fetch_arch(toolchains, col, options.fetch_arch) |
Simon Glass | af0e29f | 2023-07-19 17:48:31 -0600 | [diff] [blame] | 260 | |
Simon Glass | a3d9b4f | 2016-07-27 20:33:04 -0600 | [diff] [blame] | 261 | if no_toolchains: |
| 262 | toolchains.GetSettings() |
Simon Glass | 74579fc | 2018-11-06 16:02:10 -0700 | [diff] [blame] | 263 | toolchains.Scan(options.list_tool_chains and options.verbose) |
Simon Glass | a3d9b4f | 2016-07-27 20:33:04 -0600 | [diff] [blame] | 264 | if options.list_tool_chains: |
| 265 | toolchains.List() |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 266 | print() |
Simon Glass | a3d9b4f | 2016-07-27 20:33:04 -0600 | [diff] [blame] | 267 | return 0 |
| 268 | |
Simon Glass | d9c9863 | 2020-04-17 17:51:32 -0600 | [diff] [blame] | 269 | if not options.output_dir: |
| 270 | if options.work_in_output: |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 271 | sys.exit(col.build(col.RED, '-w requires that you specify -o')) |
Simon Glass | d9c9863 | 2020-04-17 17:51:32 -0600 | [diff] [blame] | 272 | options.output_dir = '..' |
Simon Glass | 6029af1 | 2020-04-09 15:08:51 -0600 | [diff] [blame] | 273 | |
Simon Glass | 5e728d4 | 2023-07-19 17:48:27 -0600 | [diff] [blame] | 274 | nr_cups = options.threads or multiprocessing.cpu_count() |
| 275 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 276 | # Work out what subset of the boards we are building |
Simon Glass | 5df4522 | 2022-07-11 19:04:00 -0600 | [diff] [blame] | 277 | if not brds: |
Tom Rini | 6ef6b3f | 2019-11-19 15:14:33 -0500 | [diff] [blame] | 278 | if not os.path.exists(options.output_dir): |
| 279 | os.makedirs(options.output_dir) |
Bin Meng | 0733e20 | 2019-10-28 07:24:59 -0700 | [diff] [blame] | 280 | board_file = os.path.join(options.output_dir, 'boards.cfg') |
Simon Glass | 09afcb7 | 2023-07-19 17:48:28 -0600 | [diff] [blame] | 281 | if options.regen_board_list and options.regen_board_list != '-': |
| 282 | board_file = options.regen_board_list |
Masahiro Yamada | e9bc8d2 | 2014-07-30 14:08:22 +0900 | [diff] [blame] | 283 | |
Simon Glass | 20751d6 | 2022-07-11 19:04:03 -0600 | [diff] [blame] | 284 | brds = boards.Boards() |
Simon Glass | af0e29f | 2023-07-19 17:48:31 -0600 | [diff] [blame] | 285 | |
Simon Glass | 5e728d4 | 2023-07-19 17:48:27 -0600 | [diff] [blame] | 286 | if options.maintainer_check: |
| 287 | warnings = brds.build_board_list(jobs=nr_cups)[1] |
| 288 | if warnings: |
| 289 | for warn in warnings: |
| 290 | print(warn, file=sys.stderr) |
| 291 | return 2 |
| 292 | return 0 |
| 293 | |
Simon Glass | af0e29f | 2023-07-19 17:48:31 -0600 | [diff] [blame] | 294 | okay = brds.ensure_board_list( |
| 295 | board_file, |
| 296 | options.threads or multiprocessing.cpu_count(), |
| 297 | force=options.regen_board_list, |
| 298 | quiet=not options.verbose) |
Simon Glass | 0c477b7 | 2022-07-11 19:04:04 -0600 | [diff] [blame] | 299 | if options.regen_board_list: |
Simon Glass | af0e29f | 2023-07-19 17:48:31 -0600 | [diff] [blame] | 300 | return 0 if okay else 2 |
Simon Glass | 127a239 | 2022-07-11 19:04:02 -0600 | [diff] [blame] | 301 | brds.read_boards(board_file) |
Simon Glass | 924c73a | 2014-08-28 09:43:41 -0600 | [diff] [blame] | 302 | |
| 303 | exclude = [] |
| 304 | if options.exclude: |
| 305 | for arg in options.exclude: |
| 306 | exclude += arg.split(',') |
| 307 | |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 308 | if options.boards: |
| 309 | requested_boards = [] |
Simon Glass | af0e29f | 2023-07-19 17:48:31 -0600 | [diff] [blame] | 310 | for brd in options.boards: |
| 311 | requested_boards += brd.split(',') |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 312 | else: |
| 313 | requested_boards = None |
Simon Glass | 127a239 | 2022-07-11 19:04:02 -0600 | [diff] [blame] | 314 | why_selected, board_warnings = brds.select_boards(args, exclude, |
| 315 | requested_boards) |
| 316 | selected = brds.get_selected() |
Simon Glass | af0e29f | 2023-07-19 17:48:31 -0600 | [diff] [blame] | 317 | if not selected: |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 318 | sys.exit(col.build(col.RED, 'No matching boards found')) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 319 | |
Simon Glass | 2df44be | 2020-03-18 09:42:47 -0600 | [diff] [blame] | 320 | if options.print_prefix: |
Simon Glass | c1e1e1d | 2023-07-19 17:48:30 -0600 | [diff] [blame] | 321 | err = show_toolchain_prefix(brds, toolchains) |
Simon Glass | 48ac42e | 2019-12-05 15:59:14 -0700 | [diff] [blame] | 322 | if err: |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 323 | sys.exit(col.build(col.RED, err)) |
Simon Glass | 48ac42e | 2019-12-05 15:59:14 -0700 | [diff] [blame] | 324 | return 0 |
| 325 | |
Simon Glass | 9b55091 | 2019-12-05 15:59:13 -0700 | [diff] [blame] | 326 | # Work out how many commits to build. We want to build everything on the |
| 327 | # branch. We also build the upstream commit as a control so we can see |
| 328 | # problems introduced by the first commit on the branch. |
| 329 | count = options.count |
| 330 | has_range = options.branch and '..' in options.branch |
| 331 | if count == -1: |
| 332 | if not options.branch: |
| 333 | count = 1 |
| 334 | else: |
| 335 | if has_range: |
Simon Glass | 2183b84 | 2023-07-19 17:48:33 -0600 | [diff] [blame] | 336 | count, msg = gitutil.count_commits_in_range(git_dir, |
| 337 | options.branch) |
Simon Glass | 9b55091 | 2019-12-05 15:59:13 -0700 | [diff] [blame] | 338 | else: |
Simon Glass | 2183b84 | 2023-07-19 17:48:33 -0600 | [diff] [blame] | 339 | count, msg = gitutil.count_commits_in_branch(git_dir, |
| 340 | options.branch) |
Simon Glass | 9b55091 | 2019-12-05 15:59:13 -0700 | [diff] [blame] | 341 | if count is None: |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 342 | sys.exit(col.build(col.RED, msg)) |
Simon Glass | 9b55091 | 2019-12-05 15:59:13 -0700 | [diff] [blame] | 343 | elif count == 0: |
Simon Glass | af0e29f | 2023-07-19 17:48:31 -0600 | [diff] [blame] | 344 | sys.exit(col.build(col.RED, |
| 345 | f"Range '{options.branch}' has no commits")) |
Simon Glass | 9b55091 | 2019-12-05 15:59:13 -0700 | [diff] [blame] | 346 | if msg: |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 347 | print(col.build(col.YELLOW, msg)) |
Simon Glass | 9b55091 | 2019-12-05 15:59:13 -0700 | [diff] [blame] | 348 | count += 1 # Build upstream commit also |
| 349 | |
| 350 | if not count: |
Simon Glass | af0e29f | 2023-07-19 17:48:31 -0600 | [diff] [blame] | 351 | msg = (f"No commits found to process in branch '{options.branch}': " |
| 352 | "set branch's upstream or use -c flag") |
Simon Glass | ba666eb | 2023-02-23 18:18:11 -0700 | [diff] [blame] | 353 | sys.exit(col.build(col.RED, msg)) |
Simon Glass | b6eb8cf | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 354 | if options.work_in_output: |
| 355 | if len(selected) != 1: |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 356 | sys.exit(col.build(col.RED, |
Simon Glass | b6eb8cf | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 357 | '-w can only be used with a single board')) |
| 358 | if count != 1: |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 359 | sys.exit(col.build(col.RED, |
Simon Glass | b6eb8cf | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 360 | '-w can only be used with a single commit')) |
Simon Glass | 9b55091 | 2019-12-05 15:59:13 -0700 | [diff] [blame] | 361 | |
Simon Glass | 2183b84 | 2023-07-19 17:48:33 -0600 | [diff] [blame] | 362 | series = determine_series(count, has_range, options.branch, git_dir) |
| 363 | if not series and not options.dry_run: |
| 364 | options.verbose = True |
| 365 | if not options.summary: |
| 366 | options.show_errors = True |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 367 | |
| 368 | # By default we have one thread per CPU. But if there are not enough jobs |
| 369 | # we can have fewer threads and use a high '-j' value for make. |
Simon Glass | c635d89 | 2021-01-30 22:17:46 -0700 | [diff] [blame] | 370 | if options.threads is None: |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 371 | options.threads = min(multiprocessing.cpu_count(), len(selected)) |
| 372 | if not options.jobs: |
| 373 | options.jobs = max(1, (multiprocessing.cpu_count() + |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 374 | len(selected) - 1) // len(selected)) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 375 | |
| 376 | if not options.step: |
| 377 | options.step = len(series.commits) - 1 |
| 378 | |
Simon Glass | 840be73 | 2022-01-29 14:14:05 -0700 | [diff] [blame] | 379 | gnu_make = command.output(os.path.join(options.git, |
Simon Glass | c55e056 | 2016-07-25 18:59:00 -0600 | [diff] [blame] | 380 | 'scripts/show-gnu-make'), raise_on_error=False).rstrip() |
Masahiro Yamada | 1fe610d | 2014-07-22 11:19:09 +0900 | [diff] [blame] | 381 | if not gnu_make: |
Masahiro Yamada | 880828d | 2014-08-16 00:59:26 +0900 | [diff] [blame] | 382 | sys.exit('GNU Make not found') |
Masahiro Yamada | 1fe610d | 2014-07-22 11:19:09 +0900 | [diff] [blame] | 383 | |
Tom Rini | 93ebd46 | 2022-11-09 19:14:53 -0700 | [diff] [blame] | 384 | allow_missing = get_allow_missing(options.allow_missing, |
| 385 | options.no_allow_missing, len(selected), |
| 386 | options.branch) |
| 387 | |
Simon Glass | dbc01c7 | 2014-12-01 17:33:52 -0700 | [diff] [blame] | 388 | # Create a new builder with the selected options. |
| 389 | output_dir = options.output_dir |
Simon Glass | d326ad7 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 390 | if options.branch: |
Simon Glass | 4aeceb9 | 2014-09-05 19:00:22 -0600 | [diff] [blame] | 391 | dirname = options.branch.replace('/', '_') |
Simon Glass | e87bde1 | 2014-12-01 17:33:55 -0700 | [diff] [blame] | 392 | # As a special case allow the board directory to be placed in the |
| 393 | # output directory itself rather than any subdirectory. |
| 394 | if not options.no_subdirs: |
| 395 | output_dir = os.path.join(options.output_dir, dirname) |
Lothar Waßmann | ce6df92 | 2018-04-08 05:14:11 -0600 | [diff] [blame] | 396 | if clean_dir and os.path.exists(output_dir): |
| 397 | shutil.rmtree(output_dir) |
Simon Glass | 02d537a | 2023-07-19 17:48:37 -0600 | [diff] [blame^] | 398 | |
| 399 | # For a dry run, just show our actions as a sanity check |
| 400 | if options.dry_run: |
| 401 | show_actions(series, why_selected, selected, output_dir, options, |
| 402 | board_warnings) |
| 403 | return 0 |
| 404 | |
Simon Glass | e5650a8 | 2022-01-22 05:07:33 -0700 | [diff] [blame] | 405 | adjust_cfg = cfgutil.convert_list_to_dict(options.adjust_cfg) |
| 406 | |
Simon Glass | 828d70d | 2023-02-21 12:40:29 -0700 | [diff] [blame] | 407 | # Drop LOCALVERSION_AUTO since it changes the version string on every commit |
| 408 | if options.reproducible_builds: |
| 409 | # If these are mentioned, leave the local version alone |
| 410 | if 'LOCALVERSION' in adjust_cfg or 'LOCALVERSION_AUTO' in adjust_cfg: |
| 411 | print('Not dropping LOCALVERSION_AUTO for reproducible build') |
| 412 | else: |
| 413 | adjust_cfg['LOCALVERSION_AUTO'] = '~' |
| 414 | |
Simon Glass | 2183b84 | 2023-07-19 17:48:33 -0600 | [diff] [blame] | 415 | builder = Builder(toolchains, output_dir, git_dir, |
Masahiro Yamada | 1fe610d | 2014-07-22 11:19:09 +0900 | [diff] [blame] | 416 | options.threads, options.jobs, gnu_make=gnu_make, checkout=True, |
Simon Glass | e87bde1 | 2014-12-01 17:33:55 -0700 | [diff] [blame] | 417 | show_unknown=options.show_unknown, step=options.step, |
Simon Glass | 655b610 | 2014-12-01 17:34:07 -0700 | [diff] [blame] | 418 | no_subdirs=options.no_subdirs, full_path=options.full_path, |
Stephen Warren | 97c9690 | 2016-04-11 10:48:44 -0600 | [diff] [blame] | 419 | verbose_build=options.verbose_build, |
Simon Glass | 6029af1 | 2020-04-09 15:08:51 -0600 | [diff] [blame] | 420 | mrproper=options.mrproper, |
Simon Glass | 739e851 | 2016-11-13 14:25:51 -0700 | [diff] [blame] | 421 | per_board_out_dir=options.per_board_out_dir, |
Simon Glass | cde5c30 | 2016-11-13 14:25:53 -0700 | [diff] [blame] | 422 | config_only=options.config_only, |
Daniel Schwierzeck | 20e2ea9 | 2018-01-26 16:31:05 +0100 | [diff] [blame] | 423 | squash_config_y=not options.preserve_config_y, |
Simon Glass | b6eb8cf | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 424 | warnings_as_errors=options.warnings_as_errors, |
Simon Glass | 9bf9a72 | 2021-04-11 16:27:27 +1200 | [diff] [blame] | 425 | work_in_output=options.work_in_output, |
Simon Glass | e5650a8 | 2022-01-22 05:07:33 -0700 | [diff] [blame] | 426 | test_thread_exceptions=test_thread_exceptions, |
Tom Rini | 93ebd46 | 2022-11-09 19:14:53 -0700 | [diff] [blame] | 427 | adjust_cfg=adjust_cfg, |
Simon Glass | 828d70d | 2023-02-21 12:40:29 -0700 | [diff] [blame] | 428 | allow_missing=allow_missing, no_lto=options.no_lto, |
| 429 | reproducible_builds=options.reproducible_builds) |
Simon Glass | af0e29f | 2023-07-19 17:48:31 -0600 | [diff] [blame] | 430 | TEST_BUILDER = builder |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 431 | builder.force_config_on_failure = not options.quick |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 432 | if make_func: |
| 433 | builder.do_make = make_func |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 434 | |
Simon Glass | 02d537a | 2023-07-19 17:48:37 -0600 | [diff] [blame^] | 435 | builder.force_build = options.force_build |
| 436 | builder.force_build_failures = options.force_build_failures |
| 437 | builder.force_reconfig = options.force_reconfig |
| 438 | builder.in_tree = options.in_tree |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 439 | |
Simon Glass | 02d537a | 2023-07-19 17:48:37 -0600 | [diff] [blame^] | 440 | # Work out which boards to build |
| 441 | board_selected = brds.get_selected_dict() |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 442 | |
Simon Glass | 02d537a | 2023-07-19 17:48:37 -0600 | [diff] [blame^] | 443 | if series: |
| 444 | commits = series.commits |
| 445 | # Number the commits for test purposes |
| 446 | for i, commit in enumerate(commits): |
| 447 | commit.sequence = i |
| 448 | else: |
| 449 | commits = None |
Simon Glass | d326ad7 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 450 | |
Simon Glass | 02d537a | 2023-07-19 17:48:37 -0600 | [diff] [blame^] | 451 | if not options.ide: |
| 452 | tprint(get_action_summary(options.summary, commits, board_selected, |
| 453 | options)) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 454 | |
Simon Glass | 02d537a | 2023-07-19 17:48:37 -0600 | [diff] [blame^] | 455 | # We can't show function sizes without board details at present |
| 456 | if options.show_bloat: |
| 457 | options.show_detail = True |
| 458 | builder.SetDisplayOptions( |
| 459 | options.show_errors, options.show_sizes, options.show_detail, |
| 460 | options.show_bloat, options.list_error_boards, options.show_config, |
| 461 | options.show_environment, options.filter_dtb_warnings, |
| 462 | options.filter_migration_warnings, options.ide) |
| 463 | if options.summary: |
| 464 | builder.ShowSummary(commits, board_selected) |
| 465 | else: |
| 466 | fail, warned, excs = builder.BuildBoards( |
| 467 | commits, board_selected, options.keep_outputs, options.verbose) |
| 468 | if excs: |
| 469 | return 102 |
| 470 | if fail: |
| 471 | return 100 |
| 472 | if warned and not options.ignore_warnings: |
| 473 | return 101 |
Simon Glass | c2f9107 | 2014-08-28 09:43:39 -0600 | [diff] [blame] | 474 | return 0 |