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 | |
| 5 | import multiprocessing |
Jan Kiszka | 6d7c40c | 2023-04-22 16:42:48 +0200 | [diff] [blame] | 6 | try: |
| 7 | import importlib.resources |
| 8 | except ImportError: |
| 9 | # for Python 3.6 |
| 10 | import importlib_resources |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 11 | import os |
Simon Glass | a10ebe1 | 2014-09-05 19:00:18 -0600 | [diff] [blame] | 12 | import shutil |
Simon Glass | f0d9c10 | 2020-04-17 18:09:02 -0600 | [diff] [blame] | 13 | import subprocess |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 14 | import sys |
| 15 | |
Simon Glass | 20751d6 | 2022-07-11 19:04:03 -0600 | [diff] [blame] | 16 | from buildman import boards |
Simon Glass | f0d9c10 | 2020-04-17 18:09:02 -0600 | [diff] [blame] | 17 | from buildman import bsettings |
Simon Glass | e5650a8 | 2022-01-22 05:07:33 -0700 | [diff] [blame] | 18 | from buildman import cfgutil |
Simon Glass | f0d9c10 | 2020-04-17 18:09:02 -0600 | [diff] [blame] | 19 | from buildman import toolchain |
| 20 | from buildman.builder import Builder |
Simon Glass | a997ea5 | 2020-04-17 18:09:04 -0600 | [diff] [blame] | 21 | from patman import gitutil |
| 22 | from patman import patchstream |
Simon Glass | 131444f | 2023-02-23 18:18:04 -0700 | [diff] [blame] | 23 | from u_boot_pylib import command |
| 24 | from u_boot_pylib import terminal |
| 25 | from u_boot_pylib import tools |
| 26 | from u_boot_pylib.terminal import tprint |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 27 | |
| 28 | def GetPlural(count): |
| 29 | """Returns a plural 's' if count is not 1""" |
| 30 | return 's' if count != 1 else '' |
| 31 | |
Simon Glass | d326ad7 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 32 | def GetActionSummary(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 | d326ad7 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 41 | commit_str = '%d commit%s' % (count, GetPlural(count)) |
| 42 | else: |
| 43 | commit_str = 'current source' |
| 44 | str = '%s %s for %d boards' % ( |
| 45 | 'Summary of' if is_summary else 'Building', commit_str, |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 46 | len(selected)) |
| 47 | str += ' (%d thread%s, %d job%s per thread)' % (options.threads, |
| 48 | GetPlural(options.threads), options.jobs, GetPlural(options.jobs)) |
| 49 | return str |
| 50 | |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 51 | def ShowActions(series, why_selected, boards_selected, builder, options, |
| 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 |
| 64 | builder: The builder that will be used to build the commits |
| 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 | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 75 | print(GetActionSummary(False, commits, boards_selected, |
| 76 | options)) |
| 77 | print('Build directory: %s' % builder.base_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 | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 86 | print(arg, ': %d boards' % len(why_selected[arg])) |
Simon Glass | 6af145f | 2017-01-23 05:38:56 -0700 | [diff] [blame] | 87 | if options.verbose: |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 88 | print(' %s' % ' '.join(why_selected[arg])) |
| 89 | print(('Total boards to build for each commit: %d\n' % |
| 90 | len(why_selected['all']))) |
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 | 5df4522 | 2022-07-11 19:04:00 -0600 | [diff] [blame] | 95 | def ShowToolchainPrefix(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' |
| 114 | return False |
| 115 | tc = tc_set.pop() |
Simon Glass | 2df44be | 2020-03-18 09:42:47 -0600 | [diff] [blame] | 116 | print(tc.GetEnvArgs(toolchain.VAR_CROSS_COMPILE)) |
Simon Glass | 48ac42e | 2019-12-05 15:59:14 -0700 | [diff] [blame] | 117 | return None |
| 118 | |
Tom Rini | 93ebd46 | 2022-11-09 19:14:53 -0700 | [diff] [blame] | 119 | def get_allow_missing(opt_allow, opt_no_allow, num_selected, has_branch): |
| 120 | allow_missing = False |
| 121 | am_setting = bsettings.GetGlobalItemValue('allow-missing') |
| 122 | if am_setting: |
| 123 | if am_setting == 'always': |
| 124 | allow_missing = True |
| 125 | if 'multiple' in am_setting and num_selected > 1: |
| 126 | allow_missing = True |
| 127 | if 'branch' in am_setting and has_branch: |
| 128 | allow_missing = True |
| 129 | |
| 130 | if opt_allow: |
| 131 | allow_missing = True |
| 132 | if opt_no_allow: |
| 133 | allow_missing = False |
| 134 | return allow_missing |
| 135 | |
Simon Glass | 5df4522 | 2022-07-11 19:04:00 -0600 | [diff] [blame] | 136 | def DoBuildman(options, args, toolchains=None, make_func=None, brds=None, |
Simon Glass | 9bf9a72 | 2021-04-11 16:27:27 +1200 | [diff] [blame] | 137 | clean_dir=False, test_thread_exceptions=False): |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 138 | """The main control code for buildman |
| 139 | |
| 140 | Args: |
| 141 | options: Command line options object |
| 142 | args: Command line arguments (list of strings) |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 143 | toolchains: Toolchains to use - this should be a Toolchains() |
| 144 | object. If None, then it will be created and scanned |
| 145 | make_func: Make function to use for the builder. This is called |
| 146 | to execute 'make'. If this is None, the normal function |
| 147 | will be used, which calls the 'make' tool with suitable |
| 148 | arguments. This setting is useful for tests. |
Simon Glass | 5df4522 | 2022-07-11 19:04:00 -0600 | [diff] [blame] | 149 | brds: Boards() object to use, containing a list of available |
Simon Glass | cbd3658 | 2014-09-05 19:00:16 -0600 | [diff] [blame] | 150 | boards. If this is None it will be created and scanned. |
Simon Glass | a29b3ea | 2021-04-11 16:27:25 +1200 | [diff] [blame] | 151 | clean_dir: Used for tests only, indicates that the existing output_dir |
| 152 | should be removed before starting the build |
Simon Glass | 9bf9a72 | 2021-04-11 16:27:27 +1200 | [diff] [blame] | 153 | test_thread_exceptions: Uses for tests only, True to make the threads |
| 154 | raise an exception instead of reporting their result. This simulates |
| 155 | a failure in the code somewhere |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 156 | """ |
Simon Glass | a10ebe1 | 2014-09-05 19:00:18 -0600 | [diff] [blame] | 157 | global builder |
| 158 | |
Simon Glass | ca9b06e | 2014-09-05 19:00:11 -0600 | [diff] [blame] | 159 | if options.full_help: |
Simon Glass | c573580 | 2023-02-23 18:18:12 -0700 | [diff] [blame] | 160 | with importlib.resources.path('buildman', 'README.rst') as readme: |
| 161 | tools.print_full_help(str(readme)) |
Simon Glass | ca9b06e | 2014-09-05 19:00:11 -0600 | [diff] [blame] | 162 | return 0 |
| 163 | |
Simon Glass | 761648b | 2022-01-29 14:14:11 -0700 | [diff] [blame] | 164 | gitutil.setup() |
Simon Glass | 9f1ba0f | 2016-07-27 20:33:02 -0600 | [diff] [blame] | 165 | col = terminal.Color() |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 166 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 167 | options.git_dir = os.path.join(options.git, '.git') |
| 168 | |
Simon Glass | a3d9b4f | 2016-07-27 20:33:04 -0600 | [diff] [blame] | 169 | no_toolchains = toolchains is None |
| 170 | if no_toolchains: |
Simon Glass | f77ca5b | 2019-01-07 16:44:20 -0700 | [diff] [blame] | 171 | toolchains = toolchain.Toolchains(options.override_toolchain) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 172 | |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 173 | if options.fetch_arch: |
| 174 | if options.fetch_arch == 'list': |
| 175 | sorted_list = toolchains.ListArchs() |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 176 | print(col.build(col.BLUE, 'Available architectures: %s\n' % |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 177 | ' '.join(sorted_list))) |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 178 | return 0 |
| 179 | else: |
| 180 | fetch_arch = options.fetch_arch |
| 181 | if fetch_arch == 'all': |
| 182 | fetch_arch = ','.join(toolchains.ListArchs()) |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 183 | print(col.build(col.CYAN, '\nDownloading toolchains: %s' % |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 184 | fetch_arch)) |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 185 | for arch in fetch_arch.split(','): |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 186 | print() |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 187 | ret = toolchains.FetchAndInstall(arch) |
| 188 | if ret: |
| 189 | return ret |
| 190 | return 0 |
| 191 | |
Simon Glass | a3d9b4f | 2016-07-27 20:33:04 -0600 | [diff] [blame] | 192 | if no_toolchains: |
| 193 | toolchains.GetSettings() |
Simon Glass | 74579fc | 2018-11-06 16:02:10 -0700 | [diff] [blame] | 194 | toolchains.Scan(options.list_tool_chains and options.verbose) |
Simon Glass | a3d9b4f | 2016-07-27 20:33:04 -0600 | [diff] [blame] | 195 | if options.list_tool_chains: |
| 196 | toolchains.List() |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 197 | print() |
Simon Glass | a3d9b4f | 2016-07-27 20:33:04 -0600 | [diff] [blame] | 198 | return 0 |
| 199 | |
Simon Glass | d9c9863 | 2020-04-17 17:51:32 -0600 | [diff] [blame] | 200 | if not options.output_dir: |
| 201 | if options.work_in_output: |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 202 | sys.exit(col.build(col.RED, '-w requires that you specify -o')) |
Simon Glass | d9c9863 | 2020-04-17 17:51:32 -0600 | [diff] [blame] | 203 | options.output_dir = '..' |
Simon Glass | 6029af1 | 2020-04-09 15:08:51 -0600 | [diff] [blame] | 204 | |
Simon Glass | 5e728d4 | 2023-07-19 17:48:27 -0600 | [diff] [blame^] | 205 | nr_cups = options.threads or multiprocessing.cpu_count() |
| 206 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 207 | # Work out what subset of the boards we are building |
Simon Glass | 5df4522 | 2022-07-11 19:04:00 -0600 | [diff] [blame] | 208 | if not brds: |
Tom Rini | 6ef6b3f | 2019-11-19 15:14:33 -0500 | [diff] [blame] | 209 | if not os.path.exists(options.output_dir): |
| 210 | os.makedirs(options.output_dir) |
Bin Meng | 0733e20 | 2019-10-28 07:24:59 -0700 | [diff] [blame] | 211 | board_file = os.path.join(options.output_dir, 'boards.cfg') |
Masahiro Yamada | e9bc8d2 | 2014-07-30 14:08:22 +0900 | [diff] [blame] | 212 | |
Simon Glass | 20751d6 | 2022-07-11 19:04:03 -0600 | [diff] [blame] | 213 | brds = boards.Boards() |
Simon Glass | 5e728d4 | 2023-07-19 17:48:27 -0600 | [diff] [blame^] | 214 | if options.maintainer_check: |
| 215 | warnings = brds.build_board_list(jobs=nr_cups)[1] |
| 216 | if warnings: |
| 217 | for warn in warnings: |
| 218 | print(warn, file=sys.stderr) |
| 219 | return 2 |
| 220 | return 0 |
| 221 | |
| 222 | ok = brds.ensure_board_list(board_file, nr_cups, |
Simon Glass | afbd213 | 2022-07-11 19:04:08 -0600 | [diff] [blame] | 223 | force=options.regen_board_list, |
| 224 | quiet=not options.verbose) |
Simon Glass | 0c477b7 | 2022-07-11 19:04:04 -0600 | [diff] [blame] | 225 | if options.regen_board_list: |
Simon Glass | afbd213 | 2022-07-11 19:04:08 -0600 | [diff] [blame] | 226 | return 0 if ok else 2 |
Simon Glass | 127a239 | 2022-07-11 19:04:02 -0600 | [diff] [blame] | 227 | brds.read_boards(board_file) |
Simon Glass | 924c73a | 2014-08-28 09:43:41 -0600 | [diff] [blame] | 228 | |
| 229 | exclude = [] |
| 230 | if options.exclude: |
| 231 | for arg in options.exclude: |
| 232 | exclude += arg.split(',') |
| 233 | |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 234 | if options.boards: |
| 235 | requested_boards = [] |
| 236 | for b in options.boards: |
| 237 | requested_boards += b.split(',') |
| 238 | else: |
| 239 | requested_boards = None |
Simon Glass | 127a239 | 2022-07-11 19:04:02 -0600 | [diff] [blame] | 240 | why_selected, board_warnings = brds.select_boards(args, exclude, |
| 241 | requested_boards) |
| 242 | selected = brds.get_selected() |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 243 | if not len(selected): |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 244 | sys.exit(col.build(col.RED, 'No matching boards found')) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 245 | |
Simon Glass | 2df44be | 2020-03-18 09:42:47 -0600 | [diff] [blame] | 246 | if options.print_prefix: |
Simon Glass | 5df4522 | 2022-07-11 19:04:00 -0600 | [diff] [blame] | 247 | err = ShowToolchainPrefix(brds, toolchains) |
Simon Glass | 48ac42e | 2019-12-05 15:59:14 -0700 | [diff] [blame] | 248 | if err: |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 249 | sys.exit(col.build(col.RED, err)) |
Simon Glass | 48ac42e | 2019-12-05 15:59:14 -0700 | [diff] [blame] | 250 | return 0 |
| 251 | |
Simon Glass | 9b55091 | 2019-12-05 15:59:13 -0700 | [diff] [blame] | 252 | # Work out how many commits to build. We want to build everything on the |
| 253 | # branch. We also build the upstream commit as a control so we can see |
| 254 | # problems introduced by the first commit on the branch. |
| 255 | count = options.count |
| 256 | has_range = options.branch and '..' in options.branch |
| 257 | if count == -1: |
| 258 | if not options.branch: |
| 259 | count = 1 |
| 260 | else: |
| 261 | if has_range: |
Simon Glass | 761648b | 2022-01-29 14:14:11 -0700 | [diff] [blame] | 262 | count, msg = gitutil.count_commits_in_range(options.git_dir, |
Simon Glass | 9b55091 | 2019-12-05 15:59:13 -0700 | [diff] [blame] | 263 | options.branch) |
| 264 | else: |
Simon Glass | 761648b | 2022-01-29 14:14:11 -0700 | [diff] [blame] | 265 | count, msg = gitutil.count_commits_in_branch(options.git_dir, |
Simon Glass | 9b55091 | 2019-12-05 15:59:13 -0700 | [diff] [blame] | 266 | options.branch) |
| 267 | if count is None: |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 268 | sys.exit(col.build(col.RED, msg)) |
Simon Glass | 9b55091 | 2019-12-05 15:59:13 -0700 | [diff] [blame] | 269 | elif count == 0: |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 270 | sys.exit(col.build(col.RED, "Range '%s' has no commits" % |
Simon Glass | 9b55091 | 2019-12-05 15:59:13 -0700 | [diff] [blame] | 271 | options.branch)) |
| 272 | if msg: |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 273 | print(col.build(col.YELLOW, msg)) |
Simon Glass | 9b55091 | 2019-12-05 15:59:13 -0700 | [diff] [blame] | 274 | count += 1 # Build upstream commit also |
| 275 | |
| 276 | if not count: |
Simon Glass | ba666eb | 2023-02-23 18:18:11 -0700 | [diff] [blame] | 277 | msg = ("No commits found to process in branch '%s': " |
Simon Glass | 9b55091 | 2019-12-05 15:59:13 -0700 | [diff] [blame] | 278 | "set branch's upstream or use -c flag" % options.branch) |
Simon Glass | ba666eb | 2023-02-23 18:18:11 -0700 | [diff] [blame] | 279 | sys.exit(col.build(col.RED, msg)) |
Simon Glass | b6eb8cf | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 280 | if options.work_in_output: |
| 281 | if len(selected) != 1: |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 282 | sys.exit(col.build(col.RED, |
Simon Glass | b6eb8cf | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 283 | '-w can only be used with a single board')) |
| 284 | if count != 1: |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 285 | sys.exit(col.build(col.RED, |
Simon Glass | b6eb8cf | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 286 | '-w can only be used with a single commit')) |
Simon Glass | 9b55091 | 2019-12-05 15:59:13 -0700 | [diff] [blame] | 287 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 288 | # Read the metadata from the commits. First look at the upstream commit, |
| 289 | # then the ones in the branch. We would like to do something like |
| 290 | # upstream/master~..branch but that isn't possible if upstream/master is |
| 291 | # a merge commit (it will list all the commits that form part of the |
| 292 | # merge) |
Simon Glass | 359b55a6 | 2014-09-05 19:00:23 -0600 | [diff] [blame] | 293 | # Conflicting tags are not a problem for buildman, since it does not use |
| 294 | # them. For example, Series-version is not useful for buildman. On the |
| 295 | # other hand conflicting tags will cause an error. So allow later tags |
| 296 | # to overwrite earlier ones by setting allow_overwrite=True |
Simon Glass | d326ad7 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 297 | if options.branch: |
Simon Glass | 16a5288 | 2014-08-09 15:33:09 -0600 | [diff] [blame] | 298 | if count == -1: |
Simon Glass | 5eeef46 | 2014-12-01 17:33:57 -0700 | [diff] [blame] | 299 | if has_range: |
| 300 | range_expr = options.branch |
| 301 | else: |
Simon Glass | 761648b | 2022-01-29 14:14:11 -0700 | [diff] [blame] | 302 | range_expr = gitutil.get_range_in_branch(options.git_dir, |
Simon Glass | 5eeef46 | 2014-12-01 17:33:57 -0700 | [diff] [blame] | 303 | options.branch) |
Simon Glass | 761648b | 2022-01-29 14:14:11 -0700 | [diff] [blame] | 304 | upstream_commit = gitutil.get_upstream(options.git_dir, |
Simon Glass | 16a5288 | 2014-08-09 15:33:09 -0600 | [diff] [blame] | 305 | options.branch) |
Simon Glass | 93f61c0 | 2020-10-29 21:46:19 -0600 | [diff] [blame] | 306 | series = patchstream.get_metadata_for_list(upstream_commit, |
Simon Glass | 359b55a6 | 2014-09-05 19:00:23 -0600 | [diff] [blame] | 307 | options.git_dir, 1, series=None, allow_overwrite=True) |
Simon Glass | d326ad7 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 308 | |
Simon Glass | 93f61c0 | 2020-10-29 21:46:19 -0600 | [diff] [blame] | 309 | series = patchstream.get_metadata_for_list(range_expr, |
Simon Glass | 359b55a6 | 2014-09-05 19:00:23 -0600 | [diff] [blame] | 310 | options.git_dir, None, series, allow_overwrite=True) |
Simon Glass | 16a5288 | 2014-08-09 15:33:09 -0600 | [diff] [blame] | 311 | else: |
| 312 | # Honour the count |
Simon Glass | 93f61c0 | 2020-10-29 21:46:19 -0600 | [diff] [blame] | 313 | series = patchstream.get_metadata_for_list(options.branch, |
Simon Glass | 359b55a6 | 2014-09-05 19:00:23 -0600 | [diff] [blame] | 314 | options.git_dir, count, series=None, allow_overwrite=True) |
Simon Glass | d326ad7 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 315 | else: |
| 316 | series = None |
Simon Glass | 6af145f | 2017-01-23 05:38:56 -0700 | [diff] [blame] | 317 | if not options.dry_run: |
| 318 | options.verbose = True |
| 319 | if not options.summary: |
| 320 | options.show_errors = True |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 321 | |
| 322 | # By default we have one thread per CPU. But if there are not enough jobs |
| 323 | # 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] | 324 | if options.threads is None: |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 325 | options.threads = min(multiprocessing.cpu_count(), len(selected)) |
| 326 | if not options.jobs: |
| 327 | options.jobs = max(1, (multiprocessing.cpu_count() + |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 328 | len(selected) - 1) // len(selected)) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 329 | |
| 330 | if not options.step: |
| 331 | options.step = len(series.commits) - 1 |
| 332 | |
Simon Glass | 840be73 | 2022-01-29 14:14:05 -0700 | [diff] [blame] | 333 | gnu_make = command.output(os.path.join(options.git, |
Simon Glass | c55e056 | 2016-07-25 18:59:00 -0600 | [diff] [blame] | 334 | 'scripts/show-gnu-make'), raise_on_error=False).rstrip() |
Masahiro Yamada | 1fe610d | 2014-07-22 11:19:09 +0900 | [diff] [blame] | 335 | if not gnu_make: |
Masahiro Yamada | 880828d | 2014-08-16 00:59:26 +0900 | [diff] [blame] | 336 | sys.exit('GNU Make not found') |
Masahiro Yamada | 1fe610d | 2014-07-22 11:19:09 +0900 | [diff] [blame] | 337 | |
Tom Rini | 93ebd46 | 2022-11-09 19:14:53 -0700 | [diff] [blame] | 338 | allow_missing = get_allow_missing(options.allow_missing, |
| 339 | options.no_allow_missing, len(selected), |
| 340 | options.branch) |
| 341 | |
Simon Glass | dbc01c7 | 2014-12-01 17:33:52 -0700 | [diff] [blame] | 342 | # Create a new builder with the selected options. |
| 343 | output_dir = options.output_dir |
Simon Glass | d326ad7 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 344 | if options.branch: |
Simon Glass | 4aeceb9 | 2014-09-05 19:00:22 -0600 | [diff] [blame] | 345 | dirname = options.branch.replace('/', '_') |
Simon Glass | e87bde1 | 2014-12-01 17:33:55 -0700 | [diff] [blame] | 346 | # As a special case allow the board directory to be placed in the |
| 347 | # output directory itself rather than any subdirectory. |
| 348 | if not options.no_subdirs: |
| 349 | output_dir = os.path.join(options.output_dir, dirname) |
Lothar Waßmann | ce6df92 | 2018-04-08 05:14:11 -0600 | [diff] [blame] | 350 | if clean_dir and os.path.exists(output_dir): |
| 351 | shutil.rmtree(output_dir) |
Simon Glass | e5650a8 | 2022-01-22 05:07:33 -0700 | [diff] [blame] | 352 | adjust_cfg = cfgutil.convert_list_to_dict(options.adjust_cfg) |
| 353 | |
Simon Glass | 828d70d | 2023-02-21 12:40:29 -0700 | [diff] [blame] | 354 | # Drop LOCALVERSION_AUTO since it changes the version string on every commit |
| 355 | if options.reproducible_builds: |
| 356 | # If these are mentioned, leave the local version alone |
| 357 | if 'LOCALVERSION' in adjust_cfg or 'LOCALVERSION_AUTO' in adjust_cfg: |
| 358 | print('Not dropping LOCALVERSION_AUTO for reproducible build') |
| 359 | else: |
| 360 | adjust_cfg['LOCALVERSION_AUTO'] = '~' |
| 361 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 362 | builder = Builder(toolchains, output_dir, options.git_dir, |
Masahiro Yamada | 1fe610d | 2014-07-22 11:19:09 +0900 | [diff] [blame] | 363 | options.threads, options.jobs, gnu_make=gnu_make, checkout=True, |
Simon Glass | e87bde1 | 2014-12-01 17:33:55 -0700 | [diff] [blame] | 364 | show_unknown=options.show_unknown, step=options.step, |
Simon Glass | 655b610 | 2014-12-01 17:34:07 -0700 | [diff] [blame] | 365 | no_subdirs=options.no_subdirs, full_path=options.full_path, |
Stephen Warren | 97c9690 | 2016-04-11 10:48:44 -0600 | [diff] [blame] | 366 | verbose_build=options.verbose_build, |
Simon Glass | 6029af1 | 2020-04-09 15:08:51 -0600 | [diff] [blame] | 367 | mrproper=options.mrproper, |
Simon Glass | 739e851 | 2016-11-13 14:25:51 -0700 | [diff] [blame] | 368 | per_board_out_dir=options.per_board_out_dir, |
Simon Glass | cde5c30 | 2016-11-13 14:25:53 -0700 | [diff] [blame] | 369 | config_only=options.config_only, |
Daniel Schwierzeck | 20e2ea9 | 2018-01-26 16:31:05 +0100 | [diff] [blame] | 370 | squash_config_y=not options.preserve_config_y, |
Simon Glass | b6eb8cf | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 371 | warnings_as_errors=options.warnings_as_errors, |
Simon Glass | 9bf9a72 | 2021-04-11 16:27:27 +1200 | [diff] [blame] | 372 | work_in_output=options.work_in_output, |
Simon Glass | e5650a8 | 2022-01-22 05:07:33 -0700 | [diff] [blame] | 373 | test_thread_exceptions=test_thread_exceptions, |
Tom Rini | 93ebd46 | 2022-11-09 19:14:53 -0700 | [diff] [blame] | 374 | adjust_cfg=adjust_cfg, |
Simon Glass | 828d70d | 2023-02-21 12:40:29 -0700 | [diff] [blame] | 375 | allow_missing=allow_missing, no_lto=options.no_lto, |
| 376 | reproducible_builds=options.reproducible_builds) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 377 | builder.force_config_on_failure = not options.quick |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 378 | if make_func: |
| 379 | builder.do_make = make_func |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 380 | |
| 381 | # For a dry run, just show our actions as a sanity check |
| 382 | if options.dry_run: |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 383 | ShowActions(series, why_selected, selected, builder, options, |
| 384 | board_warnings) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 385 | else: |
| 386 | builder.force_build = options.force_build |
Simon Glass | 7041c39 | 2014-07-13 12:22:31 -0600 | [diff] [blame] | 387 | builder.force_build_failures = options.force_build_failures |
Simon Glass | f3018b7a | 2014-07-14 17:51:02 -0600 | [diff] [blame] | 388 | builder.force_reconfig = options.force_reconfig |
Simon Glass | 38df2e2 | 2014-07-14 17:51:03 -0600 | [diff] [blame] | 389 | builder.in_tree = options.in_tree |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 390 | |
| 391 | # Work out which boards to build |
Simon Glass | 127a239 | 2022-07-11 19:04:02 -0600 | [diff] [blame] | 392 | board_selected = brds.get_selected_dict() |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 393 | |
Simon Glass | d326ad7 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 394 | if series: |
| 395 | commits = series.commits |
Simon Glass | a10ebe1 | 2014-09-05 19:00:18 -0600 | [diff] [blame] | 396 | # Number the commits for test purposes |
| 397 | for commit in range(len(commits)): |
| 398 | commits[commit].sequence = commit |
Simon Glass | d326ad7 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 399 | else: |
| 400 | commits = None |
| 401 | |
Simon Glass | 6c43562 | 2022-07-11 19:03:56 -0600 | [diff] [blame] | 402 | if not options.ide: |
| 403 | tprint(GetActionSummary(options.summary, commits, board_selected, |
| 404 | options)) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 405 | |
Simon Glass | 232d850 | 2014-09-14 20:23:16 -0600 | [diff] [blame] | 406 | # We can't show function sizes without board details at present |
| 407 | if options.show_bloat: |
| 408 | options.show_detail = True |
Simon Glass | 9ea9381 | 2020-04-09 15:08:52 -0600 | [diff] [blame] | 409 | builder.SetDisplayOptions( |
| 410 | options.show_errors, options.show_sizes, options.show_detail, |
| 411 | options.show_bloat, options.list_error_boards, options.show_config, |
Simon Glass | f4ebfba | 2020-04-09 15:08:53 -0600 | [diff] [blame] | 412 | options.show_environment, options.filter_dtb_warnings, |
Simon Glass | 6c43562 | 2022-07-11 19:03:56 -0600 | [diff] [blame] | 413 | options.filter_migration_warnings, options.ide) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 414 | if options.summary: |
Simon Glass | eb48bbc | 2014-08-09 15:33:02 -0600 | [diff] [blame] | 415 | builder.ShowSummary(commits, board_selected) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 416 | else: |
Simon Glass | 9bf9a72 | 2021-04-11 16:27:27 +1200 | [diff] [blame] | 417 | fail, warned, excs = builder.BuildBoards( |
| 418 | commits, board_selected, options.keep_outputs, options.verbose) |
| 419 | if excs: |
| 420 | return 102 |
| 421 | elif fail: |
Simon Glass | e4cd506 | 2020-04-09 10:49:45 -0600 | [diff] [blame] | 422 | return 100 |
Simon Glass | 35e7d38 | 2020-03-18 09:42:44 -0600 | [diff] [blame] | 423 | elif warned and not options.ignore_warnings: |
Simon Glass | e4cd506 | 2020-04-09 10:49:45 -0600 | [diff] [blame] | 424 | return 101 |
Simon Glass | c2f9107 | 2014-08-28 09:43:39 -0600 | [diff] [blame] | 425 | return 0 |