blob: 44d1cfa5175dda6f14a56c73964752ef7434fad0 [file] [log] [blame]
Simon Glassfc3fe1c2013-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 Denk1a459662013-07-08 09:37:19 +02005# SPDX-License-Identifier: GPL-2.0+
Simon Glassfc3fe1c2013-04-03 11:07:16 +00006#
7
8import collections
Simon Glassfc3fe1c2013-04-03 11:07:16 +00009from datetime import datetime, timedelta
10import glob
11import os
12import re
13import Queue
14import shutil
15import string
16import sys
Simon Glassd436e382016-09-18 16:48:35 -060017import threading
Simon Glassfc3fe1c2013-04-03 11:07:16 +000018import time
19
Simon Glass190064b2014-08-09 15:33:00 -060020import builderthread
Simon Glassfc3fe1c2013-04-03 11:07:16 +000021import command
22import gitutil
23import terminal
Simon Glass4653a882014-09-05 19:00:07 -060024from terminal import Print
Simon Glassfc3fe1c2013-04-03 11:07:16 +000025import toolchain
26
27
28"""
29Theory of Operation
30
31Please see README for user documentation, and you should be familiar with
32that before trying to make sense of this.
33
34Buildman works by keeping the machine as busy as possible, building different
35commits for different boards on multiple CPUs at once.
36
37The source repo (self.git_dir) contains all the commits to be built. Each
38thread works on a single board at a time. It checks out the first commit,
39configures it for that board, then builds it. Then it checks out the next
40commit and builds it (typically without re-configuring). When it runs out
41of commits, it gets another job from the builder and starts again with that
42board.
43
44Clearly the builder threads could work either way - they could check out a
45commit and then built it for all boards. Using separate directories for each
46commit/board pair they could leave their build product around afterwards
47also.
48
49The intent behind building a single board for multiple commits, is to make
50use of incremental builds. Since each commit is built incrementally from
51the previous one, builds are faster. Reconfiguring for a different board
52removes all intermediate object files.
53
54Many threads can be working at once, but each has its own working directory.
55When a thread finishes a build, it puts the output files into a result
56directory.
57
58The base directory used by buildman is normally '../<branch>', i.e.
59a directory higher than the source repository and named after the branch
60being built.
61
62Within the base directory, we have one subdirectory for each commit. Within
63that is one subdirectory for each board. Within that is the build output for
64that commit/board combination.
65
66Buildman also create working directories for each thread, in a .bm-work/
67subdirectory in the base dir.
68
69As an example, say we are building branch 'us-net' for boards 'sandbox' and
70'seaboard', and say that us-net has two commits. We will have directories
71like this:
72
73us-net/ base directory
74 01_of_02_g4ed4ebc_net--Add-tftp-speed-/
75 sandbox/
76 u-boot.bin
77 seaboard/
78 u-boot.bin
79 02_of_02_g4ed4ebc_net--Check-tftp-comp/
80 sandbox/
81 u-boot.bin
82 seaboard/
83 u-boot.bin
84 .bm-work/
85 00/ working directory for thread 0 (contains source checkout)
86 build/ build output
87 01/ working directory for thread 1
88 build/ build output
89 ...
90u-boot/ source directory
91 .git/ repository
92"""
93
94# Possible build outcomes
95OUTCOME_OK, OUTCOME_WARNING, OUTCOME_ERROR, OUTCOME_UNKNOWN = range(4)
96
97# Translate a commit subject into a valid filename
98trans_valid_chars = string.maketrans("/: ", "---")
99
Simon Glass843312d2015-02-05 22:06:15 -0700100CONFIG_FILENAMES = [
101 '.config', '.config-spl', '.config-tpl',
102 'autoconf.mk', 'autoconf-spl.mk', 'autoconf-tpl.mk',
103 'autoconf.h', 'autoconf-spl.h','autoconf-tpl.h',
104 'u-boot.cfg', 'u-boot-spl.cfg', 'u-boot-tpl.cfg'
105]
106
Simon Glass8270e3c2015-08-25 21:52:14 -0600107class Config:
108 """Holds information about configuration settings for a board."""
109 def __init__(self, target):
110 self.target = target
111 self.config = {}
112 for fname in CONFIG_FILENAMES:
113 self.config[fname] = {}
114
115 def Add(self, fname, key, value):
116 self.config[fname][key] = value
117
118 def __hash__(self):
119 val = 0
120 for fname in self.config:
121 for key, value in self.config[fname].iteritems():
122 print key, value
123 val = val ^ hash(key) & hash(value)
124 return val
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000125
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000126class Builder:
127 """Class for building U-Boot for a particular commit.
128
129 Public members: (many should ->private)
130 active: True if the builder is active and has not been stopped
131 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 Glass4266dc22014-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 Glassfc3fe1c2013-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 Glass97e91522014-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 Glass189a4962014-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 Glassfc3fe1c2013-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 Glasse30965d2014-08-28 09:43:44 -0600170 _base_warn_lines: Last-summarised list of warnings
Simon Glassfc3fe1c2013-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 Glass843312d2015-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 Glassfc3fe1c2013-04-03 11:07:16 +0000199 """
Simon Glass843312d2015-02-05 22:06:15 -0700200 def __init__(self, rc, err_lines, sizes, func_sizes, config):
Simon Glassfc3fe1c2013-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 Glass843312d2015-02-05 22:06:15 -0700205 self.config = config
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000206
207 def __init__(self, toolchains, base_dir, git_dir, num_threads, num_jobs,
Simon Glass5971ab52014-12-01 17:33:55 -0700208 gnu_make='make', checkout=True, show_unknown=True, step=1,
Stephen Warrenf79f1e02016-04-11 10:48:44 -0600209 no_subdirs=False, full_path=False, verbose_build=False,
210 incremental=False, per_board_out_dir=False):
Simon Glassfc3fe1c2013-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 Yamada99796922014-07-22 11:19:09 +0900219 gnu_make: the command name of GNU Make.
Simon Glassfc3fe1c2013-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 Glassbb1501f2014-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 Glassd2ce6582014-12-01 17:34:07 -0700228 verbose_build: Run build with V=1 and don't use 'make -s'
Stephen Warrenf79f1e02016-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 Glassfc3fe1c2013-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 = []
238 self.active = True
239 self.do_make = self.Make
Masahiro Yamada99796922014-07-22 11:19:09 +0900240 self.gnu_make = gnu_make
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000241 self.checkout = checkout
242 self.num_threads = num_threads
243 self.num_jobs = num_jobs
244 self.already_done = 0
245 self.force_build = False
246 self.git_dir = git_dir
247 self._show_unknown = show_unknown
248 self._timestamp_count = 10
249 self._build_period_us = None
250 self._complete_delay = None
251 self._next_delay_update = datetime.now()
252 self.force_config_on_failure = True
Simon Glass4266dc22014-07-13 12:22:31 -0600253 self.force_build_failures = False
Simon Glass97e91522014-07-14 17:51:02 -0600254 self.force_reconfig = False
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000255 self._step = step
Simon Glass189a4962014-07-14 17:51:03 -0600256 self.in_tree = False
Simon Glass28370c12014-08-09 15:33:06 -0600257 self._error_lines = 0
Simon Glass5971ab52014-12-01 17:33:55 -0700258 self.no_subdirs = no_subdirs
Simon Glassbb1501f2014-12-01 17:34:00 -0700259 self.full_path = full_path
Simon Glassd2ce6582014-12-01 17:34:07 -0700260 self.verbose_build = verbose_build
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000261
262 self.col = terminal.Color()
263
Simon Glasse30965d2014-08-28 09:43:44 -0600264 self._re_function = re.compile('(.*): In function.*')
265 self._re_files = re.compile('In file included from.*')
266 self._re_warning = re.compile('(.*):(\d*):(\d*): warning: .*')
267 self._re_note = re.compile('(.*):(\d*):(\d*): note: this is the location of the previous.*')
268
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000269 self.queue = Queue.Queue()
270 self.out_queue = Queue.Queue()
271 for i in range(self.num_threads):
Stephen Warrenf79f1e02016-04-11 10:48:44 -0600272 t = builderthread.BuilderThread(self, i, incremental,
273 per_board_out_dir)
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000274 t.setDaemon(True)
275 t.start()
276 self.threads.append(t)
277
278 self.last_line_len = 0
Simon Glass190064b2014-08-09 15:33:00 -0600279 t = builderthread.ResultThread(self)
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000280 t.setDaemon(True)
281 t.start()
282 self.threads.append(t)
283
284 ignore_lines = ['(make.*Waiting for unfinished)', '(Segmentation fault)']
285 self.re_make_err = re.compile('|'.join(ignore_lines))
286
287 def __del__(self):
288 """Get rid of all threads created by the builder"""
289 for t in self.threads:
290 del t
291
Simon Glassb2ea7ab2014-08-09 15:33:02 -0600292 def SetDisplayOptions(self, show_errors=False, show_sizes=False,
Simon Glassed966652014-08-28 09:43:43 -0600293 show_detail=False, show_bloat=False,
Simon Glass843312d2015-02-05 22:06:15 -0700294 list_error_boards=False, show_config=False):
Simon Glassb2ea7ab2014-08-09 15:33:02 -0600295 """Setup display options for the builder.
296
297 show_errors: True to show summarised error/warning info
298 show_sizes: Show size deltas
299 show_detail: Show detail for each board
300 show_bloat: Show detail for each function
Simon Glassed966652014-08-28 09:43:43 -0600301 list_error_boards: Show the boards which caused each error/warning
Simon Glass843312d2015-02-05 22:06:15 -0700302 show_config: Show config deltas
Simon Glassb2ea7ab2014-08-09 15:33:02 -0600303 """
304 self._show_errors = show_errors
305 self._show_sizes = show_sizes
306 self._show_detail = show_detail
307 self._show_bloat = show_bloat
Simon Glassed966652014-08-28 09:43:43 -0600308 self._list_error_boards = list_error_boards
Simon Glass843312d2015-02-05 22:06:15 -0700309 self._show_config = show_config
Simon Glassb2ea7ab2014-08-09 15:33:02 -0600310
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000311 def _AddTimestamp(self):
312 """Add a new timestamp to the list and record the build period.
313
314 The build period is the length of time taken to perform a single
315 build (one board, one commit).
316 """
317 now = datetime.now()
318 self._timestamps.append(now)
319 count = len(self._timestamps)
320 delta = self._timestamps[-1] - self._timestamps[0]
321 seconds = delta.total_seconds()
322
323 # If we have enough data, estimate build period (time taken for a
324 # single build) and therefore completion time.
325 if count > 1 and self._next_delay_update < now:
326 self._next_delay_update = now + timedelta(seconds=2)
327 if seconds > 0:
328 self._build_period = float(seconds) / count
329 todo = self.count - self.upto
330 self._complete_delay = timedelta(microseconds=
331 self._build_period * todo * 1000000)
332 # Round it
333 self._complete_delay -= timedelta(
334 microseconds=self._complete_delay.microseconds)
335
336 if seconds > 60:
337 self._timestamps.popleft()
338 count -= 1
339
340 def ClearLine(self, length):
341 """Clear any characters on the current line
342
343 Make way for a new line of length 'length', by outputting enough
344 spaces to clear out the old line. Then remember the new length for
345 next time.
346
347 Args:
348 length: Length of new line, in characters
349 """
350 if length < self.last_line_len:
Simon Glass4653a882014-09-05 19:00:07 -0600351 Print(' ' * (self.last_line_len - length), newline=False)
352 Print('\r', newline=False)
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000353 self.last_line_len = length
354 sys.stdout.flush()
355
356 def SelectCommit(self, commit, checkout=True):
357 """Checkout the selected commit for this build
358 """
359 self.commit = commit
360 if checkout and self.checkout:
361 gitutil.Checkout(commit.hash)
362
363 def Make(self, commit, brd, stage, cwd, *args, **kwargs):
364 """Run make
365
366 Args:
367 commit: Commit object that is being built
368 brd: Board object that is being built
Roger Meierfd18a892014-08-20 22:10:29 +0200369 stage: Stage that we are at (mrproper, config, build)
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000370 cwd: Directory where make should be run
371 args: Arguments to pass to make
372 kwargs: Arguments to pass to command.RunPipe()
373 """
Masahiro Yamada99796922014-07-22 11:19:09 +0900374 cmd = [self.gnu_make] + list(args)
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000375 result = command.RunPipe([cmd], capture=True, capture_stderr=True,
376 cwd=cwd, raise_on_error=False, **kwargs)
Simon Glass40f11fc2015-02-05 22:06:12 -0700377 if self.verbose_build:
378 result.stdout = '%s\n' % (' '.join(cmd)) + result.stdout
379 result.combined = '%s\n' % (' '.join(cmd)) + result.combined
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000380 return result
381
382 def ProcessResult(self, result):
383 """Process the result of a build, showing progress information
384
385 Args:
Simon Glasse5a0e5d2014-08-09 15:33:03 -0600386 result: A CommandResult object, which indicates the result for
387 a single build
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000388 """
389 col = terminal.Color()
390 if result:
391 target = result.brd.target
392
393 if result.return_code < 0:
394 self.active = False
395 command.StopAll()
396 return
397
398 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 Glasse5a0e5d2014-08-09 15:33:03 -0600405 if self._verbose:
Simon Glass4653a882014-09-05 19:00:07 -0600406 Print('\r', newline=False)
Simon Glasse5a0e5d2014-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 Glassfc3fe1c2013-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 Glass4653a882014-09-05 19:00:07 -0600434 Print(line + name, newline=False)
Simon Glasse5a0e5d2014-08-09 15:33:03 -0600435 length = 14 + len(name)
Simon Glassfc3fe1c2013-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 Glass5971ab52014-12-01 17:33:55 -0700446 commit_dir = None
Simon Glassfea58582014-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 Glass5971ab52014-12-01 17:33:55 -0700452 elif not self.no_subdirs:
Simon Glassfea58582014-08-09 15:32:59 -0600453 commit_dir = 'current'
Simon Glass5971ab52014-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 Glassfc3fe1c2013-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 Glass4653a882014-09-05 19:00:07 -0600552 Print("Invalid line in file '%s': '%s'" % (fname, line[:-1]))
Simon Glassfc3fe1c2013-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 Glass843312d2015-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 Glassfc3fe1c2013-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 Glass843312d2015-02-05 22:06:15 -0700604 read_config: True to read .config and autoconf.h files
Simon Glassfc3fe1c2013-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 Glass843312d2015-02-05 22:06:15 -0700613 config = {}
Simon Glassfc3fe1c2013-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 Glass843312d2015-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)
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000662
Simon Glass843312d2015-02-05 22:06:15 -0700663 return Builder.Outcome(rc, err_lines, sizes, func_sizes, config)
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000664
Simon Glass843312d2015-02-05 22:06:15 -0700665 return Builder.Outcome(OUTCOME_UNKNOWN, [], {}, {}, {})
666
667 def GetResultSummary(self, boards_selected, commit_upto, read_func_sizes,
668 read_config):
Simon Glassfc3fe1c2013-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 Glass843312d2015-02-05 22:06:15 -0700675 read_config: True to read .config and autoconf.h files
Simon Glassfc3fe1c2013-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 Glasse30965d2014-08-28 09:43:44 -0600681 List containing a summary of error lines
Simon Glassed966652014-08-28 09:43:43 -0600682 Dict keyed by error line, containing a list of the Board
683 objects with that error
Simon Glasse30965d2014-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 Glass8270e3c2015-08-25 21:52:14 -0600687 Dictionary keyed by board.target. Each value is a dictionary:
688 key: filename - e.g. '.config'
Simon Glass843312d2015-02-05 22:06:15 -0700689 value is itself a dictionary:
690 key: config name
691 value: config value
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000692 """
Simon Glasse30965d2014-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 Glassfc3fe1c2013-04-03 11:07:16 +0000701 board_dict = {}
702 err_lines_summary = []
Simon Glassed966652014-08-28 09:43:43 -0600703 err_lines_boards = {}
Simon Glasse30965d2014-08-28 09:43:44 -0600704 warn_lines_summary = []
705 warn_lines_boards = {}
Simon Glass843312d2015-02-05 22:06:15 -0700706 config = {}
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000707
708 for board in boards_selected.itervalues():
709 outcome = self.GetBuildOutcome(commit_upto, board.target,
Simon Glass843312d2015-02-05 22:06:15 -0700710 read_func_sizes, read_config)
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000711 board_dict[board.target] = outcome
Simon Glasse30965d2014-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 Glassed966652014-08-28 09:43:43 -0600719 else:
Simon Glasse30965d2014-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 Glass8270e3c2015-08-25 21:52:14 -0600736 tconfig = Config(board.target)
Simon Glass843312d2015-02-05 22:06:15 -0700737 for fname in CONFIG_FILENAMES:
Simon Glass843312d2015-02-05 22:06:15 -0700738 if outcome.config:
739 for key, value in outcome.config[fname].iteritems():
Simon Glass8270e3c2015-08-25 21:52:14 -0600740 tconfig.Add(fname, key, value)
741 config[board.target] = tconfig
Simon Glass843312d2015-02-05 22:06:15 -0700742
Simon Glasse30965d2014-08-28 09:43:44 -0600743 return (board_dict, err_lines_summary, err_lines_boards,
Simon Glass843312d2015-02-05 22:06:15 -0700744 warn_lines_summary, warn_lines_boards, config)
Simon Glassfc3fe1c2013-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 Glass63c619e2015-02-05 22:06:11 -0700768 str = ' %s %s' % (self.col.Color(color, char), str)
Simon Glassfc3fe1c2013-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 Glass843312d2015-02-05 22:06:15 -0700797 self._base_board_dict[board] = Builder.Outcome(0, [], [], {}, {})
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000798 self._base_err_lines = []
Simon Glasse30965d2014-08-28 09:43:44 -0600799 self._base_warn_lines = []
800 self._base_err_line_boards = {}
801 self._base_warn_line_boards = {}
Simon Glass8270e3c2015-08-25 21:52:14 -0600802 self._base_config = None
Simon Glassfc3fe1c2013-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 Glass4653a882014-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 Glassfc3fe1c2013-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 Glass4653a882014-09-05 19:00:07 -0600849 Print(msg, colour=color)
Simon Glassfc3fe1c2013-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 Glass4653a882014-09-05 19:00:07 -0600874 Print('%10s %-15s:' % ('', result['_target']),
875 newline=False)
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000876 printed_target = True
Simon Glass4653a882014-09-05 19:00:07 -0600877 Print(msg, colour=color, newline=False)
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000878 if printed_target:
Simon Glass4653a882014-09-05 19:00:07 -0600879 Print()
Simon Glassfc3fe1c2013-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 Glass4653a882014-09-05 19:00:07 -0600984 Print('%10s: (for %d/%d boards)' % (arch, count,
985 arch_count[arch]), newline=False)
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000986 printed_arch = True
Simon Glass4653a882014-09-05 19:00:07 -0600987 Print(msg, colour=color, newline=False)
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000988
989 if printed_arch:
Simon Glass4653a882014-09-05 19:00:07 -0600990 Print()
Simon Glassfc3fe1c2013-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 Glasse30965d2014-08-28 09:43:44 -0600996 err_line_boards, warn_lines, warn_line_boards,
Simon Glass843312d2015-02-05 22:06:15 -0700997 config, show_sizes, show_detail, show_bloat,
998 show_config):
Simon Glassfc3fe1c2013-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 Glassed966652014-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 Glasse30965d2014-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 Glass843312d2015-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 Glassfc3fe1c2013-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 Glass843312d2015-02-05 22:06:15 -07001026 show_config: Show config changes
Simon Glassfc3fe1c2013-04-03 11:07:16 +00001027 """
Simon Glasse30965d2014-08-28 09:43:44 -06001028 def _BoardList(line, line_boards):
Simon Glassed966652014-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 Glasse30965d2014-08-28 09:43:44 -06001039 for board in line_boards[line]:
Simon Glassf66153b2014-10-16 01:05:55 -06001040 if not board.target in names:
1041 names.append(board.target)
Simon Glassed966652014-08-28 09:43:43 -06001042 names_str = '(%s) ' % ','.join(names)
1043 else:
1044 names_str = ''
1045 return names_str
1046
Simon Glasse30965d2014-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 Glass843312d2015-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 Glass8270e3c2015-08-25 21:52:14 -06001077 return '%s %s: %s' % (delta, name, out)
Simon Glass843312d2015-02-05 22:06:15 -07001078
Simon Glass8270e3c2015-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 Glass843312d2015-02-05 22:06:15 -07001081
1082 Args:
Simon Glass8270e3c2015-08-25 21:52:14 -06001083 lines: list to add to
1084 name: config file name
Simon Glass843312d2015-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 Glass8270e3c2015-08-25 21:52:14 -06001096 lines.append(_CalcConfig('+', name, config_plus))
Simon Glass843312d2015-02-05 22:06:15 -07001097 if config_minus:
Simon Glass8270e3c2015-08-25 21:52:14 -06001098 lines.append(_CalcConfig('-', name, config_minus))
Simon Glass843312d2015-02-05 22:06:15 -07001099 if config_change:
Simon Glass8270e3c2015-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 Glass843312d2015-02-05 22:06:15 -07001114
Simon Glassfc3fe1c2013-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 Glasse30965d2014-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 Glassfc3fe1c2013-04-03 11:07:16 +00001142
1143 # Display results by arch
Simon Glasse30965d2014-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 Glassfc3fe1c2013-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 Glass4653a882014-09-05 19:00:07 -06001156 Print('%10s: %s' % (arch, target_list))
Simon Glass28370c12014-08-09 15:33:06 -06001157 self._error_lines += 1
Simon Glassfc3fe1c2013-04-03 11:07:16 +00001158 if better_err:
Simon Glass4653a882014-09-05 19:00:07 -06001159 Print('\n'.join(better_err), colour=self.col.GREEN)
Simon Glass28370c12014-08-09 15:33:06 -06001160 self._error_lines += 1
Simon Glassfc3fe1c2013-04-03 11:07:16 +00001161 if worse_err:
Simon Glass4653a882014-09-05 19:00:07 -06001162 Print('\n'.join(worse_err), colour=self.col.RED)
Simon Glass28370c12014-08-09 15:33:06 -06001163 self._error_lines += 1
Simon Glasse30965d2014-08-28 09:43:44 -06001164 if better_warn:
Simon Glass4653a882014-09-05 19:00:07 -06001165 Print('\n'.join(better_warn), colour=self.col.CYAN)
Simon Glasse30965d2014-08-28 09:43:44 -06001166 self._error_lines += 1
1167 if worse_warn:
Simon Glass4653a882014-09-05 19:00:07 -06001168 Print('\n'.join(worse_warn), colour=self.col.MAGENTA)
Simon Glasse30965d2014-08-28 09:43:44 -06001169 self._error_lines += 1
Simon Glassfc3fe1c2013-04-03 11:07:16 +00001170
1171 if show_sizes:
1172 self.PrintSizeSummary(board_selected, board_dict, show_detail,
1173 show_bloat)
1174
Simon Glass8270e3c2015-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:
Simon Glass843312d2015-02-05 22:06:15 -07001184 continue
Simon Glass8270e3c2015-08-25 21:52:14 -06001185 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:
1200 continue
1201
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 Glass843312d2015-02-05 22:06:15 -07001273
Simon Glassfc3fe1c2013-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 Glasse30965d2014-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 Glass843312d2015-02-05 22:06:15 -07001280 self._base_config = config
Simon Glassfc3fe1c2013-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 Glass4653a882014-09-05 19:00:07 -06001288 Print("Boards not built (%d): %s" % (len(not_built),
1289 ', '.join(not_built)))
Simon Glassfc3fe1c2013-04-03 11:07:16 +00001290
Simon Glassb2ea7ab2014-08-09 15:33:02 -06001291 def ProduceResultSummary(self, commit_upto, commits, board_selected):
Simon Glasse30965d2014-08-28 09:43:44 -06001292 (board_dict, err_lines, err_line_boards, warn_lines,
Simon Glass843312d2015-02-05 22:06:15 -07001293 warn_line_boards, config) = self.GetResultSummary(
Simon Glassed966652014-08-28 09:43:43 -06001294 board_selected, commit_upto,
Simon Glass843312d2015-02-05 22:06:15 -07001295 read_func_sizes=self._show_bloat,
1296 read_config=self._show_config)
Simon Glassb2ea7ab2014-08-09 15:33:02 -06001297 if commits:
1298 msg = '%02d: %s' % (commit_upto + 1,
1299 commits[commit_upto].subject)
Simon Glass4653a882014-09-05 19:00:07 -06001300 Print(msg, colour=self.col.BLUE)
Simon Glassb2ea7ab2014-08-09 15:33:02 -06001301 self.PrintResultSummary(board_selected, board_dict,
Simon Glassed966652014-08-28 09:43:43 -06001302 err_lines if self._show_errors else [], err_line_boards,
Simon Glasse30965d2014-08-28 09:43:44 -06001303 warn_lines if self._show_errors else [], warn_line_boards,
Simon Glass843312d2015-02-05 22:06:15 -07001304 config, self._show_sizes, self._show_detail,
1305 self._show_bloat, self._show_config)
Simon Glassfc3fe1c2013-04-03 11:07:16 +00001306
Simon Glassb2ea7ab2014-08-09 15:33:02 -06001307 def ShowSummary(self, commits, board_selected):
Simon Glassfc3fe1c2013-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 Glassfc3fe1c2013-04-03 11:07:16 +00001316 """
Simon Glassfea58582014-08-09 15:32:59 -06001317 self.commit_count = len(commits) if commits else 1
Simon Glassfc3fe1c2013-04-03 11:07:16 +00001318 self.commits = commits
1319 self.ResetResultSummary(board_selected)
Simon Glass28370c12014-08-09 15:33:06 -06001320 self._error_lines = 0
Simon Glassfc3fe1c2013-04-03 11:07:16 +00001321
1322 for commit_upto in range(0, self.commit_count, self._step):
Simon Glassb2ea7ab2014-08-09 15:33:02 -06001323 self.ProduceResultSummary(commit_upto, commits, board_selected)
Simon Glass28370c12014-08-09 15:33:06 -06001324 if not self._error_lines:
Simon Glass4653a882014-09-05 19:00:07 -06001325 Print('(no errors to report)', colour=self.col.GREEN)
Simon Glassfc3fe1c2013-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 Glassfea58582014-08-09 15:32:59 -06001336 count = (self.commit_count + self._step - 1) / self._step
Simon Glassfc3fe1c2013-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 Glassfc3fe1c2013-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 Glassfea58582014-08-09 15:32:59 -06001349 def _PrepareThread(self, thread_num, setup_git):
Simon Glassfc3fe1c2013-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 Glassfea58582014-08-09 15:32:59 -06001356 setup_git: True to set up a git repo clone
Simon Glassfc3fe1c2013-04-03 11:07:16 +00001357 """
1358 thread_dir = self.GetThreadDir(thread_num)
Simon Glass190064b2014-08-09 15:33:00 -06001359 builderthread.Mkdir(thread_dir)
Simon Glassfc3fe1c2013-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 Glassfea58582014-08-09 15:32:59 -06001365 if setup_git and self.git_dir:
Simon Glassfc3fe1c2013-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 Glass21f0eb32016-09-18 16:48:31 -06001370 Print('\rCloning repo for thread %d' % thread_num,
1371 newline=False)
Simon Glassfc3fe1c2013-04-03 11:07:16 +00001372 gitutil.Clone(src_dir, thread_dir)
Simon Glass21f0eb32016-09-18 16:48:31 -06001373 Print('\r%s\r' % (' ' * 30), newline=False)
Simon Glassfc3fe1c2013-04-03 11:07:16 +00001374
Simon Glassfea58582014-08-09 15:32:59 -06001375 def _PrepareWorkingSpace(self, max_threads, setup_git):
Simon Glassfc3fe1c2013-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 Glassfea58582014-08-09 15:32:59 -06001382 setup_git: True to set up a git repo clone
Simon Glassfc3fe1c2013-04-03 11:07:16 +00001383 """
Simon Glass190064b2014-08-09 15:33:00 -06001384 builderthread.Mkdir(self._working_dir)
Simon Glassfc3fe1c2013-04-03 11:07:16 +00001385 for thread in range(max_threads):
Simon Glassfea58582014-08-09 15:32:59 -06001386 self._PrepareThread(thread, setup_git)
Simon Glassfc3fe1c2013-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 Glass1a915672014-12-01 17:33:53 -07001395 if not self.commits:
1396 return
Simon Glassfc3fe1c2013-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 Glassb222abe2016-09-18 16:48:32 -06001401 to_remove = []
Simon Glassfc3fe1c2013-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 Glassb222abe2016-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 Glassfc3fe1c2013-04-03 11:07:16 +00001409 shutil.rmtree(dirname)
1410
Simon Glasse5a0e5d2014-08-09 15:33:03 -06001411 def BuildBoards(self, commits, board_selected, keep_outputs, verbose):
Simon Glassfc3fe1c2013-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 Glassfc3fe1c2013-04-03 11:07:16 +00001418 keep_outputs: True to save build output files
Simon Glasse5a0e5d2014-08-09 15:33:03 -06001419 verbose: Display build results as they are completed
Simon Glass2c3deb92014-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 Glassfc3fe1c2013-04-03 11:07:16 +00001424 """
Simon Glassfea58582014-08-09 15:32:59 -06001425 self.commit_count = len(commits) if commits else 1
Simon Glassfc3fe1c2013-04-03 11:07:16 +00001426 self.commits = commits
Simon Glasse5a0e5d2014-08-09 15:33:03 -06001427 self._verbose = verbose
Simon Glassfc3fe1c2013-04-03 11:07:16 +00001428
1429 self.ResetResultSummary(board_selected)
Thierry Redingf3d015c2014-08-19 10:22:39 +02001430 builderthread.Mkdir(self.base_dir, parents = True)
Simon Glassfea58582014-08-09 15:32:59 -06001431 self._PrepareWorkingSpace(min(self.num_threads, len(board_selected)),
1432 commits is not None)
Simon Glassfc3fe1c2013-04-03 11:07:16 +00001433 self._PrepareOutputSpace()
Simon Glass745b3952016-09-18 16:48:33 -06001434 Print('\rStarting build...', newline=False)
Simon Glassfc3fe1c2013-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 Glass190064b2014-08-09 15:33:00 -06001440 job = builderthread.BuilderJob()
Simon Glassfc3fe1c2013-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 Glassd436e382016-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 Glassfc3fe1c2013-04-03 11:07:16 +00001452
1453 # Wait until we have processed all output
1454 self.out_queue.join()
Simon Glass4653a882014-09-05 19:00:07 -06001455 Print()
Simon Glassfc3fe1c2013-04-03 11:07:16 +00001456 self.ClearLine(0)
Simon Glass2c3deb92014-08-28 09:43:39 -06001457 return (self.fail, self.warned)