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