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