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