Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 2 | # Copyright (c) 2014 Google, Inc |
| 3 | # |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 4 | |
| 5 | import errno |
| 6 | import glob |
| 7 | import os |
| 8 | import shutil |
Lothar Waßmann | 409fc02 | 2018-04-08 05:14:11 -0600 | [diff] [blame] | 9 | import sys |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 10 | import threading |
| 11 | |
| 12 | import command |
| 13 | import gitutil |
| 14 | |
Simon Glass | 88c8dcf | 2015-02-05 22:06:13 -0700 | [diff] [blame] | 15 | RETURN_CODE_RETRY = -1 |
| 16 | |
Thierry Reding | f3d015c | 2014-08-19 10:22:39 +0200 | [diff] [blame] | 17 | def Mkdir(dirname, parents = False): |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 18 | """Make a directory if it doesn't already exist. |
| 19 | |
| 20 | Args: |
| 21 | dirname: Directory to create |
| 22 | """ |
| 23 | try: |
Thierry Reding | f3d015c | 2014-08-19 10:22:39 +0200 | [diff] [blame] | 24 | if parents: |
| 25 | os.makedirs(dirname) |
| 26 | else: |
| 27 | os.mkdir(dirname) |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 28 | except OSError as err: |
| 29 | if err.errno == errno.EEXIST: |
Lothar Waßmann | 409fc02 | 2018-04-08 05:14:11 -0600 | [diff] [blame] | 30 | if os.path.realpath('.') == os.path.realpath(dirname): |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 31 | print("Cannot create the current working directory '%s'!" % dirname) |
Lothar Waßmann | 409fc02 | 2018-04-08 05:14:11 -0600 | [diff] [blame] | 32 | sys.exit(1) |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 33 | pass |
| 34 | else: |
| 35 | raise |
| 36 | |
| 37 | class BuilderJob: |
| 38 | """Holds information about a job to be performed by a thread |
| 39 | |
| 40 | Members: |
| 41 | board: Board object to build |
Simon Glass | e9fbbf6 | 2020-03-18 09:42:41 -0600 | [diff] [blame] | 42 | commits: List of Commit objects to build |
| 43 | keep_outputs: True to save build output files |
| 44 | step: 1 to process every commit, n to process every nth commit |
Simon Glass | d829f12 | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 45 | work_in_output: Use the output directory as the work directory and |
| 46 | don't write to a separate output directory. |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 47 | """ |
| 48 | def __init__(self): |
| 49 | self.board = None |
| 50 | self.commits = [] |
Simon Glass | e9fbbf6 | 2020-03-18 09:42:41 -0600 | [diff] [blame] | 51 | self.keep_outputs = False |
| 52 | self.step = 1 |
Simon Glass | d829f12 | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 53 | self.work_in_output = False |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 54 | |
| 55 | |
| 56 | class ResultThread(threading.Thread): |
| 57 | """This thread processes results from builder threads. |
| 58 | |
| 59 | It simply passes the results on to the builder. There is only one |
| 60 | result thread, and this helps to serialise the build output. |
| 61 | """ |
| 62 | def __init__(self, builder): |
| 63 | """Set up a new result thread |
| 64 | |
| 65 | Args: |
| 66 | builder: Builder which will be sent each result |
| 67 | """ |
| 68 | threading.Thread.__init__(self) |
| 69 | self.builder = builder |
| 70 | |
| 71 | def run(self): |
| 72 | """Called to start up the result thread. |
| 73 | |
| 74 | We collect the next result job and pass it on to the build. |
| 75 | """ |
| 76 | while True: |
| 77 | result = self.builder.out_queue.get() |
| 78 | self.builder.ProcessResult(result) |
| 79 | self.builder.out_queue.task_done() |
| 80 | |
| 81 | |
| 82 | class BuilderThread(threading.Thread): |
| 83 | """This thread builds U-Boot for a particular board. |
| 84 | |
| 85 | An input queue provides each new job. We run 'make' to build U-Boot |
| 86 | and then pass the results on to the output queue. |
| 87 | |
| 88 | Members: |
| 89 | builder: The builder which contains information we might need |
| 90 | thread_num: Our thread number (0-n-1), used to decide on a |
| 91 | temporary directory |
| 92 | """ |
Simon Glass | eb70a2c | 2020-04-09 15:08:51 -0600 | [diff] [blame] | 93 | def __init__(self, builder, thread_num, mrproper, per_board_out_dir): |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 94 | """Set up a new builder thread""" |
| 95 | threading.Thread.__init__(self) |
| 96 | self.builder = builder |
| 97 | self.thread_num = thread_num |
Simon Glass | eb70a2c | 2020-04-09 15:08:51 -0600 | [diff] [blame] | 98 | self.mrproper = mrproper |
Stephen Warren | f79f1e0 | 2016-04-11 10:48:44 -0600 | [diff] [blame] | 99 | self.per_board_out_dir = per_board_out_dir |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 100 | |
| 101 | def Make(self, commit, brd, stage, cwd, *args, **kwargs): |
| 102 | """Run 'make' on a particular commit and board. |
| 103 | |
| 104 | The source code will already be checked out, so the 'commit' |
| 105 | argument is only for information. |
| 106 | |
| 107 | Args: |
| 108 | commit: Commit object that is being built |
| 109 | brd: Board object that is being built |
| 110 | stage: Stage of the build. Valid stages are: |
Roger Meier | fd18a89 | 2014-08-20 22:10:29 +0200 | [diff] [blame] | 111 | mrproper - can be called to clean source |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 112 | config - called to configure for a board |
| 113 | build - the main make invocation - it does the build |
| 114 | args: A list of arguments to pass to 'make' |
| 115 | kwargs: A list of keyword arguments to pass to command.RunPipe() |
| 116 | |
| 117 | Returns: |
| 118 | CommandResult object |
| 119 | """ |
| 120 | return self.builder.do_make(commit, brd, stage, cwd, *args, |
| 121 | **kwargs) |
| 122 | |
Simon Glass | a9401b2 | 2016-11-16 14:09:25 -0700 | [diff] [blame] | 123 | def RunCommit(self, commit_upto, brd, work_dir, do_config, config_only, |
Simon Glass | d829f12 | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 124 | force_build, force_build_failures, work_in_output): |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 125 | """Build a particular commit. |
| 126 | |
| 127 | If the build is already done, and we are not forcing a build, we skip |
| 128 | the build and just return the previously-saved results. |
| 129 | |
| 130 | Args: |
| 131 | commit_upto: Commit number to build (0...n-1) |
| 132 | brd: Board object to build |
| 133 | work_dir: Directory to which the source will be checked out |
| 134 | do_config: True to run a make <board>_defconfig on the source |
Simon Glass | a9401b2 | 2016-11-16 14:09:25 -0700 | [diff] [blame] | 135 | config_only: Only configure the source, do not build it |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 136 | force_build: Force a build even if one was previously done |
| 137 | force_build_failures: Force a bulid if the previous result showed |
| 138 | failure |
Simon Glass | d829f12 | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 139 | work_in_output: Use the output directory as the work directory and |
| 140 | don't write to a separate output directory. |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 141 | |
| 142 | Returns: |
| 143 | tuple containing: |
| 144 | - CommandResult object containing the results of the build |
| 145 | - boolean indicating whether 'make config' is still needed |
| 146 | """ |
| 147 | # Create a default result - it will be overwritte by the call to |
| 148 | # self.Make() below, in the event that we do a build. |
| 149 | result = command.CommandResult() |
| 150 | result.return_code = 0 |
Simon Glass | d829f12 | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 151 | if work_in_output or self.builder.in_tree: |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 152 | out_dir = work_dir |
| 153 | else: |
Stephen Warren | f79f1e0 | 2016-04-11 10:48:44 -0600 | [diff] [blame] | 154 | if self.per_board_out_dir: |
| 155 | out_rel_dir = os.path.join('..', brd.target) |
| 156 | else: |
| 157 | out_rel_dir = 'build' |
| 158 | out_dir = os.path.join(work_dir, out_rel_dir) |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 159 | |
| 160 | # Check if the job was already completed last time |
| 161 | done_file = self.builder.GetDoneFile(commit_upto, brd.target) |
| 162 | result.already_done = os.path.exists(done_file) |
| 163 | will_build = (force_build or force_build_failures or |
| 164 | not result.already_done) |
Simon Glass | fb3954f | 2014-09-05 19:00:17 -0600 | [diff] [blame] | 165 | if result.already_done: |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 166 | # Get the return code from that build and use it |
| 167 | with open(done_file, 'r') as fd: |
Simon Glass | e74429b | 2018-12-10 09:05:23 -0700 | [diff] [blame] | 168 | try: |
| 169 | result.return_code = int(fd.readline()) |
| 170 | except ValueError: |
| 171 | # The file may be empty due to running out of disk space. |
| 172 | # Try a rebuild |
| 173 | result.return_code = RETURN_CODE_RETRY |
Simon Glass | 88c8dcf | 2015-02-05 22:06:13 -0700 | [diff] [blame] | 174 | |
| 175 | # Check the signal that the build needs to be retried |
| 176 | if result.return_code == RETURN_CODE_RETRY: |
| 177 | will_build = True |
| 178 | elif will_build: |
Simon Glass | fb3954f | 2014-09-05 19:00:17 -0600 | [diff] [blame] | 179 | err_file = self.builder.GetErrFile(commit_upto, brd.target) |
| 180 | if os.path.exists(err_file) and os.stat(err_file).st_size: |
| 181 | result.stderr = 'bad' |
| 182 | elif not force_build: |
| 183 | # The build passed, so no need to build it again |
| 184 | will_build = False |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 185 | |
| 186 | if will_build: |
| 187 | # We are going to have to build it. First, get a toolchain |
| 188 | if not self.toolchain: |
| 189 | try: |
| 190 | self.toolchain = self.builder.toolchains.Select(brd.arch) |
| 191 | except ValueError as err: |
| 192 | result.return_code = 10 |
| 193 | result.stdout = '' |
| 194 | result.stderr = str(err) |
| 195 | # TODO(sjg@chromium.org): This gets swallowed, but needs |
| 196 | # to be reported. |
| 197 | |
| 198 | if self.toolchain: |
| 199 | # Checkout the right commit |
| 200 | if self.builder.commits: |
| 201 | commit = self.builder.commits[commit_upto] |
| 202 | if self.builder.checkout: |
| 203 | git_dir = os.path.join(work_dir, '.git') |
| 204 | gitutil.Checkout(commit.hash, git_dir, work_dir, |
| 205 | force=True) |
| 206 | else: |
| 207 | commit = 'current' |
| 208 | |
| 209 | # Set up the environment and command line |
Simon Glass | bb1501f | 2014-12-01 17:34:00 -0700 | [diff] [blame] | 210 | env = self.toolchain.MakeEnvironment(self.builder.full_path) |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 211 | Mkdir(out_dir) |
| 212 | args = [] |
| 213 | cwd = work_dir |
Simon Glass | 48c1b6a | 2014-08-28 09:43:42 -0600 | [diff] [blame] | 214 | src_dir = os.path.realpath(work_dir) |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 215 | if not self.builder.in_tree: |
| 216 | if commit_upto is None: |
| 217 | # In this case we are building in the original source |
| 218 | # directory (i.e. the current directory where buildman |
| 219 | # is invoked. The output directory is set to this |
| 220 | # thread's selected work directory. |
| 221 | # |
| 222 | # Symlinks can confuse U-Boot's Makefile since |
| 223 | # we may use '..' in our path, so remove them. |
Stephen Warren | f79f1e0 | 2016-04-11 10:48:44 -0600 | [diff] [blame] | 224 | out_dir = os.path.realpath(out_dir) |
| 225 | args.append('O=%s' % out_dir) |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 226 | cwd = None |
Simon Glass | 48c1b6a | 2014-08-28 09:43:42 -0600 | [diff] [blame] | 227 | src_dir = os.getcwd() |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 228 | else: |
Stephen Warren | f79f1e0 | 2016-04-11 10:48:44 -0600 | [diff] [blame] | 229 | args.append('O=%s' % out_rel_dir) |
Tom Rini | f5e5ece | 2015-04-01 07:47:41 -0400 | [diff] [blame] | 230 | if self.builder.verbose_build: |
| 231 | args.append('V=1') |
| 232 | else: |
Simon Glass | d2ce658 | 2014-12-01 17:34:07 -0700 | [diff] [blame] | 233 | args.append('-s') |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 234 | if self.builder.num_jobs is not None: |
| 235 | args.extend(['-j', str(self.builder.num_jobs)]) |
Daniel Schwierzeck | 2371d1b | 2018-01-26 16:31:05 +0100 | [diff] [blame] | 236 | if self.builder.warnings_as_errors: |
| 237 | args.append('KCFLAGS=-Werror') |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 238 | config_args = ['%s_defconfig' % brd.target] |
| 239 | config_out = '' |
| 240 | args.extend(self.builder.toolchains.GetMakeArguments(brd)) |
Simon Glass | 00beb24 | 2019-01-07 16:44:20 -0700 | [diff] [blame] | 241 | args.extend(self.toolchain.MakeArgs()) |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 242 | |
| 243 | # If we need to reconfigure, do that now |
| 244 | if do_config: |
Stephen Warren | f79f1e0 | 2016-04-11 10:48:44 -0600 | [diff] [blame] | 245 | config_out = '' |
Simon Glass | eb70a2c | 2020-04-09 15:08:51 -0600 | [diff] [blame] | 246 | if self.mrproper: |
Stephen Warren | f79f1e0 | 2016-04-11 10:48:44 -0600 | [diff] [blame] | 247 | result = self.Make(commit, brd, 'mrproper', cwd, |
| 248 | 'mrproper', *args, env=env) |
| 249 | config_out += result.combined |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 250 | result = self.Make(commit, brd, 'config', cwd, |
| 251 | *(args + config_args), env=env) |
Simon Glass | 40f11fc | 2015-02-05 22:06:12 -0700 | [diff] [blame] | 252 | config_out += result.combined |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 253 | do_config = False # No need to configure next time |
| 254 | if result.return_code == 0: |
Simon Glass | a9401b2 | 2016-11-16 14:09:25 -0700 | [diff] [blame] | 255 | if config_only: |
Simon Glass | b50113f | 2016-11-13 14:25:51 -0700 | [diff] [blame] | 256 | args.append('cfg') |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 257 | result = self.Make(commit, brd, 'build', cwd, *args, |
| 258 | env=env) |
Simon Glass | 48c1b6a | 2014-08-28 09:43:42 -0600 | [diff] [blame] | 259 | result.stderr = result.stderr.replace(src_dir + '/', '') |
Simon Glass | 40f11fc | 2015-02-05 22:06:12 -0700 | [diff] [blame] | 260 | if self.builder.verbose_build: |
| 261 | result.stdout = config_out + result.stdout |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 262 | else: |
| 263 | result.return_code = 1 |
| 264 | result.stderr = 'No tool chain for %s\n' % brd.arch |
| 265 | result.already_done = False |
| 266 | |
| 267 | result.toolchain = self.toolchain |
| 268 | result.brd = brd |
| 269 | result.commit_upto = commit_upto |
| 270 | result.out_dir = out_dir |
| 271 | return result, do_config |
| 272 | |
Simon Glass | d829f12 | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 273 | def _WriteResult(self, result, keep_outputs, work_in_output): |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 274 | """Write a built result to the output directory. |
| 275 | |
| 276 | Args: |
| 277 | result: CommandResult object containing result to write |
| 278 | keep_outputs: True to store the output binaries, False |
| 279 | to delete them |
Simon Glass | d829f12 | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 280 | work_in_output: Use the output directory as the work directory and |
| 281 | don't write to a separate output directory. |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 282 | """ |
| 283 | # Fatal error |
| 284 | if result.return_code < 0: |
| 285 | return |
| 286 | |
Simon Glass | 88c8dcf | 2015-02-05 22:06:13 -0700 | [diff] [blame] | 287 | # If we think this might have been aborted with Ctrl-C, record the |
| 288 | # failure but not that we are 'done' with this board. A retry may fix |
| 289 | # it. |
| 290 | maybe_aborted = result.stderr and 'No child processes' in result.stderr |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 291 | |
| 292 | if result.already_done: |
| 293 | return |
| 294 | |
| 295 | # Write the output and stderr |
| 296 | output_dir = self.builder._GetOutputDir(result.commit_upto) |
| 297 | Mkdir(output_dir) |
| 298 | build_dir = self.builder.GetBuildDir(result.commit_upto, |
| 299 | result.brd.target) |
| 300 | Mkdir(build_dir) |
| 301 | |
| 302 | outfile = os.path.join(build_dir, 'log') |
| 303 | with open(outfile, 'w') as fd: |
| 304 | if result.stdout: |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 305 | fd.write(result.stdout) |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 306 | |
| 307 | errfile = self.builder.GetErrFile(result.commit_upto, |
| 308 | result.brd.target) |
| 309 | if result.stderr: |
| 310 | with open(errfile, 'w') as fd: |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 311 | fd.write(result.stderr) |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 312 | elif os.path.exists(errfile): |
| 313 | os.remove(errfile) |
| 314 | |
| 315 | if result.toolchain: |
| 316 | # Write the build result and toolchain information. |
| 317 | done_file = self.builder.GetDoneFile(result.commit_upto, |
| 318 | result.brd.target) |
| 319 | with open(done_file, 'w') as fd: |
Simon Glass | 88c8dcf | 2015-02-05 22:06:13 -0700 | [diff] [blame] | 320 | if maybe_aborted: |
| 321 | # Special code to indicate we need to retry |
| 322 | fd.write('%s' % RETURN_CODE_RETRY) |
| 323 | else: |
| 324 | fd.write('%s' % result.return_code) |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 325 | with open(os.path.join(build_dir, 'toolchain'), 'w') as fd: |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 326 | print('gcc', result.toolchain.gcc, file=fd) |
| 327 | print('path', result.toolchain.path, file=fd) |
| 328 | print('cross', result.toolchain.cross, file=fd) |
| 329 | print('arch', result.toolchain.arch, file=fd) |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 330 | fd.write('%s' % result.return_code) |
| 331 | |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 332 | # Write out the image and function size information and an objdump |
Simon Glass | bb1501f | 2014-12-01 17:34:00 -0700 | [diff] [blame] | 333 | env = result.toolchain.MakeEnvironment(self.builder.full_path) |
Simon Glass | 166a98a | 2020-04-17 17:51:33 -0600 | [diff] [blame] | 334 | with open(os.path.join(build_dir, 'out-env'), 'w') as fd: |
Simon Glass | e5fc79e | 2019-01-07 16:44:23 -0700 | [diff] [blame] | 335 | for var in sorted(env.keys()): |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 336 | print('%s="%s"' % (var, env[var]), file=fd) |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 337 | lines = [] |
| 338 | for fname in ['u-boot', 'spl/u-boot-spl']: |
| 339 | cmd = ['%snm' % self.toolchain.cross, '--size-sort', fname] |
| 340 | nm_result = command.RunPipe([cmd], capture=True, |
| 341 | capture_stderr=True, cwd=result.out_dir, |
| 342 | raise_on_error=False, env=env) |
| 343 | if nm_result.stdout: |
| 344 | nm = self.builder.GetFuncSizesFile(result.commit_upto, |
| 345 | result.brd.target, fname) |
| 346 | with open(nm, 'w') as fd: |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 347 | print(nm_result.stdout, end=' ', file=fd) |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 348 | |
| 349 | cmd = ['%sobjdump' % self.toolchain.cross, '-h', fname] |
| 350 | dump_result = command.RunPipe([cmd], capture=True, |
| 351 | capture_stderr=True, cwd=result.out_dir, |
| 352 | raise_on_error=False, env=env) |
| 353 | rodata_size = '' |
| 354 | if dump_result.stdout: |
| 355 | objdump = self.builder.GetObjdumpFile(result.commit_upto, |
| 356 | result.brd.target, fname) |
| 357 | with open(objdump, 'w') as fd: |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 358 | print(dump_result.stdout, end=' ', file=fd) |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 359 | for line in dump_result.stdout.splitlines(): |
| 360 | fields = line.split() |
| 361 | if len(fields) > 5 and fields[1] == '.rodata': |
| 362 | rodata_size = fields[2] |
| 363 | |
| 364 | cmd = ['%ssize' % self.toolchain.cross, fname] |
| 365 | size_result = command.RunPipe([cmd], capture=True, |
| 366 | capture_stderr=True, cwd=result.out_dir, |
| 367 | raise_on_error=False, env=env) |
| 368 | if size_result.stdout: |
| 369 | lines.append(size_result.stdout.splitlines()[1] + ' ' + |
| 370 | rodata_size) |
| 371 | |
Alex Kiernan | 0ddc510 | 2018-05-31 04:48:33 +0000 | [diff] [blame] | 372 | # Extract the environment from U-Boot and dump it out |
| 373 | cmd = ['%sobjcopy' % self.toolchain.cross, '-O', 'binary', |
| 374 | '-j', '.rodata.default_environment', |
| 375 | 'env/built-in.o', 'uboot.env'] |
| 376 | command.RunPipe([cmd], capture=True, |
| 377 | capture_stderr=True, cwd=result.out_dir, |
| 378 | raise_on_error=False, env=env) |
| 379 | ubootenv = os.path.join(result.out_dir, 'uboot.env') |
Simon Glass | 60b285f | 2020-04-17 17:51:34 -0600 | [diff] [blame^] | 380 | if not work_in_output: |
| 381 | self.CopyFiles(result.out_dir, build_dir, '', ['uboot.env']) |
Alex Kiernan | 0ddc510 | 2018-05-31 04:48:33 +0000 | [diff] [blame] | 382 | |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 383 | # Write out the image sizes file. This is similar to the output |
| 384 | # of binutil's 'size' utility, but it omits the header line and |
| 385 | # adds an additional hex value at the end of each line for the |
| 386 | # rodata size |
| 387 | if len(lines): |
| 388 | sizes = self.builder.GetSizesFile(result.commit_upto, |
| 389 | result.brd.target) |
| 390 | with open(sizes, 'w') as fd: |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 391 | print('\n'.join(lines), file=fd) |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 392 | |
Simon Glass | 60b285f | 2020-04-17 17:51:34 -0600 | [diff] [blame^] | 393 | if not work_in_output: |
| 394 | # Write out the configuration files, with a special case for SPL |
| 395 | for dirname in ['', 'spl', 'tpl']: |
| 396 | self.CopyFiles( |
| 397 | result.out_dir, build_dir, dirname, |
| 398 | ['u-boot.cfg', 'spl/u-boot-spl.cfg', 'tpl/u-boot-tpl.cfg', |
| 399 | '.config', 'include/autoconf.mk', |
| 400 | 'include/generated/autoconf.h']) |
Simon Glass | 970f932 | 2015-02-05 22:06:14 -0700 | [diff] [blame] | 401 | |
Simon Glass | 60b285f | 2020-04-17 17:51:34 -0600 | [diff] [blame^] | 402 | # Now write the actual build output |
| 403 | if keep_outputs: |
| 404 | self.CopyFiles( |
| 405 | result.out_dir, build_dir, '', |
| 406 | ['u-boot*', '*.bin', '*.map', '*.img', 'MLO', 'SPL', |
| 407 | 'include/autoconf.mk', 'spl/u-boot-spl*']) |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 408 | |
Simon Glass | 970f932 | 2015-02-05 22:06:14 -0700 | [diff] [blame] | 409 | def CopyFiles(self, out_dir, build_dir, dirname, patterns): |
| 410 | """Copy files from the build directory to the output. |
| 411 | |
| 412 | Args: |
| 413 | out_dir: Path to output directory containing the files |
| 414 | build_dir: Place to copy the files |
| 415 | dirname: Source directory, '' for normal U-Boot, 'spl' for SPL |
| 416 | patterns: A list of filenames (strings) to copy, each relative |
| 417 | to the build directory |
| 418 | """ |
| 419 | for pattern in patterns: |
| 420 | file_list = glob.glob(os.path.join(out_dir, dirname, pattern)) |
| 421 | for fname in file_list: |
| 422 | target = os.path.basename(fname) |
| 423 | if dirname: |
| 424 | base, ext = os.path.splitext(target) |
| 425 | if ext: |
| 426 | target = '%s-%s%s' % (base, dirname, ext) |
| 427 | shutil.copy(fname, os.path.join(build_dir, target)) |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 428 | |
| 429 | def RunJob(self, job): |
| 430 | """Run a single job |
| 431 | |
| 432 | A job consists of a building a list of commits for a particular board. |
| 433 | |
| 434 | Args: |
| 435 | job: Job to build |
| 436 | """ |
| 437 | brd = job.board |
| 438 | work_dir = self.builder.GetThreadDir(self.thread_num) |
| 439 | self.toolchain = None |
| 440 | if job.commits: |
| 441 | # Run 'make board_defconfig' on the first commit |
| 442 | do_config = True |
| 443 | commit_upto = 0 |
| 444 | force_build = False |
| 445 | for commit_upto in range(0, len(job.commits), job.step): |
| 446 | result, request_config = self.RunCommit(commit_upto, brd, |
Simon Glass | a9401b2 | 2016-11-16 14:09:25 -0700 | [diff] [blame] | 447 | work_dir, do_config, self.builder.config_only, |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 448 | force_build or self.builder.force_build, |
Simon Glass | d829f12 | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 449 | self.builder.force_build_failures, |
| 450 | work_in_output=job.work_in_output) |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 451 | failed = result.return_code or result.stderr |
| 452 | did_config = do_config |
| 453 | if failed and not do_config: |
| 454 | # If our incremental build failed, try building again |
| 455 | # with a reconfig. |
| 456 | if self.builder.force_config_on_failure: |
| 457 | result, request_config = self.RunCommit(commit_upto, |
Simon Glass | d829f12 | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 458 | brd, work_dir, True, False, True, False, |
| 459 | work_in_output=job.work_in_output) |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 460 | did_config = True |
| 461 | if not self.builder.force_reconfig: |
| 462 | do_config = request_config |
| 463 | |
| 464 | # If we built that commit, then config is done. But if we got |
| 465 | # an warning, reconfig next time to force it to build the same |
| 466 | # files that created warnings this time. Otherwise an |
| 467 | # incremental build may not build the same file, and we will |
| 468 | # think that the warning has gone away. |
| 469 | # We could avoid this by using -Werror everywhere... |
| 470 | # For errors, the problem doesn't happen, since presumably |
| 471 | # the build stopped and didn't generate output, so will retry |
| 472 | # that file next time. So we could detect warnings and deal |
| 473 | # with them specially here. For now, we just reconfigure if |
| 474 | # anything goes work. |
| 475 | # Of course this is substantially slower if there are build |
| 476 | # errors/warnings (e.g. 2-3x slower even if only 10% of builds |
| 477 | # have problems). |
| 478 | if (failed and not result.already_done and not did_config and |
| 479 | self.builder.force_config_on_failure): |
| 480 | # If this build failed, try the next one with a |
| 481 | # reconfigure. |
| 482 | # Sometimes if the board_config.h file changes it can mess |
| 483 | # with dependencies, and we get: |
| 484 | # make: *** No rule to make target `include/autoconf.mk', |
| 485 | # needed by `depend'. |
| 486 | do_config = True |
| 487 | force_build = True |
| 488 | else: |
| 489 | force_build = False |
| 490 | if self.builder.force_config_on_failure: |
| 491 | if failed: |
| 492 | do_config = True |
| 493 | result.commit_upto = commit_upto |
| 494 | if result.return_code < 0: |
| 495 | raise ValueError('Interrupt') |
| 496 | |
| 497 | # We have the build results, so output the result |
Simon Glass | d829f12 | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 498 | self._WriteResult(result, job.keep_outputs, job.work_in_output) |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 499 | self.builder.out_queue.put(result) |
| 500 | else: |
| 501 | # Just build the currently checked-out build |
| 502 | result, request_config = self.RunCommit(None, brd, work_dir, True, |
Simon Glass | a9401b2 | 2016-11-16 14:09:25 -0700 | [diff] [blame] | 503 | self.builder.config_only, True, |
Simon Glass | d829f12 | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 504 | self.builder.force_build_failures, |
| 505 | work_in_output=job.work_in_output) |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 506 | result.commit_upto = 0 |
Simon Glass | d829f12 | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 507 | self._WriteResult(result, job.keep_outputs, job.work_in_output) |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 508 | self.builder.out_queue.put(result) |
| 509 | |
| 510 | def run(self): |
| 511 | """Our thread's run function |
| 512 | |
| 513 | This thread picks a job from the queue, runs it, and then goes to the |
| 514 | next job. |
| 515 | """ |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 516 | while True: |
| 517 | job = self.builder.queue.get() |
Simon Glass | 2880e6b | 2016-09-18 16:48:38 -0600 | [diff] [blame] | 518 | self.RunJob(job) |
Simon Glass | 190064b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 519 | self.builder.queue.task_done() |