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