blob: 48128cf67322fba45db0eff2dbc6341cd82da2c9 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001# SPDX-License-Identifier: GPL-2.0+
Simon Glass190064b2014-08-09 15:33:00 -06002# Copyright (c) 2014 Google, Inc
3#
Simon Glass190064b2014-08-09 15:33:00 -06004
5import errno
6import glob
7import os
8import shutil
Lothar Waßmann409fc022018-04-08 05:14:11 -06009import sys
Simon Glass190064b2014-08-09 15:33:00 -060010import threading
11
Simon Glassbf776672020-04-17 18:09:04 -060012from patman import command
13from patman import gitutil
Simon Glass190064b2014-08-09 15:33:00 -060014
Simon Glass88c8dcf2015-02-05 22:06:13 -070015RETURN_CODE_RETRY = -1
Simon Glass73da3d22020-12-16 17:24:17 -070016BASE_ELF_FILENAMES = ['u-boot', 'spl/u-boot-spl', 'tpl/u-boot-tpl']
Simon Glass88c8dcf2015-02-05 22:06:13 -070017
Thierry Redingf3d015c2014-08-19 10:22:39 +020018def Mkdir(dirname, parents = False):
Simon Glass190064b2014-08-09 15:33:00 -060019 """Make a directory if it doesn't already exist.
20
21 Args:
22 dirname: Directory to create
23 """
24 try:
Thierry Redingf3d015c2014-08-19 10:22:39 +020025 if parents:
26 os.makedirs(dirname)
27 else:
28 os.mkdir(dirname)
Simon Glass190064b2014-08-09 15:33:00 -060029 except OSError as err:
30 if err.errno == errno.EEXIST:
Lothar Waßmann409fc022018-04-08 05:14:11 -060031 if os.path.realpath('.') == os.path.realpath(dirname):
Simon Glassc05aa032019-10-31 07:42:53 -060032 print("Cannot create the current working directory '%s'!" % dirname)
Lothar Waßmann409fc022018-04-08 05:14:11 -060033 sys.exit(1)
Simon Glass190064b2014-08-09 15:33:00 -060034 pass
35 else:
36 raise
37
38class BuilderJob:
39 """Holds information about a job to be performed by a thread
40
41 Members:
42 board: Board object to build
Simon Glasse9fbbf62020-03-18 09:42:41 -060043 commits: List of Commit objects to build
44 keep_outputs: True to save build output files
45 step: 1 to process every commit, n to process every nth commit
Simon Glassd829f122020-03-18 09:42:42 -060046 work_in_output: Use the output directory as the work directory and
47 don't write to a separate output directory.
Simon Glass190064b2014-08-09 15:33:00 -060048 """
49 def __init__(self):
50 self.board = None
51 self.commits = []
Simon Glasse9fbbf62020-03-18 09:42:41 -060052 self.keep_outputs = False
53 self.step = 1
Simon Glassd829f122020-03-18 09:42:42 -060054 self.work_in_output = False
Simon Glass190064b2014-08-09 15:33:00 -060055
56
57class ResultThread(threading.Thread):
58 """This thread processes results from builder threads.
59
60 It simply passes the results on to the builder. There is only one
61 result thread, and this helps to serialise the build output.
62 """
63 def __init__(self, builder):
64 """Set up a new result thread
65
66 Args:
67 builder: Builder which will be sent each result
68 """
69 threading.Thread.__init__(self)
70 self.builder = builder
71
72 def run(self):
73 """Called to start up the result thread.
74
75 We collect the next result job and pass it on to the build.
76 """
77 while True:
78 result = self.builder.out_queue.get()
79 self.builder.ProcessResult(result)
80 self.builder.out_queue.task_done()
81
82
83class BuilderThread(threading.Thread):
84 """This thread builds U-Boot for a particular board.
85
86 An input queue provides each new job. We run 'make' to build U-Boot
87 and then pass the results on to the output queue.
88
89 Members:
90 builder: The builder which contains information we might need
91 thread_num: Our thread number (0-n-1), used to decide on a
Simon Glass24993312021-04-11 16:27:25 +120092 temporary directory. If this is -1 then there are no threads
93 and we are the (only) main process
94 mrproper: Use 'make mrproper' before each reconfigure
95 per_board_out_dir: True to build in a separate persistent directory per
96 board rather than a thread-specific directory
97 test_exception: Used for testing; True to raise an exception instead of
98 reporting the build result
Simon Glass190064b2014-08-09 15:33:00 -060099 """
Simon Glass8116c782021-04-11 16:27:27 +1200100 def __init__(self, builder, thread_num, mrproper, per_board_out_dir,
101 test_exception=False):
Simon Glass190064b2014-08-09 15:33:00 -0600102 """Set up a new builder thread"""
103 threading.Thread.__init__(self)
104 self.builder = builder
105 self.thread_num = thread_num
Simon Glasseb70a2c2020-04-09 15:08:51 -0600106 self.mrproper = mrproper
Stephen Warrenf79f1e02016-04-11 10:48:44 -0600107 self.per_board_out_dir = per_board_out_dir
Simon Glass8116c782021-04-11 16:27:27 +1200108 self.test_exception = test_exception
Simon Glass190064b2014-08-09 15:33:00 -0600109
110 def Make(self, commit, brd, stage, cwd, *args, **kwargs):
111 """Run 'make' on a particular commit and board.
112
113 The source code will already be checked out, so the 'commit'
114 argument is only for information.
115
116 Args:
117 commit: Commit object that is being built
118 brd: Board object that is being built
119 stage: Stage of the build. Valid stages are:
Roger Meierfd18a892014-08-20 22:10:29 +0200120 mrproper - can be called to clean source
Simon Glass190064b2014-08-09 15:33:00 -0600121 config - called to configure for a board
122 build - the main make invocation - it does the build
123 args: A list of arguments to pass to 'make'
124 kwargs: A list of keyword arguments to pass to command.RunPipe()
125
126 Returns:
127 CommandResult object
128 """
129 return self.builder.do_make(commit, brd, stage, cwd, *args,
130 **kwargs)
131
Simon Glassa9401b22016-11-16 14:09:25 -0700132 def RunCommit(self, commit_upto, brd, work_dir, do_config, config_only,
Simon Glassd829f122020-03-18 09:42:42 -0600133 force_build, force_build_failures, work_in_output):
Simon Glass190064b2014-08-09 15:33:00 -0600134 """Build a particular commit.
135
136 If the build is already done, and we are not forcing a build, we skip
137 the build and just return the previously-saved results.
138
139 Args:
140 commit_upto: Commit number to build (0...n-1)
141 brd: Board object to build
142 work_dir: Directory to which the source will be checked out
143 do_config: True to run a make <board>_defconfig on the source
Simon Glassa9401b22016-11-16 14:09:25 -0700144 config_only: Only configure the source, do not build it
Simon Glass190064b2014-08-09 15:33:00 -0600145 force_build: Force a build even if one was previously done
146 force_build_failures: Force a bulid if the previous result showed
147 failure
Simon Glassd829f122020-03-18 09:42:42 -0600148 work_in_output: Use the output directory as the work directory and
149 don't write to a separate output directory.
Simon Glass190064b2014-08-09 15:33:00 -0600150
151 Returns:
152 tuple containing:
153 - CommandResult object containing the results of the build
154 - boolean indicating whether 'make config' is still needed
155 """
156 # Create a default result - it will be overwritte by the call to
157 # self.Make() below, in the event that we do a build.
158 result = command.CommandResult()
159 result.return_code = 0
Simon Glassd829f122020-03-18 09:42:42 -0600160 if work_in_output or self.builder.in_tree:
Simon Glass190064b2014-08-09 15:33:00 -0600161 out_dir = work_dir
162 else:
Stephen Warrenf79f1e02016-04-11 10:48:44 -0600163 if self.per_board_out_dir:
164 out_rel_dir = os.path.join('..', brd.target)
165 else:
166 out_rel_dir = 'build'
167 out_dir = os.path.join(work_dir, out_rel_dir)
Simon Glass190064b2014-08-09 15:33:00 -0600168
169 # Check if the job was already completed last time
170 done_file = self.builder.GetDoneFile(commit_upto, brd.target)
171 result.already_done = os.path.exists(done_file)
172 will_build = (force_build or force_build_failures or
173 not result.already_done)
Simon Glassfb3954f2014-09-05 19:00:17 -0600174 if result.already_done:
Simon Glass190064b2014-08-09 15:33:00 -0600175 # Get the return code from that build and use it
176 with open(done_file, 'r') as fd:
Simon Glasse74429b2018-12-10 09:05:23 -0700177 try:
178 result.return_code = int(fd.readline())
179 except ValueError:
180 # The file may be empty due to running out of disk space.
181 # Try a rebuild
182 result.return_code = RETURN_CODE_RETRY
Simon Glass88c8dcf2015-02-05 22:06:13 -0700183
184 # Check the signal that the build needs to be retried
185 if result.return_code == RETURN_CODE_RETRY:
186 will_build = True
187 elif will_build:
Simon Glassfb3954f2014-09-05 19:00:17 -0600188 err_file = self.builder.GetErrFile(commit_upto, brd.target)
189 if os.path.exists(err_file) and os.stat(err_file).st_size:
190 result.stderr = 'bad'
191 elif not force_build:
192 # The build passed, so no need to build it again
193 will_build = False
Simon Glass190064b2014-08-09 15:33:00 -0600194
195 if will_build:
196 # We are going to have to build it. First, get a toolchain
197 if not self.toolchain:
198 try:
199 self.toolchain = self.builder.toolchains.Select(brd.arch)
200 except ValueError as err:
201 result.return_code = 10
202 result.stdout = ''
203 result.stderr = str(err)
204 # TODO(sjg@chromium.org): This gets swallowed, but needs
205 # to be reported.
206
207 if self.toolchain:
208 # Checkout the right commit
209 if self.builder.commits:
210 commit = self.builder.commits[commit_upto]
211 if self.builder.checkout:
212 git_dir = os.path.join(work_dir, '.git')
213 gitutil.Checkout(commit.hash, git_dir, work_dir,
214 force=True)
215 else:
216 commit = 'current'
217
218 # Set up the environment and command line
Simon Glassbb1501f2014-12-01 17:34:00 -0700219 env = self.toolchain.MakeEnvironment(self.builder.full_path)
Simon Glass190064b2014-08-09 15:33:00 -0600220 Mkdir(out_dir)
221 args = []
222 cwd = work_dir
Simon Glass48c1b6a2014-08-28 09:43:42 -0600223 src_dir = os.path.realpath(work_dir)
Simon Glass190064b2014-08-09 15:33:00 -0600224 if not self.builder.in_tree:
225 if commit_upto is None:
226 # In this case we are building in the original source
227 # directory (i.e. the current directory where buildman
228 # is invoked. The output directory is set to this
229 # thread's selected work directory.
230 #
231 # Symlinks can confuse U-Boot's Makefile since
232 # we may use '..' in our path, so remove them.
Stephen Warrenf79f1e02016-04-11 10:48:44 -0600233 out_dir = os.path.realpath(out_dir)
234 args.append('O=%s' % out_dir)
Simon Glass190064b2014-08-09 15:33:00 -0600235 cwd = None
Simon Glass48c1b6a2014-08-28 09:43:42 -0600236 src_dir = os.getcwd()
Simon Glass190064b2014-08-09 15:33:00 -0600237 else:
Stephen Warrenf79f1e02016-04-11 10:48:44 -0600238 args.append('O=%s' % out_rel_dir)
Tom Rinif5e5ece2015-04-01 07:47:41 -0400239 if self.builder.verbose_build:
240 args.append('V=1')
241 else:
Simon Glassd2ce6582014-12-01 17:34:07 -0700242 args.append('-s')
Simon Glass190064b2014-08-09 15:33:00 -0600243 if self.builder.num_jobs is not None:
244 args.extend(['-j', str(self.builder.num_jobs)])
Daniel Schwierzeck2371d1b2018-01-26 16:31:05 +0100245 if self.builder.warnings_as_errors:
246 args.append('KCFLAGS=-Werror')
Simon Glass190064b2014-08-09 15:33:00 -0600247 config_args = ['%s_defconfig' % brd.target]
248 config_out = ''
249 args.extend(self.builder.toolchains.GetMakeArguments(brd))
Simon Glass00beb242019-01-07 16:44:20 -0700250 args.extend(self.toolchain.MakeArgs())
Simon Glass190064b2014-08-09 15:33:00 -0600251
Simon Glass73da3d22020-12-16 17:24:17 -0700252 # Remove any output targets. Since we use a build directory that
253 # was previously used by another board, it may have produced an
254 # SPL image. If we don't remove it (i.e. see do_config and
255 # self.mrproper below) then it will appear to be the output of
256 # this build, even if it does not produce SPL images.
257 build_dir = self.builder.GetBuildDir(commit_upto, brd.target)
258 for elf in BASE_ELF_FILENAMES:
259 fname = os.path.join(out_dir, elf)
260 if os.path.exists(fname):
261 os.remove(fname)
262
Simon Glass190064b2014-08-09 15:33:00 -0600263 # If we need to reconfigure, do that now
264 if do_config:
Stephen Warrenf79f1e02016-04-11 10:48:44 -0600265 config_out = ''
Simon Glasseb70a2c2020-04-09 15:08:51 -0600266 if self.mrproper:
Stephen Warrenf79f1e02016-04-11 10:48:44 -0600267 result = self.Make(commit, brd, 'mrproper', cwd,
268 'mrproper', *args, env=env)
269 config_out += result.combined
Simon Glass190064b2014-08-09 15:33:00 -0600270 result = self.Make(commit, brd, 'config', cwd,
271 *(args + config_args), env=env)
Simon Glass40f11fc2015-02-05 22:06:12 -0700272 config_out += result.combined
Simon Glass190064b2014-08-09 15:33:00 -0600273 do_config = False # No need to configure next time
274 if result.return_code == 0:
Simon Glassa9401b22016-11-16 14:09:25 -0700275 if config_only:
Simon Glassb50113f2016-11-13 14:25:51 -0700276 args.append('cfg')
Simon Glass190064b2014-08-09 15:33:00 -0600277 result = self.Make(commit, brd, 'build', cwd, *args,
278 env=env)
Simon Glass48c1b6a2014-08-28 09:43:42 -0600279 result.stderr = result.stderr.replace(src_dir + '/', '')
Simon Glass40f11fc2015-02-05 22:06:12 -0700280 if self.builder.verbose_build:
281 result.stdout = config_out + result.stdout
Simon Glass190064b2014-08-09 15:33:00 -0600282 else:
283 result.return_code = 1
284 result.stderr = 'No tool chain for %s\n' % brd.arch
285 result.already_done = False
286
287 result.toolchain = self.toolchain
288 result.brd = brd
289 result.commit_upto = commit_upto
290 result.out_dir = out_dir
291 return result, do_config
292
Simon Glassd829f122020-03-18 09:42:42 -0600293 def _WriteResult(self, result, keep_outputs, work_in_output):
Simon Glass190064b2014-08-09 15:33:00 -0600294 """Write a built result to the output directory.
295
296 Args:
297 result: CommandResult object containing result to write
298 keep_outputs: True to store the output binaries, False
299 to delete them
Simon Glassd829f122020-03-18 09:42:42 -0600300 work_in_output: Use the output directory as the work directory and
301 don't write to a separate output directory.
Simon Glass190064b2014-08-09 15:33:00 -0600302 """
303 # Fatal error
304 if result.return_code < 0:
305 return
306
Simon Glass88c8dcf2015-02-05 22:06:13 -0700307 # If we think this might have been aborted with Ctrl-C, record the
308 # failure but not that we are 'done' with this board. A retry may fix
309 # it.
310 maybe_aborted = result.stderr and 'No child processes' in result.stderr
Simon Glass190064b2014-08-09 15:33:00 -0600311
312 if result.already_done:
313 return
314
315 # Write the output and stderr
316 output_dir = self.builder._GetOutputDir(result.commit_upto)
317 Mkdir(output_dir)
318 build_dir = self.builder.GetBuildDir(result.commit_upto,
319 result.brd.target)
320 Mkdir(build_dir)
321
322 outfile = os.path.join(build_dir, 'log')
323 with open(outfile, 'w') as fd:
324 if result.stdout:
Simon Glassc05aa032019-10-31 07:42:53 -0600325 fd.write(result.stdout)
Simon Glass190064b2014-08-09 15:33:00 -0600326
327 errfile = self.builder.GetErrFile(result.commit_upto,
328 result.brd.target)
329 if result.stderr:
330 with open(errfile, 'w') as fd:
Simon Glassc05aa032019-10-31 07:42:53 -0600331 fd.write(result.stderr)
Simon Glass190064b2014-08-09 15:33:00 -0600332 elif os.path.exists(errfile):
333 os.remove(errfile)
334
335 if result.toolchain:
336 # Write the build result and toolchain information.
337 done_file = self.builder.GetDoneFile(result.commit_upto,
338 result.brd.target)
339 with open(done_file, 'w') as fd:
Simon Glass88c8dcf2015-02-05 22:06:13 -0700340 if maybe_aborted:
341 # Special code to indicate we need to retry
342 fd.write('%s' % RETURN_CODE_RETRY)
343 else:
344 fd.write('%s' % result.return_code)
Simon Glass190064b2014-08-09 15:33:00 -0600345 with open(os.path.join(build_dir, 'toolchain'), 'w') as fd:
Simon Glassc05aa032019-10-31 07:42:53 -0600346 print('gcc', result.toolchain.gcc, file=fd)
347 print('path', result.toolchain.path, file=fd)
348 print('cross', result.toolchain.cross, file=fd)
349 print('arch', result.toolchain.arch, file=fd)
Simon Glass190064b2014-08-09 15:33:00 -0600350 fd.write('%s' % result.return_code)
351
Simon Glass190064b2014-08-09 15:33:00 -0600352 # Write out the image and function size information and an objdump
Simon Glassbb1501f2014-12-01 17:34:00 -0700353 env = result.toolchain.MakeEnvironment(self.builder.full_path)
Simon Glassf1a83ab2021-04-11 16:27:28 +1200354 with open(os.path.join(build_dir, 'out-env'), 'wb') as fd:
Simon Glasse5fc79e2019-01-07 16:44:23 -0700355 for var in sorted(env.keys()):
Simon Glassf1a83ab2021-04-11 16:27:28 +1200356 fd.write(b'%s="%s"' % (var, env[var]))
Simon Glass190064b2014-08-09 15:33:00 -0600357 lines = []
Simon Glass73da3d22020-12-16 17:24:17 -0700358 for fname in BASE_ELF_FILENAMES:
Simon Glass190064b2014-08-09 15:33:00 -0600359 cmd = ['%snm' % self.toolchain.cross, '--size-sort', fname]
360 nm_result = command.RunPipe([cmd], capture=True,
361 capture_stderr=True, cwd=result.out_dir,
362 raise_on_error=False, env=env)
363 if nm_result.stdout:
364 nm = self.builder.GetFuncSizesFile(result.commit_upto,
365 result.brd.target, fname)
366 with open(nm, 'w') as fd:
Simon Glassc05aa032019-10-31 07:42:53 -0600367 print(nm_result.stdout, end=' ', file=fd)
Simon Glass190064b2014-08-09 15:33:00 -0600368
369 cmd = ['%sobjdump' % self.toolchain.cross, '-h', fname]
370 dump_result = command.RunPipe([cmd], capture=True,
371 capture_stderr=True, cwd=result.out_dir,
372 raise_on_error=False, env=env)
373 rodata_size = ''
374 if dump_result.stdout:
375 objdump = self.builder.GetObjdumpFile(result.commit_upto,
376 result.brd.target, fname)
377 with open(objdump, 'w') as fd:
Simon Glassc05aa032019-10-31 07:42:53 -0600378 print(dump_result.stdout, end=' ', file=fd)
Simon Glass190064b2014-08-09 15:33:00 -0600379 for line in dump_result.stdout.splitlines():
380 fields = line.split()
381 if len(fields) > 5 and fields[1] == '.rodata':
382 rodata_size = fields[2]
383
384 cmd = ['%ssize' % self.toolchain.cross, fname]
385 size_result = command.RunPipe([cmd], capture=True,
386 capture_stderr=True, cwd=result.out_dir,
387 raise_on_error=False, env=env)
388 if size_result.stdout:
389 lines.append(size_result.stdout.splitlines()[1] + ' ' +
390 rodata_size)
391
Alex Kiernan0ddc5102018-05-31 04:48:33 +0000392 # Extract the environment from U-Boot and dump it out
393 cmd = ['%sobjcopy' % self.toolchain.cross, '-O', 'binary',
394 '-j', '.rodata.default_environment',
395 'env/built-in.o', 'uboot.env']
396 command.RunPipe([cmd], capture=True,
397 capture_stderr=True, cwd=result.out_dir,
398 raise_on_error=False, env=env)
399 ubootenv = os.path.join(result.out_dir, 'uboot.env')
Simon Glass60b285f2020-04-17 17:51:34 -0600400 if not work_in_output:
401 self.CopyFiles(result.out_dir, build_dir, '', ['uboot.env'])
Alex Kiernan0ddc5102018-05-31 04:48:33 +0000402
Simon Glass190064b2014-08-09 15:33:00 -0600403 # Write out the image sizes file. This is similar to the output
404 # of binutil's 'size' utility, but it omits the header line and
405 # adds an additional hex value at the end of each line for the
406 # rodata size
407 if len(lines):
408 sizes = self.builder.GetSizesFile(result.commit_upto,
409 result.brd.target)
410 with open(sizes, 'w') as fd:
Simon Glassc05aa032019-10-31 07:42:53 -0600411 print('\n'.join(lines), file=fd)
Simon Glass190064b2014-08-09 15:33:00 -0600412
Simon Glass60b285f2020-04-17 17:51:34 -0600413 if not work_in_output:
414 # Write out the configuration files, with a special case for SPL
415 for dirname in ['', 'spl', 'tpl']:
416 self.CopyFiles(
417 result.out_dir, build_dir, dirname,
418 ['u-boot.cfg', 'spl/u-boot-spl.cfg', 'tpl/u-boot-tpl.cfg',
419 '.config', 'include/autoconf.mk',
420 'include/generated/autoconf.h'])
Simon Glass970f9322015-02-05 22:06:14 -0700421
Simon Glass60b285f2020-04-17 17:51:34 -0600422 # Now write the actual build output
423 if keep_outputs:
424 self.CopyFiles(
425 result.out_dir, build_dir, '',
426 ['u-boot*', '*.bin', '*.map', '*.img', 'MLO', 'SPL',
427 'include/autoconf.mk', 'spl/u-boot-spl*'])
Simon Glass190064b2014-08-09 15:33:00 -0600428
Simon Glass970f9322015-02-05 22:06:14 -0700429 def CopyFiles(self, out_dir, build_dir, dirname, patterns):
430 """Copy files from the build directory to the output.
431
432 Args:
433 out_dir: Path to output directory containing the files
434 build_dir: Place to copy the files
435 dirname: Source directory, '' for normal U-Boot, 'spl' for SPL
436 patterns: A list of filenames (strings) to copy, each relative
437 to the build directory
438 """
439 for pattern in patterns:
440 file_list = glob.glob(os.path.join(out_dir, dirname, pattern))
441 for fname in file_list:
442 target = os.path.basename(fname)
443 if dirname:
444 base, ext = os.path.splitext(target)
445 if ext:
446 target = '%s-%s%s' % (base, dirname, ext)
447 shutil.copy(fname, os.path.join(build_dir, target))
Simon Glass190064b2014-08-09 15:33:00 -0600448
Simon Glassab9b4f32021-04-11 16:27:26 +1200449 def _SendResult(self, result):
450 """Send a result to the builder for processing
451
452 Args:
453 result: CommandResult object containing the results of the build
Simon Glass8116c782021-04-11 16:27:27 +1200454
455 Raises:
456 ValueError if self.test_exception is true (for testing)
Simon Glassab9b4f32021-04-11 16:27:26 +1200457 """
Simon Glass8116c782021-04-11 16:27:27 +1200458 if self.test_exception:
459 raise ValueError('test exception')
Simon Glassab9b4f32021-04-11 16:27:26 +1200460 if self.thread_num != -1:
461 self.builder.out_queue.put(result)
462 else:
463 self.builder.ProcessResult(result)
464
Simon Glass190064b2014-08-09 15:33:00 -0600465 def RunJob(self, job):
466 """Run a single job
467
468 A job consists of a building a list of commits for a particular board.
469
470 Args:
471 job: Job to build
Simon Glassb82492b2021-01-30 22:17:46 -0700472
473 Returns:
474 List of Result objects
Simon Glass190064b2014-08-09 15:33:00 -0600475 """
476 brd = job.board
477 work_dir = self.builder.GetThreadDir(self.thread_num)
478 self.toolchain = None
479 if job.commits:
480 # Run 'make board_defconfig' on the first commit
481 do_config = True
482 commit_upto = 0
483 force_build = False
484 for commit_upto in range(0, len(job.commits), job.step):
485 result, request_config = self.RunCommit(commit_upto, brd,
Simon Glassa9401b22016-11-16 14:09:25 -0700486 work_dir, do_config, self.builder.config_only,
Simon Glass190064b2014-08-09 15:33:00 -0600487 force_build or self.builder.force_build,
Simon Glassd829f122020-03-18 09:42:42 -0600488 self.builder.force_build_failures,
489 work_in_output=job.work_in_output)
Simon Glass190064b2014-08-09 15:33:00 -0600490 failed = result.return_code or result.stderr
491 did_config = do_config
492 if failed and not do_config:
493 # If our incremental build failed, try building again
494 # with a reconfig.
495 if self.builder.force_config_on_failure:
496 result, request_config = self.RunCommit(commit_upto,
Simon Glassd829f122020-03-18 09:42:42 -0600497 brd, work_dir, True, False, True, False,
498 work_in_output=job.work_in_output)
Simon Glass190064b2014-08-09 15:33:00 -0600499 did_config = True
500 if not self.builder.force_reconfig:
501 do_config = request_config
502
503 # If we built that commit, then config is done. But if we got
504 # an warning, reconfig next time to force it to build the same
505 # files that created warnings this time. Otherwise an
506 # incremental build may not build the same file, and we will
507 # think that the warning has gone away.
508 # We could avoid this by using -Werror everywhere...
509 # For errors, the problem doesn't happen, since presumably
510 # the build stopped and didn't generate output, so will retry
511 # that file next time. So we could detect warnings and deal
512 # with them specially here. For now, we just reconfigure if
513 # anything goes work.
514 # Of course this is substantially slower if there are build
515 # errors/warnings (e.g. 2-3x slower even if only 10% of builds
516 # have problems).
517 if (failed and not result.already_done and not did_config and
518 self.builder.force_config_on_failure):
519 # If this build failed, try the next one with a
520 # reconfigure.
521 # Sometimes if the board_config.h file changes it can mess
522 # with dependencies, and we get:
523 # make: *** No rule to make target `include/autoconf.mk',
524 # needed by `depend'.
525 do_config = True
526 force_build = True
527 else:
528 force_build = False
529 if self.builder.force_config_on_failure:
530 if failed:
531 do_config = True
532 result.commit_upto = commit_upto
533 if result.return_code < 0:
534 raise ValueError('Interrupt')
535
536 # We have the build results, so output the result
Simon Glassd829f122020-03-18 09:42:42 -0600537 self._WriteResult(result, job.keep_outputs, job.work_in_output)
Simon Glassab9b4f32021-04-11 16:27:26 +1200538 self._SendResult(result)
Simon Glass190064b2014-08-09 15:33:00 -0600539 else:
540 # Just build the currently checked-out build
541 result, request_config = self.RunCommit(None, brd, work_dir, True,
Simon Glassa9401b22016-11-16 14:09:25 -0700542 self.builder.config_only, True,
Simon Glassd829f122020-03-18 09:42:42 -0600543 self.builder.force_build_failures,
544 work_in_output=job.work_in_output)
Simon Glass190064b2014-08-09 15:33:00 -0600545 result.commit_upto = 0
Simon Glassd829f122020-03-18 09:42:42 -0600546 self._WriteResult(result, job.keep_outputs, job.work_in_output)
Simon Glassab9b4f32021-04-11 16:27:26 +1200547 self._SendResult(result)
Simon Glass190064b2014-08-09 15:33:00 -0600548
549 def run(self):
550 """Our thread's run function
551
552 This thread picks a job from the queue, runs it, and then goes to the
553 next job.
554 """
Simon Glass190064b2014-08-09 15:33:00 -0600555 while True:
556 job = self.builder.queue.get()
Simon Glass8116c782021-04-11 16:27:27 +1200557 try:
558 self.RunJob(job)
559 except Exception as e:
560 print('Thread exception:', e)
561 self.builder.thread_exceptions.append(e)
Simon Glass190064b2014-08-09 15:33:00 -0600562 self.builder.queue.task_done()