Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 2 | # Copyright (c) 2014 Google, Inc |
| 3 | # |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 4 | |
Simon Glass | d07e553 | 2023-07-19 17:49:09 -0600 | [diff] [blame] | 5 | """Implementation the bulider threads |
| 6 | |
| 7 | This module provides the BuilderThread class, which handles calling the builder |
| 8 | based on the jobs provided. |
| 9 | """ |
| 10 | |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 11 | import errno |
| 12 | import glob |
| 13 | import os |
| 14 | import shutil |
Lothar Waßmann | ce6df92 | 2018-04-08 05:14:11 -0600 | [diff] [blame] | 15 | import sys |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 16 | import threading |
| 17 | |
Simon Glass | e5650a8 | 2022-01-22 05:07:33 -0700 | [diff] [blame] | 18 | from buildman import cfgutil |
Simon Glass | a997ea5 | 2020-04-17 18:09:04 -0600 | [diff] [blame] | 19 | from patman import gitutil |
Simon Glass | 131444f | 2023-02-23 18:18:04 -0700 | [diff] [blame] | 20 | from u_boot_pylib import command |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 21 | |
Simon Glass | fd3eea1 | 2015-02-05 22:06:13 -0700 | [diff] [blame] | 22 | RETURN_CODE_RETRY = -1 |
Simon Glass | e0f1971 | 2020-12-16 17:24:17 -0700 | [diff] [blame] | 23 | BASE_ELF_FILENAMES = ['u-boot', 'spl/u-boot-spl', 'tpl/u-boot-tpl'] |
Simon Glass | fd3eea1 | 2015-02-05 22:06:13 -0700 | [diff] [blame] | 24 | |
Simon Glass | c5077c3 | 2023-07-19 17:49:08 -0600 | [diff] [blame] | 25 | def mkdir(dirname, parents = False): |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 26 | """Make a directory if it doesn't already exist. |
| 27 | |
| 28 | Args: |
| 29 | dirname: Directory to create |
| 30 | """ |
| 31 | try: |
Thierry Reding | 336d5bd | 2014-08-19 10:22:39 +0200 | [diff] [blame] | 32 | if parents: |
| 33 | os.makedirs(dirname) |
| 34 | else: |
| 35 | os.mkdir(dirname) |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 36 | except OSError as err: |
| 37 | if err.errno == errno.EEXIST: |
Lothar Waßmann | ce6df92 | 2018-04-08 05:14:11 -0600 | [diff] [blame] | 38 | if os.path.realpath('.') == os.path.realpath(dirname): |
Simon Glass | d07e553 | 2023-07-19 17:49:09 -0600 | [diff] [blame] | 39 | print(f"Cannot create the current working directory '{dirname}'!") |
Lothar Waßmann | ce6df92 | 2018-04-08 05:14:11 -0600 | [diff] [blame] | 40 | sys.exit(1) |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 41 | else: |
| 42 | raise |
| 43 | |
Simon Glass | d07e553 | 2023-07-19 17:49:09 -0600 | [diff] [blame] | 44 | # pylint: disable=R0903 |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 45 | class BuilderJob: |
| 46 | """Holds information about a job to be performed by a thread |
| 47 | |
| 48 | Members: |
Simon Glass | 8132f98 | 2022-07-11 19:03:57 -0600 | [diff] [blame] | 49 | brd: Board object to build |
Simon Glass | df89015 | 2020-03-18 09:42:41 -0600 | [diff] [blame] | 50 | commits: List of Commit objects to build |
| 51 | keep_outputs: True to save build output files |
| 52 | step: 1 to process every commit, n to process every nth commit |
Simon Glass | b6eb8cf | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 53 | work_in_output: Use the output directory as the work directory and |
| 54 | don't write to a separate output directory. |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 55 | """ |
| 56 | def __init__(self): |
Simon Glass | 8132f98 | 2022-07-11 19:03:57 -0600 | [diff] [blame] | 57 | self.brd = None |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 58 | self.commits = [] |
Simon Glass | df89015 | 2020-03-18 09:42:41 -0600 | [diff] [blame] | 59 | self.keep_outputs = False |
| 60 | self.step = 1 |
Simon Glass | b6eb8cf | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 61 | self.work_in_output = False |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 62 | |
| 63 | |
| 64 | class ResultThread(threading.Thread): |
| 65 | """This thread processes results from builder threads. |
| 66 | |
| 67 | It simply passes the results on to the builder. There is only one |
| 68 | result thread, and this helps to serialise the build output. |
| 69 | """ |
| 70 | def __init__(self, builder): |
| 71 | """Set up a new result thread |
| 72 | |
| 73 | Args: |
| 74 | builder: Builder which will be sent each result |
| 75 | """ |
| 76 | threading.Thread.__init__(self) |
| 77 | self.builder = builder |
| 78 | |
| 79 | def run(self): |
| 80 | """Called to start up the result thread. |
| 81 | |
| 82 | We collect the next result job and pass it on to the build. |
| 83 | """ |
| 84 | while True: |
| 85 | result = self.builder.out_queue.get() |
Simon Glass | bc74d94 | 2023-07-19 17:49:06 -0600 | [diff] [blame] | 86 | self.builder.process_result(result) |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 87 | self.builder.out_queue.task_done() |
| 88 | |
| 89 | |
| 90 | class BuilderThread(threading.Thread): |
| 91 | """This thread builds U-Boot for a particular board. |
| 92 | |
| 93 | An input queue provides each new job. We run 'make' to build U-Boot |
| 94 | and then pass the results on to the output queue. |
| 95 | |
| 96 | Members: |
| 97 | builder: The builder which contains information we might need |
| 98 | thread_num: Our thread number (0-n-1), used to decide on a |
Simon Glass | a29b3ea | 2021-04-11 16:27:25 +1200 | [diff] [blame] | 99 | temporary directory. If this is -1 then there are no threads |
| 100 | and we are the (only) main process |
| 101 | mrproper: Use 'make mrproper' before each reconfigure |
| 102 | per_board_out_dir: True to build in a separate persistent directory per |
| 103 | board rather than a thread-specific directory |
| 104 | test_exception: Used for testing; True to raise an exception instead of |
| 105 | reporting the build result |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 106 | """ |
Simon Glass | 9bf9a72 | 2021-04-11 16:27:27 +1200 | [diff] [blame] | 107 | def __init__(self, builder, thread_num, mrproper, per_board_out_dir, |
| 108 | test_exception=False): |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 109 | """Set up a new builder thread""" |
| 110 | threading.Thread.__init__(self) |
| 111 | self.builder = builder |
| 112 | self.thread_num = thread_num |
Simon Glass | 6029af1 | 2020-04-09 15:08:51 -0600 | [diff] [blame] | 113 | self.mrproper = mrproper |
Stephen Warren | 97c9690 | 2016-04-11 10:48:44 -0600 | [diff] [blame] | 114 | self.per_board_out_dir = per_board_out_dir |
Simon Glass | 9bf9a72 | 2021-04-11 16:27:27 +1200 | [diff] [blame] | 115 | self.test_exception = test_exception |
Simon Glass | d07e553 | 2023-07-19 17:49:09 -0600 | [diff] [blame] | 116 | self.toolchain = None |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 117 | |
Simon Glass | c5077c3 | 2023-07-19 17:49:08 -0600 | [diff] [blame] | 118 | def make(self, commit, brd, stage, cwd, *args, **kwargs): |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 119 | """Run 'make' on a particular commit and board. |
| 120 | |
| 121 | The source code will already be checked out, so the 'commit' |
| 122 | argument is only for information. |
| 123 | |
| 124 | Args: |
| 125 | commit: Commit object that is being built |
| 126 | brd: Board object that is being built |
| 127 | stage: Stage of the build. Valid stages are: |
Roger Meier | e0a0e55 | 2014-08-20 22:10:29 +0200 | [diff] [blame] | 128 | mrproper - can be called to clean source |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 129 | config - called to configure for a board |
| 130 | build - the main make invocation - it does the build |
| 131 | args: A list of arguments to pass to 'make' |
Simon Glass | 840be73 | 2022-01-29 14:14:05 -0700 | [diff] [blame] | 132 | kwargs: A list of keyword arguments to pass to command.run_pipe() |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 133 | |
| 134 | Returns: |
| 135 | CommandResult object |
| 136 | """ |
| 137 | return self.builder.do_make(commit, brd, stage, cwd, *args, |
| 138 | **kwargs) |
| 139 | |
Simon Glass | 8d0b6b4 | 2023-07-19 17:49:13 -0600 | [diff] [blame^] | 140 | def _build_args(self, args): |
| 141 | """Set up arguments to the args list based on the settings |
| 142 | |
| 143 | Args: |
| 144 | args (list of str): List of string arguments to add things to |
| 145 | """ |
| 146 | if self.builder.verbose_build: |
| 147 | args.append('V=1') |
| 148 | else: |
| 149 | args.append('-s') |
| 150 | if self.builder.num_jobs is not None: |
| 151 | args.extend(['-j', str(self.builder.num_jobs)]) |
| 152 | if self.builder.warnings_as_errors: |
| 153 | args.append('KCFLAGS=-Werror') |
| 154 | args.append('HOSTCFLAGS=-Werror') |
| 155 | if self.builder.allow_missing: |
| 156 | args.append('BINMAN_ALLOW_MISSING=1') |
| 157 | if self.builder.no_lto: |
| 158 | args.append('NO_LTO=1') |
| 159 | if self.builder.reproducible_builds: |
| 160 | args.append('SOURCE_DATE_EPOCH=0') |
| 161 | |
Simon Glass | c5077c3 | 2023-07-19 17:49:08 -0600 | [diff] [blame] | 162 | def run_commit(self, commit_upto, brd, work_dir, do_config, config_only, |
Simon Glass | e5650a8 | 2022-01-22 05:07:33 -0700 | [diff] [blame] | 163 | force_build, force_build_failures, work_in_output, |
| 164 | adjust_cfg): |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 165 | """Build a particular commit. |
| 166 | |
| 167 | If the build is already done, and we are not forcing a build, we skip |
| 168 | the build and just return the previously-saved results. |
| 169 | |
| 170 | Args: |
| 171 | commit_upto: Commit number to build (0...n-1) |
| 172 | brd: Board object to build |
| 173 | work_dir: Directory to which the source will be checked out |
| 174 | do_config: True to run a make <board>_defconfig on the source |
Simon Glass | b55b57d | 2016-11-16 14:09:25 -0700 | [diff] [blame] | 175 | config_only: Only configure the source, do not build it |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 176 | force_build: Force a build even if one was previously done |
| 177 | force_build_failures: Force a bulid if the previous result showed |
| 178 | failure |
Simon Glass | b6eb8cf | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 179 | work_in_output: Use the output directory as the work directory and |
| 180 | don't write to a separate output directory. |
Simon Glass | e5650a8 | 2022-01-22 05:07:33 -0700 | [diff] [blame] | 181 | adjust_cfg (list of str): List of changes to make to .config file |
| 182 | before building. Each is one of (where C is either CONFIG_xxx |
| 183 | or just xxx): |
| 184 | C to enable C |
| 185 | ~C to disable C |
| 186 | C=val to set the value of C (val must have quotes if C is |
| 187 | a string Kconfig |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 188 | |
| 189 | Returns: |
| 190 | tuple containing: |
| 191 | - CommandResult object containing the results of the build |
| 192 | - boolean indicating whether 'make config' is still needed |
| 193 | """ |
| 194 | # Create a default result - it will be overwritte by the call to |
Simon Glass | c5077c3 | 2023-07-19 17:49:08 -0600 | [diff] [blame] | 195 | # self.make() below, in the event that we do a build. |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 196 | result = command.CommandResult() |
| 197 | result.return_code = 0 |
Simon Glass | b6eb8cf | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 198 | if work_in_output or self.builder.in_tree: |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 199 | out_dir = work_dir |
| 200 | else: |
Stephen Warren | 97c9690 | 2016-04-11 10:48:44 -0600 | [diff] [blame] | 201 | if self.per_board_out_dir: |
| 202 | out_rel_dir = os.path.join('..', brd.target) |
| 203 | else: |
| 204 | out_rel_dir = 'build' |
| 205 | out_dir = os.path.join(work_dir, out_rel_dir) |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 206 | |
| 207 | # Check if the job was already completed last time |
Simon Glass | bc74d94 | 2023-07-19 17:49:06 -0600 | [diff] [blame] | 208 | done_file = self.builder.get_done_file(commit_upto, brd.target) |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 209 | result.already_done = os.path.exists(done_file) |
| 210 | will_build = (force_build or force_build_failures or |
| 211 | not result.already_done) |
Simon Glass | 09f1fe5 | 2014-09-05 19:00:17 -0600 | [diff] [blame] | 212 | if result.already_done: |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 213 | # Get the return code from that build and use it |
Simon Glass | d07e553 | 2023-07-19 17:49:09 -0600 | [diff] [blame] | 214 | with open(done_file, 'r', encoding='utf-8') as outf: |
Simon Glass | 4345a6d | 2018-12-10 09:05:23 -0700 | [diff] [blame] | 215 | try: |
Simon Glass | d07e553 | 2023-07-19 17:49:09 -0600 | [diff] [blame] | 216 | result.return_code = int(outf.readline()) |
Simon Glass | 4345a6d | 2018-12-10 09:05:23 -0700 | [diff] [blame] | 217 | except ValueError: |
| 218 | # The file may be empty due to running out of disk space. |
| 219 | # Try a rebuild |
| 220 | result.return_code = RETURN_CODE_RETRY |
Simon Glass | fd3eea1 | 2015-02-05 22:06:13 -0700 | [diff] [blame] | 221 | |
| 222 | # Check the signal that the build needs to be retried |
| 223 | if result.return_code == RETURN_CODE_RETRY: |
| 224 | will_build = True |
| 225 | elif will_build: |
Simon Glass | bc74d94 | 2023-07-19 17:49:06 -0600 | [diff] [blame] | 226 | err_file = self.builder.get_err_file(commit_upto, brd.target) |
Simon Glass | 09f1fe5 | 2014-09-05 19:00:17 -0600 | [diff] [blame] | 227 | if os.path.exists(err_file) and os.stat(err_file).st_size: |
| 228 | result.stderr = 'bad' |
| 229 | elif not force_build: |
| 230 | # The build passed, so no need to build it again |
| 231 | will_build = False |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 232 | |
| 233 | if will_build: |
| 234 | # We are going to have to build it. First, get a toolchain |
| 235 | if not self.toolchain: |
| 236 | try: |
| 237 | self.toolchain = self.builder.toolchains.Select(brd.arch) |
| 238 | except ValueError as err: |
| 239 | result.return_code = 10 |
| 240 | result.stdout = '' |
| 241 | result.stderr = str(err) |
| 242 | # TODO(sjg@chromium.org): This gets swallowed, but needs |
| 243 | # to be reported. |
| 244 | |
| 245 | if self.toolchain: |
| 246 | # Checkout the right commit |
| 247 | if self.builder.commits: |
| 248 | commit = self.builder.commits[commit_upto] |
| 249 | if self.builder.checkout: |
| 250 | git_dir = os.path.join(work_dir, '.git') |
Simon Glass | 761648b | 2022-01-29 14:14:11 -0700 | [diff] [blame] | 251 | gitutil.checkout(commit.hash, git_dir, work_dir, |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 252 | force=True) |
| 253 | else: |
| 254 | commit = 'current' |
| 255 | |
| 256 | # Set up the environment and command line |
Simon Glass | d48a46c | 2014-12-01 17:34:00 -0700 | [diff] [blame] | 257 | env = self.toolchain.MakeEnvironment(self.builder.full_path) |
Simon Glass | c5077c3 | 2023-07-19 17:49:08 -0600 | [diff] [blame] | 258 | mkdir(out_dir) |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 259 | args = [] |
| 260 | cwd = work_dir |
Simon Glass | e309625 | 2014-08-28 09:43:42 -0600 | [diff] [blame] | 261 | src_dir = os.path.realpath(work_dir) |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 262 | if not self.builder.in_tree: |
| 263 | if commit_upto is None: |
| 264 | # In this case we are building in the original source |
| 265 | # directory (i.e. the current directory where buildman |
| 266 | # is invoked. The output directory is set to this |
| 267 | # thread's selected work directory. |
| 268 | # |
| 269 | # Symlinks can confuse U-Boot's Makefile since |
| 270 | # we may use '..' in our path, so remove them. |
Simon Glass | 21ca0c4 | 2023-07-19 17:49:11 -0600 | [diff] [blame] | 271 | real_dir = os.path.realpath(out_dir) |
| 272 | args.append(f'O={real_dir}') |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 273 | cwd = None |
Simon Glass | e309625 | 2014-08-28 09:43:42 -0600 | [diff] [blame] | 274 | src_dir = os.getcwd() |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 275 | else: |
Simon Glass | d07e553 | 2023-07-19 17:49:09 -0600 | [diff] [blame] | 276 | args.append(f'O={out_rel_dir}') |
Simon Glass | 8d0b6b4 | 2023-07-19 17:49:13 -0600 | [diff] [blame^] | 277 | self._build_args(args) |
Simon Glass | d07e553 | 2023-07-19 17:49:09 -0600 | [diff] [blame] | 278 | config_args = [f'{brd.target}_defconfig'] |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 279 | config_out = '' |
| 280 | args.extend(self.builder.toolchains.GetMakeArguments(brd)) |
Simon Glass | f77ca5b | 2019-01-07 16:44:20 -0700 | [diff] [blame] | 281 | args.extend(self.toolchain.MakeArgs()) |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 282 | |
Simon Glass | e0f1971 | 2020-12-16 17:24:17 -0700 | [diff] [blame] | 283 | # Remove any output targets. Since we use a build directory that |
| 284 | # was previously used by another board, it may have produced an |
| 285 | # SPL image. If we don't remove it (i.e. see do_config and |
| 286 | # self.mrproper below) then it will appear to be the output of |
| 287 | # this build, even if it does not produce SPL images. |
Simon Glass | e0f1971 | 2020-12-16 17:24:17 -0700 | [diff] [blame] | 288 | for elf in BASE_ELF_FILENAMES: |
| 289 | fname = os.path.join(out_dir, elf) |
| 290 | if os.path.exists(fname): |
| 291 | os.remove(fname) |
| 292 | |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 293 | # If we need to reconfigure, do that now |
Simon Glass | e5650a8 | 2022-01-22 05:07:33 -0700 | [diff] [blame] | 294 | cfg_file = os.path.join(out_dir, '.config') |
Simon Glass | 1382b1d | 2023-02-21 12:40:27 -0700 | [diff] [blame] | 295 | cmd_list = [] |
Simon Glass | e5650a8 | 2022-01-22 05:07:33 -0700 | [diff] [blame] | 296 | if do_config or adjust_cfg: |
Simon Glass | 6029af1 | 2020-04-09 15:08:51 -0600 | [diff] [blame] | 297 | if self.mrproper: |
Simon Glass | c5077c3 | 2023-07-19 17:49:08 -0600 | [diff] [blame] | 298 | result = self.make(commit, brd, 'mrproper', cwd, |
Stephen Warren | 97c9690 | 2016-04-11 10:48:44 -0600 | [diff] [blame] | 299 | 'mrproper', *args, env=env) |
| 300 | config_out += result.combined |
Simon Glass | 1382b1d | 2023-02-21 12:40:27 -0700 | [diff] [blame] | 301 | cmd_list.append([self.builder.gnu_make, 'mrproper', |
| 302 | *args]) |
Simon Glass | c5077c3 | 2023-07-19 17:49:08 -0600 | [diff] [blame] | 303 | result = self.make(commit, brd, 'config', cwd, |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 304 | *(args + config_args), env=env) |
Simon Glass | 1382b1d | 2023-02-21 12:40:27 -0700 | [diff] [blame] | 305 | cmd_list.append([self.builder.gnu_make] + args + |
| 306 | config_args) |
Simon Glass | 413f91a | 2015-02-05 22:06:12 -0700 | [diff] [blame] | 307 | config_out += result.combined |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 308 | do_config = False # No need to configure next time |
Simon Glass | e5650a8 | 2022-01-22 05:07:33 -0700 | [diff] [blame] | 309 | if adjust_cfg: |
| 310 | cfgutil.adjust_cfg_file(cfg_file, adjust_cfg) |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 311 | if result.return_code == 0: |
Simon Glass | b55b57d | 2016-11-16 14:09:25 -0700 | [diff] [blame] | 312 | if config_only: |
Simon Glass | 739e851 | 2016-11-13 14:25:51 -0700 | [diff] [blame] | 313 | args.append('cfg') |
Simon Glass | c5077c3 | 2023-07-19 17:49:08 -0600 | [diff] [blame] | 314 | result = self.make(commit, brd, 'build', cwd, *args, |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 315 | env=env) |
Simon Glass | 1382b1d | 2023-02-21 12:40:27 -0700 | [diff] [blame] | 316 | cmd_list.append([self.builder.gnu_make] + args) |
Simon Glass | 199da41 | 2022-11-09 19:14:48 -0700 | [diff] [blame] | 317 | if (result.return_code == 2 and |
| 318 | ('Some images are invalid' in result.stderr)): |
| 319 | # This is handled later by the check for output in |
| 320 | # stderr |
| 321 | result.return_code = 0 |
Simon Glass | e5650a8 | 2022-01-22 05:07:33 -0700 | [diff] [blame] | 322 | if adjust_cfg: |
| 323 | errs = cfgutil.check_cfg_file(cfg_file, adjust_cfg) |
| 324 | if errs: |
Simon Glass | e5650a8 | 2022-01-22 05:07:33 -0700 | [diff] [blame] | 325 | result.stderr += errs |
| 326 | result.return_code = 1 |
Simon Glass | e309625 | 2014-08-28 09:43:42 -0600 | [diff] [blame] | 327 | result.stderr = result.stderr.replace(src_dir + '/', '') |
Simon Glass | 413f91a | 2015-02-05 22:06:12 -0700 | [diff] [blame] | 328 | if self.builder.verbose_build: |
| 329 | result.stdout = config_out + result.stdout |
Simon Glass | 1382b1d | 2023-02-21 12:40:27 -0700 | [diff] [blame] | 330 | result.cmd_list = cmd_list |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 331 | else: |
| 332 | result.return_code = 1 |
Simon Glass | d07e553 | 2023-07-19 17:49:09 -0600 | [diff] [blame] | 333 | result.stderr = f'No tool chain for {brd.arch}\n' |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 334 | result.already_done = False |
| 335 | |
| 336 | result.toolchain = self.toolchain |
| 337 | result.brd = brd |
| 338 | result.commit_upto = commit_upto |
| 339 | result.out_dir = out_dir |
| 340 | return result, do_config |
| 341 | |
Simon Glass | c5077c3 | 2023-07-19 17:49:08 -0600 | [diff] [blame] | 342 | def _write_result(self, result, keep_outputs, work_in_output): |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 343 | """Write a built result to the output directory. |
| 344 | |
| 345 | Args: |
| 346 | result: CommandResult object containing result to write |
| 347 | keep_outputs: True to store the output binaries, False |
| 348 | to delete them |
Simon Glass | b6eb8cf | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 349 | work_in_output: Use the output directory as the work directory and |
| 350 | don't write to a separate output directory. |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 351 | """ |
Simon Glass | fd3eea1 | 2015-02-05 22:06:13 -0700 | [diff] [blame] | 352 | # If we think this might have been aborted with Ctrl-C, record the |
| 353 | # failure but not that we are 'done' with this board. A retry may fix |
| 354 | # it. |
Simon Glass | 2e73745 | 2021-10-19 21:43:23 -0600 | [diff] [blame] | 355 | maybe_aborted = result.stderr and 'No child processes' in result.stderr |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 356 | |
Simon Glass | 2e73745 | 2021-10-19 21:43:23 -0600 | [diff] [blame] | 357 | if result.return_code >= 0 and result.already_done: |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 358 | return |
| 359 | |
| 360 | # Write the output and stderr |
Simon Glass | 4cb5468 | 2023-07-19 17:49:10 -0600 | [diff] [blame] | 361 | output_dir = self.builder.get_output_dir(result.commit_upto) |
Simon Glass | c5077c3 | 2023-07-19 17:49:08 -0600 | [diff] [blame] | 362 | mkdir(output_dir) |
Simon Glass | bc74d94 | 2023-07-19 17:49:06 -0600 | [diff] [blame] | 363 | build_dir = self.builder.get_build_dir(result.commit_upto, |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 364 | result.brd.target) |
Simon Glass | c5077c3 | 2023-07-19 17:49:08 -0600 | [diff] [blame] | 365 | mkdir(build_dir) |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 366 | |
| 367 | outfile = os.path.join(build_dir, 'log') |
Simon Glass | d07e553 | 2023-07-19 17:49:09 -0600 | [diff] [blame] | 368 | with open(outfile, 'w', encoding='utf-8') as outf: |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 369 | if result.stdout: |
Simon Glass | d07e553 | 2023-07-19 17:49:09 -0600 | [diff] [blame] | 370 | outf.write(result.stdout) |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 371 | |
Simon Glass | bc74d94 | 2023-07-19 17:49:06 -0600 | [diff] [blame] | 372 | errfile = self.builder.get_err_file(result.commit_upto, |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 373 | result.brd.target) |
| 374 | if result.stderr: |
Simon Glass | d07e553 | 2023-07-19 17:49:09 -0600 | [diff] [blame] | 375 | with open(errfile, 'w', encoding='utf-8') as outf: |
| 376 | outf.write(result.stderr) |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 377 | elif os.path.exists(errfile): |
| 378 | os.remove(errfile) |
| 379 | |
Simon Glass | 2e73745 | 2021-10-19 21:43:23 -0600 | [diff] [blame] | 380 | # Fatal error |
| 381 | if result.return_code < 0: |
| 382 | return |
| 383 | |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 384 | if result.toolchain: |
| 385 | # Write the build result and toolchain information. |
Simon Glass | bc74d94 | 2023-07-19 17:49:06 -0600 | [diff] [blame] | 386 | done_file = self.builder.get_done_file(result.commit_upto, |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 387 | result.brd.target) |
Simon Glass | d07e553 | 2023-07-19 17:49:09 -0600 | [diff] [blame] | 388 | with open(done_file, 'w', encoding='utf-8') as outf: |
Simon Glass | fd3eea1 | 2015-02-05 22:06:13 -0700 | [diff] [blame] | 389 | if maybe_aborted: |
| 390 | # Special code to indicate we need to retry |
Simon Glass | d07e553 | 2023-07-19 17:49:09 -0600 | [diff] [blame] | 391 | outf.write(f'{RETURN_CODE_RETRY}') |
Simon Glass | fd3eea1 | 2015-02-05 22:06:13 -0700 | [diff] [blame] | 392 | else: |
Simon Glass | d07e553 | 2023-07-19 17:49:09 -0600 | [diff] [blame] | 393 | outf.write(f'{result.return_code}') |
| 394 | with open(os.path.join(build_dir, 'toolchain'), 'w', |
| 395 | encoding='utf-8') as outf: |
| 396 | print('gcc', result.toolchain.gcc, file=outf) |
| 397 | print('path', result.toolchain.path, file=outf) |
| 398 | print('cross', result.toolchain.cross, file=outf) |
| 399 | print('arch', result.toolchain.arch, file=outf) |
| 400 | outf.write(f'{result.return_code}') |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 401 | |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 402 | # Write out the image and function size information and an objdump |
Simon Glass | d48a46c | 2014-12-01 17:34:00 -0700 | [diff] [blame] | 403 | env = result.toolchain.MakeEnvironment(self.builder.full_path) |
Simon Glass | d07e553 | 2023-07-19 17:49:09 -0600 | [diff] [blame] | 404 | with open(os.path.join(build_dir, 'out-env'), 'wb') as outf: |
Simon Glass | 9e90d31 | 2019-01-07 16:44:23 -0700 | [diff] [blame] | 405 | for var in sorted(env.keys()): |
Simon Glass | d07e553 | 2023-07-19 17:49:09 -0600 | [diff] [blame] | 406 | outf.write(b'%s="%s"' % (var, env[var])) |
Simon Glass | 1382b1d | 2023-02-21 12:40:27 -0700 | [diff] [blame] | 407 | |
| 408 | with open(os.path.join(build_dir, 'out-cmd'), 'w', |
Simon Glass | d07e553 | 2023-07-19 17:49:09 -0600 | [diff] [blame] | 409 | encoding='utf-8') as outf: |
Simon Glass | 1382b1d | 2023-02-21 12:40:27 -0700 | [diff] [blame] | 410 | for cmd in result.cmd_list: |
Simon Glass | d07e553 | 2023-07-19 17:49:09 -0600 | [diff] [blame] | 411 | print(' '.join(cmd), file=outf) |
Simon Glass | 1382b1d | 2023-02-21 12:40:27 -0700 | [diff] [blame] | 412 | |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 413 | lines = [] |
Simon Glass | e0f1971 | 2020-12-16 17:24:17 -0700 | [diff] [blame] | 414 | for fname in BASE_ELF_FILENAMES: |
Simon Glass | d07e553 | 2023-07-19 17:49:09 -0600 | [diff] [blame] | 415 | cmd = [f'{self.toolchain.cross}nm', '--size-sort', fname] |
Simon Glass | 840be73 | 2022-01-29 14:14:05 -0700 | [diff] [blame] | 416 | nm_result = command.run_pipe([cmd], capture=True, |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 417 | capture_stderr=True, cwd=result.out_dir, |
| 418 | raise_on_error=False, env=env) |
| 419 | if nm_result.stdout: |
Simon Glass | d07e553 | 2023-07-19 17:49:09 -0600 | [diff] [blame] | 420 | nm_fname = self.builder.get_func_sizes_file( |
| 421 | result.commit_upto, result.brd.target, fname) |
| 422 | with open(nm_fname, 'w', encoding='utf-8') as outf: |
| 423 | print(nm_result.stdout, end=' ', file=outf) |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 424 | |
Simon Glass | d07e553 | 2023-07-19 17:49:09 -0600 | [diff] [blame] | 425 | cmd = [f'{self.toolchain.cross}objdump', '-h', fname] |
Simon Glass | 840be73 | 2022-01-29 14:14:05 -0700 | [diff] [blame] | 426 | dump_result = command.run_pipe([cmd], capture=True, |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 427 | capture_stderr=True, cwd=result.out_dir, |
| 428 | raise_on_error=False, env=env) |
| 429 | rodata_size = '' |
| 430 | if dump_result.stdout: |
Simon Glass | bc74d94 | 2023-07-19 17:49:06 -0600 | [diff] [blame] | 431 | objdump = self.builder.get_objdump_file(result.commit_upto, |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 432 | result.brd.target, fname) |
Simon Glass | d07e553 | 2023-07-19 17:49:09 -0600 | [diff] [blame] | 433 | with open(objdump, 'w', encoding='utf-8') as outf: |
| 434 | print(dump_result.stdout, end=' ', file=outf) |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 435 | for line in dump_result.stdout.splitlines(): |
| 436 | fields = line.split() |
| 437 | if len(fields) > 5 and fields[1] == '.rodata': |
| 438 | rodata_size = fields[2] |
| 439 | |
Simon Glass | d07e553 | 2023-07-19 17:49:09 -0600 | [diff] [blame] | 440 | cmd = [f'{self.toolchain.cross}size', fname] |
Simon Glass | 840be73 | 2022-01-29 14:14:05 -0700 | [diff] [blame] | 441 | size_result = command.run_pipe([cmd], capture=True, |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 442 | capture_stderr=True, cwd=result.out_dir, |
| 443 | raise_on_error=False, env=env) |
| 444 | if size_result.stdout: |
| 445 | lines.append(size_result.stdout.splitlines()[1] + ' ' + |
| 446 | rodata_size) |
| 447 | |
Alex Kiernan | f07ed23 | 2018-05-31 04:48:33 +0000 | [diff] [blame] | 448 | # Extract the environment from U-Boot and dump it out |
Simon Glass | d07e553 | 2023-07-19 17:49:09 -0600 | [diff] [blame] | 449 | cmd = [f'{self.toolchain.cross}objcopy', '-O', 'binary', |
Alex Kiernan | f07ed23 | 2018-05-31 04:48:33 +0000 | [diff] [blame] | 450 | '-j', '.rodata.default_environment', |
| 451 | 'env/built-in.o', 'uboot.env'] |
Simon Glass | 840be73 | 2022-01-29 14:14:05 -0700 | [diff] [blame] | 452 | command.run_pipe([cmd], capture=True, |
Alex Kiernan | f07ed23 | 2018-05-31 04:48:33 +0000 | [diff] [blame] | 453 | capture_stderr=True, cwd=result.out_dir, |
| 454 | raise_on_error=False, env=env) |
Simon Glass | e3c85ab | 2020-04-17 17:51:34 -0600 | [diff] [blame] | 455 | if not work_in_output: |
Simon Glass | c5077c3 | 2023-07-19 17:49:08 -0600 | [diff] [blame] | 456 | self.copy_files(result.out_dir, build_dir, '', ['uboot.env']) |
Alex Kiernan | f07ed23 | 2018-05-31 04:48:33 +0000 | [diff] [blame] | 457 | |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 458 | # Write out the image sizes file. This is similar to the output |
| 459 | # of binutil's 'size' utility, but it omits the header line and |
| 460 | # adds an additional hex value at the end of each line for the |
| 461 | # rodata size |
Simon Glass | d07e553 | 2023-07-19 17:49:09 -0600 | [diff] [blame] | 462 | if lines: |
Simon Glass | bc74d94 | 2023-07-19 17:49:06 -0600 | [diff] [blame] | 463 | sizes = self.builder.get_sizes_file(result.commit_upto, |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 464 | result.brd.target) |
Simon Glass | d07e553 | 2023-07-19 17:49:09 -0600 | [diff] [blame] | 465 | with open(sizes, 'w', encoding='utf-8') as outf: |
| 466 | print('\n'.join(lines), file=outf) |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 467 | |
Simon Glass | e3c85ab | 2020-04-17 17:51:34 -0600 | [diff] [blame] | 468 | if not work_in_output: |
| 469 | # Write out the configuration files, with a special case for SPL |
| 470 | for dirname in ['', 'spl', 'tpl']: |
Simon Glass | c5077c3 | 2023-07-19 17:49:08 -0600 | [diff] [blame] | 471 | self.copy_files( |
Simon Glass | e3c85ab | 2020-04-17 17:51:34 -0600 | [diff] [blame] | 472 | result.out_dir, build_dir, dirname, |
| 473 | ['u-boot.cfg', 'spl/u-boot-spl.cfg', 'tpl/u-boot-tpl.cfg', |
| 474 | '.config', 'include/autoconf.mk', |
| 475 | 'include/generated/autoconf.h']) |
Simon Glass | 4b14c53 | 2015-02-05 22:06:14 -0700 | [diff] [blame] | 476 | |
Simon Glass | e3c85ab | 2020-04-17 17:51:34 -0600 | [diff] [blame] | 477 | # Now write the actual build output |
| 478 | if keep_outputs: |
Simon Glass | c5077c3 | 2023-07-19 17:49:08 -0600 | [diff] [blame] | 479 | self.copy_files( |
Simon Glass | e3c85ab | 2020-04-17 17:51:34 -0600 | [diff] [blame] | 480 | result.out_dir, build_dir, '', |
| 481 | ['u-boot*', '*.bin', '*.map', '*.img', 'MLO', 'SPL', |
| 482 | 'include/autoconf.mk', 'spl/u-boot-spl*']) |
Simon Glass | 4b14c53 | 2015-02-05 22:06:14 -0700 | [diff] [blame] | 483 | |
Simon Glass | c5077c3 | 2023-07-19 17:49:08 -0600 | [diff] [blame] | 484 | def copy_files(self, out_dir, build_dir, dirname, patterns): |
Simon Glass | 4b14c53 | 2015-02-05 22:06:14 -0700 | [diff] [blame] | 485 | """Copy files from the build directory to the output. |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 486 | |
Simon Glass | 4b14c53 | 2015-02-05 22:06:14 -0700 | [diff] [blame] | 487 | Args: |
| 488 | out_dir: Path to output directory containing the files |
| 489 | build_dir: Place to copy the files |
| 490 | dirname: Source directory, '' for normal U-Boot, 'spl' for SPL |
| 491 | patterns: A list of filenames (strings) to copy, each relative |
| 492 | to the build directory |
| 493 | """ |
| 494 | for pattern in patterns: |
| 495 | file_list = glob.glob(os.path.join(out_dir, dirname, pattern)) |
| 496 | for fname in file_list: |
| 497 | target = os.path.basename(fname) |
| 498 | if dirname: |
| 499 | base, ext = os.path.splitext(target) |
| 500 | if ext: |
Simon Glass | d07e553 | 2023-07-19 17:49:09 -0600 | [diff] [blame] | 501 | target = f'{base}-{dirname}{ext}' |
Simon Glass | 4b14c53 | 2015-02-05 22:06:14 -0700 | [diff] [blame] | 502 | shutil.copy(fname, os.path.join(build_dir, target)) |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 503 | |
Simon Glass | c5077c3 | 2023-07-19 17:49:08 -0600 | [diff] [blame] | 504 | def _send_result(self, result): |
Simon Glass | a3d0144 | 2021-04-11 16:27:26 +1200 | [diff] [blame] | 505 | """Send a result to the builder for processing |
| 506 | |
| 507 | Args: |
| 508 | result: CommandResult object containing the results of the build |
Simon Glass | 9bf9a72 | 2021-04-11 16:27:27 +1200 | [diff] [blame] | 509 | |
| 510 | Raises: |
| 511 | ValueError if self.test_exception is true (for testing) |
Simon Glass | a3d0144 | 2021-04-11 16:27:26 +1200 | [diff] [blame] | 512 | """ |
Simon Glass | 9bf9a72 | 2021-04-11 16:27:27 +1200 | [diff] [blame] | 513 | if self.test_exception: |
| 514 | raise ValueError('test exception') |
Simon Glass | a3d0144 | 2021-04-11 16:27:26 +1200 | [diff] [blame] | 515 | if self.thread_num != -1: |
| 516 | self.builder.out_queue.put(result) |
| 517 | else: |
Simon Glass | bc74d94 | 2023-07-19 17:49:06 -0600 | [diff] [blame] | 518 | self.builder.process_result(result) |
Simon Glass | a3d0144 | 2021-04-11 16:27:26 +1200 | [diff] [blame] | 519 | |
Simon Glass | c5077c3 | 2023-07-19 17:49:08 -0600 | [diff] [blame] | 520 | def run_job(self, job): |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 521 | """Run a single job |
| 522 | |
| 523 | A job consists of a building a list of commits for a particular board. |
| 524 | |
| 525 | Args: |
| 526 | job: Job to build |
Simon Glass | c635d89 | 2021-01-30 22:17:46 -0700 | [diff] [blame] | 527 | |
| 528 | Returns: |
| 529 | List of Result objects |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 530 | """ |
Simon Glass | 8132f98 | 2022-07-11 19:03:57 -0600 | [diff] [blame] | 531 | brd = job.brd |
Simon Glass | bc74d94 | 2023-07-19 17:49:06 -0600 | [diff] [blame] | 532 | work_dir = self.builder.get_thread_dir(self.thread_num) |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 533 | self.toolchain = None |
| 534 | if job.commits: |
| 535 | # Run 'make board_defconfig' on the first commit |
| 536 | do_config = True |
| 537 | commit_upto = 0 |
| 538 | force_build = False |
| 539 | for commit_upto in range(0, len(job.commits), job.step): |
Simon Glass | c5077c3 | 2023-07-19 17:49:08 -0600 | [diff] [blame] | 540 | result, request_config = self.run_commit(commit_upto, brd, |
Simon Glass | b55b57d | 2016-11-16 14:09:25 -0700 | [diff] [blame] | 541 | work_dir, do_config, self.builder.config_only, |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 542 | force_build or self.builder.force_build, |
Simon Glass | b6eb8cf | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 543 | self.builder.force_build_failures, |
Simon Glass | e5650a8 | 2022-01-22 05:07:33 -0700 | [diff] [blame] | 544 | job.work_in_output, job.adjust_cfg) |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 545 | failed = result.return_code or result.stderr |
| 546 | did_config = do_config |
| 547 | if failed and not do_config: |
| 548 | # If our incremental build failed, try building again |
| 549 | # with a reconfig. |
| 550 | if self.builder.force_config_on_failure: |
Simon Glass | c5077c3 | 2023-07-19 17:49:08 -0600 | [diff] [blame] | 551 | result, request_config = self.run_commit(commit_upto, |
Simon Glass | b6eb8cf | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 552 | brd, work_dir, True, False, True, False, |
Simon Glass | e5650a8 | 2022-01-22 05:07:33 -0700 | [diff] [blame] | 553 | job.work_in_output, job.adjust_cfg) |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 554 | did_config = True |
| 555 | if not self.builder.force_reconfig: |
| 556 | do_config = request_config |
| 557 | |
| 558 | # If we built that commit, then config is done. But if we got |
| 559 | # an warning, reconfig next time to force it to build the same |
| 560 | # files that created warnings this time. Otherwise an |
| 561 | # incremental build may not build the same file, and we will |
| 562 | # think that the warning has gone away. |
| 563 | # We could avoid this by using -Werror everywhere... |
| 564 | # For errors, the problem doesn't happen, since presumably |
| 565 | # the build stopped and didn't generate output, so will retry |
| 566 | # that file next time. So we could detect warnings and deal |
| 567 | # with them specially here. For now, we just reconfigure if |
| 568 | # anything goes work. |
| 569 | # Of course this is substantially slower if there are build |
| 570 | # errors/warnings (e.g. 2-3x slower even if only 10% of builds |
| 571 | # have problems). |
| 572 | if (failed and not result.already_done and not did_config and |
| 573 | self.builder.force_config_on_failure): |
| 574 | # If this build failed, try the next one with a |
| 575 | # reconfigure. |
| 576 | # Sometimes if the board_config.h file changes it can mess |
| 577 | # with dependencies, and we get: |
| 578 | # make: *** No rule to make target `include/autoconf.mk', |
| 579 | # needed by `depend'. |
| 580 | do_config = True |
| 581 | force_build = True |
| 582 | else: |
| 583 | force_build = False |
| 584 | if self.builder.force_config_on_failure: |
| 585 | if failed: |
| 586 | do_config = True |
| 587 | result.commit_upto = commit_upto |
| 588 | if result.return_code < 0: |
| 589 | raise ValueError('Interrupt') |
| 590 | |
| 591 | # We have the build results, so output the result |
Simon Glass | c5077c3 | 2023-07-19 17:49:08 -0600 | [diff] [blame] | 592 | self._write_result(result, job.keep_outputs, job.work_in_output) |
| 593 | self._send_result(result) |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 594 | else: |
| 595 | # Just build the currently checked-out build |
Simon Glass | c5077c3 | 2023-07-19 17:49:08 -0600 | [diff] [blame] | 596 | result, request_config = self.run_commit(None, brd, work_dir, True, |
Simon Glass | b55b57d | 2016-11-16 14:09:25 -0700 | [diff] [blame] | 597 | self.builder.config_only, True, |
Simon Glass | e5650a8 | 2022-01-22 05:07:33 -0700 | [diff] [blame] | 598 | self.builder.force_build_failures, job.work_in_output, |
| 599 | job.adjust_cfg) |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 600 | result.commit_upto = 0 |
Simon Glass | c5077c3 | 2023-07-19 17:49:08 -0600 | [diff] [blame] | 601 | self._write_result(result, job.keep_outputs, job.work_in_output) |
| 602 | self._send_result(result) |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 603 | |
| 604 | def run(self): |
| 605 | """Our thread's run function |
| 606 | |
| 607 | This thread picks a job from the queue, runs it, and then goes to the |
| 608 | next job. |
| 609 | """ |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 610 | while True: |
| 611 | job = self.builder.queue.get() |
Simon Glass | 9bf9a72 | 2021-04-11 16:27:27 +1200 | [diff] [blame] | 612 | try: |
Simon Glass | c5077c3 | 2023-07-19 17:49:08 -0600 | [diff] [blame] | 613 | self.run_job(job) |
Simon Glass | d07e553 | 2023-07-19 17:49:09 -0600 | [diff] [blame] | 614 | except Exception as exc: |
| 615 | print('Thread exception (use -T0 to run without threads):', |
| 616 | exc) |
| 617 | self.builder.thread_exceptions.append(exc) |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 618 | self.builder.queue.task_done() |