2018-05-06 21:58:06 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0+
|
2014-08-09 21:33:00 +00:00
|
|
|
# Copyright (c) 2014 Google, Inc
|
|
|
|
#
|
|
|
|
|
|
|
|
import errno
|
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
import shutil
|
2018-04-08 11:14:11 +00:00
|
|
|
import sys
|
2014-08-09 21:33:00 +00:00
|
|
|
import threading
|
|
|
|
|
2020-04-18 00:09:04 +00:00
|
|
|
from patman import command
|
|
|
|
from patman import gitutil
|
2014-08-09 21:33:00 +00:00
|
|
|
|
2015-02-06 05:06:13 +00:00
|
|
|
RETURN_CODE_RETRY = -1
|
2020-12-17 00:24:17 +00:00
|
|
|
BASE_ELF_FILENAMES = ['u-boot', 'spl/u-boot-spl', 'tpl/u-boot-tpl']
|
2015-02-06 05:06:13 +00:00
|
|
|
|
2014-08-19 08:22:39 +00:00
|
|
|
def Mkdir(dirname, parents = False):
|
2014-08-09 21:33:00 +00:00
|
|
|
"""Make a directory if it doesn't already exist.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
dirname: Directory to create
|
|
|
|
"""
|
|
|
|
try:
|
2014-08-19 08:22:39 +00:00
|
|
|
if parents:
|
|
|
|
os.makedirs(dirname)
|
|
|
|
else:
|
|
|
|
os.mkdir(dirname)
|
2014-08-09 21:33:00 +00:00
|
|
|
except OSError as err:
|
|
|
|
if err.errno == errno.EEXIST:
|
2018-04-08 11:14:11 +00:00
|
|
|
if os.path.realpath('.') == os.path.realpath(dirname):
|
2019-10-31 13:42:53 +00:00
|
|
|
print("Cannot create the current working directory '%s'!" % dirname)
|
2018-04-08 11:14:11 +00:00
|
|
|
sys.exit(1)
|
2014-08-09 21:33:00 +00:00
|
|
|
pass
|
|
|
|
else:
|
|
|
|
raise
|
|
|
|
|
|
|
|
class BuilderJob:
|
|
|
|
"""Holds information about a job to be performed by a thread
|
|
|
|
|
|
|
|
Members:
|
|
|
|
board: Board object to build
|
2020-03-18 15:42:41 +00:00
|
|
|
commits: List of Commit objects to build
|
|
|
|
keep_outputs: True to save build output files
|
|
|
|
step: 1 to process every commit, n to process every nth commit
|
2020-03-18 15:42:42 +00:00
|
|
|
work_in_output: Use the output directory as the work directory and
|
|
|
|
don't write to a separate output directory.
|
2014-08-09 21:33:00 +00:00
|
|
|
"""
|
|
|
|
def __init__(self):
|
|
|
|
self.board = None
|
|
|
|
self.commits = []
|
2020-03-18 15:42:41 +00:00
|
|
|
self.keep_outputs = False
|
|
|
|
self.step = 1
|
2020-03-18 15:42:42 +00:00
|
|
|
self.work_in_output = False
|
2014-08-09 21:33:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ResultThread(threading.Thread):
|
|
|
|
"""This thread processes results from builder threads.
|
|
|
|
|
|
|
|
It simply passes the results on to the builder. There is only one
|
|
|
|
result thread, and this helps to serialise the build output.
|
|
|
|
"""
|
|
|
|
def __init__(self, builder):
|
|
|
|
"""Set up a new result thread
|
|
|
|
|
|
|
|
Args:
|
|
|
|
builder: Builder which will be sent each result
|
|
|
|
"""
|
|
|
|
threading.Thread.__init__(self)
|
|
|
|
self.builder = builder
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
"""Called to start up the result thread.
|
|
|
|
|
|
|
|
We collect the next result job and pass it on to the build.
|
|
|
|
"""
|
|
|
|
while True:
|
|
|
|
result = self.builder.out_queue.get()
|
|
|
|
self.builder.ProcessResult(result)
|
|
|
|
self.builder.out_queue.task_done()
|
|
|
|
|
|
|
|
|
|
|
|
class BuilderThread(threading.Thread):
|
|
|
|
"""This thread builds U-Boot for a particular board.
|
|
|
|
|
|
|
|
An input queue provides each new job. We run 'make' to build U-Boot
|
|
|
|
and then pass the results on to the output queue.
|
|
|
|
|
|
|
|
Members:
|
|
|
|
builder: The builder which contains information we might need
|
|
|
|
thread_num: Our thread number (0-n-1), used to decide on a
|
2021-04-11 04:27:25 +00:00
|
|
|
temporary directory. If this is -1 then there are no threads
|
|
|
|
and we are the (only) main process
|
|
|
|
mrproper: Use 'make mrproper' before each reconfigure
|
|
|
|
per_board_out_dir: True to build in a separate persistent directory per
|
|
|
|
board rather than a thread-specific directory
|
|
|
|
test_exception: Used for testing; True to raise an exception instead of
|
|
|
|
reporting the build result
|
2014-08-09 21:33:00 +00:00
|
|
|
"""
|
2021-04-11 04:27:27 +00:00
|
|
|
def __init__(self, builder, thread_num, mrproper, per_board_out_dir,
|
|
|
|
test_exception=False):
|
2014-08-09 21:33:00 +00:00
|
|
|
"""Set up a new builder thread"""
|
|
|
|
threading.Thread.__init__(self)
|
|
|
|
self.builder = builder
|
|
|
|
self.thread_num = thread_num
|
2020-04-09 21:08:51 +00:00
|
|
|
self.mrproper = mrproper
|
2016-04-11 16:48:44 +00:00
|
|
|
self.per_board_out_dir = per_board_out_dir
|
2021-04-11 04:27:27 +00:00
|
|
|
self.test_exception = test_exception
|
2014-08-09 21:33:00 +00:00
|
|
|
|
|
|
|
def Make(self, commit, brd, stage, cwd, *args, **kwargs):
|
|
|
|
"""Run 'make' on a particular commit and board.
|
|
|
|
|
|
|
|
The source code will already be checked out, so the 'commit'
|
|
|
|
argument is only for information.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
commit: Commit object that is being built
|
|
|
|
brd: Board object that is being built
|
|
|
|
stage: Stage of the build. Valid stages are:
|
2014-08-20 20:10:29 +00:00
|
|
|
mrproper - can be called to clean source
|
2014-08-09 21:33:00 +00:00
|
|
|
config - called to configure for a board
|
|
|
|
build - the main make invocation - it does the build
|
|
|
|
args: A list of arguments to pass to 'make'
|
|
|
|
kwargs: A list of keyword arguments to pass to command.RunPipe()
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
CommandResult object
|
|
|
|
"""
|
|
|
|
return self.builder.do_make(commit, brd, stage, cwd, *args,
|
|
|
|
**kwargs)
|
|
|
|
|
2016-11-16 21:09:25 +00:00
|
|
|
def RunCommit(self, commit_upto, brd, work_dir, do_config, config_only,
|
2020-03-18 15:42:42 +00:00
|
|
|
force_build, force_build_failures, work_in_output):
|
2014-08-09 21:33:00 +00:00
|
|
|
"""Build a particular commit.
|
|
|
|
|
|
|
|
If the build is already done, and we are not forcing a build, we skip
|
|
|
|
the build and just return the previously-saved results.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
commit_upto: Commit number to build (0...n-1)
|
|
|
|
brd: Board object to build
|
|
|
|
work_dir: Directory to which the source will be checked out
|
|
|
|
do_config: True to run a make <board>_defconfig on the source
|
2016-11-16 21:09:25 +00:00
|
|
|
config_only: Only configure the source, do not build it
|
2014-08-09 21:33:00 +00:00
|
|
|
force_build: Force a build even if one was previously done
|
|
|
|
force_build_failures: Force a bulid if the previous result showed
|
|
|
|
failure
|
2020-03-18 15:42:42 +00:00
|
|
|
work_in_output: Use the output directory as the work directory and
|
|
|
|
don't write to a separate output directory.
|
2014-08-09 21:33:00 +00:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
tuple containing:
|
|
|
|
- CommandResult object containing the results of the build
|
|
|
|
- boolean indicating whether 'make config' is still needed
|
|
|
|
"""
|
|
|
|
# Create a default result - it will be overwritte by the call to
|
|
|
|
# self.Make() below, in the event that we do a build.
|
|
|
|
result = command.CommandResult()
|
|
|
|
result.return_code = 0
|
2020-03-18 15:42:42 +00:00
|
|
|
if work_in_output or self.builder.in_tree:
|
2014-08-09 21:33:00 +00:00
|
|
|
out_dir = work_dir
|
|
|
|
else:
|
2016-04-11 16:48:44 +00:00
|
|
|
if self.per_board_out_dir:
|
|
|
|
out_rel_dir = os.path.join('..', brd.target)
|
|
|
|
else:
|
|
|
|
out_rel_dir = 'build'
|
|
|
|
out_dir = os.path.join(work_dir, out_rel_dir)
|
2014-08-09 21:33:00 +00:00
|
|
|
|
|
|
|
# Check if the job was already completed last time
|
|
|
|
done_file = self.builder.GetDoneFile(commit_upto, brd.target)
|
|
|
|
result.already_done = os.path.exists(done_file)
|
|
|
|
will_build = (force_build or force_build_failures or
|
|
|
|
not result.already_done)
|
2014-09-06 01:00:17 +00:00
|
|
|
if result.already_done:
|
2014-08-09 21:33:00 +00:00
|
|
|
# Get the return code from that build and use it
|
|
|
|
with open(done_file, 'r') as fd:
|
2018-12-10 16:05:23 +00:00
|
|
|
try:
|
|
|
|
result.return_code = int(fd.readline())
|
|
|
|
except ValueError:
|
|
|
|
# The file may be empty due to running out of disk space.
|
|
|
|
# Try a rebuild
|
|
|
|
result.return_code = RETURN_CODE_RETRY
|
2015-02-06 05:06:13 +00:00
|
|
|
|
|
|
|
# Check the signal that the build needs to be retried
|
|
|
|
if result.return_code == RETURN_CODE_RETRY:
|
|
|
|
will_build = True
|
|
|
|
elif will_build:
|
2014-09-06 01:00:17 +00:00
|
|
|
err_file = self.builder.GetErrFile(commit_upto, brd.target)
|
|
|
|
if os.path.exists(err_file) and os.stat(err_file).st_size:
|
|
|
|
result.stderr = 'bad'
|
|
|
|
elif not force_build:
|
|
|
|
# The build passed, so no need to build it again
|
|
|
|
will_build = False
|
2014-08-09 21:33:00 +00:00
|
|
|
|
|
|
|
if will_build:
|
|
|
|
# We are going to have to build it. First, get a toolchain
|
|
|
|
if not self.toolchain:
|
|
|
|
try:
|
|
|
|
self.toolchain = self.builder.toolchains.Select(brd.arch)
|
|
|
|
except ValueError as err:
|
|
|
|
result.return_code = 10
|
|
|
|
result.stdout = ''
|
|
|
|
result.stderr = str(err)
|
|
|
|
# TODO(sjg@chromium.org): This gets swallowed, but needs
|
|
|
|
# to be reported.
|
|
|
|
|
|
|
|
if self.toolchain:
|
|
|
|
# Checkout the right commit
|
|
|
|
if self.builder.commits:
|
|
|
|
commit = self.builder.commits[commit_upto]
|
|
|
|
if self.builder.checkout:
|
|
|
|
git_dir = os.path.join(work_dir, '.git')
|
|
|
|
gitutil.Checkout(commit.hash, git_dir, work_dir,
|
|
|
|
force=True)
|
|
|
|
else:
|
|
|
|
commit = 'current'
|
|
|
|
|
|
|
|
# Set up the environment and command line
|
2014-12-02 00:34:00 +00:00
|
|
|
env = self.toolchain.MakeEnvironment(self.builder.full_path)
|
2014-08-09 21:33:00 +00:00
|
|
|
Mkdir(out_dir)
|
|
|
|
args = []
|
|
|
|
cwd = work_dir
|
2014-08-28 15:43:42 +00:00
|
|
|
src_dir = os.path.realpath(work_dir)
|
2014-08-09 21:33:00 +00:00
|
|
|
if not self.builder.in_tree:
|
|
|
|
if commit_upto is None:
|
|
|
|
# In this case we are building in the original source
|
|
|
|
# directory (i.e. the current directory where buildman
|
|
|
|
# is invoked. The output directory is set to this
|
|
|
|
# thread's selected work directory.
|
|
|
|
#
|
|
|
|
# Symlinks can confuse U-Boot's Makefile since
|
|
|
|
# we may use '..' in our path, so remove them.
|
2016-04-11 16:48:44 +00:00
|
|
|
out_dir = os.path.realpath(out_dir)
|
|
|
|
args.append('O=%s' % out_dir)
|
2014-08-09 21:33:00 +00:00
|
|
|
cwd = None
|
2014-08-28 15:43:42 +00:00
|
|
|
src_dir = os.getcwd()
|
2014-08-09 21:33:00 +00:00
|
|
|
else:
|
2016-04-11 16:48:44 +00:00
|
|
|
args.append('O=%s' % out_rel_dir)
|
2015-04-01 11:47:41 +00:00
|
|
|
if self.builder.verbose_build:
|
|
|
|
args.append('V=1')
|
|
|
|
else:
|
2014-12-02 00:34:07 +00:00
|
|
|
args.append('-s')
|
2014-08-09 21:33:00 +00:00
|
|
|
if self.builder.num_jobs is not None:
|
|
|
|
args.extend(['-j', str(self.builder.num_jobs)])
|
2018-01-26 15:31:05 +00:00
|
|
|
if self.builder.warnings_as_errors:
|
|
|
|
args.append('KCFLAGS=-Werror')
|
2014-08-09 21:33:00 +00:00
|
|
|
config_args = ['%s_defconfig' % brd.target]
|
|
|
|
config_out = ''
|
|
|
|
args.extend(self.builder.toolchains.GetMakeArguments(brd))
|
2019-01-07 23:44:20 +00:00
|
|
|
args.extend(self.toolchain.MakeArgs())
|
2014-08-09 21:33:00 +00:00
|
|
|
|
2020-12-17 00:24:17 +00:00
|
|
|
# Remove any output targets. Since we use a build directory that
|
|
|
|
# was previously used by another board, it may have produced an
|
|
|
|
# SPL image. If we don't remove it (i.e. see do_config and
|
|
|
|
# self.mrproper below) then it will appear to be the output of
|
|
|
|
# this build, even if it does not produce SPL images.
|
|
|
|
build_dir = self.builder.GetBuildDir(commit_upto, brd.target)
|
|
|
|
for elf in BASE_ELF_FILENAMES:
|
|
|
|
fname = os.path.join(out_dir, elf)
|
|
|
|
if os.path.exists(fname):
|
|
|
|
os.remove(fname)
|
|
|
|
|
2014-08-09 21:33:00 +00:00
|
|
|
# If we need to reconfigure, do that now
|
|
|
|
if do_config:
|
2016-04-11 16:48:44 +00:00
|
|
|
config_out = ''
|
2020-04-09 21:08:51 +00:00
|
|
|
if self.mrproper:
|
2016-04-11 16:48:44 +00:00
|
|
|
result = self.Make(commit, brd, 'mrproper', cwd,
|
|
|
|
'mrproper', *args, env=env)
|
|
|
|
config_out += result.combined
|
2014-08-09 21:33:00 +00:00
|
|
|
result = self.Make(commit, brd, 'config', cwd,
|
|
|
|
*(args + config_args), env=env)
|
2015-02-06 05:06:12 +00:00
|
|
|
config_out += result.combined
|
2014-08-09 21:33:00 +00:00
|
|
|
do_config = False # No need to configure next time
|
|
|
|
if result.return_code == 0:
|
2016-11-16 21:09:25 +00:00
|
|
|
if config_only:
|
2016-11-13 21:25:51 +00:00
|
|
|
args.append('cfg')
|
2014-08-09 21:33:00 +00:00
|
|
|
result = self.Make(commit, brd, 'build', cwd, *args,
|
|
|
|
env=env)
|
2014-08-28 15:43:42 +00:00
|
|
|
result.stderr = result.stderr.replace(src_dir + '/', '')
|
2015-02-06 05:06:12 +00:00
|
|
|
if self.builder.verbose_build:
|
|
|
|
result.stdout = config_out + result.stdout
|
2014-08-09 21:33:00 +00:00
|
|
|
else:
|
|
|
|
result.return_code = 1
|
|
|
|
result.stderr = 'No tool chain for %s\n' % brd.arch
|
|
|
|
result.already_done = False
|
|
|
|
|
|
|
|
result.toolchain = self.toolchain
|
|
|
|
result.brd = brd
|
|
|
|
result.commit_upto = commit_upto
|
|
|
|
result.out_dir = out_dir
|
|
|
|
return result, do_config
|
|
|
|
|
2020-03-18 15:42:42 +00:00
|
|
|
def _WriteResult(self, result, keep_outputs, work_in_output):
|
2014-08-09 21:33:00 +00:00
|
|
|
"""Write a built result to the output directory.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
result: CommandResult object containing result to write
|
|
|
|
keep_outputs: True to store the output binaries, False
|
|
|
|
to delete them
|
2020-03-18 15:42:42 +00:00
|
|
|
work_in_output: Use the output directory as the work directory and
|
|
|
|
don't write to a separate output directory.
|
2014-08-09 21:33:00 +00:00
|
|
|
"""
|
2015-02-06 05:06:13 +00:00
|
|
|
# If we think this might have been aborted with Ctrl-C, record the
|
|
|
|
# failure but not that we are 'done' with this board. A retry may fix
|
|
|
|
# it.
|
2021-10-20 03:43:23 +00:00
|
|
|
maybe_aborted = result.stderr and 'No child processes' in result.stderr
|
2014-08-09 21:33:00 +00:00
|
|
|
|
2021-10-20 03:43:23 +00:00
|
|
|
if result.return_code >= 0 and result.already_done:
|
2014-08-09 21:33:00 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
# Write the output and stderr
|
|
|
|
output_dir = self.builder._GetOutputDir(result.commit_upto)
|
|
|
|
Mkdir(output_dir)
|
|
|
|
build_dir = self.builder.GetBuildDir(result.commit_upto,
|
|
|
|
result.brd.target)
|
|
|
|
Mkdir(build_dir)
|
|
|
|
|
|
|
|
outfile = os.path.join(build_dir, 'log')
|
|
|
|
with open(outfile, 'w') as fd:
|
|
|
|
if result.stdout:
|
2019-10-31 13:42:53 +00:00
|
|
|
fd.write(result.stdout)
|
2014-08-09 21:33:00 +00:00
|
|
|
|
|
|
|
errfile = self.builder.GetErrFile(result.commit_upto,
|
|
|
|
result.brd.target)
|
|
|
|
if result.stderr:
|
|
|
|
with open(errfile, 'w') as fd:
|
2019-10-31 13:42:53 +00:00
|
|
|
fd.write(result.stderr)
|
2014-08-09 21:33:00 +00:00
|
|
|
elif os.path.exists(errfile):
|
|
|
|
os.remove(errfile)
|
|
|
|
|
2021-10-20 03:43:23 +00:00
|
|
|
# Fatal error
|
|
|
|
if result.return_code < 0:
|
|
|
|
return
|
|
|
|
|
2014-08-09 21:33:00 +00:00
|
|
|
if result.toolchain:
|
|
|
|
# Write the build result and toolchain information.
|
|
|
|
done_file = self.builder.GetDoneFile(result.commit_upto,
|
|
|
|
result.brd.target)
|
|
|
|
with open(done_file, 'w') as fd:
|
2015-02-06 05:06:13 +00:00
|
|
|
if maybe_aborted:
|
|
|
|
# Special code to indicate we need to retry
|
|
|
|
fd.write('%s' % RETURN_CODE_RETRY)
|
|
|
|
else:
|
|
|
|
fd.write('%s' % result.return_code)
|
2014-08-09 21:33:00 +00:00
|
|
|
with open(os.path.join(build_dir, 'toolchain'), 'w') as fd:
|
2019-10-31 13:42:53 +00:00
|
|
|
print('gcc', result.toolchain.gcc, file=fd)
|
|
|
|
print('path', result.toolchain.path, file=fd)
|
|
|
|
print('cross', result.toolchain.cross, file=fd)
|
|
|
|
print('arch', result.toolchain.arch, file=fd)
|
2014-08-09 21:33:00 +00:00
|
|
|
fd.write('%s' % result.return_code)
|
|
|
|
|
|
|
|
# Write out the image and function size information and an objdump
|
2014-12-02 00:34:00 +00:00
|
|
|
env = result.toolchain.MakeEnvironment(self.builder.full_path)
|
2021-04-11 04:27:28 +00:00
|
|
|
with open(os.path.join(build_dir, 'out-env'), 'wb') as fd:
|
2019-01-07 23:44:23 +00:00
|
|
|
for var in sorted(env.keys()):
|
2021-04-11 04:27:28 +00:00
|
|
|
fd.write(b'%s="%s"' % (var, env[var]))
|
2014-08-09 21:33:00 +00:00
|
|
|
lines = []
|
2020-12-17 00:24:17 +00:00
|
|
|
for fname in BASE_ELF_FILENAMES:
|
2014-08-09 21:33:00 +00:00
|
|
|
cmd = ['%snm' % self.toolchain.cross, '--size-sort', fname]
|
|
|
|
nm_result = command.RunPipe([cmd], capture=True,
|
|
|
|
capture_stderr=True, cwd=result.out_dir,
|
|
|
|
raise_on_error=False, env=env)
|
|
|
|
if nm_result.stdout:
|
|
|
|
nm = self.builder.GetFuncSizesFile(result.commit_upto,
|
|
|
|
result.brd.target, fname)
|
|
|
|
with open(nm, 'w') as fd:
|
2019-10-31 13:42:53 +00:00
|
|
|
print(nm_result.stdout, end=' ', file=fd)
|
2014-08-09 21:33:00 +00:00
|
|
|
|
|
|
|
cmd = ['%sobjdump' % self.toolchain.cross, '-h', fname]
|
|
|
|
dump_result = command.RunPipe([cmd], capture=True,
|
|
|
|
capture_stderr=True, cwd=result.out_dir,
|
|
|
|
raise_on_error=False, env=env)
|
|
|
|
rodata_size = ''
|
|
|
|
if dump_result.stdout:
|
|
|
|
objdump = self.builder.GetObjdumpFile(result.commit_upto,
|
|
|
|
result.brd.target, fname)
|
|
|
|
with open(objdump, 'w') as fd:
|
2019-10-31 13:42:53 +00:00
|
|
|
print(dump_result.stdout, end=' ', file=fd)
|
2014-08-09 21:33:00 +00:00
|
|
|
for line in dump_result.stdout.splitlines():
|
|
|
|
fields = line.split()
|
|
|
|
if len(fields) > 5 and fields[1] == '.rodata':
|
|
|
|
rodata_size = fields[2]
|
|
|
|
|
|
|
|
cmd = ['%ssize' % self.toolchain.cross, fname]
|
|
|
|
size_result = command.RunPipe([cmd], capture=True,
|
|
|
|
capture_stderr=True, cwd=result.out_dir,
|
|
|
|
raise_on_error=False, env=env)
|
|
|
|
if size_result.stdout:
|
|
|
|
lines.append(size_result.stdout.splitlines()[1] + ' ' +
|
|
|
|
rodata_size)
|
|
|
|
|
2018-05-31 04:48:33 +00:00
|
|
|
# Extract the environment from U-Boot and dump it out
|
|
|
|
cmd = ['%sobjcopy' % self.toolchain.cross, '-O', 'binary',
|
|
|
|
'-j', '.rodata.default_environment',
|
|
|
|
'env/built-in.o', 'uboot.env']
|
|
|
|
command.RunPipe([cmd], capture=True,
|
|
|
|
capture_stderr=True, cwd=result.out_dir,
|
|
|
|
raise_on_error=False, env=env)
|
|
|
|
ubootenv = os.path.join(result.out_dir, 'uboot.env')
|
2020-04-17 23:51:34 +00:00
|
|
|
if not work_in_output:
|
|
|
|
self.CopyFiles(result.out_dir, build_dir, '', ['uboot.env'])
|
2018-05-31 04:48:33 +00:00
|
|
|
|
2014-08-09 21:33:00 +00:00
|
|
|
# Write out the image sizes file. This is similar to the output
|
|
|
|
# of binutil's 'size' utility, but it omits the header line and
|
|
|
|
# adds an additional hex value at the end of each line for the
|
|
|
|
# rodata size
|
|
|
|
if len(lines):
|
|
|
|
sizes = self.builder.GetSizesFile(result.commit_upto,
|
|
|
|
result.brd.target)
|
|
|
|
with open(sizes, 'w') as fd:
|
2019-10-31 13:42:53 +00:00
|
|
|
print('\n'.join(lines), file=fd)
|
2014-08-09 21:33:00 +00:00
|
|
|
|
2020-04-17 23:51:34 +00:00
|
|
|
if not work_in_output:
|
|
|
|
# Write out the configuration files, with a special case for SPL
|
|
|
|
for dirname in ['', 'spl', 'tpl']:
|
|
|
|
self.CopyFiles(
|
|
|
|
result.out_dir, build_dir, dirname,
|
|
|
|
['u-boot.cfg', 'spl/u-boot-spl.cfg', 'tpl/u-boot-tpl.cfg',
|
|
|
|
'.config', 'include/autoconf.mk',
|
|
|
|
'include/generated/autoconf.h'])
|
|
|
|
|
|
|
|
# Now write the actual build output
|
|
|
|
if keep_outputs:
|
|
|
|
self.CopyFiles(
|
|
|
|
result.out_dir, build_dir, '',
|
|
|
|
['u-boot*', '*.bin', '*.map', '*.img', 'MLO', 'SPL',
|
|
|
|
'include/autoconf.mk', 'spl/u-boot-spl*'])
|
2015-02-06 05:06:14 +00:00
|
|
|
|
|
|
|
def CopyFiles(self, out_dir, build_dir, dirname, patterns):
|
|
|
|
"""Copy files from the build directory to the output.
|
2014-08-09 21:33:00 +00:00
|
|
|
|
2015-02-06 05:06:14 +00:00
|
|
|
Args:
|
|
|
|
out_dir: Path to output directory containing the files
|
|
|
|
build_dir: Place to copy the files
|
|
|
|
dirname: Source directory, '' for normal U-Boot, 'spl' for SPL
|
|
|
|
patterns: A list of filenames (strings) to copy, each relative
|
|
|
|
to the build directory
|
|
|
|
"""
|
|
|
|
for pattern in patterns:
|
|
|
|
file_list = glob.glob(os.path.join(out_dir, dirname, pattern))
|
|
|
|
for fname in file_list:
|
|
|
|
target = os.path.basename(fname)
|
|
|
|
if dirname:
|
|
|
|
base, ext = os.path.splitext(target)
|
|
|
|
if ext:
|
|
|
|
target = '%s-%s%s' % (base, dirname, ext)
|
|
|
|
shutil.copy(fname, os.path.join(build_dir, target))
|
2014-08-09 21:33:00 +00:00
|
|
|
|
2021-04-11 04:27:26 +00:00
|
|
|
def _SendResult(self, result):
|
|
|
|
"""Send a result to the builder for processing
|
|
|
|
|
|
|
|
Args:
|
|
|
|
result: CommandResult object containing the results of the build
|
2021-04-11 04:27:27 +00:00
|
|
|
|
|
|
|
Raises:
|
|
|
|
ValueError if self.test_exception is true (for testing)
|
2021-04-11 04:27:26 +00:00
|
|
|
"""
|
2021-04-11 04:27:27 +00:00
|
|
|
if self.test_exception:
|
|
|
|
raise ValueError('test exception')
|
2021-04-11 04:27:26 +00:00
|
|
|
if self.thread_num != -1:
|
|
|
|
self.builder.out_queue.put(result)
|
|
|
|
else:
|
|
|
|
self.builder.ProcessResult(result)
|
|
|
|
|
2014-08-09 21:33:00 +00:00
|
|
|
def RunJob(self, job):
|
|
|
|
"""Run a single job
|
|
|
|
|
|
|
|
A job consists of a building a list of commits for a particular board.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
job: Job to build
|
2021-01-31 05:17:46 +00:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
List of Result objects
|
2014-08-09 21:33:00 +00:00
|
|
|
"""
|
|
|
|
brd = job.board
|
|
|
|
work_dir = self.builder.GetThreadDir(self.thread_num)
|
|
|
|
self.toolchain = None
|
|
|
|
if job.commits:
|
|
|
|
# Run 'make board_defconfig' on the first commit
|
|
|
|
do_config = True
|
|
|
|
commit_upto = 0
|
|
|
|
force_build = False
|
|
|
|
for commit_upto in range(0, len(job.commits), job.step):
|
|
|
|
result, request_config = self.RunCommit(commit_upto, brd,
|
2016-11-16 21:09:25 +00:00
|
|
|
work_dir, do_config, self.builder.config_only,
|
2014-08-09 21:33:00 +00:00
|
|
|
force_build or self.builder.force_build,
|
2020-03-18 15:42:42 +00:00
|
|
|
self.builder.force_build_failures,
|
|
|
|
work_in_output=job.work_in_output)
|
2014-08-09 21:33:00 +00:00
|
|
|
failed = result.return_code or result.stderr
|
|
|
|
did_config = do_config
|
|
|
|
if failed and not do_config:
|
|
|
|
# If our incremental build failed, try building again
|
|
|
|
# with a reconfig.
|
|
|
|
if self.builder.force_config_on_failure:
|
|
|
|
result, request_config = self.RunCommit(commit_upto,
|
2020-03-18 15:42:42 +00:00
|
|
|
brd, work_dir, True, False, True, False,
|
|
|
|
work_in_output=job.work_in_output)
|
2014-08-09 21:33:00 +00:00
|
|
|
did_config = True
|
|
|
|
if not self.builder.force_reconfig:
|
|
|
|
do_config = request_config
|
|
|
|
|
|
|
|
# If we built that commit, then config is done. But if we got
|
|
|
|
# an warning, reconfig next time to force it to build the same
|
|
|
|
# files that created warnings this time. Otherwise an
|
|
|
|
# incremental build may not build the same file, and we will
|
|
|
|
# think that the warning has gone away.
|
|
|
|
# We could avoid this by using -Werror everywhere...
|
|
|
|
# For errors, the problem doesn't happen, since presumably
|
|
|
|
# the build stopped and didn't generate output, so will retry
|
|
|
|
# that file next time. So we could detect warnings and deal
|
|
|
|
# with them specially here. For now, we just reconfigure if
|
|
|
|
# anything goes work.
|
|
|
|
# Of course this is substantially slower if there are build
|
|
|
|
# errors/warnings (e.g. 2-3x slower even if only 10% of builds
|
|
|
|
# have problems).
|
|
|
|
if (failed and not result.already_done and not did_config and
|
|
|
|
self.builder.force_config_on_failure):
|
|
|
|
# If this build failed, try the next one with a
|
|
|
|
# reconfigure.
|
|
|
|
# Sometimes if the board_config.h file changes it can mess
|
|
|
|
# with dependencies, and we get:
|
|
|
|
# make: *** No rule to make target `include/autoconf.mk',
|
|
|
|
# needed by `depend'.
|
|
|
|
do_config = True
|
|
|
|
force_build = True
|
|
|
|
else:
|
|
|
|
force_build = False
|
|
|
|
if self.builder.force_config_on_failure:
|
|
|
|
if failed:
|
|
|
|
do_config = True
|
|
|
|
result.commit_upto = commit_upto
|
|
|
|
if result.return_code < 0:
|
|
|
|
raise ValueError('Interrupt')
|
|
|
|
|
|
|
|
# We have the build results, so output the result
|
2020-03-18 15:42:42 +00:00
|
|
|
self._WriteResult(result, job.keep_outputs, job.work_in_output)
|
2021-04-11 04:27:26 +00:00
|
|
|
self._SendResult(result)
|
2014-08-09 21:33:00 +00:00
|
|
|
else:
|
|
|
|
# Just build the currently checked-out build
|
|
|
|
result, request_config = self.RunCommit(None, brd, work_dir, True,
|
2016-11-16 21:09:25 +00:00
|
|
|
self.builder.config_only, True,
|
2020-03-18 15:42:42 +00:00
|
|
|
self.builder.force_build_failures,
|
|
|
|
work_in_output=job.work_in_output)
|
2014-08-09 21:33:00 +00:00
|
|
|
result.commit_upto = 0
|
2020-03-18 15:42:42 +00:00
|
|
|
self._WriteResult(result, job.keep_outputs, job.work_in_output)
|
2021-04-11 04:27:26 +00:00
|
|
|
self._SendResult(result)
|
2014-08-09 21:33:00 +00:00
|
|
|
|
|
|
|
def run(self):
|
|
|
|
"""Our thread's run function
|
|
|
|
|
|
|
|
This thread picks a job from the queue, runs it, and then goes to the
|
|
|
|
next job.
|
|
|
|
"""
|
|
|
|
while True:
|
|
|
|
job = self.builder.queue.get()
|
2021-04-11 04:27:27 +00:00
|
|
|
try:
|
|
|
|
self.RunJob(job)
|
|
|
|
except Exception as e:
|
|
|
|
print('Thread exception:', e)
|
|
|
|
self.builder.thread_exceptions.append(e)
|
2014-08-09 21:33:00 +00:00
|
|
|
self.builder.queue.task_done()
|