X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=tools%2Fbuildman%2Fbuilderthread.py;h=7561f399428b0ae29feb1a908f662303fc67fb2c;hb=ea09fb5bf1ec87ed573674c361be50a7ad96ca74;hp=8974351225ce6ace5f6082901da3bdd005681118;hpb=c69f6d04ec66433f2360490a5cd0263c83aab18f;p=oweals%2Fu-boot.git diff --git a/tools/buildman/builderthread.py b/tools/buildman/builderthread.py index 8974351225..7561f39942 100644 --- a/tools/buildman/builderthread.py +++ b/tools/buildman/builderthread.py @@ -1,12 +1,12 @@ +# SPDX-License-Identifier: GPL-2.0+ # Copyright (c) 2014 Google, Inc # -# SPDX-License-Identifier: GPL-2.0+ -# import errno import glob import os import shutil +import sys import threading import command @@ -27,6 +27,9 @@ def Mkdir(dirname, parents = False): os.mkdir(dirname) except OSError as err: if err.errno == errno.EEXIST: + if os.path.realpath('.') == os.path.realpath(dirname): + print("Cannot create the current working directory '%s'!" % dirname) + sys.exit(1) pass else: raise @@ -36,11 +39,18 @@ class BuilderJob: Members: board: Board object to build - commits: List of commit options to build. + 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 + work_in_output: Use the output directory as the work directory and + don't write to a separate output directory. """ def __init__(self): self.board = None self.commits = [] + self.keep_outputs = False + self.step = 1 + self.work_in_output = False class ResultThread(threading.Thread): @@ -110,8 +120,8 @@ class BuilderThread(threading.Thread): return self.builder.do_make(commit, brd, stage, cwd, *args, **kwargs) - def RunCommit(self, commit_upto, brd, work_dir, do_config, force_build, - force_build_failures): + def RunCommit(self, commit_upto, brd, work_dir, do_config, config_only, + force_build, force_build_failures, work_in_output): """Build a particular commit. If the build is already done, and we are not forcing a build, we skip @@ -122,9 +132,12 @@ class BuilderThread(threading.Thread): brd: Board object to build work_dir: Directory to which the source will be checked out do_config: True to run a make _defconfig on the source + config_only: Only configure the source, do not build it force_build: Force a build even if one was previously done force_build_failures: Force a bulid if the previous result showed failure + work_in_output: Use the output directory as the work directory and + don't write to a separate output directory. Returns: tuple containing: @@ -135,7 +148,7 @@ class BuilderThread(threading.Thread): # self.Make() below, in the event that we do a build. result = command.CommandResult() result.return_code = 0 - if self.builder.in_tree: + if work_in_output or self.builder.in_tree: out_dir = work_dir else: if self.per_board_out_dir: @@ -152,7 +165,12 @@ class BuilderThread(threading.Thread): if result.already_done: # Get the return code from that build and use it with open(done_file, 'r') as fd: - result.return_code = int(fd.readline()) + 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 # Check the signal that the build needs to be retried if result.return_code == RETURN_CODE_RETRY: @@ -215,9 +233,12 @@ class BuilderThread(threading.Thread): args.append('-s') if self.builder.num_jobs is not None: args.extend(['-j', str(self.builder.num_jobs)]) + if self.builder.warnings_as_errors: + args.append('KCFLAGS=-Werror') config_args = ['%s_defconfig' % brd.target] config_out = '' args.extend(self.builder.toolchains.GetMakeArguments(brd)) + args.extend(self.toolchain.MakeArgs()) # If we need to reconfigure, do that now if do_config: @@ -231,6 +252,8 @@ class BuilderThread(threading.Thread): config_out += result.combined do_config = False # No need to configure next time if result.return_code == 0: + if config_only: + args.append('cfg') result = self.Make(commit, brd, 'build', cwd, *args, env=env) result.stderr = result.stderr.replace(src_dir + '/', '') @@ -247,14 +270,18 @@ class BuilderThread(threading.Thread): result.out_dir = out_dir return result, do_config - def _WriteResult(self, result, keep_outputs): + def _WriteResult(self, result, keep_outputs, work_in_output): """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 + work_in_output: Use the output directory as the work directory and + don't write to a separate output directory. """ + if work_in_output: + return # Fatal error if result.return_code < 0: return @@ -298,14 +325,17 @@ class BuilderThread(threading.Thread): else: fd.write('%s' % result.return_code) with open(os.path.join(build_dir, 'toolchain'), 'w') as fd: - print >>fd, 'gcc', result.toolchain.gcc - print >>fd, 'path', result.toolchain.path - print >>fd, 'cross', result.toolchain.cross - print >>fd, 'arch', result.toolchain.arch + 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) fd.write('%s' % result.return_code) # Write out the image and function size information and an objdump env = result.toolchain.MakeEnvironment(self.builder.full_path) + with open(os.path.join(build_dir, 'env'), 'w') as fd: + for var in sorted(env.keys()): + print('%s="%s"' % (var, env[var]), file=fd) lines = [] for fname in ['u-boot', 'spl/u-boot-spl']: cmd = ['%snm' % self.toolchain.cross, '--size-sort', fname] @@ -316,7 +346,7 @@ class BuilderThread(threading.Thread): nm = self.builder.GetFuncSizesFile(result.commit_upto, result.brd.target, fname) with open(nm, 'w') as fd: - print >>fd, nm_result.stdout, + print(nm_result.stdout, end=' ', file=fd) cmd = ['%sobjdump' % self.toolchain.cross, '-h', fname] dump_result = command.RunPipe([cmd], capture=True, @@ -327,7 +357,7 @@ class BuilderThread(threading.Thread): objdump = self.builder.GetObjdumpFile(result.commit_upto, result.brd.target, fname) with open(objdump, 'w') as fd: - print >>fd, dump_result.stdout, + print(dump_result.stdout, end=' ', file=fd) for line in dump_result.stdout.splitlines(): fields = line.split() if len(fields) > 5 and fields[1] == '.rodata': @@ -341,6 +371,16 @@ class BuilderThread(threading.Thread): lines.append(size_result.stdout.splitlines()[1] + ' ' + rodata_size) + # 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') + self.CopyFiles(result.out_dir, build_dir, '', ['uboot.env']) + # 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 @@ -349,7 +389,7 @@ class BuilderThread(threading.Thread): sizes = self.builder.GetSizesFile(result.commit_upto, result.brd.target) with open(sizes, 'w') as fd: - print >>fd, '\n'.join(lines) + print('\n'.join(lines), file=fd) # Write out the configuration files, with a special case for SPL for dirname in ['', 'spl', 'tpl']: @@ -401,9 +441,10 @@ class BuilderThread(threading.Thread): force_build = False for commit_upto in range(0, len(job.commits), job.step): result, request_config = self.RunCommit(commit_upto, brd, - work_dir, do_config, + work_dir, do_config, self.builder.config_only, force_build or self.builder.force_build, - self.builder.force_build_failures) + self.builder.force_build_failures, + work_in_output=job.work_in_output) failed = result.return_code or result.stderr did_config = do_config if failed and not do_config: @@ -411,7 +452,8 @@ class BuilderThread(threading.Thread): # with a reconfig. if self.builder.force_config_on_failure: result, request_config = self.RunCommit(commit_upto, - brd, work_dir, True, True, False) + brd, work_dir, True, False, True, False, + work_in_output=job.work_in_output) did_config = True if not self.builder.force_reconfig: do_config = request_config @@ -450,14 +492,16 @@ class BuilderThread(threading.Thread): raise ValueError('Interrupt') # We have the build results, so output the result - self._WriteResult(result, job.keep_outputs) + self._WriteResult(result, job.keep_outputs, job.work_in_output) self.builder.out_queue.put(result) else: # Just build the currently checked-out build result, request_config = self.RunCommit(None, brd, work_dir, True, - True, self.builder.force_build_failures) + self.builder.config_only, True, + self.builder.force_build_failures, + work_in_output=job.work_in_output) result.commit_upto = 0 - self._WriteResult(result, job.keep_outputs) + self._WriteResult(result, job.keep_outputs, job.work_in_output) self.builder.out_queue.put(result) def run(self):