blob: e27a28577c2547a134acf65f392b05668137d0da [file] [log] [blame]
Simon Glassc05694f2013-04-03 11:07:16 +00001# Copyright (c) 2013 The Chromium OS Authors.
2#
3# Bloat-o-meter code used here Copyright 2004 Matt Mackall <mpm@selenic.com>
4#
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005# SPDX-License-Identifier: GPL-2.0+
Simon Glassc05694f2013-04-03 11:07:16 +00006#
7
8import collections
Simon Glassc05694f2013-04-03 11:07:16 +00009from datetime import datetime, timedelta
10import glob
11import os
12import re
13import Queue
14import shutil
Simon Glass205ac042016-09-18 16:48:37 -060015import signal
Simon Glassc05694f2013-04-03 11:07:16 +000016import string
17import sys
Simon Glassd26e1442016-09-18 16:48:35 -060018import threading
Simon Glassc05694f2013-04-03 11:07:16 +000019import time
20
Simon Glass4a1e88b2014-08-09 15:33:00 -060021import builderthread
Simon Glassc05694f2013-04-03 11:07:16 +000022import command
23import gitutil
24import terminal
Simon Glass4433aa92014-09-05 19:00:07 -060025from terminal import Print
Simon Glassc05694f2013-04-03 11:07:16 +000026import toolchain
27
28
29"""
30Theory of Operation
31
32Please see README for user documentation, and you should be familiar with
33that before trying to make sense of this.
34
35Buildman works by keeping the machine as busy as possible, building different
36commits for different boards on multiple CPUs at once.
37
38The source repo (self.git_dir) contains all the commits to be built. Each
39thread works on a single board at a time. It checks out the first commit,
40configures it for that board, then builds it. Then it checks out the next
41commit and builds it (typically without re-configuring). When it runs out
42of commits, it gets another job from the builder and starts again with that
43board.
44
45Clearly the builder threads could work either way - they could check out a
46commit and then built it for all boards. Using separate directories for each
47commit/board pair they could leave their build product around afterwards
48also.
49
50The intent behind building a single board for multiple commits, is to make
51use of incremental builds. Since each commit is built incrementally from
52the previous one, builds are faster. Reconfiguring for a different board
53removes all intermediate object files.
54
55Many threads can be working at once, but each has its own working directory.
56When a thread finishes a build, it puts the output files into a result
57directory.
58
59The base directory used by buildman is normally '../<branch>', i.e.
60a directory higher than the source repository and named after the branch
61being built.
62
63Within the base directory, we have one subdirectory for each commit. Within
64that is one subdirectory for each board. Within that is the build output for
65that commit/board combination.
66
67Buildman also create working directories for each thread, in a .bm-work/
68subdirectory in the base dir.
69
70As an example, say we are building branch 'us-net' for boards 'sandbox' and
71'seaboard', and say that us-net has two commits. We will have directories
72like this:
73
74us-net/ base directory
75 01_of_02_g4ed4ebc_net--Add-tftp-speed-/
76 sandbox/
77 u-boot.bin
78 seaboard/
79 u-boot.bin
80 02_of_02_g4ed4ebc_net--Check-tftp-comp/
81 sandbox/
82 u-boot.bin
83 seaboard/
84 u-boot.bin
85 .bm-work/
86 00/ working directory for thread 0 (contains source checkout)
87 build/ build output
88 01/ working directory for thread 1
89 build/ build output
90 ...
91u-boot/ source directory
92 .git/ repository
93"""
94
95# Possible build outcomes
96OUTCOME_OK, OUTCOME_WARNING, OUTCOME_ERROR, OUTCOME_UNKNOWN = range(4)
97
98# Translate a commit subject into a valid filename
99trans_valid_chars = string.maketrans("/: ", "---")
100
Simon Glassdb17fb82015-02-05 22:06:15 -0700101CONFIG_FILENAMES = [
102 '.config', '.config-spl', '.config-tpl',
103 'autoconf.mk', 'autoconf-spl.mk', 'autoconf-tpl.mk',
104 'autoconf.h', 'autoconf-spl.h','autoconf-tpl.h',
105 'u-boot.cfg', 'u-boot-spl.cfg', 'u-boot-tpl.cfg'
106]
107
Simon Glasscad8abf2015-08-25 21:52:14 -0600108class Config:
109 """Holds information about configuration settings for a board."""
110 def __init__(self, target):
111 self.target = target
112 self.config = {}
113 for fname in CONFIG_FILENAMES:
114 self.config[fname] = {}
115
116 def Add(self, fname, key, value):
117 self.config[fname][key] = value
118
119 def __hash__(self):
120 val = 0
121 for fname in self.config:
122 for key, value in self.config[fname].iteritems():
123 print key, value
124 val = val ^ hash(key) & hash(value)
125 return val
Simon Glassc05694f2013-04-03 11:07:16 +0000126
Simon Glassc05694f2013-04-03 11:07:16 +0000127class Builder:
128 """Class for building U-Boot for a particular commit.
129
130 Public members: (many should ->private)
Simon Glassc05694f2013-04-03 11:07:16 +0000131 already_done: Number of builds already completed
132 base_dir: Base directory to use for builder
133 checkout: True to check out source, False to skip that step.
134 This is used for testing.
135 col: terminal.Color() object
136 count: Number of commits to build
137 do_make: Method to call to invoke Make
138 fail: Number of builds that failed due to error
139 force_build: Force building even if a build already exists
140 force_config_on_failure: If a commit fails for a board, disable
141 incremental building for the next commit we build for that
142 board, so that we will see all warnings/errors again.
Simon Glass7041c392014-07-13 12:22:31 -0600143 force_build_failures: If a previously-built build (i.e. built on
144 a previous run of buildman) is marked as failed, rebuild it.
Simon Glassc05694f2013-04-03 11:07:16 +0000145 git_dir: Git directory containing source repository
146 last_line_len: Length of the last line we printed (used for erasing
147 it with new progress information)
148 num_jobs: Number of jobs to run at once (passed to make as -j)
149 num_threads: Number of builder threads to run
150 out_queue: Queue of results to process
151 re_make_err: Compiled regular expression for ignore_lines
152 queue: Queue of jobs to run
153 threads: List of active threads
154 toolchains: Toolchains object to use for building
155 upto: Current commit number we are building (0.count-1)
156 warned: Number of builds that produced at least one warning
Simon Glassf3018b7a2014-07-14 17:51:02 -0600157 force_reconfig: Reconfigure U-Boot on each comiit. This disables
158 incremental building, where buildman reconfigures on the first
159 commit for a baord, and then just does an incremental build for
160 the following commits. In fact buildman will reconfigure and
161 retry for any failing commits, so generally the only effect of
162 this option is to slow things down.
Simon Glass38df2e22014-07-14 17:51:03 -0600163 in_tree: Build U-Boot in-tree instead of specifying an output
164 directory separate from the source code. This option is really
165 only useful for testing in-tree builds.
Simon Glassc05694f2013-04-03 11:07:16 +0000166
167 Private members:
168 _base_board_dict: Last-summarised Dict of boards
169 _base_err_lines: Last-summarised list of errors
Simon Glass03749d42014-08-28 09:43:44 -0600170 _base_warn_lines: Last-summarised list of warnings
Simon Glassc05694f2013-04-03 11:07:16 +0000171 _build_period_us: Time taken for a single build (float object).
172 _complete_delay: Expected delay until completion (timedelta)
173 _next_delay_update: Next time we plan to display a progress update
174 (datatime)
175 _show_unknown: Show unknown boards (those not built) in summary
176 _timestamps: List of timestamps for the completion of the last
177 last _timestamp_count builds. Each is a datetime object.
178 _timestamp_count: Number of timestamps to keep in our list.
179 _working_dir: Base working directory containing all threads
180 """
181 class Outcome:
182 """Records a build outcome for a single make invocation
183
184 Public Members:
185 rc: Outcome value (OUTCOME_...)
186 err_lines: List of error lines or [] if none
187 sizes: Dictionary of image size information, keyed by filename
188 - Each value is itself a dictionary containing
189 values for 'text', 'data' and 'bss', being the integer
190 size in bytes of each section.
191 func_sizes: Dictionary keyed by filename - e.g. 'u-boot'. Each
192 value is itself a dictionary:
193 key: function name
194 value: Size of function in bytes
Simon Glassdb17fb82015-02-05 22:06:15 -0700195 config: Dictionary keyed by filename - e.g. '.config'. Each
196 value is itself a dictionary:
197 key: config name
198 value: config value
Simon Glassc05694f2013-04-03 11:07:16 +0000199 """
Simon Glassdb17fb82015-02-05 22:06:15 -0700200 def __init__(self, rc, err_lines, sizes, func_sizes, config):
Simon Glassc05694f2013-04-03 11:07:16 +0000201 self.rc = rc
202 self.err_lines = err_lines
203 self.sizes = sizes
204 self.func_sizes = func_sizes
Simon Glassdb17fb82015-02-05 22:06:15 -0700205 self.config = config
Simon Glassc05694f2013-04-03 11:07:16 +0000206
207 def __init__(self, toolchains, base_dir, git_dir, num_threads, num_jobs,
Simon Glasse87bde12014-12-01 17:33:55 -0700208 gnu_make='make', checkout=True, show_unknown=True, step=1,
Stephen Warren97c96902016-04-11 10:48:44 -0600209 no_subdirs=False, full_path=False, verbose_build=False,
210 incremental=False, per_board_out_dir=False):
Simon Glassc05694f2013-04-03 11:07:16 +0000211 """Create a new Builder object
212
213 Args:
214 toolchains: Toolchains object to use for building
215 base_dir: Base directory to use for builder
216 git_dir: Git directory containing source repository
217 num_threads: Number of builder threads to run
218 num_jobs: Number of jobs to run at once (passed to make as -j)
Masahiro Yamada1fe610d2014-07-22 11:19:09 +0900219 gnu_make: the command name of GNU Make.
Simon Glassc05694f2013-04-03 11:07:16 +0000220 checkout: True to check out source, False to skip that step.
221 This is used for testing.
222 show_unknown: Show unknown boards (those not built) in summary
223 step: 1 to process every commit, n to process every nth commit
Simon Glassd48a46c2014-12-01 17:34:00 -0700224 no_subdirs: Don't create subdirectories when building current
225 source for a single board
226 full_path: Return the full path in CROSS_COMPILE and don't set
227 PATH
Simon Glass655b6102014-12-01 17:34:07 -0700228 verbose_build: Run build with V=1 and don't use 'make -s'
Stephen Warren97c96902016-04-11 10:48:44 -0600229 incremental: Always perform incremental builds; don't run make
230 mrproper when configuring
231 per_board_out_dir: Build in a separate persistent directory per
232 board rather than a thread-specific directory
Simon Glassc05694f2013-04-03 11:07:16 +0000233 """
234 self.toolchains = toolchains
235 self.base_dir = base_dir
236 self._working_dir = os.path.join(base_dir, '.bm-work')
237 self.threads = []
Simon Glassc05694f2013-04-03 11:07:16 +0000238 self.do_make = self.Make
Masahiro Yamada1fe610d2014-07-22 11:19:09 +0900239 self.gnu_make = gnu_make
Simon Glassc05694f2013-04-03 11:07:16 +0000240 self.checkout = checkout
241 self.num_threads = num_threads
242 self.num_jobs = num_jobs
243 self.already_done = 0
244 self.force_build = False
245 self.git_dir = git_dir
246 self._show_unknown = show_unknown
247 self._timestamp_count = 10
248 self._build_period_us = None
249 self._complete_delay = None
250 self._next_delay_update = datetime.now()
251 self.force_config_on_failure = True
Simon Glass7041c392014-07-13 12:22:31 -0600252 self.force_build_failures = False
Simon Glassf3018b7a2014-07-14 17:51:02 -0600253 self.force_reconfig = False
Simon Glassc05694f2013-04-03 11:07:16 +0000254 self._step = step
Simon Glass38df2e22014-07-14 17:51:03 -0600255 self.in_tree = False
Simon Glassbb4dffb2014-08-09 15:33:06 -0600256 self._error_lines = 0
Simon Glasse87bde12014-12-01 17:33:55 -0700257 self.no_subdirs = no_subdirs
Simon Glassd48a46c2014-12-01 17:34:00 -0700258 self.full_path = full_path
Simon Glass655b6102014-12-01 17:34:07 -0700259 self.verbose_build = verbose_build
Simon Glassc05694f2013-04-03 11:07:16 +0000260
261 self.col = terminal.Color()
262
Simon Glass03749d42014-08-28 09:43:44 -0600263 self._re_function = re.compile('(.*): In function.*')
264 self._re_files = re.compile('In file included from.*')
265 self._re_warning = re.compile('(.*):(\d*):(\d*): warning: .*')
266 self._re_note = re.compile('(.*):(\d*):(\d*): note: this is the location of the previous.*')
267
Simon Glassc05694f2013-04-03 11:07:16 +0000268 self.queue = Queue.Queue()
269 self.out_queue = Queue.Queue()
270 for i in range(self.num_threads):
Stephen Warren97c96902016-04-11 10:48:44 -0600271 t = builderthread.BuilderThread(self, i, incremental,
272 per_board_out_dir)
Simon Glassc05694f2013-04-03 11:07:16 +0000273 t.setDaemon(True)
274 t.start()
275 self.threads.append(t)
276
277 self.last_line_len = 0
Simon Glass4a1e88b2014-08-09 15:33:00 -0600278 t = builderthread.ResultThread(self)
Simon Glassc05694f2013-04-03 11:07:16 +0000279 t.setDaemon(True)
280 t.start()
281 self.threads.append(t)
282
283 ignore_lines = ['(make.*Waiting for unfinished)', '(Segmentation fault)']
284 self.re_make_err = re.compile('|'.join(ignore_lines))
285
Simon Glass205ac042016-09-18 16:48:37 -0600286 # Handle existing graceful with SIGINT / Ctrl-C
287 signal.signal(signal.SIGINT, self.signal_handler)
288
Simon Glassc05694f2013-04-03 11:07:16 +0000289 def __del__(self):
290 """Get rid of all threads created by the builder"""
291 for t in self.threads:
292 del t
293
Simon Glass205ac042016-09-18 16:48:37 -0600294 def signal_handler(self, signal, frame):
295 sys.exit(1)
296
Simon Glasseb48bbc2014-08-09 15:33:02 -0600297 def SetDisplayOptions(self, show_errors=False, show_sizes=False,
Simon Glass3394c9f2014-08-28 09:43:43 -0600298 show_detail=False, show_bloat=False,
Simon Glassdb17fb82015-02-05 22:06:15 -0700299 list_error_boards=False, show_config=False):
Simon Glasseb48bbc2014-08-09 15:33:02 -0600300 """Setup display options for the builder.
301
302 show_errors: True to show summarised error/warning info
303 show_sizes: Show size deltas
304 show_detail: Show detail for each board
305 show_bloat: Show detail for each function
Simon Glass3394c9f2014-08-28 09:43:43 -0600306 list_error_boards: Show the boards which caused each error/warning
Simon Glassdb17fb82015-02-05 22:06:15 -0700307 show_config: Show config deltas
Simon Glasseb48bbc2014-08-09 15:33:02 -0600308 """
309 self._show_errors = show_errors
310 self._show_sizes = show_sizes
311 self._show_detail = show_detail
312 self._show_bloat = show_bloat
Simon Glass3394c9f2014-08-28 09:43:43 -0600313 self._list_error_boards = list_error_boards
Simon Glassdb17fb82015-02-05 22:06:15 -0700314 self._show_config = show_config
Simon Glasseb48bbc2014-08-09 15:33:02 -0600315
Simon Glassc05694f2013-04-03 11:07:16 +0000316 def _AddTimestamp(self):
317 """Add a new timestamp to the list and record the build period.
318
319 The build period is the length of time taken to perform a single
320 build (one board, one commit).
321 """
322 now = datetime.now()
323 self._timestamps.append(now)
324 count = len(self._timestamps)
325 delta = self._timestamps[-1] - self._timestamps[0]
326 seconds = delta.total_seconds()
327
328 # If we have enough data, estimate build period (time taken for a
329 # single build) and therefore completion time.
330 if count > 1 and self._next_delay_update < now:
331 self._next_delay_update = now + timedelta(seconds=2)
332 if seconds > 0:
333 self._build_period = float(seconds) / count
334 todo = self.count - self.upto
335 self._complete_delay = timedelta(microseconds=
336 self._build_period * todo * 1000000)
337 # Round it
338 self._complete_delay -= timedelta(
339 microseconds=self._complete_delay.microseconds)
340
341 if seconds > 60:
342 self._timestamps.popleft()
343 count -= 1
344
345 def ClearLine(self, length):
346 """Clear any characters on the current line
347
348 Make way for a new line of length 'length', by outputting enough
349 spaces to clear out the old line. Then remember the new length for
350 next time.
351
352 Args:
353 length: Length of new line, in characters
354 """
355 if length < self.last_line_len:
Simon Glass4433aa92014-09-05 19:00:07 -0600356 Print(' ' * (self.last_line_len - length), newline=False)
357 Print('\r', newline=False)
Simon Glassc05694f2013-04-03 11:07:16 +0000358 self.last_line_len = length
359 sys.stdout.flush()
360
361 def SelectCommit(self, commit, checkout=True):
362 """Checkout the selected commit for this build
363 """
364 self.commit = commit
365 if checkout and self.checkout:
366 gitutil.Checkout(commit.hash)
367
368 def Make(self, commit, brd, stage, cwd, *args, **kwargs):
369 """Run make
370
371 Args:
372 commit: Commit object that is being built
373 brd: Board object that is being built
Roger Meiere0a0e552014-08-20 22:10:29 +0200374 stage: Stage that we are at (mrproper, config, build)
Simon Glassc05694f2013-04-03 11:07:16 +0000375 cwd: Directory where make should be run
376 args: Arguments to pass to make
377 kwargs: Arguments to pass to command.RunPipe()
378 """
Masahiro Yamada1fe610d2014-07-22 11:19:09 +0900379 cmd = [self.gnu_make] + list(args)
Simon Glassc05694f2013-04-03 11:07:16 +0000380 result = command.RunPipe([cmd], capture=True, capture_stderr=True,
381 cwd=cwd, raise_on_error=False, **kwargs)
Simon Glass413f91a2015-02-05 22:06:12 -0700382 if self.verbose_build:
383 result.stdout = '%s\n' % (' '.join(cmd)) + result.stdout
384 result.combined = '%s\n' % (' '.join(cmd)) + result.combined
Simon Glassc05694f2013-04-03 11:07:16 +0000385 return result
386
387 def ProcessResult(self, result):
388 """Process the result of a build, showing progress information
389
390 Args:
Simon Glass78e418e2014-08-09 15:33:03 -0600391 result: A CommandResult object, which indicates the result for
392 a single build
Simon Glassc05694f2013-04-03 11:07:16 +0000393 """
394 col = terminal.Color()
395 if result:
396 target = result.brd.target
397
Simon Glassc05694f2013-04-03 11:07:16 +0000398 self.upto += 1
399 if result.return_code != 0:
400 self.fail += 1
401 elif result.stderr:
402 self.warned += 1
403 if result.already_done:
404 self.already_done += 1
Simon Glass78e418e2014-08-09 15:33:03 -0600405 if self._verbose:
Simon Glass4433aa92014-09-05 19:00:07 -0600406 Print('\r', newline=False)
Simon Glass78e418e2014-08-09 15:33:03 -0600407 self.ClearLine(0)
408 boards_selected = {target : result.brd}
409 self.ResetResultSummary(boards_selected)
410 self.ProduceResultSummary(result.commit_upto, self.commits,
411 boards_selected)
Simon Glassc05694f2013-04-03 11:07:16 +0000412 else:
413 target = '(starting)'
414
415 # Display separate counts for ok, warned and fail
416 ok = self.upto - self.warned - self.fail
417 line = '\r' + self.col.Color(self.col.GREEN, '%5d' % ok)
418 line += self.col.Color(self.col.YELLOW, '%5d' % self.warned)
419 line += self.col.Color(self.col.RED, '%5d' % self.fail)
420
421 name = ' /%-5d ' % self.count
422
423 # Add our current completion time estimate
424 self._AddTimestamp()
425 if self._complete_delay:
426 name += '%s : ' % self._complete_delay
427 # When building all boards for a commit, we can print a commit
428 # progress message.
429 if result and result.commit_upto is None:
430 name += 'commit %2d/%-3d' % (self.commit_upto + 1,
431 self.commit_count)
432
433 name += target
Simon Glass4433aa92014-09-05 19:00:07 -0600434 Print(line + name, newline=False)
Simon Glass78e418e2014-08-09 15:33:03 -0600435 length = 14 + len(name)
Simon Glassc05694f2013-04-03 11:07:16 +0000436 self.ClearLine(length)
437
438 def _GetOutputDir(self, commit_upto):
439 """Get the name of the output directory for a commit number
440
441 The output directory is typically .../<branch>/<commit>.
442
443 Args:
444 commit_upto: Commit number to use (0..self.count-1)
445 """
Simon Glasse87bde12014-12-01 17:33:55 -0700446 commit_dir = None
Simon Glassd326ad72014-08-09 15:32:59 -0600447 if self.commits:
448 commit = self.commits[commit_upto]
449 subject = commit.subject.translate(trans_valid_chars)
450 commit_dir = ('%02d_of_%02d_g%s_%s' % (commit_upto + 1,
451 self.commit_count, commit.hash, subject[:20]))
Simon Glasse87bde12014-12-01 17:33:55 -0700452 elif not self.no_subdirs:
Simon Glassd326ad72014-08-09 15:32:59 -0600453 commit_dir = 'current'
Simon Glasse87bde12014-12-01 17:33:55 -0700454 if not commit_dir:
455 return self.base_dir
456 return os.path.join(self.base_dir, commit_dir)
Simon Glassc05694f2013-04-03 11:07:16 +0000457
458 def GetBuildDir(self, commit_upto, target):
459 """Get the name of the build directory for a commit number
460
461 The build directory is typically .../<branch>/<commit>/<target>.
462
463 Args:
464 commit_upto: Commit number to use (0..self.count-1)
465 target: Target name
466 """
467 output_dir = self._GetOutputDir(commit_upto)
468 return os.path.join(output_dir, target)
469
470 def GetDoneFile(self, commit_upto, target):
471 """Get the name of the done file for a commit number
472
473 Args:
474 commit_upto: Commit number to use (0..self.count-1)
475 target: Target name
476 """
477 return os.path.join(self.GetBuildDir(commit_upto, target), 'done')
478
479 def GetSizesFile(self, commit_upto, target):
480 """Get the name of the sizes file for a commit number
481
482 Args:
483 commit_upto: Commit number to use (0..self.count-1)
484 target: Target name
485 """
486 return os.path.join(self.GetBuildDir(commit_upto, target), 'sizes')
487
488 def GetFuncSizesFile(self, commit_upto, target, elf_fname):
489 """Get the name of the funcsizes file for a commit number and ELF file
490
491 Args:
492 commit_upto: Commit number to use (0..self.count-1)
493 target: Target name
494 elf_fname: Filename of elf image
495 """
496 return os.path.join(self.GetBuildDir(commit_upto, target),
497 '%s.sizes' % elf_fname.replace('/', '-'))
498
499 def GetObjdumpFile(self, commit_upto, target, elf_fname):
500 """Get the name of the objdump file for a commit number and ELF file
501
502 Args:
503 commit_upto: Commit number to use (0..self.count-1)
504 target: Target name
505 elf_fname: Filename of elf image
506 """
507 return os.path.join(self.GetBuildDir(commit_upto, target),
508 '%s.objdump' % elf_fname.replace('/', '-'))
509
510 def GetErrFile(self, commit_upto, target):
511 """Get the name of the err file for a commit number
512
513 Args:
514 commit_upto: Commit number to use (0..self.count-1)
515 target: Target name
516 """
517 output_dir = self.GetBuildDir(commit_upto, target)
518 return os.path.join(output_dir, 'err')
519
520 def FilterErrors(self, lines):
521 """Filter out errors in which we have no interest
522
523 We should probably use map().
524
525 Args:
526 lines: List of error lines, each a string
527 Returns:
528 New list with only interesting lines included
529 """
530 out_lines = []
531 for line in lines:
532 if not self.re_make_err.search(line):
533 out_lines.append(line)
534 return out_lines
535
536 def ReadFuncSizes(self, fname, fd):
537 """Read function sizes from the output of 'nm'
538
539 Args:
540 fd: File containing data to read
541 fname: Filename we are reading from (just for errors)
542
543 Returns:
544 Dictionary containing size of each function in bytes, indexed by
545 function name.
546 """
547 sym = {}
548 for line in fd.readlines():
549 try:
550 size, type, name = line[:-1].split()
551 except:
Simon Glass4433aa92014-09-05 19:00:07 -0600552 Print("Invalid line in file '%s': '%s'" % (fname, line[:-1]))
Simon Glassc05694f2013-04-03 11:07:16 +0000553 continue
554 if type in 'tTdDbB':
555 # function names begin with '.' on 64-bit powerpc
556 if '.' in name[1:]:
557 name = 'static.' + name.split('.')[0]
558 sym[name] = sym.get(name, 0) + int(size, 16)
559 return sym
560
Simon Glassdb17fb82015-02-05 22:06:15 -0700561 def _ProcessConfig(self, fname):
562 """Read in a .config, autoconf.mk or autoconf.h file
563
564 This function handles all config file types. It ignores comments and
565 any #defines which don't start with CONFIG_.
566
567 Args:
568 fname: Filename to read
569
570 Returns:
571 Dictionary:
572 key: Config name (e.g. CONFIG_DM)
573 value: Config value (e.g. 1)
574 """
575 config = {}
576 if os.path.exists(fname):
577 with open(fname) as fd:
578 for line in fd:
579 line = line.strip()
580 if line.startswith('#define'):
581 values = line[8:].split(' ', 1)
582 if len(values) > 1:
583 key, value = values
584 else:
585 key = values[0]
586 value = ''
587 if not key.startswith('CONFIG_'):
588 continue
589 elif not line or line[0] in ['#', '*', '/']:
590 continue
591 else:
592 key, value = line.split('=', 1)
593 config[key] = value
594 return config
595
596 def GetBuildOutcome(self, commit_upto, target, read_func_sizes,
597 read_config):
Simon Glassc05694f2013-04-03 11:07:16 +0000598 """Work out the outcome of a build.
599
600 Args:
601 commit_upto: Commit number to check (0..n-1)
602 target: Target board to check
603 read_func_sizes: True to read function size information
Simon Glassdb17fb82015-02-05 22:06:15 -0700604 read_config: True to read .config and autoconf.h files
Simon Glassc05694f2013-04-03 11:07:16 +0000605
606 Returns:
607 Outcome object
608 """
609 done_file = self.GetDoneFile(commit_upto, target)
610 sizes_file = self.GetSizesFile(commit_upto, target)
611 sizes = {}
612 func_sizes = {}
Simon Glassdb17fb82015-02-05 22:06:15 -0700613 config = {}
Simon Glassc05694f2013-04-03 11:07:16 +0000614 if os.path.exists(done_file):
615 with open(done_file, 'r') as fd:
616 return_code = int(fd.readline())
617 err_lines = []
618 err_file = self.GetErrFile(commit_upto, target)
619 if os.path.exists(err_file):
620 with open(err_file, 'r') as fd:
621 err_lines = self.FilterErrors(fd.readlines())
622
623 # Decide whether the build was ok, failed or created warnings
624 if return_code:
625 rc = OUTCOME_ERROR
626 elif len(err_lines):
627 rc = OUTCOME_WARNING
628 else:
629 rc = OUTCOME_OK
630
631 # Convert size information to our simple format
632 if os.path.exists(sizes_file):
633 with open(sizes_file, 'r') as fd:
634 for line in fd.readlines():
635 values = line.split()
636 rodata = 0
637 if len(values) > 6:
638 rodata = int(values[6], 16)
639 size_dict = {
640 'all' : int(values[0]) + int(values[1]) +
641 int(values[2]),
642 'text' : int(values[0]) - rodata,
643 'data' : int(values[1]),
644 'bss' : int(values[2]),
645 'rodata' : rodata,
646 }
647 sizes[values[5]] = size_dict
648
649 if read_func_sizes:
650 pattern = self.GetFuncSizesFile(commit_upto, target, '*')
651 for fname in glob.glob(pattern):
652 with open(fname, 'r') as fd:
653 dict_name = os.path.basename(fname).replace('.sizes',
654 '')
655 func_sizes[dict_name] = self.ReadFuncSizes(fname, fd)
656
Simon Glassdb17fb82015-02-05 22:06:15 -0700657 if read_config:
658 output_dir = self.GetBuildDir(commit_upto, target)
659 for name in CONFIG_FILENAMES:
660 fname = os.path.join(output_dir, name)
661 config[name] = self._ProcessConfig(fname)
662
663 return Builder.Outcome(rc, err_lines, sizes, func_sizes, config)
Simon Glassc05694f2013-04-03 11:07:16 +0000664
Simon Glassdb17fb82015-02-05 22:06:15 -0700665 return Builder.Outcome(OUTCOME_UNKNOWN, [], {}, {}, {})
Simon Glassc05694f2013-04-03 11:07:16 +0000666
Simon Glassdb17fb82015-02-05 22:06:15 -0700667 def GetResultSummary(self, boards_selected, commit_upto, read_func_sizes,
668 read_config):
Simon Glassc05694f2013-04-03 11:07:16 +0000669 """Calculate a summary of the results of building a commit.
670
671 Args:
672 board_selected: Dict containing boards to summarise
673 commit_upto: Commit number to summarize (0..self.count-1)
674 read_func_sizes: True to read function size information
Simon Glassdb17fb82015-02-05 22:06:15 -0700675 read_config: True to read .config and autoconf.h files
Simon Glassc05694f2013-04-03 11:07:16 +0000676
677 Returns:
678 Tuple:
679 Dict containing boards which passed building this commit.
680 keyed by board.target
Simon Glass03749d42014-08-28 09:43:44 -0600681 List containing a summary of error lines
Simon Glass3394c9f2014-08-28 09:43:43 -0600682 Dict keyed by error line, containing a list of the Board
683 objects with that error
Simon Glass03749d42014-08-28 09:43:44 -0600684 List containing a summary of warning lines
685 Dict keyed by error line, containing a list of the Board
686 objects with that warning
Simon Glasscad8abf2015-08-25 21:52:14 -0600687 Dictionary keyed by board.target. Each value is a dictionary:
688 key: filename - e.g. '.config'
Simon Glassdb17fb82015-02-05 22:06:15 -0700689 value is itself a dictionary:
690 key: config name
691 value: config value
Simon Glassc05694f2013-04-03 11:07:16 +0000692 """
Simon Glass03749d42014-08-28 09:43:44 -0600693 def AddLine(lines_summary, lines_boards, line, board):
694 line = line.rstrip()
695 if line in lines_boards:
696 lines_boards[line].append(board)
697 else:
698 lines_boards[line] = [board]
699 lines_summary.append(line)
700
Simon Glassc05694f2013-04-03 11:07:16 +0000701 board_dict = {}
702 err_lines_summary = []
Simon Glass3394c9f2014-08-28 09:43:43 -0600703 err_lines_boards = {}
Simon Glass03749d42014-08-28 09:43:44 -0600704 warn_lines_summary = []
705 warn_lines_boards = {}
Simon Glassdb17fb82015-02-05 22:06:15 -0700706 config = {}
Simon Glassc05694f2013-04-03 11:07:16 +0000707
708 for board in boards_selected.itervalues():
709 outcome = self.GetBuildOutcome(commit_upto, board.target,
Simon Glassdb17fb82015-02-05 22:06:15 -0700710 read_func_sizes, read_config)
Simon Glassc05694f2013-04-03 11:07:16 +0000711 board_dict[board.target] = outcome
Simon Glass03749d42014-08-28 09:43:44 -0600712 last_func = None
713 last_was_warning = False
714 for line in outcome.err_lines:
715 if line:
716 if (self._re_function.match(line) or
717 self._re_files.match(line)):
718 last_func = line
Simon Glass3394c9f2014-08-28 09:43:43 -0600719 else:
Simon Glass03749d42014-08-28 09:43:44 -0600720 is_warning = self._re_warning.match(line)
721 is_note = self._re_note.match(line)
722 if is_warning or (last_was_warning and is_note):
723 if last_func:
724 AddLine(warn_lines_summary, warn_lines_boards,
725 last_func, board)
726 AddLine(warn_lines_summary, warn_lines_boards,
727 line, board)
728 else:
729 if last_func:
730 AddLine(err_lines_summary, err_lines_boards,
731 last_func, board)
732 AddLine(err_lines_summary, err_lines_boards,
733 line, board)
734 last_was_warning = is_warning
735 last_func = None
Simon Glasscad8abf2015-08-25 21:52:14 -0600736 tconfig = Config(board.target)
Simon Glassdb17fb82015-02-05 22:06:15 -0700737 for fname in CONFIG_FILENAMES:
Simon Glassdb17fb82015-02-05 22:06:15 -0700738 if outcome.config:
739 for key, value in outcome.config[fname].iteritems():
Simon Glasscad8abf2015-08-25 21:52:14 -0600740 tconfig.Add(fname, key, value)
741 config[board.target] = tconfig
Simon Glassdb17fb82015-02-05 22:06:15 -0700742
Simon Glass03749d42014-08-28 09:43:44 -0600743 return (board_dict, err_lines_summary, err_lines_boards,
Simon Glassdb17fb82015-02-05 22:06:15 -0700744 warn_lines_summary, warn_lines_boards, config)
Simon Glassc05694f2013-04-03 11:07:16 +0000745
746 def AddOutcome(self, board_dict, arch_list, changes, char, color):
747 """Add an output to our list of outcomes for each architecture
748
749 This simple function adds failing boards (changes) to the
750 relevant architecture string, so we can print the results out
751 sorted by architecture.
752
753 Args:
754 board_dict: Dict containing all boards
755 arch_list: Dict keyed by arch name. Value is a string containing
756 a list of board names which failed for that arch.
757 changes: List of boards to add to arch_list
758 color: terminal.Colour object
759 """
760 done_arch = {}
761 for target in changes:
762 if target in board_dict:
763 arch = board_dict[target].arch
764 else:
765 arch = 'unknown'
766 str = self.col.Color(color, ' ' + target)
767 if not arch in done_arch:
Simon Glass26f72372015-02-05 22:06:11 -0700768 str = ' %s %s' % (self.col.Color(color, char), str)
Simon Glassc05694f2013-04-03 11:07:16 +0000769 done_arch[arch] = True
770 if not arch in arch_list:
771 arch_list[arch] = str
772 else:
773 arch_list[arch] += str
774
775
776 def ColourNum(self, num):
777 color = self.col.RED if num > 0 else self.col.GREEN
778 if num == 0:
779 return '0'
780 return self.col.Color(color, str(num))
781
782 def ResetResultSummary(self, board_selected):
783 """Reset the results summary ready for use.
784
785 Set up the base board list to be all those selected, and set the
786 error lines to empty.
787
788 Following this, calls to PrintResultSummary() will use this
789 information to work out what has changed.
790
791 Args:
792 board_selected: Dict containing boards to summarise, keyed by
793 board.target
794 """
795 self._base_board_dict = {}
796 for board in board_selected:
Simon Glassdb17fb82015-02-05 22:06:15 -0700797 self._base_board_dict[board] = Builder.Outcome(0, [], [], {}, {})
Simon Glassc05694f2013-04-03 11:07:16 +0000798 self._base_err_lines = []
Simon Glass03749d42014-08-28 09:43:44 -0600799 self._base_warn_lines = []
800 self._base_err_line_boards = {}
801 self._base_warn_line_boards = {}
Simon Glasscad8abf2015-08-25 21:52:14 -0600802 self._base_config = None
Simon Glassc05694f2013-04-03 11:07:16 +0000803
804 def PrintFuncSizeDetail(self, fname, old, new):
805 grow, shrink, add, remove, up, down = 0, 0, 0, 0, 0, 0
806 delta, common = [], {}
807
808 for a in old:
809 if a in new:
810 common[a] = 1
811
812 for name in old:
813 if name not in common:
814 remove += 1
815 down += old[name]
816 delta.append([-old[name], name])
817
818 for name in new:
819 if name not in common:
820 add += 1
821 up += new[name]
822 delta.append([new[name], name])
823
824 for name in common:
825 diff = new.get(name, 0) - old.get(name, 0)
826 if diff > 0:
827 grow, up = grow + 1, up + diff
828 elif diff < 0:
829 shrink, down = shrink + 1, down - diff
830 delta.append([diff, name])
831
832 delta.sort()
833 delta.reverse()
834
835 args = [add, -remove, grow, -shrink, up, -down, up - down]
836 if max(args) == 0:
837 return
838 args = [self.ColourNum(x) for x in args]
839 indent = ' ' * 15
Simon Glass4433aa92014-09-05 19:00:07 -0600840 Print('%s%s: add: %s/%s, grow: %s/%s bytes: %s/%s (%s)' %
841 tuple([indent, self.col.Color(self.col.YELLOW, fname)] + args))
842 Print('%s %-38s %7s %7s %+7s' % (indent, 'function', 'old', 'new',
843 'delta'))
Simon Glassc05694f2013-04-03 11:07:16 +0000844 for diff, name in delta:
845 if diff:
846 color = self.col.RED if diff > 0 else self.col.GREEN
847 msg = '%s %-38s %7s %7s %+7d' % (indent, name,
848 old.get(name, '-'), new.get(name,'-'), diff)
Simon Glass4433aa92014-09-05 19:00:07 -0600849 Print(msg, colour=color)
Simon Glassc05694f2013-04-03 11:07:16 +0000850
851
852 def PrintSizeDetail(self, target_list, show_bloat):
853 """Show details size information for each board
854
855 Args:
856 target_list: List of targets, each a dict containing:
857 'target': Target name
858 'total_diff': Total difference in bytes across all areas
859 <part_name>: Difference for that part
860 show_bloat: Show detail for each function
861 """
862 targets_by_diff = sorted(target_list, reverse=True,
863 key=lambda x: x['_total_diff'])
864 for result in targets_by_diff:
865 printed_target = False
866 for name in sorted(result):
867 diff = result[name]
868 if name.startswith('_'):
869 continue
870 if diff != 0:
871 color = self.col.RED if diff > 0 else self.col.GREEN
872 msg = ' %s %+d' % (name, diff)
873 if not printed_target:
Simon Glass4433aa92014-09-05 19:00:07 -0600874 Print('%10s %-15s:' % ('', result['_target']),
875 newline=False)
Simon Glassc05694f2013-04-03 11:07:16 +0000876 printed_target = True
Simon Glass4433aa92014-09-05 19:00:07 -0600877 Print(msg, colour=color, newline=False)
Simon Glassc05694f2013-04-03 11:07:16 +0000878 if printed_target:
Simon Glass4433aa92014-09-05 19:00:07 -0600879 Print()
Simon Glassc05694f2013-04-03 11:07:16 +0000880 if show_bloat:
881 target = result['_target']
882 outcome = result['_outcome']
883 base_outcome = self._base_board_dict[target]
884 for fname in outcome.func_sizes:
885 self.PrintFuncSizeDetail(fname,
886 base_outcome.func_sizes[fname],
887 outcome.func_sizes[fname])
888
889
890 def PrintSizeSummary(self, board_selected, board_dict, show_detail,
891 show_bloat):
892 """Print a summary of image sizes broken down by section.
893
894 The summary takes the form of one line per architecture. The
895 line contains deltas for each of the sections (+ means the section
896 got bigger, - means smaller). The nunmbers are the average number
897 of bytes that a board in this section increased by.
898
899 For example:
900 powerpc: (622 boards) text -0.0
901 arm: (285 boards) text -0.0
902 nds32: (3 boards) text -8.0
903
904 Args:
905 board_selected: Dict containing boards to summarise, keyed by
906 board.target
907 board_dict: Dict containing boards for which we built this
908 commit, keyed by board.target. The value is an Outcome object.
909 show_detail: Show detail for each board
910 show_bloat: Show detail for each function
911 """
912 arch_list = {}
913 arch_count = {}
914
915 # Calculate changes in size for different image parts
916 # The previous sizes are in Board.sizes, for each board
917 for target in board_dict:
918 if target not in board_selected:
919 continue
920 base_sizes = self._base_board_dict[target].sizes
921 outcome = board_dict[target]
922 sizes = outcome.sizes
923
924 # Loop through the list of images, creating a dict of size
925 # changes for each image/part. We end up with something like
926 # {'target' : 'snapper9g45, 'data' : 5, 'u-boot-spl:text' : -4}
927 # which means that U-Boot data increased by 5 bytes and SPL
928 # text decreased by 4.
929 err = {'_target' : target}
930 for image in sizes:
931 if image in base_sizes:
932 base_image = base_sizes[image]
933 # Loop through the text, data, bss parts
934 for part in sorted(sizes[image]):
935 diff = sizes[image][part] - base_image[part]
936 col = None
937 if diff:
938 if image == 'u-boot':
939 name = part
940 else:
941 name = image + ':' + part
942 err[name] = diff
943 arch = board_selected[target].arch
944 if not arch in arch_count:
945 arch_count[arch] = 1
946 else:
947 arch_count[arch] += 1
948 if not sizes:
949 pass # Only add to our list when we have some stats
950 elif not arch in arch_list:
951 arch_list[arch] = [err]
952 else:
953 arch_list[arch].append(err)
954
955 # We now have a list of image size changes sorted by arch
956 # Print out a summary of these
957 for arch, target_list in arch_list.iteritems():
958 # Get total difference for each type
959 totals = {}
960 for result in target_list:
961 total = 0
962 for name, diff in result.iteritems():
963 if name.startswith('_'):
964 continue
965 total += diff
966 if name in totals:
967 totals[name] += diff
968 else:
969 totals[name] = diff
970 result['_total_diff'] = total
971 result['_outcome'] = board_dict[result['_target']]
972
973 count = len(target_list)
974 printed_arch = False
975 for name in sorted(totals):
976 diff = totals[name]
977 if diff:
978 # Display the average difference in this name for this
979 # architecture
980 avg_diff = float(diff) / count
981 color = self.col.RED if avg_diff > 0 else self.col.GREEN
982 msg = ' %s %+1.1f' % (name, avg_diff)
983 if not printed_arch:
Simon Glass4433aa92014-09-05 19:00:07 -0600984 Print('%10s: (for %d/%d boards)' % (arch, count,
985 arch_count[arch]), newline=False)
Simon Glassc05694f2013-04-03 11:07:16 +0000986 printed_arch = True
Simon Glass4433aa92014-09-05 19:00:07 -0600987 Print(msg, colour=color, newline=False)
Simon Glassc05694f2013-04-03 11:07:16 +0000988
989 if printed_arch:
Simon Glass4433aa92014-09-05 19:00:07 -0600990 Print()
Simon Glassc05694f2013-04-03 11:07:16 +0000991 if show_detail:
992 self.PrintSizeDetail(target_list, show_bloat)
993
994
995 def PrintResultSummary(self, board_selected, board_dict, err_lines,
Simon Glass03749d42014-08-28 09:43:44 -0600996 err_line_boards, warn_lines, warn_line_boards,
Simon Glassdb17fb82015-02-05 22:06:15 -0700997 config, show_sizes, show_detail, show_bloat,
998 show_config):
Simon Glassc05694f2013-04-03 11:07:16 +0000999 """Compare results with the base results and display delta.
1000
1001 Only boards mentioned in board_selected will be considered. This
1002 function is intended to be called repeatedly with the results of
1003 each commit. It therefore shows a 'diff' between what it saw in
1004 the last call and what it sees now.
1005
1006 Args:
1007 board_selected: Dict containing boards to summarise, keyed by
1008 board.target
1009 board_dict: Dict containing boards for which we built this
1010 commit, keyed by board.target. The value is an Outcome object.
1011 err_lines: A list of errors for this commit, or [] if there is
1012 none, or we don't want to print errors
Simon Glass3394c9f2014-08-28 09:43:43 -06001013 err_line_boards: Dict keyed by error line, containing a list of
1014 the Board objects with that error
Simon Glass03749d42014-08-28 09:43:44 -06001015 warn_lines: A list of warnings for this commit, or [] if there is
1016 none, or we don't want to print errors
1017 warn_line_boards: Dict keyed by warning line, containing a list of
1018 the Board objects with that warning
Simon Glassdb17fb82015-02-05 22:06:15 -07001019 config: Dictionary keyed by filename - e.g. '.config'. Each
1020 value is itself a dictionary:
1021 key: config name
1022 value: config value
Simon Glassc05694f2013-04-03 11:07:16 +00001023 show_sizes: Show image size deltas
1024 show_detail: Show detail for each board
1025 show_bloat: Show detail for each function
Simon Glassdb17fb82015-02-05 22:06:15 -07001026 show_config: Show config changes
Simon Glassc05694f2013-04-03 11:07:16 +00001027 """
Simon Glass03749d42014-08-28 09:43:44 -06001028 def _BoardList(line, line_boards):
Simon Glass3394c9f2014-08-28 09:43:43 -06001029 """Helper function to get a line of boards containing a line
1030
1031 Args:
1032 line: Error line to search for
1033 Return:
1034 String containing a list of boards with that error line, or
1035 '' if the user has not requested such a list
1036 """
1037 if self._list_error_boards:
1038 names = []
Simon Glass03749d42014-08-28 09:43:44 -06001039 for board in line_boards[line]:
Simon Glass85620bb2014-10-16 01:05:55 -06001040 if not board.target in names:
1041 names.append(board.target)
Simon Glass3394c9f2014-08-28 09:43:43 -06001042 names_str = '(%s) ' % ','.join(names)
1043 else:
1044 names_str = ''
1045 return names_str
1046
Simon Glass03749d42014-08-28 09:43:44 -06001047 def _CalcErrorDelta(base_lines, base_line_boards, lines, line_boards,
1048 char):
1049 better_lines = []
1050 worse_lines = []
1051 for line in lines:
1052 if line not in base_lines:
1053 worse_lines.append(char + '+' +
1054 _BoardList(line, line_boards) + line)
1055 for line in base_lines:
1056 if line not in lines:
1057 better_lines.append(char + '-' +
1058 _BoardList(line, base_line_boards) + line)
1059 return better_lines, worse_lines
1060
Simon Glassdb17fb82015-02-05 22:06:15 -07001061 def _CalcConfig(delta, name, config):
1062 """Calculate configuration changes
1063
1064 Args:
1065 delta: Type of the delta, e.g. '+'
1066 name: name of the file which changed (e.g. .config)
1067 config: configuration change dictionary
1068 key: config name
1069 value: config value
1070 Returns:
1071 String containing the configuration changes which can be
1072 printed
1073 """
1074 out = ''
1075 for key in sorted(config.keys()):
1076 out += '%s=%s ' % (key, config[key])
Simon Glasscad8abf2015-08-25 21:52:14 -06001077 return '%s %s: %s' % (delta, name, out)
Simon Glassdb17fb82015-02-05 22:06:15 -07001078
Simon Glasscad8abf2015-08-25 21:52:14 -06001079 def _AddConfig(lines, name, config_plus, config_minus, config_change):
1080 """Add changes in configuration to a list
Simon Glassdb17fb82015-02-05 22:06:15 -07001081
1082 Args:
Simon Glasscad8abf2015-08-25 21:52:14 -06001083 lines: list to add to
1084 name: config file name
Simon Glassdb17fb82015-02-05 22:06:15 -07001085 config_plus: configurations added, dictionary
1086 key: config name
1087 value: config value
1088 config_minus: configurations removed, dictionary
1089 key: config name
1090 value: config value
1091 config_change: configurations changed, dictionary
1092 key: config name
1093 value: config value
1094 """
1095 if config_plus:
Simon Glasscad8abf2015-08-25 21:52:14 -06001096 lines.append(_CalcConfig('+', name, config_plus))
Simon Glassdb17fb82015-02-05 22:06:15 -07001097 if config_minus:
Simon Glasscad8abf2015-08-25 21:52:14 -06001098 lines.append(_CalcConfig('-', name, config_minus))
Simon Glassdb17fb82015-02-05 22:06:15 -07001099 if config_change:
Simon Glasscad8abf2015-08-25 21:52:14 -06001100 lines.append(_CalcConfig('c', name, config_change))
1101
1102 def _OutputConfigInfo(lines):
1103 for line in lines:
1104 if not line:
1105 continue
1106 if line[0] == '+':
1107 col = self.col.GREEN
1108 elif line[0] == '-':
1109 col = self.col.RED
1110 elif line[0] == 'c':
1111 col = self.col.YELLOW
1112 Print(' ' + line, newline=True, colour=col)
1113
Simon Glassdb17fb82015-02-05 22:06:15 -07001114
Simon Glassc05694f2013-04-03 11:07:16 +00001115 better = [] # List of boards fixed since last commit
1116 worse = [] # List of new broken boards since last commit
1117 new = [] # List of boards that didn't exist last time
1118 unknown = [] # List of boards that were not built
1119
1120 for target in board_dict:
1121 if target not in board_selected:
1122 continue
1123
1124 # If the board was built last time, add its outcome to a list
1125 if target in self._base_board_dict:
1126 base_outcome = self._base_board_dict[target].rc
1127 outcome = board_dict[target]
1128 if outcome.rc == OUTCOME_UNKNOWN:
1129 unknown.append(target)
1130 elif outcome.rc < base_outcome:
1131 better.append(target)
1132 elif outcome.rc > base_outcome:
1133 worse.append(target)
1134 else:
1135 new.append(target)
1136
1137 # Get a list of errors that have appeared, and disappeared
Simon Glass03749d42014-08-28 09:43:44 -06001138 better_err, worse_err = _CalcErrorDelta(self._base_err_lines,
1139 self._base_err_line_boards, err_lines, err_line_boards, '')
1140 better_warn, worse_warn = _CalcErrorDelta(self._base_warn_lines,
1141 self._base_warn_line_boards, warn_lines, warn_line_boards, 'w')
Simon Glassc05694f2013-04-03 11:07:16 +00001142
1143 # Display results by arch
Simon Glass03749d42014-08-28 09:43:44 -06001144 if (better or worse or unknown or new or worse_err or better_err
1145 or worse_warn or better_warn):
Simon Glassc05694f2013-04-03 11:07:16 +00001146 arch_list = {}
1147 self.AddOutcome(board_selected, arch_list, better, '',
1148 self.col.GREEN)
1149 self.AddOutcome(board_selected, arch_list, worse, '+',
1150 self.col.RED)
1151 self.AddOutcome(board_selected, arch_list, new, '*', self.col.BLUE)
1152 if self._show_unknown:
1153 self.AddOutcome(board_selected, arch_list, unknown, '?',
1154 self.col.MAGENTA)
1155 for arch, target_list in arch_list.iteritems():
Simon Glass4433aa92014-09-05 19:00:07 -06001156 Print('%10s: %s' % (arch, target_list))
Simon Glassbb4dffb2014-08-09 15:33:06 -06001157 self._error_lines += 1
Simon Glassc05694f2013-04-03 11:07:16 +00001158 if better_err:
Simon Glass4433aa92014-09-05 19:00:07 -06001159 Print('\n'.join(better_err), colour=self.col.GREEN)
Simon Glassbb4dffb2014-08-09 15:33:06 -06001160 self._error_lines += 1
Simon Glassc05694f2013-04-03 11:07:16 +00001161 if worse_err:
Simon Glass4433aa92014-09-05 19:00:07 -06001162 Print('\n'.join(worse_err), colour=self.col.RED)
Simon Glassbb4dffb2014-08-09 15:33:06 -06001163 self._error_lines += 1
Simon Glass03749d42014-08-28 09:43:44 -06001164 if better_warn:
Simon Glass4433aa92014-09-05 19:00:07 -06001165 Print('\n'.join(better_warn), colour=self.col.CYAN)
Simon Glass03749d42014-08-28 09:43:44 -06001166 self._error_lines += 1
1167 if worse_warn:
Simon Glass4433aa92014-09-05 19:00:07 -06001168 Print('\n'.join(worse_warn), colour=self.col.MAGENTA)
Simon Glass03749d42014-08-28 09:43:44 -06001169 self._error_lines += 1
Simon Glassc05694f2013-04-03 11:07:16 +00001170
1171 if show_sizes:
1172 self.PrintSizeSummary(board_selected, board_dict, show_detail,
1173 show_bloat)
1174
Simon Glasscad8abf2015-08-25 21:52:14 -06001175 if show_config and self._base_config:
1176 summary = {}
1177 arch_config_plus = {}
1178 arch_config_minus = {}
1179 arch_config_change = {}
1180 arch_list = []
1181
1182 for target in board_dict:
1183 if target not in board_selected:
1184 continue
1185 arch = board_selected[target].arch
1186 if arch not in arch_list:
1187 arch_list.append(arch)
1188
1189 for arch in arch_list:
1190 arch_config_plus[arch] = {}
1191 arch_config_minus[arch] = {}
1192 arch_config_change[arch] = {}
1193 for name in CONFIG_FILENAMES:
1194 arch_config_plus[arch][name] = {}
1195 arch_config_minus[arch][name] = {}
1196 arch_config_change[arch][name] = {}
1197
1198 for target in board_dict:
1199 if target not in board_selected:
Simon Glassdb17fb82015-02-05 22:06:15 -07001200 continue
Simon Glasscad8abf2015-08-25 21:52:14 -06001201
1202 arch = board_selected[target].arch
1203
1204 all_config_plus = {}
1205 all_config_minus = {}
1206 all_config_change = {}
1207 tbase = self._base_config[target]
1208 tconfig = config[target]
1209 lines = []
1210 for name in CONFIG_FILENAMES:
1211 if not tconfig.config[name]:
1212 continue
1213 config_plus = {}
1214 config_minus = {}
1215 config_change = {}
1216 base = tbase.config[name]
1217 for key, value in tconfig.config[name].iteritems():
1218 if key not in base:
1219 config_plus[key] = value
1220 all_config_plus[key] = value
1221 for key, value in base.iteritems():
1222 if key not in tconfig.config[name]:
1223 config_minus[key] = value
1224 all_config_minus[key] = value
1225 for key, value in base.iteritems():
1226 new_value = tconfig.config.get(key)
1227 if new_value and value != new_value:
1228 desc = '%s -> %s' % (value, new_value)
1229 config_change[key] = desc
1230 all_config_change[key] = desc
1231
1232 arch_config_plus[arch][name].update(config_plus)
1233 arch_config_minus[arch][name].update(config_minus)
1234 arch_config_change[arch][name].update(config_change)
1235
1236 _AddConfig(lines, name, config_plus, config_minus,
1237 config_change)
1238 _AddConfig(lines, 'all', all_config_plus, all_config_minus,
1239 all_config_change)
1240 summary[target] = '\n'.join(lines)
1241
1242 lines_by_target = {}
1243 for target, lines in summary.iteritems():
1244 if lines in lines_by_target:
1245 lines_by_target[lines].append(target)
1246 else:
1247 lines_by_target[lines] = [target]
1248
1249 for arch in arch_list:
1250 lines = []
1251 all_plus = {}
1252 all_minus = {}
1253 all_change = {}
1254 for name in CONFIG_FILENAMES:
1255 all_plus.update(arch_config_plus[arch][name])
1256 all_minus.update(arch_config_minus[arch][name])
1257 all_change.update(arch_config_change[arch][name])
1258 _AddConfig(lines, name, arch_config_plus[arch][name],
1259 arch_config_minus[arch][name],
1260 arch_config_change[arch][name])
1261 _AddConfig(lines, 'all', all_plus, all_minus, all_change)
1262 #arch_summary[target] = '\n'.join(lines)
1263 if lines:
1264 Print('%s:' % arch)
1265 _OutputConfigInfo(lines)
1266
1267 for lines, targets in lines_by_target.iteritems():
1268 if not lines:
1269 continue
1270 Print('%s :' % ' '.join(sorted(targets)))
1271 _OutputConfigInfo(lines.split('\n'))
1272
Simon Glassdb17fb82015-02-05 22:06:15 -07001273
Simon Glassc05694f2013-04-03 11:07:16 +00001274 # Save our updated information for the next call to this function
1275 self._base_board_dict = board_dict
1276 self._base_err_lines = err_lines
Simon Glass03749d42014-08-28 09:43:44 -06001277 self._base_warn_lines = warn_lines
1278 self._base_err_line_boards = err_line_boards
1279 self._base_warn_line_boards = warn_line_boards
Simon Glassdb17fb82015-02-05 22:06:15 -07001280 self._base_config = config
Simon Glassc05694f2013-04-03 11:07:16 +00001281
1282 # Get a list of boards that did not get built, if needed
1283 not_built = []
1284 for board in board_selected:
1285 if not board in board_dict:
1286 not_built.append(board)
1287 if not_built:
Simon Glass4433aa92014-09-05 19:00:07 -06001288 Print("Boards not built (%d): %s" % (len(not_built),
1289 ', '.join(not_built)))
Simon Glassc05694f2013-04-03 11:07:16 +00001290
Simon Glasseb48bbc2014-08-09 15:33:02 -06001291 def ProduceResultSummary(self, commit_upto, commits, board_selected):
Simon Glass03749d42014-08-28 09:43:44 -06001292 (board_dict, err_lines, err_line_boards, warn_lines,
Simon Glassdb17fb82015-02-05 22:06:15 -07001293 warn_line_boards, config) = self.GetResultSummary(
Simon Glass3394c9f2014-08-28 09:43:43 -06001294 board_selected, commit_upto,
Simon Glassdb17fb82015-02-05 22:06:15 -07001295 read_func_sizes=self._show_bloat,
1296 read_config=self._show_config)
Simon Glasseb48bbc2014-08-09 15:33:02 -06001297 if commits:
1298 msg = '%02d: %s' % (commit_upto + 1,
1299 commits[commit_upto].subject)
Simon Glass4433aa92014-09-05 19:00:07 -06001300 Print(msg, colour=self.col.BLUE)
Simon Glasseb48bbc2014-08-09 15:33:02 -06001301 self.PrintResultSummary(board_selected, board_dict,
Simon Glass3394c9f2014-08-28 09:43:43 -06001302 err_lines if self._show_errors else [], err_line_boards,
Simon Glass03749d42014-08-28 09:43:44 -06001303 warn_lines if self._show_errors else [], warn_line_boards,
Simon Glassdb17fb82015-02-05 22:06:15 -07001304 config, self._show_sizes, self._show_detail,
1305 self._show_bloat, self._show_config)
Simon Glassc05694f2013-04-03 11:07:16 +00001306
Simon Glasseb48bbc2014-08-09 15:33:02 -06001307 def ShowSummary(self, commits, board_selected):
Simon Glassc05694f2013-04-03 11:07:16 +00001308 """Show a build summary for U-Boot for a given board list.
1309
1310 Reset the result summary, then repeatedly call GetResultSummary on
1311 each commit's results, then display the differences we see.
1312
1313 Args:
1314 commit: Commit objects to summarise
1315 board_selected: Dict containing boards to summarise
Simon Glassc05694f2013-04-03 11:07:16 +00001316 """
Simon Glassd326ad72014-08-09 15:32:59 -06001317 self.commit_count = len(commits) if commits else 1
Simon Glassc05694f2013-04-03 11:07:16 +00001318 self.commits = commits
1319 self.ResetResultSummary(board_selected)
Simon Glassbb4dffb2014-08-09 15:33:06 -06001320 self._error_lines = 0
Simon Glassc05694f2013-04-03 11:07:16 +00001321
1322 for commit_upto in range(0, self.commit_count, self._step):
Simon Glasseb48bbc2014-08-09 15:33:02 -06001323 self.ProduceResultSummary(commit_upto, commits, board_selected)
Simon Glassbb4dffb2014-08-09 15:33:06 -06001324 if not self._error_lines:
Simon Glass4433aa92014-09-05 19:00:07 -06001325 Print('(no errors to report)', colour=self.col.GREEN)
Simon Glassc05694f2013-04-03 11:07:16 +00001326
1327
1328 def SetupBuild(self, board_selected, commits):
1329 """Set up ready to start a build.
1330
1331 Args:
1332 board_selected: Selected boards to build
1333 commits: Selected commits to build
1334 """
1335 # First work out how many commits we will build
Simon Glassd326ad72014-08-09 15:32:59 -06001336 count = (self.commit_count + self._step - 1) / self._step
Simon Glassc05694f2013-04-03 11:07:16 +00001337 self.count = len(board_selected) * count
1338 self.upto = self.warned = self.fail = 0
1339 self._timestamps = collections.deque()
1340
Simon Glassc05694f2013-04-03 11:07:16 +00001341 def GetThreadDir(self, thread_num):
1342 """Get the directory path to the working dir for a thread.
1343
1344 Args:
1345 thread_num: Number of thread to check.
1346 """
1347 return os.path.join(self._working_dir, '%02d' % thread_num)
1348
Simon Glassd326ad72014-08-09 15:32:59 -06001349 def _PrepareThread(self, thread_num, setup_git):
Simon Glassc05694f2013-04-03 11:07:16 +00001350 """Prepare the working directory for a thread.
1351
1352 This clones or fetches the repo into the thread's work directory.
1353
1354 Args:
1355 thread_num: Thread number (0, 1, ...)
Simon Glassd326ad72014-08-09 15:32:59 -06001356 setup_git: True to set up a git repo clone
Simon Glassc05694f2013-04-03 11:07:16 +00001357 """
1358 thread_dir = self.GetThreadDir(thread_num)
Simon Glass4a1e88b2014-08-09 15:33:00 -06001359 builderthread.Mkdir(thread_dir)
Simon Glassc05694f2013-04-03 11:07:16 +00001360 git_dir = os.path.join(thread_dir, '.git')
1361
1362 # Clone the repo if it doesn't already exist
1363 # TODO(sjg@chromium): Perhaps some git hackery to symlink instead, so
1364 # we have a private index but uses the origin repo's contents?
Simon Glassd326ad72014-08-09 15:32:59 -06001365 if setup_git and self.git_dir:
Simon Glassc05694f2013-04-03 11:07:16 +00001366 src_dir = os.path.abspath(self.git_dir)
1367 if os.path.exists(git_dir):
1368 gitutil.Fetch(git_dir, thread_dir)
1369 else:
Simon Glass2e2a6e62016-09-18 16:48:31 -06001370 Print('\rCloning repo for thread %d' % thread_num,
1371 newline=False)
Simon Glassc05694f2013-04-03 11:07:16 +00001372 gitutil.Clone(src_dir, thread_dir)
Simon Glass2e2a6e62016-09-18 16:48:31 -06001373 Print('\r%s\r' % (' ' * 30), newline=False)
Simon Glassc05694f2013-04-03 11:07:16 +00001374
Simon Glassd326ad72014-08-09 15:32:59 -06001375 def _PrepareWorkingSpace(self, max_threads, setup_git):
Simon Glassc05694f2013-04-03 11:07:16 +00001376 """Prepare the working directory for use.
1377
1378 Set up the git repo for each thread.
1379
1380 Args:
1381 max_threads: Maximum number of threads we expect to need.
Simon Glassd326ad72014-08-09 15:32:59 -06001382 setup_git: True to set up a git repo clone
Simon Glassc05694f2013-04-03 11:07:16 +00001383 """
Simon Glass4a1e88b2014-08-09 15:33:00 -06001384 builderthread.Mkdir(self._working_dir)
Simon Glassc05694f2013-04-03 11:07:16 +00001385 for thread in range(max_threads):
Simon Glassd326ad72014-08-09 15:32:59 -06001386 self._PrepareThread(thread, setup_git)
Simon Glassc05694f2013-04-03 11:07:16 +00001387
1388 def _PrepareOutputSpace(self):
1389 """Get the output directories ready to receive files.
1390
1391 We delete any output directories which look like ones we need to
1392 create. Having left over directories is confusing when the user wants
1393 to check the output manually.
1394 """
Simon Glassb9a9b7c2014-12-01 17:33:53 -07001395 if not self.commits:
1396 return
Simon Glassc05694f2013-04-03 11:07:16 +00001397 dir_list = []
1398 for commit_upto in range(self.commit_count):
1399 dir_list.append(self._GetOutputDir(commit_upto))
1400
Simon Glass83cb6cc2016-09-18 16:48:32 -06001401 to_remove = []
Simon Glassc05694f2013-04-03 11:07:16 +00001402 for dirname in glob.glob(os.path.join(self.base_dir, '*')):
1403 if dirname not in dir_list:
Simon Glass83cb6cc2016-09-18 16:48:32 -06001404 to_remove.append(dirname)
1405 if to_remove:
1406 Print('Removing %d old build directories' % len(to_remove),
1407 newline=False)
1408 for dirname in to_remove:
Simon Glassc05694f2013-04-03 11:07:16 +00001409 shutil.rmtree(dirname)
1410
Simon Glass78e418e2014-08-09 15:33:03 -06001411 def BuildBoards(self, commits, board_selected, keep_outputs, verbose):
Simon Glassc05694f2013-04-03 11:07:16 +00001412 """Build all commits for a list of boards
1413
1414 Args:
1415 commits: List of commits to be build, each a Commit object
1416 boards_selected: Dict of selected boards, key is target name,
1417 value is Board object
Simon Glassc05694f2013-04-03 11:07:16 +00001418 keep_outputs: True to save build output files
Simon Glass78e418e2014-08-09 15:33:03 -06001419 verbose: Display build results as they are completed
Simon Glassc2f91072014-08-28 09:43:39 -06001420 Returns:
1421 Tuple containing:
1422 - number of boards that failed to build
1423 - number of boards that issued warnings
Simon Glassc05694f2013-04-03 11:07:16 +00001424 """
Simon Glassd326ad72014-08-09 15:32:59 -06001425 self.commit_count = len(commits) if commits else 1
Simon Glassc05694f2013-04-03 11:07:16 +00001426 self.commits = commits
Simon Glass78e418e2014-08-09 15:33:03 -06001427 self._verbose = verbose
Simon Glassc05694f2013-04-03 11:07:16 +00001428
1429 self.ResetResultSummary(board_selected)
Thierry Reding336d5bd2014-08-19 10:22:39 +02001430 builderthread.Mkdir(self.base_dir, parents = True)
Simon Glassd326ad72014-08-09 15:32:59 -06001431 self._PrepareWorkingSpace(min(self.num_threads, len(board_selected)),
1432 commits is not None)
Simon Glassc05694f2013-04-03 11:07:16 +00001433 self._PrepareOutputSpace()
Simon Glasse0f23602016-09-18 16:48:33 -06001434 Print('\rStarting build...', newline=False)
Simon Glassc05694f2013-04-03 11:07:16 +00001435 self.SetupBuild(board_selected, commits)
1436 self.ProcessResult(None)
1437
1438 # Create jobs to build all commits for each board
1439 for brd in board_selected.itervalues():
Simon Glass4a1e88b2014-08-09 15:33:00 -06001440 job = builderthread.BuilderJob()
Simon Glassc05694f2013-04-03 11:07:16 +00001441 job.board = brd
1442 job.commits = commits
1443 job.keep_outputs = keep_outputs
1444 job.step = self._step
1445 self.queue.put(job)
1446
Simon Glassd26e1442016-09-18 16:48:35 -06001447 term = threading.Thread(target=self.queue.join)
1448 term.setDaemon(True)
1449 term.start()
1450 while term.isAlive():
1451 term.join(100)
Simon Glassc05694f2013-04-03 11:07:16 +00001452
1453 # Wait until we have processed all output
1454 self.out_queue.join()
Simon Glass4433aa92014-09-05 19:00:07 -06001455 Print()
Simon Glassc05694f2013-04-03 11:07:16 +00001456 self.ClearLine(0)
Simon Glassc2f91072014-08-28 09:43:39 -06001457 return (self.fail, self.warned)