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