Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 2 | # Copyright (c) 2013 The Chromium OS Authors. |
| 3 | # |
| 4 | # Bloat-o-meter code used here Copyright 2004 Matt Mackall <mpm@selenic.com> |
| 5 | # |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 6 | |
| 7 | import collections |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 8 | from datetime import datetime, timedelta |
| 9 | import glob |
| 10 | import os |
| 11 | import re |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 12 | import queue |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 13 | import shutil |
Simon Glass | 205ac04 | 2016-09-18 16:48:37 -0600 | [diff] [blame] | 14 | import signal |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 15 | import string |
| 16 | import sys |
Simon Glass | d26e144 | 2016-09-18 16:48:35 -0600 | [diff] [blame] | 17 | import threading |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 18 | import time |
| 19 | |
Simon Glass | f0d9c10 | 2020-04-17 18:09:02 -0600 | [diff] [blame] | 20 | from buildman import builderthread |
| 21 | from buildman import toolchain |
Simon Glass | a997ea5 | 2020-04-17 18:09:04 -0600 | [diff] [blame] | 22 | from patman import command |
| 23 | from patman import gitutil |
| 24 | from patman import terminal |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 25 | from patman.terminal import tprint |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 26 | |
Simon Glass | 146b602 | 2021-10-19 21:43:24 -0600 | [diff] [blame] | 27 | # This indicates an new int or hex Kconfig property with no default |
| 28 | # It hangs the build since the 'conf' tool cannot proceed without valid input. |
| 29 | # |
| 30 | # We get a repeat sequence of something like this: |
| 31 | # >> |
| 32 | # Break things (BREAK_ME) [] (NEW) |
| 33 | # Error in reading or end of file. |
| 34 | # << |
| 35 | # which indicates that BREAK_ME has an empty default |
| 36 | RE_NO_DEFAULT = re.compile(b'\((\w+)\) \[] \(NEW\)') |
| 37 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 38 | """ |
| 39 | Theory of Operation |
| 40 | |
| 41 | Please see README for user documentation, and you should be familiar with |
| 42 | that before trying to make sense of this. |
| 43 | |
| 44 | Buildman works by keeping the machine as busy as possible, building different |
| 45 | commits for different boards on multiple CPUs at once. |
| 46 | |
| 47 | The source repo (self.git_dir) contains all the commits to be built. Each |
| 48 | thread works on a single board at a time. It checks out the first commit, |
| 49 | configures it for that board, then builds it. Then it checks out the next |
| 50 | commit and builds it (typically without re-configuring). When it runs out |
| 51 | of commits, it gets another job from the builder and starts again with that |
| 52 | board. |
| 53 | |
| 54 | Clearly the builder threads could work either way - they could check out a |
| 55 | commit and then built it for all boards. Using separate directories for each |
| 56 | commit/board pair they could leave their build product around afterwards |
| 57 | also. |
| 58 | |
| 59 | The intent behind building a single board for multiple commits, is to make |
| 60 | use of incremental builds. Since each commit is built incrementally from |
| 61 | the previous one, builds are faster. Reconfiguring for a different board |
| 62 | removes all intermediate object files. |
| 63 | |
| 64 | Many threads can be working at once, but each has its own working directory. |
| 65 | When a thread finishes a build, it puts the output files into a result |
| 66 | directory. |
| 67 | |
| 68 | The base directory used by buildman is normally '../<branch>', i.e. |
| 69 | a directory higher than the source repository and named after the branch |
| 70 | being built. |
| 71 | |
| 72 | Within the base directory, we have one subdirectory for each commit. Within |
| 73 | that is one subdirectory for each board. Within that is the build output for |
| 74 | that commit/board combination. |
| 75 | |
| 76 | Buildman also create working directories for each thread, in a .bm-work/ |
| 77 | subdirectory in the base dir. |
| 78 | |
| 79 | As an example, say we are building branch 'us-net' for boards 'sandbox' and |
| 80 | 'seaboard', and say that us-net has two commits. We will have directories |
| 81 | like this: |
| 82 | |
| 83 | us-net/ base directory |
Ovidiu Panait | ee8e9cb | 2020-05-15 09:30:12 +0300 | [diff] [blame] | 84 | 01_g4ed4ebc_net--Add-tftp-speed-/ |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 85 | sandbox/ |
| 86 | u-boot.bin |
| 87 | seaboard/ |
| 88 | u-boot.bin |
Ovidiu Panait | ee8e9cb | 2020-05-15 09:30:12 +0300 | [diff] [blame] | 89 | 02_g4ed4ebc_net--Check-tftp-comp/ |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 90 | sandbox/ |
| 91 | u-boot.bin |
| 92 | seaboard/ |
| 93 | u-boot.bin |
| 94 | .bm-work/ |
| 95 | 00/ working directory for thread 0 (contains source checkout) |
| 96 | build/ build output |
| 97 | 01/ working directory for thread 1 |
| 98 | build/ build output |
| 99 | ... |
| 100 | u-boot/ source directory |
| 101 | .git/ repository |
| 102 | """ |
| 103 | |
Simon Glass | de0fefc | 2020-04-09 15:08:36 -0600 | [diff] [blame] | 104 | """Holds information about a particular error line we are outputing |
| 105 | |
| 106 | char: Character representation: '+': error, '-': fixed error, 'w+': warning, |
| 107 | 'w-' = fixed warning |
| 108 | boards: List of Board objects which have line in the error/warning output |
| 109 | errline: The text of the error line |
| 110 | """ |
Simon Glass | 5df4522 | 2022-07-11 19:04:00 -0600 | [diff] [blame] | 111 | ErrLine = collections.namedtuple('ErrLine', 'char,brds,errline') |
Simon Glass | de0fefc | 2020-04-09 15:08:36 -0600 | [diff] [blame] | 112 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 113 | # Possible build outcomes |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 114 | OUTCOME_OK, OUTCOME_WARNING, OUTCOME_ERROR, OUTCOME_UNKNOWN = list(range(4)) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 115 | |
Simon Glass | d214bef | 2017-04-12 18:23:26 -0600 | [diff] [blame] | 116 | # Translate a commit subject into a valid filename (and handle unicode) |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 117 | trans_valid_chars = str.maketrans('/: ', '---') |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 118 | |
Simon Glass | cde5c30 | 2016-11-13 14:25:53 -0700 | [diff] [blame] | 119 | BASE_CONFIG_FILENAMES = [ |
| 120 | 'u-boot.cfg', 'u-boot-spl.cfg', 'u-boot-tpl.cfg' |
| 121 | ] |
| 122 | |
| 123 | EXTRA_CONFIG_FILENAMES = [ |
Simon Glass | db17fb8 | 2015-02-05 22:06:15 -0700 | [diff] [blame] | 124 | '.config', '.config-spl', '.config-tpl', |
| 125 | 'autoconf.mk', 'autoconf-spl.mk', 'autoconf-tpl.mk', |
| 126 | 'autoconf.h', 'autoconf-spl.h','autoconf-tpl.h', |
Simon Glass | db17fb8 | 2015-02-05 22:06:15 -0700 | [diff] [blame] | 127 | ] |
| 128 | |
Simon Glass | cad8abf | 2015-08-25 21:52:14 -0600 | [diff] [blame] | 129 | class Config: |
| 130 | """Holds information about configuration settings for a board.""" |
Simon Glass | cde5c30 | 2016-11-13 14:25:53 -0700 | [diff] [blame] | 131 | def __init__(self, config_filename, target): |
Simon Glass | cad8abf | 2015-08-25 21:52:14 -0600 | [diff] [blame] | 132 | self.target = target |
| 133 | self.config = {} |
Simon Glass | cde5c30 | 2016-11-13 14:25:53 -0700 | [diff] [blame] | 134 | for fname in config_filename: |
Simon Glass | cad8abf | 2015-08-25 21:52:14 -0600 | [diff] [blame] | 135 | self.config[fname] = {} |
| 136 | |
| 137 | def Add(self, fname, key, value): |
| 138 | self.config[fname][key] = value |
| 139 | |
| 140 | def __hash__(self): |
| 141 | val = 0 |
| 142 | for fname in self.config: |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 143 | for key, value in self.config[fname].items(): |
| 144 | print(key, value) |
Simon Glass | cad8abf | 2015-08-25 21:52:14 -0600 | [diff] [blame] | 145 | val = val ^ hash(key) & hash(value) |
| 146 | return val |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 147 | |
Alex Kiernan | 4059e30 | 2018-05-31 04:48:34 +0000 | [diff] [blame] | 148 | class Environment: |
| 149 | """Holds information about environment variables for a board.""" |
| 150 | def __init__(self, target): |
| 151 | self.target = target |
| 152 | self.environment = {} |
| 153 | |
| 154 | def Add(self, key, value): |
| 155 | self.environment[key] = value |
| 156 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 157 | class Builder: |
| 158 | """Class for building U-Boot for a particular commit. |
| 159 | |
| 160 | Public members: (many should ->private) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 161 | already_done: Number of builds already completed |
| 162 | base_dir: Base directory to use for builder |
| 163 | checkout: True to check out source, False to skip that step. |
| 164 | This is used for testing. |
| 165 | col: terminal.Color() object |
| 166 | count: Number of commits to build |
| 167 | do_make: Method to call to invoke Make |
| 168 | fail: Number of builds that failed due to error |
| 169 | force_build: Force building even if a build already exists |
| 170 | force_config_on_failure: If a commit fails for a board, disable |
| 171 | incremental building for the next commit we build for that |
| 172 | board, so that we will see all warnings/errors again. |
Simon Glass | 7041c39 | 2014-07-13 12:22:31 -0600 | [diff] [blame] | 173 | force_build_failures: If a previously-built build (i.e. built on |
| 174 | a previous run of buildman) is marked as failed, rebuild it. |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 175 | git_dir: Git directory containing source repository |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 176 | num_jobs: Number of jobs to run at once (passed to make as -j) |
| 177 | num_threads: Number of builder threads to run |
| 178 | out_queue: Queue of results to process |
| 179 | re_make_err: Compiled regular expression for ignore_lines |
| 180 | queue: Queue of jobs to run |
| 181 | threads: List of active threads |
| 182 | toolchains: Toolchains object to use for building |
| 183 | upto: Current commit number we are building (0.count-1) |
| 184 | warned: Number of builds that produced at least one warning |
Simon Glass | f3018b7a | 2014-07-14 17:51:02 -0600 | [diff] [blame] | 185 | force_reconfig: Reconfigure U-Boot on each comiit. This disables |
| 186 | incremental building, where buildman reconfigures on the first |
| 187 | commit for a baord, and then just does an incremental build for |
| 188 | the following commits. In fact buildman will reconfigure and |
| 189 | retry for any failing commits, so generally the only effect of |
| 190 | this option is to slow things down. |
Simon Glass | 38df2e2 | 2014-07-14 17:51:03 -0600 | [diff] [blame] | 191 | in_tree: Build U-Boot in-tree instead of specifying an output |
| 192 | directory separate from the source code. This option is really |
| 193 | only useful for testing in-tree builds. |
Simon Glass | b6eb8cf | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 194 | work_in_output: Use the output directory as the work directory and |
| 195 | don't write to a separate output directory. |
Simon Glass | 9bf9a72 | 2021-04-11 16:27:27 +1200 | [diff] [blame] | 196 | thread_exceptions: List of exceptions raised by thread jobs |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 197 | |
| 198 | Private members: |
| 199 | _base_board_dict: Last-summarised Dict of boards |
| 200 | _base_err_lines: Last-summarised list of errors |
Simon Glass | 03749d4 | 2014-08-28 09:43:44 -0600 | [diff] [blame] | 201 | _base_warn_lines: Last-summarised list of warnings |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 202 | _build_period_us: Time taken for a single build (float object). |
| 203 | _complete_delay: Expected delay until completion (timedelta) |
| 204 | _next_delay_update: Next time we plan to display a progress update |
| 205 | (datatime) |
| 206 | _show_unknown: Show unknown boards (those not built) in summary |
Simon Glass | 726ae81 | 2020-04-09 15:08:47 -0600 | [diff] [blame] | 207 | _start_time: Start time for the build |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 208 | _timestamps: List of timestamps for the completion of the last |
| 209 | last _timestamp_count builds. Each is a datetime object. |
| 210 | _timestamp_count: Number of timestamps to keep in our list. |
| 211 | _working_dir: Base working directory containing all threads |
Simon Glass | c635d89 | 2021-01-30 22:17:46 -0700 | [diff] [blame] | 212 | _single_builder: BuilderThread object for the singer builder, if |
| 213 | threading is not being used |
Simon Glass | 146b602 | 2021-10-19 21:43:24 -0600 | [diff] [blame] | 214 | _terminated: Thread was terminated due to an error |
| 215 | _restarting_config: True if 'Restart config' is detected in output |
Simon Glass | 6c43562 | 2022-07-11 19:03:56 -0600 | [diff] [blame] | 216 | _ide: Produce output suitable for an Integrated Development Environment, |
| 217 | i.e. dont emit progress information and put errors/warnings on stderr |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 218 | """ |
| 219 | class Outcome: |
| 220 | """Records a build outcome for a single make invocation |
| 221 | |
| 222 | Public Members: |
| 223 | rc: Outcome value (OUTCOME_...) |
| 224 | err_lines: List of error lines or [] if none |
| 225 | sizes: Dictionary of image size information, keyed by filename |
| 226 | - Each value is itself a dictionary containing |
| 227 | values for 'text', 'data' and 'bss', being the integer |
| 228 | size in bytes of each section. |
| 229 | func_sizes: Dictionary keyed by filename - e.g. 'u-boot'. Each |
| 230 | value is itself a dictionary: |
| 231 | key: function name |
| 232 | value: Size of function in bytes |
Simon Glass | db17fb8 | 2015-02-05 22:06:15 -0700 | [diff] [blame] | 233 | config: Dictionary keyed by filename - e.g. '.config'. Each |
| 234 | value is itself a dictionary: |
| 235 | key: config name |
| 236 | value: config value |
Alex Kiernan | 4059e30 | 2018-05-31 04:48:34 +0000 | [diff] [blame] | 237 | environment: Dictionary keyed by environment variable, Each |
| 238 | value is the value of environment variable. |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 239 | """ |
Alex Kiernan | 4059e30 | 2018-05-31 04:48:34 +0000 | [diff] [blame] | 240 | def __init__(self, rc, err_lines, sizes, func_sizes, config, |
| 241 | environment): |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 242 | self.rc = rc |
| 243 | self.err_lines = err_lines |
| 244 | self.sizes = sizes |
| 245 | self.func_sizes = func_sizes |
Simon Glass | db17fb8 | 2015-02-05 22:06:15 -0700 | [diff] [blame] | 246 | self.config = config |
Alex Kiernan | 4059e30 | 2018-05-31 04:48:34 +0000 | [diff] [blame] | 247 | self.environment = environment |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 248 | |
| 249 | def __init__(self, toolchains, base_dir, git_dir, num_threads, num_jobs, |
Simon Glass | e87bde1 | 2014-12-01 17:33:55 -0700 | [diff] [blame] | 250 | gnu_make='make', checkout=True, show_unknown=True, step=1, |
Stephen Warren | 97c9690 | 2016-04-11 10:48:44 -0600 | [diff] [blame] | 251 | no_subdirs=False, full_path=False, verbose_build=False, |
Simon Glass | 6029af1 | 2020-04-09 15:08:51 -0600 | [diff] [blame] | 252 | mrproper=False, per_board_out_dir=False, |
Daniel Schwierzeck | 20e2ea9 | 2018-01-26 16:31:05 +0100 | [diff] [blame] | 253 | config_only=False, squash_config_y=False, |
Simon Glass | 9bf9a72 | 2021-04-11 16:27:27 +1200 | [diff] [blame] | 254 | warnings_as_errors=False, work_in_output=False, |
Simon Glass | e5650a8 | 2022-01-22 05:07:33 -0700 | [diff] [blame] | 255 | test_thread_exceptions=False, adjust_cfg=None): |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 256 | """Create a new Builder object |
| 257 | |
| 258 | Args: |
| 259 | toolchains: Toolchains object to use for building |
| 260 | base_dir: Base directory to use for builder |
| 261 | git_dir: Git directory containing source repository |
| 262 | num_threads: Number of builder threads to run |
| 263 | num_jobs: Number of jobs to run at once (passed to make as -j) |
Masahiro Yamada | 1fe610d | 2014-07-22 11:19:09 +0900 | [diff] [blame] | 264 | gnu_make: the command name of GNU Make. |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 265 | checkout: True to check out source, False to skip that step. |
| 266 | This is used for testing. |
| 267 | show_unknown: Show unknown boards (those not built) in summary |
| 268 | step: 1 to process every commit, n to process every nth commit |
Simon Glass | d48a46c | 2014-12-01 17:34:00 -0700 | [diff] [blame] | 269 | no_subdirs: Don't create subdirectories when building current |
| 270 | source for a single board |
| 271 | full_path: Return the full path in CROSS_COMPILE and don't set |
| 272 | PATH |
Simon Glass | 655b610 | 2014-12-01 17:34:07 -0700 | [diff] [blame] | 273 | verbose_build: Run build with V=1 and don't use 'make -s' |
Simon Glass | 6029af1 | 2020-04-09 15:08:51 -0600 | [diff] [blame] | 274 | mrproper: Always run 'make mrproper' when configuring |
Stephen Warren | 97c9690 | 2016-04-11 10:48:44 -0600 | [diff] [blame] | 275 | per_board_out_dir: Build in a separate persistent directory per |
| 276 | board rather than a thread-specific directory |
Simon Glass | 739e851 | 2016-11-13 14:25:51 -0700 | [diff] [blame] | 277 | config_only: Only configure each build, don't build it |
Simon Glass | cde5c30 | 2016-11-13 14:25:53 -0700 | [diff] [blame] | 278 | squash_config_y: Convert CONFIG options with the value 'y' to '1' |
Daniel Schwierzeck | 20e2ea9 | 2018-01-26 16:31:05 +0100 | [diff] [blame] | 279 | warnings_as_errors: Treat all compiler warnings as errors |
Simon Glass | b6eb8cf | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 280 | work_in_output: Use the output directory as the work directory and |
| 281 | don't write to a separate output directory. |
Simon Glass | 9bf9a72 | 2021-04-11 16:27:27 +1200 | [diff] [blame] | 282 | test_thread_exceptions: Uses for tests only, True to make the |
| 283 | threads raise an exception instead of reporting their result. |
| 284 | This simulates a failure in the code somewhere |
Simon Glass | e5650a8 | 2022-01-22 05:07:33 -0700 | [diff] [blame] | 285 | adjust_cfg_list (list of str): List of changes to make to .config |
| 286 | file before building. Each is one of (where C is the config |
| 287 | option with or without the CONFIG_ prefix) |
| 288 | |
| 289 | C to enable C |
| 290 | ~C to disable C |
| 291 | C=val to set the value of C (val must have quotes if C is |
| 292 | a string Kconfig |
| 293 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 294 | """ |
| 295 | self.toolchains = toolchains |
| 296 | self.base_dir = base_dir |
Simon Glass | b6eb8cf | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 297 | if work_in_output: |
| 298 | self._working_dir = base_dir |
| 299 | else: |
| 300 | self._working_dir = os.path.join(base_dir, '.bm-work') |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 301 | self.threads = [] |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 302 | self.do_make = self.Make |
Masahiro Yamada | 1fe610d | 2014-07-22 11:19:09 +0900 | [diff] [blame] | 303 | self.gnu_make = gnu_make |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 304 | self.checkout = checkout |
| 305 | self.num_threads = num_threads |
| 306 | self.num_jobs = num_jobs |
| 307 | self.already_done = 0 |
| 308 | self.force_build = False |
| 309 | self.git_dir = git_dir |
| 310 | self._show_unknown = show_unknown |
| 311 | self._timestamp_count = 10 |
| 312 | self._build_period_us = None |
| 313 | self._complete_delay = None |
| 314 | self._next_delay_update = datetime.now() |
Simon Glass | 726ae81 | 2020-04-09 15:08:47 -0600 | [diff] [blame] | 315 | self._start_time = datetime.now() |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 316 | self.force_config_on_failure = True |
Simon Glass | 7041c39 | 2014-07-13 12:22:31 -0600 | [diff] [blame] | 317 | self.force_build_failures = False |
Simon Glass | f3018b7a | 2014-07-14 17:51:02 -0600 | [diff] [blame] | 318 | self.force_reconfig = False |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 319 | self._step = step |
Simon Glass | 38df2e2 | 2014-07-14 17:51:03 -0600 | [diff] [blame] | 320 | self.in_tree = False |
Simon Glass | bb4dffb | 2014-08-09 15:33:06 -0600 | [diff] [blame] | 321 | self._error_lines = 0 |
Simon Glass | e87bde1 | 2014-12-01 17:33:55 -0700 | [diff] [blame] | 322 | self.no_subdirs = no_subdirs |
Simon Glass | d48a46c | 2014-12-01 17:34:00 -0700 | [diff] [blame] | 323 | self.full_path = full_path |
Simon Glass | 655b610 | 2014-12-01 17:34:07 -0700 | [diff] [blame] | 324 | self.verbose_build = verbose_build |
Simon Glass | 739e851 | 2016-11-13 14:25:51 -0700 | [diff] [blame] | 325 | self.config_only = config_only |
Simon Glass | cde5c30 | 2016-11-13 14:25:53 -0700 | [diff] [blame] | 326 | self.squash_config_y = squash_config_y |
| 327 | self.config_filenames = BASE_CONFIG_FILENAMES |
Simon Glass | b6eb8cf | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 328 | self.work_in_output = work_in_output |
Simon Glass | e5650a8 | 2022-01-22 05:07:33 -0700 | [diff] [blame] | 329 | self.adjust_cfg = adjust_cfg |
Simon Glass | 6c43562 | 2022-07-11 19:03:56 -0600 | [diff] [blame] | 330 | self._ide = False |
Simon Glass | e5650a8 | 2022-01-22 05:07:33 -0700 | [diff] [blame] | 331 | |
Simon Glass | cde5c30 | 2016-11-13 14:25:53 -0700 | [diff] [blame] | 332 | if not self.squash_config_y: |
| 333 | self.config_filenames += EXTRA_CONFIG_FILENAMES |
Simon Glass | 146b602 | 2021-10-19 21:43:24 -0600 | [diff] [blame] | 334 | self._terminated = False |
| 335 | self._restarting_config = False |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 336 | |
Daniel Schwierzeck | 20e2ea9 | 2018-01-26 16:31:05 +0100 | [diff] [blame] | 337 | self.warnings_as_errors = warnings_as_errors |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 338 | self.col = terminal.Color() |
| 339 | |
Simon Glass | 03749d4 | 2014-08-28 09:43:44 -0600 | [diff] [blame] | 340 | self._re_function = re.compile('(.*): In function.*') |
| 341 | self._re_files = re.compile('In file included from.*') |
| 342 | self._re_warning = re.compile('(.*):(\d*):(\d*): warning: .*') |
Simon Glass | 0db9443 | 2018-11-06 16:02:11 -0700 | [diff] [blame] | 343 | self._re_dtb_warning = re.compile('(.*): Warning .*') |
Simon Glass | 03749d4 | 2014-08-28 09:43:44 -0600 | [diff] [blame] | 344 | self._re_note = re.compile('(.*):(\d*):(\d*): note: this is the location of the previous.*') |
Simon Glass | f4ebfba | 2020-04-09 15:08:53 -0600 | [diff] [blame] | 345 | self._re_migration_warning = re.compile(r'^={21} WARNING ={22}\n.*\n=+\n', |
| 346 | re.MULTILINE | re.DOTALL) |
Simon Glass | 03749d4 | 2014-08-28 09:43:44 -0600 | [diff] [blame] | 347 | |
Simon Glass | 9bf9a72 | 2021-04-11 16:27:27 +1200 | [diff] [blame] | 348 | self.thread_exceptions = [] |
| 349 | self.test_thread_exceptions = test_thread_exceptions |
Simon Glass | c635d89 | 2021-01-30 22:17:46 -0700 | [diff] [blame] | 350 | if self.num_threads: |
| 351 | self._single_builder = None |
| 352 | self.queue = queue.Queue() |
| 353 | self.out_queue = queue.Queue() |
| 354 | for i in range(self.num_threads): |
Simon Glass | 9bf9a72 | 2021-04-11 16:27:27 +1200 | [diff] [blame] | 355 | t = builderthread.BuilderThread( |
| 356 | self, i, mrproper, per_board_out_dir, |
| 357 | test_exception=test_thread_exceptions) |
Simon Glass | c635d89 | 2021-01-30 22:17:46 -0700 | [diff] [blame] | 358 | t.setDaemon(True) |
| 359 | t.start() |
| 360 | self.threads.append(t) |
| 361 | |
| 362 | t = builderthread.ResultThread(self) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 363 | t.setDaemon(True) |
| 364 | t.start() |
| 365 | self.threads.append(t) |
Simon Glass | c635d89 | 2021-01-30 22:17:46 -0700 | [diff] [blame] | 366 | else: |
| 367 | self._single_builder = builderthread.BuilderThread( |
| 368 | self, -1, mrproper, per_board_out_dir) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 369 | |
| 370 | ignore_lines = ['(make.*Waiting for unfinished)', '(Segmentation fault)'] |
| 371 | self.re_make_err = re.compile('|'.join(ignore_lines)) |
| 372 | |
Simon Glass | 205ac04 | 2016-09-18 16:48:37 -0600 | [diff] [blame] | 373 | # Handle existing graceful with SIGINT / Ctrl-C |
| 374 | signal.signal(signal.SIGINT, self.signal_handler) |
| 375 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 376 | def __del__(self): |
| 377 | """Get rid of all threads created by the builder""" |
| 378 | for t in self.threads: |
| 379 | del t |
| 380 | |
Simon Glass | 205ac04 | 2016-09-18 16:48:37 -0600 | [diff] [blame] | 381 | def signal_handler(self, signal, frame): |
| 382 | sys.exit(1) |
| 383 | |
Simon Glass | eb48bbc | 2014-08-09 15:33:02 -0600 | [diff] [blame] | 384 | def SetDisplayOptions(self, show_errors=False, show_sizes=False, |
Simon Glass | 3394c9f | 2014-08-28 09:43:43 -0600 | [diff] [blame] | 385 | show_detail=False, show_bloat=False, |
Alex Kiernan | 4059e30 | 2018-05-31 04:48:34 +0000 | [diff] [blame] | 386 | list_error_boards=False, show_config=False, |
Simon Glass | f4ebfba | 2020-04-09 15:08:53 -0600 | [diff] [blame] | 387 | show_environment=False, filter_dtb_warnings=False, |
Simon Glass | 6c43562 | 2022-07-11 19:03:56 -0600 | [diff] [blame] | 388 | filter_migration_warnings=False, ide=False): |
Simon Glass | eb48bbc | 2014-08-09 15:33:02 -0600 | [diff] [blame] | 389 | """Setup display options for the builder. |
| 390 | |
Simon Glass | 9ea9381 | 2020-04-09 15:08:52 -0600 | [diff] [blame] | 391 | Args: |
| 392 | show_errors: True to show summarised error/warning info |
| 393 | show_sizes: Show size deltas |
| 394 | show_detail: Show size delta detail for each board if show_sizes |
| 395 | show_bloat: Show detail for each function |
| 396 | list_error_boards: Show the boards which caused each error/warning |
| 397 | show_config: Show config deltas |
| 398 | show_environment: Show environment deltas |
| 399 | filter_dtb_warnings: Filter out any warnings from the device-tree |
| 400 | compiler |
Simon Glass | f4ebfba | 2020-04-09 15:08:53 -0600 | [diff] [blame] | 401 | filter_migration_warnings: Filter out any warnings about migrating |
| 402 | a board to driver model |
Simon Glass | 6c43562 | 2022-07-11 19:03:56 -0600 | [diff] [blame] | 403 | ide: Create output that can be parsed by an IDE. There is no '+' prefix on |
| 404 | error lines and output on stderr stays on stderr. |
Simon Glass | eb48bbc | 2014-08-09 15:33:02 -0600 | [diff] [blame] | 405 | """ |
| 406 | self._show_errors = show_errors |
| 407 | self._show_sizes = show_sizes |
| 408 | self._show_detail = show_detail |
| 409 | self._show_bloat = show_bloat |
Simon Glass | 3394c9f | 2014-08-28 09:43:43 -0600 | [diff] [blame] | 410 | self._list_error_boards = list_error_boards |
Simon Glass | db17fb8 | 2015-02-05 22:06:15 -0700 | [diff] [blame] | 411 | self._show_config = show_config |
Alex Kiernan | 4059e30 | 2018-05-31 04:48:34 +0000 | [diff] [blame] | 412 | self._show_environment = show_environment |
Simon Glass | 9ea9381 | 2020-04-09 15:08:52 -0600 | [diff] [blame] | 413 | self._filter_dtb_warnings = filter_dtb_warnings |
Simon Glass | f4ebfba | 2020-04-09 15:08:53 -0600 | [diff] [blame] | 414 | self._filter_migration_warnings = filter_migration_warnings |
Simon Glass | 6c43562 | 2022-07-11 19:03:56 -0600 | [diff] [blame] | 415 | self._ide = ide |
Simon Glass | eb48bbc | 2014-08-09 15:33:02 -0600 | [diff] [blame] | 416 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 417 | def _AddTimestamp(self): |
| 418 | """Add a new timestamp to the list and record the build period. |
| 419 | |
| 420 | The build period is the length of time taken to perform a single |
| 421 | build (one board, one commit). |
| 422 | """ |
| 423 | now = datetime.now() |
| 424 | self._timestamps.append(now) |
| 425 | count = len(self._timestamps) |
| 426 | delta = self._timestamps[-1] - self._timestamps[0] |
| 427 | seconds = delta.total_seconds() |
| 428 | |
| 429 | # If we have enough data, estimate build period (time taken for a |
| 430 | # single build) and therefore completion time. |
| 431 | if count > 1 and self._next_delay_update < now: |
| 432 | self._next_delay_update = now + timedelta(seconds=2) |
| 433 | if seconds > 0: |
| 434 | self._build_period = float(seconds) / count |
| 435 | todo = self.count - self.upto |
| 436 | self._complete_delay = timedelta(microseconds= |
| 437 | self._build_period * todo * 1000000) |
| 438 | # Round it |
| 439 | self._complete_delay -= timedelta( |
| 440 | microseconds=self._complete_delay.microseconds) |
| 441 | |
| 442 | if seconds > 60: |
| 443 | self._timestamps.popleft() |
| 444 | count -= 1 |
| 445 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 446 | def SelectCommit(self, commit, checkout=True): |
| 447 | """Checkout the selected commit for this build |
| 448 | """ |
| 449 | self.commit = commit |
| 450 | if checkout and self.checkout: |
Simon Glass | 761648b | 2022-01-29 14:14:11 -0700 | [diff] [blame] | 451 | gitutil.checkout(commit.hash) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 452 | |
| 453 | def Make(self, commit, brd, stage, cwd, *args, **kwargs): |
| 454 | """Run make |
| 455 | |
| 456 | Args: |
| 457 | commit: Commit object that is being built |
| 458 | brd: Board object that is being built |
Roger Meier | e0a0e55 | 2014-08-20 22:10:29 +0200 | [diff] [blame] | 459 | stage: Stage that we are at (mrproper, config, build) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 460 | cwd: Directory where make should be run |
| 461 | args: Arguments to pass to make |
Simon Glass | 840be73 | 2022-01-29 14:14:05 -0700 | [diff] [blame] | 462 | kwargs: Arguments to pass to command.run_pipe() |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 463 | """ |
Simon Glass | 146b602 | 2021-10-19 21:43:24 -0600 | [diff] [blame] | 464 | |
| 465 | def check_output(stream, data): |
| 466 | if b'Restart config' in data: |
| 467 | self._restarting_config = True |
| 468 | |
| 469 | # If we see 'Restart config' following by multiple errors |
| 470 | if self._restarting_config: |
| 471 | m = RE_NO_DEFAULT.findall(data) |
| 472 | |
| 473 | # Number of occurences of each Kconfig item |
| 474 | multiple = [m.count(val) for val in set(m)] |
| 475 | |
| 476 | # If any of them occur more than once, we have a loop |
| 477 | if [val for val in multiple if val > 1]: |
| 478 | self._terminated = True |
| 479 | return True |
| 480 | return False |
| 481 | |
| 482 | self._restarting_config = False |
| 483 | self._terminated = False |
Masahiro Yamada | 1fe610d | 2014-07-22 11:19:09 +0900 | [diff] [blame] | 484 | cmd = [self.gnu_make] + list(args) |
Simon Glass | 840be73 | 2022-01-29 14:14:05 -0700 | [diff] [blame] | 485 | result = command.run_pipe([cmd], capture=True, capture_stderr=True, |
Simon Glass | 146b602 | 2021-10-19 21:43:24 -0600 | [diff] [blame] | 486 | cwd=cwd, raise_on_error=False, infile='/dev/null', |
| 487 | output_func=check_output, **kwargs) |
| 488 | |
| 489 | if self._terminated: |
| 490 | # Try to be helpful |
| 491 | result.stderr += '(** did you define an int/hex Kconfig with no default? **)' |
| 492 | |
Simon Glass | 413f91a | 2015-02-05 22:06:12 -0700 | [diff] [blame] | 493 | if self.verbose_build: |
| 494 | result.stdout = '%s\n' % (' '.join(cmd)) + result.stdout |
| 495 | result.combined = '%s\n' % (' '.join(cmd)) + result.combined |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 496 | return result |
| 497 | |
| 498 | def ProcessResult(self, result): |
| 499 | """Process the result of a build, showing progress information |
| 500 | |
| 501 | Args: |
Simon Glass | 78e418e | 2014-08-09 15:33:03 -0600 | [diff] [blame] | 502 | result: A CommandResult object, which indicates the result for |
| 503 | a single build |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 504 | """ |
| 505 | col = terminal.Color() |
| 506 | if result: |
| 507 | target = result.brd.target |
| 508 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 509 | self.upto += 1 |
| 510 | if result.return_code != 0: |
| 511 | self.fail += 1 |
| 512 | elif result.stderr: |
| 513 | self.warned += 1 |
| 514 | if result.already_done: |
| 515 | self.already_done += 1 |
Simon Glass | 78e418e | 2014-08-09 15:33:03 -0600 | [diff] [blame] | 516 | if self._verbose: |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 517 | terminal.print_clear() |
Simon Glass | 78e418e | 2014-08-09 15:33:03 -0600 | [diff] [blame] | 518 | boards_selected = {target : result.brd} |
| 519 | self.ResetResultSummary(boards_selected) |
| 520 | self.ProduceResultSummary(result.commit_upto, self.commits, |
| 521 | boards_selected) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 522 | else: |
| 523 | target = '(starting)' |
| 524 | |
| 525 | # Display separate counts for ok, warned and fail |
| 526 | ok = self.upto - self.warned - self.fail |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 527 | line = '\r' + self.col.build(self.col.GREEN, '%5d' % ok) |
| 528 | line += self.col.build(self.col.YELLOW, '%5d' % self.warned) |
| 529 | line += self.col.build(self.col.RED, '%5d' % self.fail) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 530 | |
Simon Glass | 69c3a8a | 2020-04-09 15:08:45 -0600 | [diff] [blame] | 531 | line += ' /%-5d ' % self.count |
| 532 | remaining = self.count - self.upto |
| 533 | if remaining: |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 534 | line += self.col.build(self.col.MAGENTA, ' -%-5d ' % remaining) |
Simon Glass | 69c3a8a | 2020-04-09 15:08:45 -0600 | [diff] [blame] | 535 | else: |
| 536 | line += ' ' * 8 |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 537 | |
| 538 | # Add our current completion time estimate |
| 539 | self._AddTimestamp() |
| 540 | if self._complete_delay: |
Simon Glass | 69c3a8a | 2020-04-09 15:08:45 -0600 | [diff] [blame] | 541 | line += '%s : ' % self._complete_delay |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 542 | |
Simon Glass | 69c3a8a | 2020-04-09 15:08:45 -0600 | [diff] [blame] | 543 | line += target |
Simon Glass | 6c43562 | 2022-07-11 19:03:56 -0600 | [diff] [blame] | 544 | if not self._ide: |
| 545 | terminal.print_clear() |
| 546 | tprint(line, newline=False, limit_to_line=True) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 547 | |
| 548 | def _GetOutputDir(self, commit_upto): |
| 549 | """Get the name of the output directory for a commit number |
| 550 | |
| 551 | The output directory is typically .../<branch>/<commit>. |
| 552 | |
| 553 | Args: |
| 554 | commit_upto: Commit number to use (0..self.count-1) |
| 555 | """ |
Simon Glass | e3c85ab | 2020-04-17 17:51:34 -0600 | [diff] [blame] | 556 | if self.work_in_output: |
| 557 | return self._working_dir |
| 558 | |
Simon Glass | e87bde1 | 2014-12-01 17:33:55 -0700 | [diff] [blame] | 559 | commit_dir = None |
Simon Glass | d326ad7 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 560 | if self.commits: |
| 561 | commit = self.commits[commit_upto] |
| 562 | subject = commit.subject.translate(trans_valid_chars) |
Simon Glass | 5dc1ca7 | 2020-03-18 09:42:45 -0600 | [diff] [blame] | 563 | # See _GetOutputSpaceRemovals() which parses this name |
Ovidiu Panait | ee8e9cb | 2020-05-15 09:30:12 +0300 | [diff] [blame] | 564 | commit_dir = ('%02d_g%s_%s' % (commit_upto + 1, |
| 565 | commit.hash, subject[:20])) |
Simon Glass | e87bde1 | 2014-12-01 17:33:55 -0700 | [diff] [blame] | 566 | elif not self.no_subdirs: |
Simon Glass | d326ad7 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 567 | commit_dir = 'current' |
Simon Glass | e87bde1 | 2014-12-01 17:33:55 -0700 | [diff] [blame] | 568 | if not commit_dir: |
| 569 | return self.base_dir |
| 570 | return os.path.join(self.base_dir, commit_dir) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 571 | |
| 572 | def GetBuildDir(self, commit_upto, target): |
| 573 | """Get the name of the build directory for a commit number |
| 574 | |
| 575 | The build directory is typically .../<branch>/<commit>/<target>. |
| 576 | |
| 577 | Args: |
| 578 | commit_upto: Commit number to use (0..self.count-1) |
| 579 | target: Target name |
| 580 | """ |
| 581 | output_dir = self._GetOutputDir(commit_upto) |
Simon Glass | e3c85ab | 2020-04-17 17:51:34 -0600 | [diff] [blame] | 582 | if self.work_in_output: |
| 583 | return output_dir |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 584 | return os.path.join(output_dir, target) |
| 585 | |
| 586 | def GetDoneFile(self, commit_upto, target): |
| 587 | """Get the name of the done file for a commit number |
| 588 | |
| 589 | Args: |
| 590 | commit_upto: Commit number to use (0..self.count-1) |
| 591 | target: Target name |
| 592 | """ |
| 593 | return os.path.join(self.GetBuildDir(commit_upto, target), 'done') |
| 594 | |
| 595 | def GetSizesFile(self, commit_upto, target): |
| 596 | """Get the name of the sizes file for a commit number |
| 597 | |
| 598 | Args: |
| 599 | commit_upto: Commit number to use (0..self.count-1) |
| 600 | target: Target name |
| 601 | """ |
| 602 | return os.path.join(self.GetBuildDir(commit_upto, target), 'sizes') |
| 603 | |
| 604 | def GetFuncSizesFile(self, commit_upto, target, elf_fname): |
| 605 | """Get the name of the funcsizes file for a commit number and ELF file |
| 606 | |
| 607 | Args: |
| 608 | commit_upto: Commit number to use (0..self.count-1) |
| 609 | target: Target name |
| 610 | elf_fname: Filename of elf image |
| 611 | """ |
| 612 | return os.path.join(self.GetBuildDir(commit_upto, target), |
| 613 | '%s.sizes' % elf_fname.replace('/', '-')) |
| 614 | |
| 615 | def GetObjdumpFile(self, commit_upto, target, elf_fname): |
| 616 | """Get the name of the objdump file for a commit number and ELF file |
| 617 | |
| 618 | Args: |
| 619 | commit_upto: Commit number to use (0..self.count-1) |
| 620 | target: Target name |
| 621 | elf_fname: Filename of elf image |
| 622 | """ |
| 623 | return os.path.join(self.GetBuildDir(commit_upto, target), |
| 624 | '%s.objdump' % elf_fname.replace('/', '-')) |
| 625 | |
| 626 | def GetErrFile(self, commit_upto, target): |
| 627 | """Get the name of the err file for a commit number |
| 628 | |
| 629 | Args: |
| 630 | commit_upto: Commit number to use (0..self.count-1) |
| 631 | target: Target name |
| 632 | """ |
| 633 | output_dir = self.GetBuildDir(commit_upto, target) |
| 634 | return os.path.join(output_dir, 'err') |
| 635 | |
| 636 | def FilterErrors(self, lines): |
| 637 | """Filter out errors in which we have no interest |
| 638 | |
| 639 | We should probably use map(). |
| 640 | |
| 641 | Args: |
| 642 | lines: List of error lines, each a string |
| 643 | Returns: |
| 644 | New list with only interesting lines included |
| 645 | """ |
| 646 | out_lines = [] |
Simon Glass | f4ebfba | 2020-04-09 15:08:53 -0600 | [diff] [blame] | 647 | if self._filter_migration_warnings: |
| 648 | text = '\n'.join(lines) |
| 649 | text = self._re_migration_warning.sub('', text) |
| 650 | lines = text.splitlines() |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 651 | for line in lines: |
Simon Glass | 9ea9381 | 2020-04-09 15:08:52 -0600 | [diff] [blame] | 652 | if self.re_make_err.search(line): |
| 653 | continue |
| 654 | if self._filter_dtb_warnings and self._re_dtb_warning.search(line): |
| 655 | continue |
| 656 | out_lines.append(line) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 657 | return out_lines |
| 658 | |
| 659 | def ReadFuncSizes(self, fname, fd): |
| 660 | """Read function sizes from the output of 'nm' |
| 661 | |
| 662 | Args: |
| 663 | fd: File containing data to read |
| 664 | fname: Filename we are reading from (just for errors) |
| 665 | |
| 666 | Returns: |
| 667 | Dictionary containing size of each function in bytes, indexed by |
| 668 | function name. |
| 669 | """ |
| 670 | sym = {} |
| 671 | for line in fd.readlines(): |
Simon Glass | 86a2afe | 2022-07-11 19:04:11 -0600 | [diff] [blame] | 672 | line = line.strip() |
| 673 | parts = line.split() |
| 674 | if line and len(parts) == 3: |
| 675 | size, type, name = line.split() |
| 676 | if type in 'tTdDbB': |
| 677 | # function names begin with '.' on 64-bit powerpc |
| 678 | if '.' in name[1:]: |
| 679 | name = 'static.' + name.split('.')[0] |
| 680 | sym[name] = sym.get(name, 0) + int(size, 16) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 681 | return sym |
| 682 | |
Simon Glass | db17fb8 | 2015-02-05 22:06:15 -0700 | [diff] [blame] | 683 | def _ProcessConfig(self, fname): |
| 684 | """Read in a .config, autoconf.mk or autoconf.h file |
| 685 | |
| 686 | This function handles all config file types. It ignores comments and |
| 687 | any #defines which don't start with CONFIG_. |
| 688 | |
| 689 | Args: |
| 690 | fname: Filename to read |
| 691 | |
| 692 | Returns: |
| 693 | Dictionary: |
| 694 | key: Config name (e.g. CONFIG_DM) |
| 695 | value: Config value (e.g. 1) |
| 696 | """ |
| 697 | config = {} |
| 698 | if os.path.exists(fname): |
| 699 | with open(fname) as fd: |
| 700 | for line in fd: |
| 701 | line = line.strip() |
| 702 | if line.startswith('#define'): |
| 703 | values = line[8:].split(' ', 1) |
| 704 | if len(values) > 1: |
| 705 | key, value = values |
| 706 | else: |
| 707 | key = values[0] |
Simon Glass | cde5c30 | 2016-11-13 14:25:53 -0700 | [diff] [blame] | 708 | value = '1' if self.squash_config_y else '' |
Simon Glass | db17fb8 | 2015-02-05 22:06:15 -0700 | [diff] [blame] | 709 | if not key.startswith('CONFIG_'): |
| 710 | continue |
| 711 | elif not line or line[0] in ['#', '*', '/']: |
| 712 | continue |
| 713 | else: |
| 714 | key, value = line.split('=', 1) |
Simon Glass | cde5c30 | 2016-11-13 14:25:53 -0700 | [diff] [blame] | 715 | if self.squash_config_y and value == 'y': |
| 716 | value = '1' |
Simon Glass | db17fb8 | 2015-02-05 22:06:15 -0700 | [diff] [blame] | 717 | config[key] = value |
| 718 | return config |
| 719 | |
Alex Kiernan | 4059e30 | 2018-05-31 04:48:34 +0000 | [diff] [blame] | 720 | def _ProcessEnvironment(self, fname): |
| 721 | """Read in a uboot.env file |
| 722 | |
| 723 | This function reads in environment variables from a file. |
| 724 | |
| 725 | Args: |
| 726 | fname: Filename to read |
| 727 | |
| 728 | Returns: |
| 729 | Dictionary: |
| 730 | key: environment variable (e.g. bootlimit) |
| 731 | value: value of environment variable (e.g. 1) |
| 732 | """ |
| 733 | environment = {} |
| 734 | if os.path.exists(fname): |
| 735 | with open(fname) as fd: |
| 736 | for line in fd.read().split('\0'): |
| 737 | try: |
| 738 | key, value = line.split('=', 1) |
| 739 | environment[key] = value |
| 740 | except ValueError: |
| 741 | # ignore lines we can't parse |
| 742 | pass |
| 743 | return environment |
| 744 | |
Simon Glass | db17fb8 | 2015-02-05 22:06:15 -0700 | [diff] [blame] | 745 | def GetBuildOutcome(self, commit_upto, target, read_func_sizes, |
Alex Kiernan | 4059e30 | 2018-05-31 04:48:34 +0000 | [diff] [blame] | 746 | read_config, read_environment): |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 747 | """Work out the outcome of a build. |
| 748 | |
| 749 | Args: |
| 750 | commit_upto: Commit number to check (0..n-1) |
| 751 | target: Target board to check |
| 752 | read_func_sizes: True to read function size information |
Simon Glass | db17fb8 | 2015-02-05 22:06:15 -0700 | [diff] [blame] | 753 | read_config: True to read .config and autoconf.h files |
Alex Kiernan | 4059e30 | 2018-05-31 04:48:34 +0000 | [diff] [blame] | 754 | read_environment: True to read uboot.env files |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 755 | |
| 756 | Returns: |
| 757 | Outcome object |
| 758 | """ |
| 759 | done_file = self.GetDoneFile(commit_upto, target) |
| 760 | sizes_file = self.GetSizesFile(commit_upto, target) |
| 761 | sizes = {} |
| 762 | func_sizes = {} |
Simon Glass | db17fb8 | 2015-02-05 22:06:15 -0700 | [diff] [blame] | 763 | config = {} |
Alex Kiernan | 4059e30 | 2018-05-31 04:48:34 +0000 | [diff] [blame] | 764 | environment = {} |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 765 | if os.path.exists(done_file): |
| 766 | with open(done_file, 'r') as fd: |
Simon Glass | 91c54a4 | 2019-04-26 19:02:23 -0600 | [diff] [blame] | 767 | try: |
| 768 | return_code = int(fd.readline()) |
| 769 | except ValueError: |
| 770 | # The file may be empty due to running out of disk space. |
| 771 | # Try a rebuild |
| 772 | return_code = 1 |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 773 | err_lines = [] |
| 774 | err_file = self.GetErrFile(commit_upto, target) |
| 775 | if os.path.exists(err_file): |
| 776 | with open(err_file, 'r') as fd: |
| 777 | err_lines = self.FilterErrors(fd.readlines()) |
| 778 | |
| 779 | # Decide whether the build was ok, failed or created warnings |
| 780 | if return_code: |
| 781 | rc = OUTCOME_ERROR |
| 782 | elif len(err_lines): |
| 783 | rc = OUTCOME_WARNING |
| 784 | else: |
| 785 | rc = OUTCOME_OK |
| 786 | |
| 787 | # Convert size information to our simple format |
| 788 | if os.path.exists(sizes_file): |
| 789 | with open(sizes_file, 'r') as fd: |
| 790 | for line in fd.readlines(): |
| 791 | values = line.split() |
| 792 | rodata = 0 |
| 793 | if len(values) > 6: |
| 794 | rodata = int(values[6], 16) |
| 795 | size_dict = { |
| 796 | 'all' : int(values[0]) + int(values[1]) + |
| 797 | int(values[2]), |
| 798 | 'text' : int(values[0]) - rodata, |
| 799 | 'data' : int(values[1]), |
| 800 | 'bss' : int(values[2]), |
| 801 | 'rodata' : rodata, |
| 802 | } |
| 803 | sizes[values[5]] = size_dict |
| 804 | |
| 805 | if read_func_sizes: |
| 806 | pattern = self.GetFuncSizesFile(commit_upto, target, '*') |
| 807 | for fname in glob.glob(pattern): |
| 808 | with open(fname, 'r') as fd: |
| 809 | dict_name = os.path.basename(fname).replace('.sizes', |
| 810 | '') |
| 811 | func_sizes[dict_name] = self.ReadFuncSizes(fname, fd) |
| 812 | |
Simon Glass | db17fb8 | 2015-02-05 22:06:15 -0700 | [diff] [blame] | 813 | if read_config: |
| 814 | output_dir = self.GetBuildDir(commit_upto, target) |
Simon Glass | cde5c30 | 2016-11-13 14:25:53 -0700 | [diff] [blame] | 815 | for name in self.config_filenames: |
Simon Glass | db17fb8 | 2015-02-05 22:06:15 -0700 | [diff] [blame] | 816 | fname = os.path.join(output_dir, name) |
| 817 | config[name] = self._ProcessConfig(fname) |
| 818 | |
Alex Kiernan | 4059e30 | 2018-05-31 04:48:34 +0000 | [diff] [blame] | 819 | if read_environment: |
| 820 | output_dir = self.GetBuildDir(commit_upto, target) |
| 821 | fname = os.path.join(output_dir, 'uboot.env') |
| 822 | environment = self._ProcessEnvironment(fname) |
| 823 | |
| 824 | return Builder.Outcome(rc, err_lines, sizes, func_sizes, config, |
| 825 | environment) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 826 | |
Alex Kiernan | 4059e30 | 2018-05-31 04:48:34 +0000 | [diff] [blame] | 827 | return Builder.Outcome(OUTCOME_UNKNOWN, [], {}, {}, {}, {}) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 828 | |
Simon Glass | db17fb8 | 2015-02-05 22:06:15 -0700 | [diff] [blame] | 829 | def GetResultSummary(self, boards_selected, commit_upto, read_func_sizes, |
Alex Kiernan | 4059e30 | 2018-05-31 04:48:34 +0000 | [diff] [blame] | 830 | read_config, read_environment): |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 831 | """Calculate a summary of the results of building a commit. |
| 832 | |
| 833 | Args: |
| 834 | board_selected: Dict containing boards to summarise |
| 835 | commit_upto: Commit number to summarize (0..self.count-1) |
| 836 | read_func_sizes: True to read function size information |
Simon Glass | db17fb8 | 2015-02-05 22:06:15 -0700 | [diff] [blame] | 837 | read_config: True to read .config and autoconf.h files |
Alex Kiernan | 4059e30 | 2018-05-31 04:48:34 +0000 | [diff] [blame] | 838 | read_environment: True to read uboot.env files |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 839 | |
| 840 | Returns: |
| 841 | Tuple: |
Simon Glass | 6c43562 | 2022-07-11 19:03:56 -0600 | [diff] [blame] | 842 | Dict containing boards which built this commit: |
| 843 | key: board.target |
| 844 | value: Builder.Outcome object |
Simon Glass | 03749d4 | 2014-08-28 09:43:44 -0600 | [diff] [blame] | 845 | List containing a summary of error lines |
Simon Glass | 3394c9f | 2014-08-28 09:43:43 -0600 | [diff] [blame] | 846 | Dict keyed by error line, containing a list of the Board |
| 847 | objects with that error |
Simon Glass | 03749d4 | 2014-08-28 09:43:44 -0600 | [diff] [blame] | 848 | List containing a summary of warning lines |
| 849 | Dict keyed by error line, containing a list of the Board |
| 850 | objects with that warning |
Simon Glass | cad8abf | 2015-08-25 21:52:14 -0600 | [diff] [blame] | 851 | Dictionary keyed by board.target. Each value is a dictionary: |
| 852 | key: filename - e.g. '.config' |
Simon Glass | db17fb8 | 2015-02-05 22:06:15 -0700 | [diff] [blame] | 853 | value is itself a dictionary: |
| 854 | key: config name |
| 855 | value: config value |
Alex Kiernan | 4059e30 | 2018-05-31 04:48:34 +0000 | [diff] [blame] | 856 | Dictionary keyed by board.target. Each value is a dictionary: |
| 857 | key: environment variable |
| 858 | value: value of environment variable |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 859 | """ |
Simon Glass | 03749d4 | 2014-08-28 09:43:44 -0600 | [diff] [blame] | 860 | def AddLine(lines_summary, lines_boards, line, board): |
| 861 | line = line.rstrip() |
| 862 | if line in lines_boards: |
| 863 | lines_boards[line].append(board) |
| 864 | else: |
| 865 | lines_boards[line] = [board] |
| 866 | lines_summary.append(line) |
| 867 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 868 | board_dict = {} |
| 869 | err_lines_summary = [] |
Simon Glass | 3394c9f | 2014-08-28 09:43:43 -0600 | [diff] [blame] | 870 | err_lines_boards = {} |
Simon Glass | 03749d4 | 2014-08-28 09:43:44 -0600 | [diff] [blame] | 871 | warn_lines_summary = [] |
| 872 | warn_lines_boards = {} |
Simon Glass | db17fb8 | 2015-02-05 22:06:15 -0700 | [diff] [blame] | 873 | config = {} |
Alex Kiernan | 4059e30 | 2018-05-31 04:48:34 +0000 | [diff] [blame] | 874 | environment = {} |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 875 | |
Simon Glass | 8132f98 | 2022-07-11 19:03:57 -0600 | [diff] [blame] | 876 | for brd in boards_selected.values(): |
| 877 | outcome = self.GetBuildOutcome(commit_upto, brd.target, |
Alex Kiernan | 4059e30 | 2018-05-31 04:48:34 +0000 | [diff] [blame] | 878 | read_func_sizes, read_config, |
| 879 | read_environment) |
Simon Glass | 8132f98 | 2022-07-11 19:03:57 -0600 | [diff] [blame] | 880 | board_dict[brd.target] = outcome |
Simon Glass | 03749d4 | 2014-08-28 09:43:44 -0600 | [diff] [blame] | 881 | last_func = None |
| 882 | last_was_warning = False |
| 883 | for line in outcome.err_lines: |
| 884 | if line: |
| 885 | if (self._re_function.match(line) or |
| 886 | self._re_files.match(line)): |
| 887 | last_func = line |
Simon Glass | 3394c9f | 2014-08-28 09:43:43 -0600 | [diff] [blame] | 888 | else: |
Simon Glass | 0db9443 | 2018-11-06 16:02:11 -0700 | [diff] [blame] | 889 | is_warning = (self._re_warning.match(line) or |
| 890 | self._re_dtb_warning.match(line)) |
Simon Glass | 03749d4 | 2014-08-28 09:43:44 -0600 | [diff] [blame] | 891 | is_note = self._re_note.match(line) |
| 892 | if is_warning or (last_was_warning and is_note): |
| 893 | if last_func: |
| 894 | AddLine(warn_lines_summary, warn_lines_boards, |
Simon Glass | 8132f98 | 2022-07-11 19:03:57 -0600 | [diff] [blame] | 895 | last_func, brd) |
Simon Glass | 03749d4 | 2014-08-28 09:43:44 -0600 | [diff] [blame] | 896 | AddLine(warn_lines_summary, warn_lines_boards, |
Simon Glass | 8132f98 | 2022-07-11 19:03:57 -0600 | [diff] [blame] | 897 | line, brd) |
Simon Glass | 03749d4 | 2014-08-28 09:43:44 -0600 | [diff] [blame] | 898 | else: |
| 899 | if last_func: |
| 900 | AddLine(err_lines_summary, err_lines_boards, |
Simon Glass | 8132f98 | 2022-07-11 19:03:57 -0600 | [diff] [blame] | 901 | last_func, brd) |
Simon Glass | 03749d4 | 2014-08-28 09:43:44 -0600 | [diff] [blame] | 902 | AddLine(err_lines_summary, err_lines_boards, |
Simon Glass | 8132f98 | 2022-07-11 19:03:57 -0600 | [diff] [blame] | 903 | line, brd) |
Simon Glass | 03749d4 | 2014-08-28 09:43:44 -0600 | [diff] [blame] | 904 | last_was_warning = is_warning |
| 905 | last_func = None |
Simon Glass | 8132f98 | 2022-07-11 19:03:57 -0600 | [diff] [blame] | 906 | tconfig = Config(self.config_filenames, brd.target) |
Simon Glass | cde5c30 | 2016-11-13 14:25:53 -0700 | [diff] [blame] | 907 | for fname in self.config_filenames: |
Simon Glass | db17fb8 | 2015-02-05 22:06:15 -0700 | [diff] [blame] | 908 | if outcome.config: |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 909 | for key, value in outcome.config[fname].items(): |
Simon Glass | cad8abf | 2015-08-25 21:52:14 -0600 | [diff] [blame] | 910 | tconfig.Add(fname, key, value) |
Simon Glass | 8132f98 | 2022-07-11 19:03:57 -0600 | [diff] [blame] | 911 | config[brd.target] = tconfig |
Simon Glass | db17fb8 | 2015-02-05 22:06:15 -0700 | [diff] [blame] | 912 | |
Simon Glass | 8132f98 | 2022-07-11 19:03:57 -0600 | [diff] [blame] | 913 | tenvironment = Environment(brd.target) |
Alex Kiernan | 4059e30 | 2018-05-31 04:48:34 +0000 | [diff] [blame] | 914 | if outcome.environment: |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 915 | for key, value in outcome.environment.items(): |
Alex Kiernan | 4059e30 | 2018-05-31 04:48:34 +0000 | [diff] [blame] | 916 | tenvironment.Add(key, value) |
Simon Glass | 8132f98 | 2022-07-11 19:03:57 -0600 | [diff] [blame] | 917 | environment[brd.target] = tenvironment |
Alex Kiernan | 4059e30 | 2018-05-31 04:48:34 +0000 | [diff] [blame] | 918 | |
Simon Glass | 03749d4 | 2014-08-28 09:43:44 -0600 | [diff] [blame] | 919 | return (board_dict, err_lines_summary, err_lines_boards, |
Alex Kiernan | 4059e30 | 2018-05-31 04:48:34 +0000 | [diff] [blame] | 920 | warn_lines_summary, warn_lines_boards, config, environment) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 921 | |
| 922 | def AddOutcome(self, board_dict, arch_list, changes, char, color): |
| 923 | """Add an output to our list of outcomes for each architecture |
| 924 | |
| 925 | This simple function adds failing boards (changes) to the |
| 926 | relevant architecture string, so we can print the results out |
| 927 | sorted by architecture. |
| 928 | |
| 929 | Args: |
| 930 | board_dict: Dict containing all boards |
| 931 | arch_list: Dict keyed by arch name. Value is a string containing |
| 932 | a list of board names which failed for that arch. |
| 933 | changes: List of boards to add to arch_list |
| 934 | color: terminal.Colour object |
| 935 | """ |
| 936 | done_arch = {} |
| 937 | for target in changes: |
| 938 | if target in board_dict: |
| 939 | arch = board_dict[target].arch |
| 940 | else: |
| 941 | arch = 'unknown' |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 942 | str = self.col.build(color, ' ' + target) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 943 | if not arch in done_arch: |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 944 | str = ' %s %s' % (self.col.build(color, char), str) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 945 | done_arch[arch] = True |
| 946 | if not arch in arch_list: |
| 947 | arch_list[arch] = str |
| 948 | else: |
| 949 | arch_list[arch] += str |
| 950 | |
| 951 | |
| 952 | def ColourNum(self, num): |
| 953 | color = self.col.RED if num > 0 else self.col.GREEN |
| 954 | if num == 0: |
| 955 | return '0' |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 956 | return self.col.build(color, str(num)) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 957 | |
| 958 | def ResetResultSummary(self, board_selected): |
| 959 | """Reset the results summary ready for use. |
| 960 | |
| 961 | Set up the base board list to be all those selected, and set the |
| 962 | error lines to empty. |
| 963 | |
| 964 | Following this, calls to PrintResultSummary() will use this |
| 965 | information to work out what has changed. |
| 966 | |
| 967 | Args: |
| 968 | board_selected: Dict containing boards to summarise, keyed by |
| 969 | board.target |
| 970 | """ |
| 971 | self._base_board_dict = {} |
Simon Glass | 8132f98 | 2022-07-11 19:03:57 -0600 | [diff] [blame] | 972 | for brd in board_selected: |
| 973 | self._base_board_dict[brd] = Builder.Outcome(0, [], [], {}, {}, {}) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 974 | self._base_err_lines = [] |
Simon Glass | 03749d4 | 2014-08-28 09:43:44 -0600 | [diff] [blame] | 975 | self._base_warn_lines = [] |
| 976 | self._base_err_line_boards = {} |
| 977 | self._base_warn_line_boards = {} |
Simon Glass | cad8abf | 2015-08-25 21:52:14 -0600 | [diff] [blame] | 978 | self._base_config = None |
Alex Kiernan | 4059e30 | 2018-05-31 04:48:34 +0000 | [diff] [blame] | 979 | self._base_environment = None |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 980 | |
| 981 | def PrintFuncSizeDetail(self, fname, old, new): |
| 982 | grow, shrink, add, remove, up, down = 0, 0, 0, 0, 0, 0 |
| 983 | delta, common = [], {} |
| 984 | |
| 985 | for a in old: |
| 986 | if a in new: |
| 987 | common[a] = 1 |
| 988 | |
| 989 | for name in old: |
| 990 | if name not in common: |
| 991 | remove += 1 |
| 992 | down += old[name] |
| 993 | delta.append([-old[name], name]) |
| 994 | |
| 995 | for name in new: |
| 996 | if name not in common: |
| 997 | add += 1 |
| 998 | up += new[name] |
| 999 | delta.append([new[name], name]) |
| 1000 | |
| 1001 | for name in common: |
| 1002 | diff = new.get(name, 0) - old.get(name, 0) |
| 1003 | if diff > 0: |
| 1004 | grow, up = grow + 1, up + diff |
| 1005 | elif diff < 0: |
| 1006 | shrink, down = shrink + 1, down - diff |
| 1007 | delta.append([diff, name]) |
| 1008 | |
| 1009 | delta.sort() |
| 1010 | delta.reverse() |
| 1011 | |
| 1012 | args = [add, -remove, grow, -shrink, up, -down, up - down] |
Tom Rini | 0b48cd6 | 2017-05-22 13:48:52 -0400 | [diff] [blame] | 1013 | if max(args) == 0 and min(args) == 0: |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1014 | return |
| 1015 | args = [self.ColourNum(x) for x in args] |
| 1016 | indent = ' ' * 15 |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 1017 | tprint('%s%s: add: %s/%s, grow: %s/%s bytes: %s/%s (%s)' % |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 1018 | tuple([indent, self.col.build(self.col.YELLOW, fname)] + args)) |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 1019 | tprint('%s %-38s %7s %7s %+7s' % (indent, 'function', 'old', 'new', |
Simon Glass | 4433aa9 | 2014-09-05 19:00:07 -0600 | [diff] [blame] | 1020 | 'delta')) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1021 | for diff, name in delta: |
| 1022 | if diff: |
| 1023 | color = self.col.RED if diff > 0 else self.col.GREEN |
| 1024 | msg = '%s %-38s %7s %7s %+7d' % (indent, name, |
| 1025 | old.get(name, '-'), new.get(name,'-'), diff) |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 1026 | tprint(msg, colour=color) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1027 | |
| 1028 | |
| 1029 | def PrintSizeDetail(self, target_list, show_bloat): |
| 1030 | """Show details size information for each board |
| 1031 | |
| 1032 | Args: |
| 1033 | target_list: List of targets, each a dict containing: |
| 1034 | 'target': Target name |
| 1035 | 'total_diff': Total difference in bytes across all areas |
| 1036 | <part_name>: Difference for that part |
| 1037 | show_bloat: Show detail for each function |
| 1038 | """ |
| 1039 | targets_by_diff = sorted(target_list, reverse=True, |
| 1040 | key=lambda x: x['_total_diff']) |
| 1041 | for result in targets_by_diff: |
| 1042 | printed_target = False |
| 1043 | for name in sorted(result): |
| 1044 | diff = result[name] |
| 1045 | if name.startswith('_'): |
| 1046 | continue |
| 1047 | if diff != 0: |
| 1048 | color = self.col.RED if diff > 0 else self.col.GREEN |
| 1049 | msg = ' %s %+d' % (name, diff) |
| 1050 | if not printed_target: |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 1051 | tprint('%10s %-15s:' % ('', result['_target']), |
Simon Glass | 4433aa9 | 2014-09-05 19:00:07 -0600 | [diff] [blame] | 1052 | newline=False) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1053 | printed_target = True |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 1054 | tprint(msg, colour=color, newline=False) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1055 | if printed_target: |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 1056 | tprint() |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1057 | if show_bloat: |
| 1058 | target = result['_target'] |
| 1059 | outcome = result['_outcome'] |
| 1060 | base_outcome = self._base_board_dict[target] |
| 1061 | for fname in outcome.func_sizes: |
| 1062 | self.PrintFuncSizeDetail(fname, |
| 1063 | base_outcome.func_sizes[fname], |
| 1064 | outcome.func_sizes[fname]) |
| 1065 | |
| 1066 | |
| 1067 | def PrintSizeSummary(self, board_selected, board_dict, show_detail, |
| 1068 | show_bloat): |
| 1069 | """Print a summary of image sizes broken down by section. |
| 1070 | |
| 1071 | The summary takes the form of one line per architecture. The |
| 1072 | line contains deltas for each of the sections (+ means the section |
Flavio Suligoi | e5e3c11 | 2020-01-29 09:56:05 +0100 | [diff] [blame] | 1073 | got bigger, - means smaller). The numbers are the average number |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1074 | of bytes that a board in this section increased by. |
| 1075 | |
| 1076 | For example: |
| 1077 | powerpc: (622 boards) text -0.0 |
| 1078 | arm: (285 boards) text -0.0 |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1079 | |
| 1080 | Args: |
| 1081 | board_selected: Dict containing boards to summarise, keyed by |
| 1082 | board.target |
| 1083 | board_dict: Dict containing boards for which we built this |
| 1084 | commit, keyed by board.target. The value is an Outcome object. |
Simon Glass | b400246 | 2020-03-18 09:42:43 -0600 | [diff] [blame] | 1085 | show_detail: Show size delta detail for each board |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1086 | show_bloat: Show detail for each function |
| 1087 | """ |
| 1088 | arch_list = {} |
| 1089 | arch_count = {} |
| 1090 | |
| 1091 | # Calculate changes in size for different image parts |
| 1092 | # The previous sizes are in Board.sizes, for each board |
| 1093 | for target in board_dict: |
| 1094 | if target not in board_selected: |
| 1095 | continue |
| 1096 | base_sizes = self._base_board_dict[target].sizes |
| 1097 | outcome = board_dict[target] |
| 1098 | sizes = outcome.sizes |
| 1099 | |
| 1100 | # Loop through the list of images, creating a dict of size |
| 1101 | # changes for each image/part. We end up with something like |
| 1102 | # {'target' : 'snapper9g45, 'data' : 5, 'u-boot-spl:text' : -4} |
| 1103 | # which means that U-Boot data increased by 5 bytes and SPL |
| 1104 | # text decreased by 4. |
| 1105 | err = {'_target' : target} |
| 1106 | for image in sizes: |
| 1107 | if image in base_sizes: |
| 1108 | base_image = base_sizes[image] |
| 1109 | # Loop through the text, data, bss parts |
| 1110 | for part in sorted(sizes[image]): |
| 1111 | diff = sizes[image][part] - base_image[part] |
| 1112 | col = None |
| 1113 | if diff: |
| 1114 | if image == 'u-boot': |
| 1115 | name = part |
| 1116 | else: |
| 1117 | name = image + ':' + part |
| 1118 | err[name] = diff |
| 1119 | arch = board_selected[target].arch |
| 1120 | if not arch in arch_count: |
| 1121 | arch_count[arch] = 1 |
| 1122 | else: |
| 1123 | arch_count[arch] += 1 |
| 1124 | if not sizes: |
| 1125 | pass # Only add to our list when we have some stats |
| 1126 | elif not arch in arch_list: |
| 1127 | arch_list[arch] = [err] |
| 1128 | else: |
| 1129 | arch_list[arch].append(err) |
| 1130 | |
| 1131 | # We now have a list of image size changes sorted by arch |
| 1132 | # Print out a summary of these |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 1133 | for arch, target_list in arch_list.items(): |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1134 | # Get total difference for each type |
| 1135 | totals = {} |
| 1136 | for result in target_list: |
| 1137 | total = 0 |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 1138 | for name, diff in result.items(): |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1139 | if name.startswith('_'): |
| 1140 | continue |
| 1141 | total += diff |
| 1142 | if name in totals: |
| 1143 | totals[name] += diff |
| 1144 | else: |
| 1145 | totals[name] = diff |
| 1146 | result['_total_diff'] = total |
| 1147 | result['_outcome'] = board_dict[result['_target']] |
| 1148 | |
| 1149 | count = len(target_list) |
| 1150 | printed_arch = False |
| 1151 | for name in sorted(totals): |
| 1152 | diff = totals[name] |
| 1153 | if diff: |
| 1154 | # Display the average difference in this name for this |
| 1155 | # architecture |
| 1156 | avg_diff = float(diff) / count |
| 1157 | color = self.col.RED if avg_diff > 0 else self.col.GREEN |
| 1158 | msg = ' %s %+1.1f' % (name, avg_diff) |
| 1159 | if not printed_arch: |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 1160 | tprint('%10s: (for %d/%d boards)' % (arch, count, |
Simon Glass | 4433aa9 | 2014-09-05 19:00:07 -0600 | [diff] [blame] | 1161 | arch_count[arch]), newline=False) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1162 | printed_arch = True |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 1163 | tprint(msg, colour=color, newline=False) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1164 | |
| 1165 | if printed_arch: |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 1166 | tprint() |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1167 | if show_detail: |
| 1168 | self.PrintSizeDetail(target_list, show_bloat) |
| 1169 | |
| 1170 | |
| 1171 | def PrintResultSummary(self, board_selected, board_dict, err_lines, |
Simon Glass | 03749d4 | 2014-08-28 09:43:44 -0600 | [diff] [blame] | 1172 | err_line_boards, warn_lines, warn_line_boards, |
Alex Kiernan | 4059e30 | 2018-05-31 04:48:34 +0000 | [diff] [blame] | 1173 | config, environment, show_sizes, show_detail, |
| 1174 | show_bloat, show_config, show_environment): |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1175 | """Compare results with the base results and display delta. |
| 1176 | |
| 1177 | Only boards mentioned in board_selected will be considered. This |
| 1178 | function is intended to be called repeatedly with the results of |
| 1179 | each commit. It therefore shows a 'diff' between what it saw in |
| 1180 | the last call and what it sees now. |
| 1181 | |
| 1182 | Args: |
| 1183 | board_selected: Dict containing boards to summarise, keyed by |
| 1184 | board.target |
| 1185 | board_dict: Dict containing boards for which we built this |
| 1186 | commit, keyed by board.target. The value is an Outcome object. |
| 1187 | err_lines: A list of errors for this commit, or [] if there is |
| 1188 | none, or we don't want to print errors |
Simon Glass | 3394c9f | 2014-08-28 09:43:43 -0600 | [diff] [blame] | 1189 | err_line_boards: Dict keyed by error line, containing a list of |
| 1190 | the Board objects with that error |
Simon Glass | 03749d4 | 2014-08-28 09:43:44 -0600 | [diff] [blame] | 1191 | warn_lines: A list of warnings for this commit, or [] if there is |
| 1192 | none, or we don't want to print errors |
| 1193 | warn_line_boards: Dict keyed by warning line, containing a list of |
| 1194 | the Board objects with that warning |
Simon Glass | db17fb8 | 2015-02-05 22:06:15 -0700 | [diff] [blame] | 1195 | config: Dictionary keyed by filename - e.g. '.config'. Each |
| 1196 | value is itself a dictionary: |
| 1197 | key: config name |
| 1198 | value: config value |
Alex Kiernan | 4059e30 | 2018-05-31 04:48:34 +0000 | [diff] [blame] | 1199 | environment: Dictionary keyed by environment variable, Each |
| 1200 | value is the value of environment variable. |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1201 | show_sizes: Show image size deltas |
Simon Glass | b400246 | 2020-03-18 09:42:43 -0600 | [diff] [blame] | 1202 | show_detail: Show size delta detail for each board if show_sizes |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1203 | show_bloat: Show detail for each function |
Simon Glass | db17fb8 | 2015-02-05 22:06:15 -0700 | [diff] [blame] | 1204 | show_config: Show config changes |
Alex Kiernan | 4059e30 | 2018-05-31 04:48:34 +0000 | [diff] [blame] | 1205 | show_environment: Show environment changes |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1206 | """ |
Simon Glass | 03749d4 | 2014-08-28 09:43:44 -0600 | [diff] [blame] | 1207 | def _BoardList(line, line_boards): |
Simon Glass | 3394c9f | 2014-08-28 09:43:43 -0600 | [diff] [blame] | 1208 | """Helper function to get a line of boards containing a line |
| 1209 | |
| 1210 | Args: |
| 1211 | line: Error line to search for |
Simon Glass | de0fefc | 2020-04-09 15:08:36 -0600 | [diff] [blame] | 1212 | line_boards: boards to search, each a Board |
Simon Glass | 3394c9f | 2014-08-28 09:43:43 -0600 | [diff] [blame] | 1213 | Return: |
Simon Glass | de0fefc | 2020-04-09 15:08:36 -0600 | [diff] [blame] | 1214 | List of boards with that error line, or [] if the user has not |
| 1215 | requested such a list |
Simon Glass | 3394c9f | 2014-08-28 09:43:43 -0600 | [diff] [blame] | 1216 | """ |
Simon Glass | 5df4522 | 2022-07-11 19:04:00 -0600 | [diff] [blame] | 1217 | brds = [] |
Simon Glass | de0fefc | 2020-04-09 15:08:36 -0600 | [diff] [blame] | 1218 | board_set = set() |
Simon Glass | 3394c9f | 2014-08-28 09:43:43 -0600 | [diff] [blame] | 1219 | if self._list_error_boards: |
Simon Glass | 8132f98 | 2022-07-11 19:03:57 -0600 | [diff] [blame] | 1220 | for brd in line_boards[line]: |
| 1221 | if not brd in board_set: |
Simon Glass | 5df4522 | 2022-07-11 19:04:00 -0600 | [diff] [blame] | 1222 | brds.append(brd) |
Simon Glass | 8132f98 | 2022-07-11 19:03:57 -0600 | [diff] [blame] | 1223 | board_set.add(brd) |
Simon Glass | 5df4522 | 2022-07-11 19:04:00 -0600 | [diff] [blame] | 1224 | return brds |
Simon Glass | 3394c9f | 2014-08-28 09:43:43 -0600 | [diff] [blame] | 1225 | |
Simon Glass | 03749d4 | 2014-08-28 09:43:44 -0600 | [diff] [blame] | 1226 | def _CalcErrorDelta(base_lines, base_line_boards, lines, line_boards, |
| 1227 | char): |
Simon Glass | de0fefc | 2020-04-09 15:08:36 -0600 | [diff] [blame] | 1228 | """Calculate the required output based on changes in errors |
| 1229 | |
| 1230 | Args: |
| 1231 | base_lines: List of errors/warnings for previous commit |
| 1232 | base_line_boards: Dict keyed by error line, containing a list |
| 1233 | of the Board objects with that error in the previous commit |
| 1234 | lines: List of errors/warning for this commit, each a str |
| 1235 | line_boards: Dict keyed by error line, containing a list |
| 1236 | of the Board objects with that error in this commit |
| 1237 | char: Character representing error ('') or warning ('w'). The |
| 1238 | broken ('+') or fixed ('-') characters are added in this |
| 1239 | function |
| 1240 | |
| 1241 | Returns: |
| 1242 | Tuple |
| 1243 | List of ErrLine objects for 'better' lines |
| 1244 | List of ErrLine objects for 'worse' lines |
| 1245 | """ |
Simon Glass | 03749d4 | 2014-08-28 09:43:44 -0600 | [diff] [blame] | 1246 | better_lines = [] |
| 1247 | worse_lines = [] |
| 1248 | for line in lines: |
| 1249 | if line not in base_lines: |
Simon Glass | de0fefc | 2020-04-09 15:08:36 -0600 | [diff] [blame] | 1250 | errline = ErrLine(char + '+', _BoardList(line, line_boards), |
| 1251 | line) |
| 1252 | worse_lines.append(errline) |
Simon Glass | 03749d4 | 2014-08-28 09:43:44 -0600 | [diff] [blame] | 1253 | for line in base_lines: |
| 1254 | if line not in lines: |
Simon Glass | de0fefc | 2020-04-09 15:08:36 -0600 | [diff] [blame] | 1255 | errline = ErrLine(char + '-', |
| 1256 | _BoardList(line, base_line_boards), line) |
| 1257 | better_lines.append(errline) |
Simon Glass | 03749d4 | 2014-08-28 09:43:44 -0600 | [diff] [blame] | 1258 | return better_lines, worse_lines |
| 1259 | |
Simon Glass | db17fb8 | 2015-02-05 22:06:15 -0700 | [diff] [blame] | 1260 | def _CalcConfig(delta, name, config): |
| 1261 | """Calculate configuration changes |
| 1262 | |
| 1263 | Args: |
| 1264 | delta: Type of the delta, e.g. '+' |
| 1265 | name: name of the file which changed (e.g. .config) |
| 1266 | config: configuration change dictionary |
| 1267 | key: config name |
| 1268 | value: config value |
| 1269 | Returns: |
| 1270 | String containing the configuration changes which can be |
| 1271 | printed |
| 1272 | """ |
| 1273 | out = '' |
| 1274 | for key in sorted(config.keys()): |
| 1275 | out += '%s=%s ' % (key, config[key]) |
Simon Glass | cad8abf | 2015-08-25 21:52:14 -0600 | [diff] [blame] | 1276 | return '%s %s: %s' % (delta, name, out) |
Simon Glass | db17fb8 | 2015-02-05 22:06:15 -0700 | [diff] [blame] | 1277 | |
Simon Glass | cad8abf | 2015-08-25 21:52:14 -0600 | [diff] [blame] | 1278 | def _AddConfig(lines, name, config_plus, config_minus, config_change): |
| 1279 | """Add changes in configuration to a list |
Simon Glass | db17fb8 | 2015-02-05 22:06:15 -0700 | [diff] [blame] | 1280 | |
| 1281 | Args: |
Simon Glass | cad8abf | 2015-08-25 21:52:14 -0600 | [diff] [blame] | 1282 | lines: list to add to |
| 1283 | name: config file name |
Simon Glass | db17fb8 | 2015-02-05 22:06:15 -0700 | [diff] [blame] | 1284 | config_plus: configurations added, dictionary |
| 1285 | key: config name |
| 1286 | value: config value |
| 1287 | config_minus: configurations removed, dictionary |
| 1288 | key: config name |
| 1289 | value: config value |
| 1290 | config_change: configurations changed, dictionary |
| 1291 | key: config name |
| 1292 | value: config value |
| 1293 | """ |
| 1294 | if config_plus: |
Simon Glass | cad8abf | 2015-08-25 21:52:14 -0600 | [diff] [blame] | 1295 | lines.append(_CalcConfig('+', name, config_plus)) |
Simon Glass | db17fb8 | 2015-02-05 22:06:15 -0700 | [diff] [blame] | 1296 | if config_minus: |
Simon Glass | cad8abf | 2015-08-25 21:52:14 -0600 | [diff] [blame] | 1297 | lines.append(_CalcConfig('-', name, config_minus)) |
Simon Glass | db17fb8 | 2015-02-05 22:06:15 -0700 | [diff] [blame] | 1298 | if config_change: |
Simon Glass | cad8abf | 2015-08-25 21:52:14 -0600 | [diff] [blame] | 1299 | lines.append(_CalcConfig('c', name, config_change)) |
| 1300 | |
| 1301 | def _OutputConfigInfo(lines): |
| 1302 | for line in lines: |
| 1303 | if not line: |
| 1304 | continue |
| 1305 | if line[0] == '+': |
| 1306 | col = self.col.GREEN |
| 1307 | elif line[0] == '-': |
| 1308 | col = self.col.RED |
| 1309 | elif line[0] == 'c': |
| 1310 | col = self.col.YELLOW |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 1311 | tprint(' ' + line, newline=True, colour=col) |
Simon Glass | cad8abf | 2015-08-25 21:52:14 -0600 | [diff] [blame] | 1312 | |
Simon Glass | ac50022 | 2020-04-09 15:08:28 -0600 | [diff] [blame] | 1313 | def _OutputErrLines(err_lines, colour): |
| 1314 | """Output the line of error/warning lines, if not empty |
| 1315 | |
| 1316 | Also increments self._error_lines if err_lines not empty |
| 1317 | |
| 1318 | Args: |
Simon Glass | de0fefc | 2020-04-09 15:08:36 -0600 | [diff] [blame] | 1319 | err_lines: List of ErrLine objects, each an error or warning |
| 1320 | line, possibly including a list of boards with that |
| 1321 | error/warning |
Simon Glass | ac50022 | 2020-04-09 15:08:28 -0600 | [diff] [blame] | 1322 | colour: Colour to use for output |
| 1323 | """ |
| 1324 | if err_lines: |
Simon Glass | ea49f9b | 2020-04-09 15:08:37 -0600 | [diff] [blame] | 1325 | out_list = [] |
Simon Glass | de0fefc | 2020-04-09 15:08:36 -0600 | [diff] [blame] | 1326 | for line in err_lines: |
Simon Glass | 5df4522 | 2022-07-11 19:04:00 -0600 | [diff] [blame] | 1327 | names = [brd.target for brd in line.brds] |
Simon Glass | 070589b | 2020-04-09 15:08:38 -0600 | [diff] [blame] | 1328 | board_str = ' '.join(names) if names else '' |
Simon Glass | ea49f9b | 2020-04-09 15:08:37 -0600 | [diff] [blame] | 1329 | if board_str: |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 1330 | out = self.col.build(colour, line.char + '(') |
| 1331 | out += self.col.build(self.col.MAGENTA, board_str, |
Simon Glass | ea49f9b | 2020-04-09 15:08:37 -0600 | [diff] [blame] | 1332 | bright=False) |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 1333 | out += self.col.build(colour, ') %s' % line.errline) |
Simon Glass | ea49f9b | 2020-04-09 15:08:37 -0600 | [diff] [blame] | 1334 | else: |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 1335 | out = self.col.build(colour, line.char + line.errline) |
Simon Glass | ea49f9b | 2020-04-09 15:08:37 -0600 | [diff] [blame] | 1336 | out_list.append(out) |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 1337 | tprint('\n'.join(out_list)) |
Simon Glass | ac50022 | 2020-04-09 15:08:28 -0600 | [diff] [blame] | 1338 | self._error_lines += 1 |
| 1339 | |
Simon Glass | db17fb8 | 2015-02-05 22:06:15 -0700 | [diff] [blame] | 1340 | |
Simon Glass | 454507f | 2018-11-06 16:02:12 -0700 | [diff] [blame] | 1341 | ok_boards = [] # List of boards fixed since last commit |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 1342 | warn_boards = [] # List of boards with warnings since last commit |
Simon Glass | 454507f | 2018-11-06 16:02:12 -0700 | [diff] [blame] | 1343 | err_boards = [] # List of new broken boards since last commit |
| 1344 | new_boards = [] # List of boards that didn't exist last time |
| 1345 | unknown_boards = [] # List of boards that were not built |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1346 | |
| 1347 | for target in board_dict: |
| 1348 | if target not in board_selected: |
| 1349 | continue |
| 1350 | |
| 1351 | # If the board was built last time, add its outcome to a list |
| 1352 | if target in self._base_board_dict: |
| 1353 | base_outcome = self._base_board_dict[target].rc |
| 1354 | outcome = board_dict[target] |
| 1355 | if outcome.rc == OUTCOME_UNKNOWN: |
Simon Glass | 454507f | 2018-11-06 16:02:12 -0700 | [diff] [blame] | 1356 | unknown_boards.append(target) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1357 | elif outcome.rc < base_outcome: |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 1358 | if outcome.rc == OUTCOME_WARNING: |
| 1359 | warn_boards.append(target) |
| 1360 | else: |
| 1361 | ok_boards.append(target) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1362 | elif outcome.rc > base_outcome: |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 1363 | if outcome.rc == OUTCOME_WARNING: |
| 1364 | warn_boards.append(target) |
| 1365 | else: |
| 1366 | err_boards.append(target) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1367 | else: |
Simon Glass | 454507f | 2018-11-06 16:02:12 -0700 | [diff] [blame] | 1368 | new_boards.append(target) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1369 | |
Simon Glass | ac50022 | 2020-04-09 15:08:28 -0600 | [diff] [blame] | 1370 | # Get a list of errors and warnings that have appeared, and disappeared |
Simon Glass | 03749d4 | 2014-08-28 09:43:44 -0600 | [diff] [blame] | 1371 | better_err, worse_err = _CalcErrorDelta(self._base_err_lines, |
| 1372 | self._base_err_line_boards, err_lines, err_line_boards, '') |
| 1373 | better_warn, worse_warn = _CalcErrorDelta(self._base_warn_lines, |
| 1374 | self._base_warn_line_boards, warn_lines, warn_line_boards, 'w') |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1375 | |
Simon Glass | 6c43562 | 2022-07-11 19:03:56 -0600 | [diff] [blame] | 1376 | # For the IDE mode, print out all the output |
| 1377 | if self._ide: |
| 1378 | outcome = board_dict[target] |
| 1379 | for line in outcome.err_lines: |
| 1380 | sys.stderr.write(line) |
| 1381 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1382 | # Display results by arch |
Simon Glass | 6c43562 | 2022-07-11 19:03:56 -0600 | [diff] [blame] | 1383 | elif any((ok_boards, warn_boards, err_boards, unknown_boards, new_boards, |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 1384 | worse_err, better_err, worse_warn, better_warn)): |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1385 | arch_list = {} |
Simon Glass | 454507f | 2018-11-06 16:02:12 -0700 | [diff] [blame] | 1386 | self.AddOutcome(board_selected, arch_list, ok_boards, '', |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1387 | self.col.GREEN) |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 1388 | self.AddOutcome(board_selected, arch_list, warn_boards, 'w+', |
| 1389 | self.col.YELLOW) |
Simon Glass | 454507f | 2018-11-06 16:02:12 -0700 | [diff] [blame] | 1390 | self.AddOutcome(board_selected, arch_list, err_boards, '+', |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1391 | self.col.RED) |
Simon Glass | 454507f | 2018-11-06 16:02:12 -0700 | [diff] [blame] | 1392 | self.AddOutcome(board_selected, arch_list, new_boards, '*', self.col.BLUE) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1393 | if self._show_unknown: |
Simon Glass | 454507f | 2018-11-06 16:02:12 -0700 | [diff] [blame] | 1394 | self.AddOutcome(board_selected, arch_list, unknown_boards, '?', |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1395 | self.col.MAGENTA) |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 1396 | for arch, target_list in arch_list.items(): |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 1397 | tprint('%10s: %s' % (arch, target_list)) |
Simon Glass | bb4dffb | 2014-08-09 15:33:06 -0600 | [diff] [blame] | 1398 | self._error_lines += 1 |
Simon Glass | ac50022 | 2020-04-09 15:08:28 -0600 | [diff] [blame] | 1399 | _OutputErrLines(better_err, colour=self.col.GREEN) |
| 1400 | _OutputErrLines(worse_err, colour=self.col.RED) |
| 1401 | _OutputErrLines(better_warn, colour=self.col.CYAN) |
Simon Glass | 564ddac | 2020-04-09 15:08:35 -0600 | [diff] [blame] | 1402 | _OutputErrLines(worse_warn, colour=self.col.YELLOW) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1403 | |
| 1404 | if show_sizes: |
| 1405 | self.PrintSizeSummary(board_selected, board_dict, show_detail, |
| 1406 | show_bloat) |
| 1407 | |
Alex Kiernan | 4059e30 | 2018-05-31 04:48:34 +0000 | [diff] [blame] | 1408 | if show_environment and self._base_environment: |
| 1409 | lines = [] |
| 1410 | |
| 1411 | for target in board_dict: |
| 1412 | if target not in board_selected: |
| 1413 | continue |
| 1414 | |
| 1415 | tbase = self._base_environment[target] |
| 1416 | tenvironment = environment[target] |
| 1417 | environment_plus = {} |
| 1418 | environment_minus = {} |
| 1419 | environment_change = {} |
| 1420 | base = tbase.environment |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 1421 | for key, value in tenvironment.environment.items(): |
Alex Kiernan | 4059e30 | 2018-05-31 04:48:34 +0000 | [diff] [blame] | 1422 | if key not in base: |
| 1423 | environment_plus[key] = value |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 1424 | for key, value in base.items(): |
Alex Kiernan | 4059e30 | 2018-05-31 04:48:34 +0000 | [diff] [blame] | 1425 | if key not in tenvironment.environment: |
| 1426 | environment_minus[key] = value |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 1427 | for key, value in base.items(): |
Alex Kiernan | 4059e30 | 2018-05-31 04:48:34 +0000 | [diff] [blame] | 1428 | new_value = tenvironment.environment.get(key) |
| 1429 | if new_value and value != new_value: |
| 1430 | desc = '%s -> %s' % (value, new_value) |
| 1431 | environment_change[key] = desc |
| 1432 | |
| 1433 | _AddConfig(lines, target, environment_plus, environment_minus, |
| 1434 | environment_change) |
| 1435 | |
| 1436 | _OutputConfigInfo(lines) |
| 1437 | |
Simon Glass | cad8abf | 2015-08-25 21:52:14 -0600 | [diff] [blame] | 1438 | if show_config and self._base_config: |
| 1439 | summary = {} |
| 1440 | arch_config_plus = {} |
| 1441 | arch_config_minus = {} |
| 1442 | arch_config_change = {} |
| 1443 | arch_list = [] |
| 1444 | |
| 1445 | for target in board_dict: |
| 1446 | if target not in board_selected: |
| 1447 | continue |
| 1448 | arch = board_selected[target].arch |
| 1449 | if arch not in arch_list: |
| 1450 | arch_list.append(arch) |
| 1451 | |
| 1452 | for arch in arch_list: |
| 1453 | arch_config_plus[arch] = {} |
| 1454 | arch_config_minus[arch] = {} |
| 1455 | arch_config_change[arch] = {} |
Simon Glass | cde5c30 | 2016-11-13 14:25:53 -0700 | [diff] [blame] | 1456 | for name in self.config_filenames: |
Simon Glass | cad8abf | 2015-08-25 21:52:14 -0600 | [diff] [blame] | 1457 | arch_config_plus[arch][name] = {} |
| 1458 | arch_config_minus[arch][name] = {} |
| 1459 | arch_config_change[arch][name] = {} |
| 1460 | |
| 1461 | for target in board_dict: |
| 1462 | if target not in board_selected: |
Simon Glass | db17fb8 | 2015-02-05 22:06:15 -0700 | [diff] [blame] | 1463 | continue |
Simon Glass | cad8abf | 2015-08-25 21:52:14 -0600 | [diff] [blame] | 1464 | |
| 1465 | arch = board_selected[target].arch |
| 1466 | |
| 1467 | all_config_plus = {} |
| 1468 | all_config_minus = {} |
| 1469 | all_config_change = {} |
| 1470 | tbase = self._base_config[target] |
| 1471 | tconfig = config[target] |
| 1472 | lines = [] |
Simon Glass | cde5c30 | 2016-11-13 14:25:53 -0700 | [diff] [blame] | 1473 | for name in self.config_filenames: |
Simon Glass | cad8abf | 2015-08-25 21:52:14 -0600 | [diff] [blame] | 1474 | if not tconfig.config[name]: |
| 1475 | continue |
| 1476 | config_plus = {} |
| 1477 | config_minus = {} |
| 1478 | config_change = {} |
| 1479 | base = tbase.config[name] |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 1480 | for key, value in tconfig.config[name].items(): |
Simon Glass | cad8abf | 2015-08-25 21:52:14 -0600 | [diff] [blame] | 1481 | if key not in base: |
| 1482 | config_plus[key] = value |
| 1483 | all_config_plus[key] = value |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 1484 | for key, value in base.items(): |
Simon Glass | cad8abf | 2015-08-25 21:52:14 -0600 | [diff] [blame] | 1485 | if key not in tconfig.config[name]: |
| 1486 | config_minus[key] = value |
| 1487 | all_config_minus[key] = value |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 1488 | for key, value in base.items(): |
Simon Glass | cad8abf | 2015-08-25 21:52:14 -0600 | [diff] [blame] | 1489 | new_value = tconfig.config.get(key) |
| 1490 | if new_value and value != new_value: |
| 1491 | desc = '%s -> %s' % (value, new_value) |
| 1492 | config_change[key] = desc |
| 1493 | all_config_change[key] = desc |
| 1494 | |
| 1495 | arch_config_plus[arch][name].update(config_plus) |
| 1496 | arch_config_minus[arch][name].update(config_minus) |
| 1497 | arch_config_change[arch][name].update(config_change) |
| 1498 | |
| 1499 | _AddConfig(lines, name, config_plus, config_minus, |
| 1500 | config_change) |
| 1501 | _AddConfig(lines, 'all', all_config_plus, all_config_minus, |
| 1502 | all_config_change) |
| 1503 | summary[target] = '\n'.join(lines) |
| 1504 | |
| 1505 | lines_by_target = {} |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 1506 | for target, lines in summary.items(): |
Simon Glass | cad8abf | 2015-08-25 21:52:14 -0600 | [diff] [blame] | 1507 | if lines in lines_by_target: |
| 1508 | lines_by_target[lines].append(target) |
| 1509 | else: |
| 1510 | lines_by_target[lines] = [target] |
| 1511 | |
| 1512 | for arch in arch_list: |
| 1513 | lines = [] |
| 1514 | all_plus = {} |
| 1515 | all_minus = {} |
| 1516 | all_change = {} |
Simon Glass | cde5c30 | 2016-11-13 14:25:53 -0700 | [diff] [blame] | 1517 | for name in self.config_filenames: |
Simon Glass | cad8abf | 2015-08-25 21:52:14 -0600 | [diff] [blame] | 1518 | all_plus.update(arch_config_plus[arch][name]) |
| 1519 | all_minus.update(arch_config_minus[arch][name]) |
| 1520 | all_change.update(arch_config_change[arch][name]) |
| 1521 | _AddConfig(lines, name, arch_config_plus[arch][name], |
| 1522 | arch_config_minus[arch][name], |
| 1523 | arch_config_change[arch][name]) |
| 1524 | _AddConfig(lines, 'all', all_plus, all_minus, all_change) |
| 1525 | #arch_summary[target] = '\n'.join(lines) |
| 1526 | if lines: |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 1527 | tprint('%s:' % arch) |
Simon Glass | cad8abf | 2015-08-25 21:52:14 -0600 | [diff] [blame] | 1528 | _OutputConfigInfo(lines) |
| 1529 | |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 1530 | for lines, targets in lines_by_target.items(): |
Simon Glass | cad8abf | 2015-08-25 21:52:14 -0600 | [diff] [blame] | 1531 | if not lines: |
| 1532 | continue |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 1533 | tprint('%s :' % ' '.join(sorted(targets))) |
Simon Glass | cad8abf | 2015-08-25 21:52:14 -0600 | [diff] [blame] | 1534 | _OutputConfigInfo(lines.split('\n')) |
| 1535 | |
Simon Glass | db17fb8 | 2015-02-05 22:06:15 -0700 | [diff] [blame] | 1536 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1537 | # Save our updated information for the next call to this function |
| 1538 | self._base_board_dict = board_dict |
| 1539 | self._base_err_lines = err_lines |
Simon Glass | 03749d4 | 2014-08-28 09:43:44 -0600 | [diff] [blame] | 1540 | self._base_warn_lines = warn_lines |
| 1541 | self._base_err_line_boards = err_line_boards |
| 1542 | self._base_warn_line_boards = warn_line_boards |
Simon Glass | db17fb8 | 2015-02-05 22:06:15 -0700 | [diff] [blame] | 1543 | self._base_config = config |
Alex Kiernan | 4059e30 | 2018-05-31 04:48:34 +0000 | [diff] [blame] | 1544 | self._base_environment = environment |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1545 | |
| 1546 | # Get a list of boards that did not get built, if needed |
| 1547 | not_built = [] |
Simon Glass | 8132f98 | 2022-07-11 19:03:57 -0600 | [diff] [blame] | 1548 | for brd in board_selected: |
| 1549 | if not brd in board_dict: |
| 1550 | not_built.append(brd) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1551 | if not_built: |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 1552 | tprint("Boards not built (%d): %s" % (len(not_built), |
Simon Glass | 4433aa9 | 2014-09-05 19:00:07 -0600 | [diff] [blame] | 1553 | ', '.join(not_built))) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1554 | |
Simon Glass | eb48bbc | 2014-08-09 15:33:02 -0600 | [diff] [blame] | 1555 | def ProduceResultSummary(self, commit_upto, commits, board_selected): |
Simon Glass | 03749d4 | 2014-08-28 09:43:44 -0600 | [diff] [blame] | 1556 | (board_dict, err_lines, err_line_boards, warn_lines, |
Alex Kiernan | 4059e30 | 2018-05-31 04:48:34 +0000 | [diff] [blame] | 1557 | warn_line_boards, config, environment) = self.GetResultSummary( |
Simon Glass | 3394c9f | 2014-08-28 09:43:43 -0600 | [diff] [blame] | 1558 | board_selected, commit_upto, |
Simon Glass | db17fb8 | 2015-02-05 22:06:15 -0700 | [diff] [blame] | 1559 | read_func_sizes=self._show_bloat, |
Alex Kiernan | 4059e30 | 2018-05-31 04:48:34 +0000 | [diff] [blame] | 1560 | read_config=self._show_config, |
| 1561 | read_environment=self._show_environment) |
Simon Glass | eb48bbc | 2014-08-09 15:33:02 -0600 | [diff] [blame] | 1562 | if commits: |
| 1563 | msg = '%02d: %s' % (commit_upto + 1, |
| 1564 | commits[commit_upto].subject) |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 1565 | tprint(msg, colour=self.col.BLUE) |
Simon Glass | eb48bbc | 2014-08-09 15:33:02 -0600 | [diff] [blame] | 1566 | self.PrintResultSummary(board_selected, board_dict, |
Simon Glass | 3394c9f | 2014-08-28 09:43:43 -0600 | [diff] [blame] | 1567 | err_lines if self._show_errors else [], err_line_boards, |
Simon Glass | 03749d4 | 2014-08-28 09:43:44 -0600 | [diff] [blame] | 1568 | warn_lines if self._show_errors else [], warn_line_boards, |
Alex Kiernan | 4059e30 | 2018-05-31 04:48:34 +0000 | [diff] [blame] | 1569 | config, environment, self._show_sizes, self._show_detail, |
| 1570 | self._show_bloat, self._show_config, self._show_environment) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1571 | |
Simon Glass | eb48bbc | 2014-08-09 15:33:02 -0600 | [diff] [blame] | 1572 | def ShowSummary(self, commits, board_selected): |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1573 | """Show a build summary for U-Boot for a given board list. |
| 1574 | |
| 1575 | Reset the result summary, then repeatedly call GetResultSummary on |
| 1576 | each commit's results, then display the differences we see. |
| 1577 | |
| 1578 | Args: |
| 1579 | commit: Commit objects to summarise |
| 1580 | board_selected: Dict containing boards to summarise |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1581 | """ |
Simon Glass | d326ad7 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 1582 | self.commit_count = len(commits) if commits else 1 |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1583 | self.commits = commits |
| 1584 | self.ResetResultSummary(board_selected) |
Simon Glass | bb4dffb | 2014-08-09 15:33:06 -0600 | [diff] [blame] | 1585 | self._error_lines = 0 |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1586 | |
| 1587 | for commit_upto in range(0, self.commit_count, self._step): |
Simon Glass | eb48bbc | 2014-08-09 15:33:02 -0600 | [diff] [blame] | 1588 | self.ProduceResultSummary(commit_upto, commits, board_selected) |
Simon Glass | bb4dffb | 2014-08-09 15:33:06 -0600 | [diff] [blame] | 1589 | if not self._error_lines: |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 1590 | tprint('(no errors to report)', colour=self.col.GREEN) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1591 | |
| 1592 | |
| 1593 | def SetupBuild(self, board_selected, commits): |
| 1594 | """Set up ready to start a build. |
| 1595 | |
| 1596 | Args: |
| 1597 | board_selected: Selected boards to build |
| 1598 | commits: Selected commits to build |
| 1599 | """ |
| 1600 | # First work out how many commits we will build |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 1601 | count = (self.commit_count + self._step - 1) // self._step |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1602 | self.count = len(board_selected) * count |
| 1603 | self.upto = self.warned = self.fail = 0 |
| 1604 | self._timestamps = collections.deque() |
| 1605 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1606 | def GetThreadDir(self, thread_num): |
| 1607 | """Get the directory path to the working dir for a thread. |
| 1608 | |
| 1609 | Args: |
Simon Glass | c635d89 | 2021-01-30 22:17:46 -0700 | [diff] [blame] | 1610 | thread_num: Number of thread to check (-1 for main process, which |
| 1611 | is treated as 0) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1612 | """ |
Simon Glass | b6eb8cf | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 1613 | if self.work_in_output: |
| 1614 | return self._working_dir |
Simon Glass | c635d89 | 2021-01-30 22:17:46 -0700 | [diff] [blame] | 1615 | return os.path.join(self._working_dir, '%02d' % max(thread_num, 0)) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1616 | |
Simon Glass | d326ad7 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 1617 | def _PrepareThread(self, thread_num, setup_git): |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1618 | """Prepare the working directory for a thread. |
| 1619 | |
| 1620 | This clones or fetches the repo into the thread's work directory. |
Alper Nebi Yasak | fede44a | 2020-09-03 15:51:03 +0300 | [diff] [blame] | 1621 | Optionally, it can create a linked working tree of the repo in the |
| 1622 | thread's work directory instead. |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1623 | |
| 1624 | Args: |
| 1625 | thread_num: Thread number (0, 1, ...) |
Alper Nebi Yasak | fede44a | 2020-09-03 15:51:03 +0300 | [diff] [blame] | 1626 | setup_git: |
| 1627 | 'clone' to set up a git clone |
| 1628 | 'worktree' to set up a git worktree |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1629 | """ |
| 1630 | thread_dir = self.GetThreadDir(thread_num) |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 1631 | builderthread.Mkdir(thread_dir) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1632 | git_dir = os.path.join(thread_dir, '.git') |
| 1633 | |
Alper Nebi Yasak | fede44a | 2020-09-03 15:51:03 +0300 | [diff] [blame] | 1634 | # Create a worktree or a git repo clone for this thread if it |
| 1635 | # doesn't already exist |
Simon Glass | d326ad7 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 1636 | if setup_git and self.git_dir: |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1637 | src_dir = os.path.abspath(self.git_dir) |
Alper Nebi Yasak | fede44a | 2020-09-03 15:51:03 +0300 | [diff] [blame] | 1638 | if os.path.isdir(git_dir): |
| 1639 | # This is a clone of the src_dir repo, we can keep using |
| 1640 | # it but need to fetch from src_dir. |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 1641 | tprint('\rFetching repo for thread %d' % thread_num, |
Simon Glass | 4305493 | 2020-04-09 15:08:43 -0600 | [diff] [blame] | 1642 | newline=False) |
Simon Glass | 761648b | 2022-01-29 14:14:11 -0700 | [diff] [blame] | 1643 | gitutil.fetch(git_dir, thread_dir) |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 1644 | terminal.print_clear() |
Alper Nebi Yasak | fede44a | 2020-09-03 15:51:03 +0300 | [diff] [blame] | 1645 | elif os.path.isfile(git_dir): |
| 1646 | # This is a worktree of the src_dir repo, we don't need to |
| 1647 | # create it again or update it in any way. |
| 1648 | pass |
| 1649 | elif os.path.exists(git_dir): |
| 1650 | # Don't know what could trigger this, but we probably |
| 1651 | # can't create a git worktree/clone here. |
| 1652 | raise ValueError('Git dir %s exists, but is not a file ' |
| 1653 | 'or a directory.' % git_dir) |
| 1654 | elif setup_git == 'worktree': |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 1655 | tprint('\rChecking out worktree for thread %d' % thread_num, |
Alper Nebi Yasak | fede44a | 2020-09-03 15:51:03 +0300 | [diff] [blame] | 1656 | newline=False) |
Simon Glass | 761648b | 2022-01-29 14:14:11 -0700 | [diff] [blame] | 1657 | gitutil.add_worktree(src_dir, thread_dir) |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 1658 | terminal.print_clear() |
Alper Nebi Yasak | fede44a | 2020-09-03 15:51:03 +0300 | [diff] [blame] | 1659 | elif setup_git == 'clone' or setup_git == True: |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 1660 | tprint('\rCloning repo for thread %d' % thread_num, |
Simon Glass | 2e2a6e6 | 2016-09-18 16:48:31 -0600 | [diff] [blame] | 1661 | newline=False) |
Simon Glass | 761648b | 2022-01-29 14:14:11 -0700 | [diff] [blame] | 1662 | gitutil.clone(src_dir, thread_dir) |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 1663 | terminal.print_clear() |
Alper Nebi Yasak | fede44a | 2020-09-03 15:51:03 +0300 | [diff] [blame] | 1664 | else: |
| 1665 | raise ValueError("Can't setup git repo with %s." % setup_git) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1666 | |
Simon Glass | d326ad7 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 1667 | def _PrepareWorkingSpace(self, max_threads, setup_git): |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1668 | """Prepare the working directory for use. |
| 1669 | |
Alper Nebi Yasak | fede44a | 2020-09-03 15:51:03 +0300 | [diff] [blame] | 1670 | Set up the git repo for each thread. Creates a linked working tree |
| 1671 | if git-worktree is available, or clones the repo if it isn't. |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1672 | |
| 1673 | Args: |
Simon Glass | c635d89 | 2021-01-30 22:17:46 -0700 | [diff] [blame] | 1674 | max_threads: Maximum number of threads we expect to need. If 0 then |
| 1675 | 1 is set up, since the main process still needs somewhere to |
| 1676 | work |
Alper Nebi Yasak | fede44a | 2020-09-03 15:51:03 +0300 | [diff] [blame] | 1677 | setup_git: True to set up a git worktree or a git clone |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1678 | """ |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 1679 | builderthread.Mkdir(self._working_dir) |
Alper Nebi Yasak | fede44a | 2020-09-03 15:51:03 +0300 | [diff] [blame] | 1680 | if setup_git and self.git_dir: |
| 1681 | src_dir = os.path.abspath(self.git_dir) |
Simon Glass | 761648b | 2022-01-29 14:14:11 -0700 | [diff] [blame] | 1682 | if gitutil.check_worktree_is_available(src_dir): |
Alper Nebi Yasak | fede44a | 2020-09-03 15:51:03 +0300 | [diff] [blame] | 1683 | setup_git = 'worktree' |
| 1684 | # If we previously added a worktree but the directory for it |
| 1685 | # got deleted, we need to prune its files from the repo so |
| 1686 | # that we can check out another in its place. |
Simon Glass | 761648b | 2022-01-29 14:14:11 -0700 | [diff] [blame] | 1687 | gitutil.prune_worktrees(src_dir) |
Alper Nebi Yasak | fede44a | 2020-09-03 15:51:03 +0300 | [diff] [blame] | 1688 | else: |
| 1689 | setup_git = 'clone' |
Simon Glass | c635d89 | 2021-01-30 22:17:46 -0700 | [diff] [blame] | 1690 | |
| 1691 | # Always do at least one thread |
| 1692 | for thread in range(max(max_threads, 1)): |
Simon Glass | d326ad7 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 1693 | self._PrepareThread(thread, setup_git) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1694 | |
Simon Glass | 5dc1ca7 | 2020-03-18 09:42:45 -0600 | [diff] [blame] | 1695 | def _GetOutputSpaceRemovals(self): |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1696 | """Get the output directories ready to receive files. |
| 1697 | |
Simon Glass | 5dc1ca7 | 2020-03-18 09:42:45 -0600 | [diff] [blame] | 1698 | Figure out what needs to be deleted in the output directory before it |
| 1699 | can be used. We only delete old buildman directories which have the |
| 1700 | expected name pattern. See _GetOutputDir(). |
| 1701 | |
| 1702 | Returns: |
| 1703 | List of full paths of directories to remove |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1704 | """ |
Simon Glass | b9a9b7c | 2014-12-01 17:33:53 -0700 | [diff] [blame] | 1705 | if not self.commits: |
| 1706 | return |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1707 | dir_list = [] |
| 1708 | for commit_upto in range(self.commit_count): |
| 1709 | dir_list.append(self._GetOutputDir(commit_upto)) |
| 1710 | |
Simon Glass | 83cb6cc | 2016-09-18 16:48:32 -0600 | [diff] [blame] | 1711 | to_remove = [] |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1712 | for dirname in glob.glob(os.path.join(self.base_dir, '*')): |
| 1713 | if dirname not in dir_list: |
Simon Glass | 5dc1ca7 | 2020-03-18 09:42:45 -0600 | [diff] [blame] | 1714 | leaf = dirname[len(self.base_dir) + 1:] |
Ovidiu Panait | ee8e9cb | 2020-05-15 09:30:12 +0300 | [diff] [blame] | 1715 | m = re.match('[0-9]+_g[0-9a-f]+_.*', leaf) |
Simon Glass | 5dc1ca7 | 2020-03-18 09:42:45 -0600 | [diff] [blame] | 1716 | if m: |
| 1717 | to_remove.append(dirname) |
| 1718 | return to_remove |
| 1719 | |
| 1720 | def _PrepareOutputSpace(self): |
| 1721 | """Get the output directories ready to receive files. |
| 1722 | |
| 1723 | We delete any output directories which look like ones we need to |
| 1724 | create. Having left over directories is confusing when the user wants |
| 1725 | to check the output manually. |
| 1726 | """ |
| 1727 | to_remove = self._GetOutputSpaceRemovals() |
Simon Glass | 83cb6cc | 2016-09-18 16:48:32 -0600 | [diff] [blame] | 1728 | if to_remove: |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 1729 | tprint('Removing %d old build directories...' % len(to_remove), |
Simon Glass | 83cb6cc | 2016-09-18 16:48:32 -0600 | [diff] [blame] | 1730 | newline=False) |
| 1731 | for dirname in to_remove: |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1732 | shutil.rmtree(dirname) |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 1733 | terminal.print_clear() |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1734 | |
Simon Glass | 78e418e | 2014-08-09 15:33:03 -0600 | [diff] [blame] | 1735 | def BuildBoards(self, commits, board_selected, keep_outputs, verbose): |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1736 | """Build all commits for a list of boards |
| 1737 | |
| 1738 | Args: |
| 1739 | commits: List of commits to be build, each a Commit object |
| 1740 | boards_selected: Dict of selected boards, key is target name, |
| 1741 | value is Board object |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1742 | keep_outputs: True to save build output files |
Simon Glass | 78e418e | 2014-08-09 15:33:03 -0600 | [diff] [blame] | 1743 | verbose: Display build results as they are completed |
Simon Glass | c2f9107 | 2014-08-28 09:43:39 -0600 | [diff] [blame] | 1744 | Returns: |
| 1745 | Tuple containing: |
| 1746 | - number of boards that failed to build |
| 1747 | - number of boards that issued warnings |
Simon Glass | 9bf9a72 | 2021-04-11 16:27:27 +1200 | [diff] [blame] | 1748 | - list of thread exceptions raised |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1749 | """ |
Simon Glass | d326ad7 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 1750 | self.commit_count = len(commits) if commits else 1 |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1751 | self.commits = commits |
Simon Glass | 78e418e | 2014-08-09 15:33:03 -0600 | [diff] [blame] | 1752 | self._verbose = verbose |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1753 | |
| 1754 | self.ResetResultSummary(board_selected) |
Thierry Reding | 336d5bd | 2014-08-19 10:22:39 +0200 | [diff] [blame] | 1755 | builderthread.Mkdir(self.base_dir, parents = True) |
Simon Glass | d326ad7 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 1756 | self._PrepareWorkingSpace(min(self.num_threads, len(board_selected)), |
| 1757 | commits is not None) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1758 | self._PrepareOutputSpace() |
Simon Glass | 6c43562 | 2022-07-11 19:03:56 -0600 | [diff] [blame] | 1759 | if not self._ide: |
| 1760 | tprint('\rStarting build...', newline=False) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1761 | self.SetupBuild(board_selected, commits) |
| 1762 | self.ProcessResult(None) |
Simon Glass | 9bf9a72 | 2021-04-11 16:27:27 +1200 | [diff] [blame] | 1763 | self.thread_exceptions = [] |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1764 | # Create jobs to build all commits for each board |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 1765 | for brd in board_selected.values(): |
Simon Glass | 4a1e88b | 2014-08-09 15:33:00 -0600 | [diff] [blame] | 1766 | job = builderthread.BuilderJob() |
Simon Glass | 8132f98 | 2022-07-11 19:03:57 -0600 | [diff] [blame] | 1767 | job.brd = brd |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1768 | job.commits = commits |
| 1769 | job.keep_outputs = keep_outputs |
Simon Glass | b6eb8cf | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 1770 | job.work_in_output = self.work_in_output |
Simon Glass | e5650a8 | 2022-01-22 05:07:33 -0700 | [diff] [blame] | 1771 | job.adjust_cfg = self.adjust_cfg |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1772 | job.step = self._step |
Simon Glass | c635d89 | 2021-01-30 22:17:46 -0700 | [diff] [blame] | 1773 | if self.num_threads: |
| 1774 | self.queue.put(job) |
| 1775 | else: |
Simon Glass | e36fe01 | 2022-02-11 13:23:19 -0700 | [diff] [blame] | 1776 | self._single_builder.RunJob(job) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1777 | |
Simon Glass | c635d89 | 2021-01-30 22:17:46 -0700 | [diff] [blame] | 1778 | if self.num_threads: |
| 1779 | term = threading.Thread(target=self.queue.join) |
| 1780 | term.setDaemon(True) |
| 1781 | term.start() |
| 1782 | while term.is_alive(): |
| 1783 | term.join(100) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1784 | |
Simon Glass | c635d89 | 2021-01-30 22:17:46 -0700 | [diff] [blame] | 1785 | # Wait until we have processed all output |
| 1786 | self.out_queue.join() |
Simon Glass | 6c43562 | 2022-07-11 19:03:56 -0600 | [diff] [blame] | 1787 | if not self._ide: |
| 1788 | tprint() |
Simon Glass | 726ae81 | 2020-04-09 15:08:47 -0600 | [diff] [blame] | 1789 | |
Simon Glass | 6c43562 | 2022-07-11 19:03:56 -0600 | [diff] [blame] | 1790 | msg = 'Completed: %d total built' % self.count |
| 1791 | if self.already_done: |
| 1792 | msg += ' (%d previously' % self.already_done |
| 1793 | if self.already_done != self.count: |
| 1794 | msg += ', %d newly' % (self.count - self.already_done) |
| 1795 | msg += ')' |
| 1796 | duration = datetime.now() - self._start_time |
| 1797 | if duration > timedelta(microseconds=1000000): |
| 1798 | if duration.microseconds >= 500000: |
| 1799 | duration = duration + timedelta(seconds=1) |
| 1800 | duration = duration - timedelta(microseconds=duration.microseconds) |
| 1801 | rate = float(self.count) / duration.total_seconds() |
| 1802 | msg += ', duration %s, rate %1.2f' % (duration, rate) |
| 1803 | tprint(msg) |
| 1804 | if self.thread_exceptions: |
| 1805 | tprint('Failed: %d thread exceptions' % len(self.thread_exceptions), |
| 1806 | colour=self.col.RED) |
Simon Glass | 726ae81 | 2020-04-09 15:08:47 -0600 | [diff] [blame] | 1807 | |
Simon Glass | 9bf9a72 | 2021-04-11 16:27:27 +1200 | [diff] [blame] | 1808 | return (self.fail, self.warned, self.thread_exceptions) |