"Das U-Boot" Source Tree

buildman - U-Boot multi-threaded builder and summary tool

This tool handles building U-Boot to check that you have not broken it
with your patch series. It can build each individual commit and report
which boards fail on which commits, and which errors come up. It also
shows differences in image sizes due to particular commits.

Buildman aims to make full use of multi-processor machines.

Documentation and caveats are in tools/buildman/README.

Signed-off-by: Simon Glass <sjg@chromium.org>

+3030
+1
tools/buildman/.gitignore
··· 1 + *.pyc
+679
tools/buildman/README
··· 1 + # Copyright (c) 2013 The Chromium OS Authors. 2 + # 3 + # See file CREDITS for list of people who contributed to this 4 + # project. 5 + # 6 + # This program is free software; you can redistribute it and/or 7 + # modify it under the terms of the GNU General Public License as 8 + # published by the Free Software Foundation; either version 2 of 9 + # the License, or (at your option) any later version. 10 + # 11 + # This program is distributed in the hope that it will be useful, 12 + # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + # GNU General Public License for more details. 15 + # 16 + # You should have received a copy of the GNU General Public License 17 + # along with this program; if not, write to the Free Software 18 + # Foundation, Inc., 59 Temple Place, Suite 330, Boston, 19 + # MA 02111-1307 USA 20 + # 21 + 22 + What is this? 23 + ============= 24 + 25 + This tool handles building U-Boot to check that you have not broken it 26 + with your patch series. It can build each individual commit and report 27 + which boards fail on which commits, and which errors come up. It aims 28 + to make full use of multi-processor machines. 29 + 30 + A key feature of buildman is its output summary, which allows warnings, 31 + errors or image size increases in a particular commit or board to be 32 + quickly identified and the offending commit pinpointed. This can be a big 33 + help for anyone working with >10 patches at a time. 34 + 35 + 36 + Caveats 37 + ======= 38 + 39 + Buildman is still in its infancy. It is already a very useful tool, but 40 + expect to find problems and send patches. 41 + 42 + Buildman can be stopped and restarted, in which case it will continue 43 + where it left off. This should happen cleanly and without side-effects. 44 + If not, it is a bug, for which a patch would be welcome. 45 + 46 + Buildman gets so tied up in its work that it can ignore the outside world. 47 + You may need to press Ctrl-C several times to quit it. Also it will print 48 + out various exceptions when stopped. 49 + 50 + 51 + Theory of Operation 52 + =================== 53 + 54 + (please read this section in full twice or you will be perpetually confused) 55 + 56 + Buildman is a builder. It is not make, although it runs make. It does not 57 + produce any useful output on the terminal while building, except for 58 + progress information. All the output (errors, warnings and binaries if you 59 + are ask for them) is stored in output directories, which you can look at 60 + while the build is progressing, or when it is finished. 61 + 62 + Buildman produces a concise summary of which boards succeeded and failed. 63 + It shows which commit introduced which board failure using a simple 64 + red/green colour coding. Full error information can be requested, in which 65 + case it is de-duped and displayed against the commit that introduced the 66 + error. An example workflow is below. 67 + 68 + Buildman stores image size information and can report changes in image size 69 + from commit to commit. An example of this is below. 70 + 71 + Buildman starts multiple threads, and each thread builds for one board at 72 + a time. A thread starts at the first commit, configures the source for your 73 + board and builds it. Then it checks out the next commit and does an 74 + incremental build. Eventually the thread reaches the last commit and stops. 75 + If errors or warnings are found along the way, the thread will reconfigure 76 + after every commit, and your build will be very slow. This is because a 77 + file that produces just a warning would not normally be rebuilt in an 78 + incremental build. 79 + 80 + Buildman works in an entirely separate place from your U-Boot repository. 81 + It creates a separate working directory for each thread, and puts the 82 + output files in the working directory, organised by commit name and board 83 + name, in a two-level hierarchy. 84 + 85 + Buildman is invoked in your U-Boot directory, the one with the .git 86 + directory. It clones this repository into a copy for each thread, and the 87 + threads do not affect the state of your git repository. Any checkouts done 88 + by the thread affect only the working directory for that thread. 89 + 90 + Buildman automatically selects the correct toolchain for each board. You 91 + must supply suitable toolchains, but buildman takes care of selecting the 92 + right one. 93 + 94 + Buildman always builds a branch, and always builds the upstream commit as 95 + well, for comparison. It cannot build individual commits at present, unless 96 + (maybe) you point it at an empty branch. Put all your commits in a branch, 97 + set the branch's upstream to a valid value, and all will be well. Otherwise 98 + buildman will perform random actions. Use -n to check what the random 99 + actions might be. 100 + 101 + Buildman is optimised for building many commits at once, for many boards. 102 + On multi-core machines, Buildman is fast because it uses most of the 103 + available CPU power. When it gets to the end, or if you are building just 104 + a few commits or boards, it will be pretty slow. As a tip, if you don't 105 + plan to use your machine for anything else, you can use -T to increase the 106 + number of threads beyond the default. 107 + 108 + Buildman lets you build all boards, or a subset. Specify the subset using 109 + the board name, architecture name, SOC name, or anything else in the 110 + boards.cfg file. So 'at91' will build all AT91 boards (arm), powerpc will 111 + build all PowerPC boards. 112 + 113 + Buildman does not store intermediate object files. It optionally copies 114 + the binary output into a directory when a build is successful. Size 115 + information is always recorded. It needs a fair bit of disk space to work, 116 + typically 250MB per thread. 117 + 118 + 119 + Setting up 120 + ========== 121 + 122 + 1. Get the U-Boot source. You probably already have it, but if not these 123 + steps should get you started with a repo and some commits for testing. 124 + 125 + $ cd /path/to/u-boot 126 + $ git clone git://git.denx.de/u-boot.git . 127 + $ git checkout -b my-branch origin/master 128 + $ # Add some commits to the branch, reading for testing 129 + 130 + 2. Create ~/.buildman to tell buildman where to find tool chains. As an 131 + example: 132 + 133 + # Buildman settings file 134 + 135 + [toolchain] 136 + root: / 137 + rest: /toolchains/* 138 + eldk: /opt/eldk-4.2 139 + 140 + [toolchain-alias] 141 + x86: i386 142 + blackfin: bfin 143 + sh: sh4 144 + nds32: nds32le 145 + openrisc: or32 146 + 147 + 148 + This selects the available toolchain paths. Add the base directory for 149 + each of your toolchains here. Buildman will search inside these directories 150 + and also in any '/usr' and '/usr/bin' subdirectories. 151 + 152 + Make sure the tags (here root: rest: and eldk:) are unique. 153 + 154 + The toolchain-alias section indicates that the i386 toolchain should be used 155 + to build x86 commits. 156 + 157 + 158 + 2. Check the available toolchains 159 + 160 + Run this check to make sure that you have a toolchain for every architecture. 161 + 162 + $ ./tools/buildman/buildman --list-tool-chains 163 + Scanning for tool chains 164 + - scanning path '/' 165 + - looking in '/.' 166 + - looking in '/bin' 167 + - looking in '/usr/bin' 168 + - found '/usr/bin/gcc' 169 + Tool chain test: OK 170 + - found '/usr/bin/c89-gcc' 171 + Tool chain test: OK 172 + - found '/usr/bin/c99-gcc' 173 + Tool chain test: OK 174 + - found '/usr/bin/x86_64-linux-gnu-gcc' 175 + Tool chain test: OK 176 + - scanning path '/toolchains/powerpc-linux' 177 + - looking in '/toolchains/powerpc-linux/.' 178 + - looking in '/toolchains/powerpc-linux/bin' 179 + - found '/toolchains/powerpc-linux/bin/powerpc-linux-gcc' 180 + Tool chain test: OK 181 + - looking in '/toolchains/powerpc-linux/usr/bin' 182 + - scanning path '/toolchains/nds32le-linux-glibc-v1f' 183 + - looking in '/toolchains/nds32le-linux-glibc-v1f/.' 184 + - looking in '/toolchains/nds32le-linux-glibc-v1f/bin' 185 + - found '/toolchains/nds32le-linux-glibc-v1f/bin/nds32le-linux-gcc' 186 + Tool chain test: OK 187 + - looking in '/toolchains/nds32le-linux-glibc-v1f/usr/bin' 188 + - scanning path '/toolchains/nios2' 189 + - looking in '/toolchains/nios2/.' 190 + - looking in '/toolchains/nios2/bin' 191 + - found '/toolchains/nios2/bin/nios2-linux-gcc' 192 + Tool chain test: OK 193 + - found '/toolchains/nios2/bin/nios2-linux-uclibc-gcc' 194 + Tool chain test: OK 195 + - looking in '/toolchains/nios2/usr/bin' 196 + - found '/toolchains/nios2/usr/bin/nios2-linux-gcc' 197 + Tool chain test: OK 198 + - found '/toolchains/nios2/usr/bin/nios2-linux-uclibc-gcc' 199 + Tool chain test: OK 200 + - scanning path '/toolchains/microblaze-unknown-linux-gnu' 201 + - looking in '/toolchains/microblaze-unknown-linux-gnu/.' 202 + - looking in '/toolchains/microblaze-unknown-linux-gnu/bin' 203 + - found '/toolchains/microblaze-unknown-linux-gnu/bin/microblaze-unknown-linux-gnu-gcc' 204 + Tool chain test: OK 205 + - found '/toolchains/microblaze-unknown-linux-gnu/bin/mb-linux-gcc' 206 + Tool chain test: OK 207 + - looking in '/toolchains/microblaze-unknown-linux-gnu/usr/bin' 208 + - scanning path '/toolchains/mips-linux' 209 + - looking in '/toolchains/mips-linux/.' 210 + - looking in '/toolchains/mips-linux/bin' 211 + - found '/toolchains/mips-linux/bin/mips-linux-gcc' 212 + Tool chain test: OK 213 + - looking in '/toolchains/mips-linux/usr/bin' 214 + - scanning path '/toolchains/old' 215 + - looking in '/toolchains/old/.' 216 + - looking in '/toolchains/old/bin' 217 + - looking in '/toolchains/old/usr/bin' 218 + - scanning path '/toolchains/i386-linux' 219 + - looking in '/toolchains/i386-linux/.' 220 + - looking in '/toolchains/i386-linux/bin' 221 + - found '/toolchains/i386-linux/bin/i386-linux-gcc' 222 + Tool chain test: OK 223 + - looking in '/toolchains/i386-linux/usr/bin' 224 + - scanning path '/toolchains/bfin-uclinux' 225 + - looking in '/toolchains/bfin-uclinux/.' 226 + - looking in '/toolchains/bfin-uclinux/bin' 227 + - found '/toolchains/bfin-uclinux/bin/bfin-uclinux-gcc' 228 + Tool chain test: OK 229 + - looking in '/toolchains/bfin-uclinux/usr/bin' 230 + - scanning path '/toolchains/sparc-elf' 231 + - looking in '/toolchains/sparc-elf/.' 232 + - looking in '/toolchains/sparc-elf/bin' 233 + - found '/toolchains/sparc-elf/bin/sparc-elf-gcc' 234 + Tool chain test: OK 235 + - looking in '/toolchains/sparc-elf/usr/bin' 236 + - scanning path '/toolchains/arm-2010q1' 237 + - looking in '/toolchains/arm-2010q1/.' 238 + - looking in '/toolchains/arm-2010q1/bin' 239 + - found '/toolchains/arm-2010q1/bin/arm-none-linux-gnueabi-gcc' 240 + Tool chain test: OK 241 + - looking in '/toolchains/arm-2010q1/usr/bin' 242 + - scanning path '/toolchains/from' 243 + - looking in '/toolchains/from/.' 244 + - looking in '/toolchains/from/bin' 245 + - looking in '/toolchains/from/usr/bin' 246 + - scanning path '/toolchains/sh4-gentoo-linux-gnu' 247 + - looking in '/toolchains/sh4-gentoo-linux-gnu/.' 248 + - looking in '/toolchains/sh4-gentoo-linux-gnu/bin' 249 + - found '/toolchains/sh4-gentoo-linux-gnu/bin/sh4-gentoo-linux-gnu-gcc' 250 + Tool chain test: OK 251 + - looking in '/toolchains/sh4-gentoo-linux-gnu/usr/bin' 252 + - scanning path '/toolchains/avr32-linux' 253 + - looking in '/toolchains/avr32-linux/.' 254 + - looking in '/toolchains/avr32-linux/bin' 255 + - found '/toolchains/avr32-linux/bin/avr32-gcc' 256 + Tool chain test: OK 257 + - looking in '/toolchains/avr32-linux/usr/bin' 258 + - scanning path '/toolchains/m68k-linux' 259 + - looking in '/toolchains/m68k-linux/.' 260 + - looking in '/toolchains/m68k-linux/bin' 261 + - found '/toolchains/m68k-linux/bin/m68k-linux-gcc' 262 + Tool chain test: OK 263 + - looking in '/toolchains/m68k-linux/usr/bin' 264 + List of available toolchains (17): 265 + arm : /toolchains/arm-2010q1/bin/arm-none-linux-gnueabi-gcc 266 + avr32 : /toolchains/avr32-linux/bin/avr32-gcc 267 + bfin : /toolchains/bfin-uclinux/bin/bfin-uclinux-gcc 268 + c89 : /usr/bin/c89-gcc 269 + c99 : /usr/bin/c99-gcc 270 + i386 : /toolchains/i386-linux/bin/i386-linux-gcc 271 + m68k : /toolchains/m68k-linux/bin/m68k-linux-gcc 272 + mb : /toolchains/microblaze-unknown-linux-gnu/bin/mb-linux-gcc 273 + microblaze: /toolchains/microblaze-unknown-linux-gnu/bin/microblaze-unknown-linux-gnu-gcc 274 + mips : /toolchains/mips-linux/bin/mips-linux-gcc 275 + nds32le : /toolchains/nds32le-linux-glibc-v1f/bin/nds32le-linux-gcc 276 + nios2 : /toolchains/nios2/bin/nios2-linux-gcc 277 + powerpc : /toolchains/powerpc-linux/bin/powerpc-linux-gcc 278 + sandbox : /usr/bin/gcc 279 + sh4 : /toolchains/sh4-gentoo-linux-gnu/bin/sh4-gentoo-linux-gnu-gcc 280 + sparc : /toolchains/sparc-elf/bin/sparc-elf-gcc 281 + x86_64 : /usr/bin/x86_64-linux-gnu-gcc 282 + 283 + 284 + You can see that everything is covered, even some strange ones that won't 285 + be used (c88 and c99). This is a feature. 286 + 287 + 288 + How to run it 289 + ============= 290 + 291 + First do a dry run using the -n flag: (replace <branch> with a real, local 292 + branch with a valid upstream) 293 + 294 + $ ./tools/buildman/buildman -b <branch> -n 295 + 296 + If it can't detect the upstream branch, try checking out the branch, and 297 + doing something like 'git branch --set-upstream <branch> upstream/master' 298 + or something similar. 299 + 300 + As an exmmple: 301 + 302 + Dry run, so not doing much. But I would do this: 303 + 304 + Building 18 commits for 1059 boards (4 threads, 1 job per thread) 305 + Build directory: ../lcd9b 306 + 5bb3505 Merge branch 'master' of git://git.denx.de/u-boot-arm 307 + c18f1b4 tegra: Use const for pinmux_config_pingroup/table() 308 + 2f043ae tegra: Add display support to funcmux 309 + e349900 tegra: fdt: Add pwm binding and node 310 + 424a5f0 tegra: fdt: Add LCD definitions for Tegra 311 + 0636ccf tegra: Add support for PWM 312 + a994fe7 tegra: Add SOC support for display/lcd 313 + fcd7350 tegra: Add LCD driver 314 + 4d46e9d tegra: Add LCD support to Nvidia boards 315 + 991bd48 arm: Add control over cachability of memory regions 316 + 54e8019 lcd: Add CONFIG_LCD_ALIGNMENT to select frame buffer alignment 317 + d92aff7 lcd: Add support for flushing LCD fb from dcache after update 318 + dbd0677 tegra: Align LCD frame buffer to section boundary 319 + 0cff9b8 tegra: Support control of cache settings for LCD 320 + 9c56900 tegra: fdt: Add LCD definitions for Seaboard 321 + 5cc29db lcd: Add CONFIG_CONSOLE_SCROLL_LINES option to speed console 322 + cac5a23 tegra: Enable display/lcd support on Seaboard 323 + 49ff541 wip 324 + 325 + Total boards to build for each commit: 1059 326 + 327 + This shows that it will build all 1059 boards, using 4 threads (because 328 + we have a 4-core CPU). Each thread will run with -j1, meaning that each 329 + make job will use a single CPU. The list of commits to be built helps you 330 + confirm that things look about right. Notice that buildman has chosen a 331 + 'base' directory for you, immediately above your source tree. 332 + 333 + Buildman works entirely inside the base directory, here ../lcd9b, 334 + creating a working directory for each thread, and creating output 335 + directories for each commit and board. 336 + 337 + 338 + Suggested Workflow 339 + ================== 340 + 341 + To run the build for real, take off the -n: 342 + 343 + $ ./tools/buildman/buildman -b <branch> 344 + 345 + Buildman will set up some working directories, and get started. After a 346 + minute or so it will settle down to a steady pace, with a display like this: 347 + 348 + Building 18 commits for 1059 boards (4 threads, 1 job per thread) 349 + 528 36 124 /19062 1:13:30 : SIMPC8313_SP 350 + 351 + This means that it is building 19062 board/commit combinations. So far it 352 + has managed to succesfully build 528. Another 36 have built with warnings, 353 + and 124 more didn't build at all. Buildman expects to complete the process 354 + in an hour and 15 minutes. Use this time to buy a faster computer. 355 + 356 + 357 + To find out how the build went, ask for a summary with -s. You can do this 358 + either before the build completes (presumably in another terminal) or or 359 + afterwards. Let's work through an example of how this is used: 360 + 361 + $ ./tools/buildman/buildman -b lcd9b -s 362 + ... 363 + 01: Merge branch 'master' of git://git.denx.de/u-boot-arm 364 + powerpc: + galaxy5200_LOWBOOT 365 + 02: tegra: Use const for pinmux_config_pingroup/table() 366 + 03: tegra: Add display support to funcmux 367 + 04: tegra: fdt: Add pwm binding and node 368 + 05: tegra: fdt: Add LCD definitions for Tegra 369 + 06: tegra: Add support for PWM 370 + 07: tegra: Add SOC support for display/lcd 371 + 08: tegra: Add LCD driver 372 + 09: tegra: Add LCD support to Nvidia boards 373 + 10: arm: Add control over cachability of memory regions 374 + 11: lcd: Add CONFIG_LCD_ALIGNMENT to select frame buffer alignment 375 + 12: lcd: Add support for flushing LCD fb from dcache after update 376 + arm: + lubbock 377 + 13: tegra: Align LCD frame buffer to section boundary 378 + 14: tegra: Support control of cache settings for LCD 379 + 15: tegra: fdt: Add LCD definitions for Seaboard 380 + 16: lcd: Add CONFIG_CONSOLE_SCROLL_LINES option to speed console 381 + 17: tegra: Enable display/lcd support on Seaboard 382 + 18: wip 383 + 384 + This shows which commits have succeeded and which have failed. In this case 385 + the build is still in progress so many boards are not built yet (use -u to 386 + see which ones). But still we can see a few failures. The galaxy5200_LOWBOOT 387 + never builds correctly. This could be a problem with our toolchain, or it 388 + could be a bug in the upstream. The good news is that we probably don't need 389 + to blame our commits. The bad news is it isn't tested on that board. 390 + 391 + Commit 12 broke lubbock. That's what the '+ lubbock' means. The failure 392 + is never fixed by a later commit, or you would see lubbock again, in green, 393 + without the +. 394 + 395 + To see the actual error: 396 + 397 + $ ./tools/buildman/buildman -b <branch> -se lubbock 398 + ... 399 + 12: lcd: Add support for flushing LCD fb from dcache after update 400 + arm: + lubbock 401 + +common/libcommon.o: In function `lcd_sync': 402 + +/u-boot/lcd9b/.bm-work/00/common/lcd.c:120: undefined reference to `flush_dcache_range' 403 + +arm-none-linux-gnueabi-ld: BFD (Sourcery G++ Lite 2010q1-202) 2.19.51.20090709 assertion fail /scratch/julian/2010q1-release-linux-lite/obj/binutils-src-2010q1-202-arm-none-linux-gnueabi-i686-pc-linux-gnu/bfd/elf32-arm.c:12572 404 + +make: *** [/u-boot/lcd9b/.bm-work/00/build/u-boot] Error 139 405 + 13: tegra: Align LCD frame buffer to section boundary 406 + 14: tegra: Support control of cache settings for LCD 407 + 15: tegra: fdt: Add LCD definitions for Seaboard 408 + 16: lcd: Add CONFIG_CONSOLE_SCROLL_LINES option to speed console 409 + -/u-boot/lcd9b/.bm-work/00/common/lcd.c:120: undefined reference to `flush_dcache_range' 410 + +/u-boot/lcd9b/.bm-work/00/common/lcd.c:125: undefined reference to `flush_dcache_range' 411 + 17: tegra: Enable display/lcd support on Seaboard 412 + 18: wip 413 + 414 + So the problem is in lcd.c, due to missing cache operations. This information 415 + should be enough to work out what that commit is doing to break these 416 + boards. (In this case pxa did not have cache operations defined). 417 + 418 + If you see error lines marked with - that means that the errors were fixed 419 + by that commit. Sometimes commits can be in the wrong order, so that a 420 + breakage is introduced for a few commits and fixed by later commits. This 421 + shows up clearly with buildman. You can then reorder the commits and try 422 + again. 423 + 424 + At commit 16, the error moves - you can see that the old error at line 120 425 + is fixed, but there is a new one at line 126. This is probably only because 426 + we added some code and moved the broken line futher down the file. 427 + 428 + If many boards have the same error, then -e will display the error only 429 + once. This makes the output as concise as possible. 430 + 431 + The full build output in this case is available in: 432 + 433 + ../lcd9b/12_of_18_gd92aff7_lcd--Add-support-for/lubbock/ 434 + 435 + done: Indicates the build was done, and holds the return code from make. 436 + This is 0 for a good build, typically 2 for a failure. 437 + 438 + err: Output from stderr, if any. Errors and warnings appear here. 439 + 440 + log: Output from stdout. Normally there isn't any since buildman runs 441 + in silent mode for now. 442 + 443 + toolchain: Shows information about the toolchain used for the build. 444 + 445 + sizes: Shows image size information. 446 + 447 + It is possible to get the build output there also. Use the -k option for 448 + this. In that case you will also see some output files, like: 449 + 450 + System.map toolchain u-boot u-boot.bin u-boot.map autoconf.mk 451 + (also SPL versions u-boot-spl and u-boot-spl.bin if available) 452 + 453 + 454 + Checking Image Sizes 455 + ==================== 456 + 457 + A key requirement for U-Boot is that you keep code/data size to a minimum. 458 + Where a new feature increases this noticeably it should normally be put 459 + behind a CONFIG flag so that boards can leave it off and keep the image 460 + size more or less the same with each new release. 461 + 462 + To check the impact of your commits on image size, use -S. For example: 463 + 464 + $ ./tools/buildman/buildman -b us-x86 -sS 465 + Summary of 10 commits for 1066 boards (4 threads, 1 job per thread) 466 + 01: MAKEALL: add support for per architecture toolchains 467 + 02: x86: Add function to get top of usable ram 468 + x86: (for 1/3 boards) text -272.0 rodata +41.0 469 + 03: x86: Add basic cache operations 470 + 04: x86: Permit bootstage and timer data to be used prior to relocation 471 + x86: (for 1/3 boards) data +16.0 472 + 05: x86: Add an __end symbol to signal the end of the U-Boot binary 473 + x86: (for 1/3 boards) text +76.0 474 + 06: x86: Rearrange the output input to remove BSS 475 + x86: (for 1/3 boards) bss -2140.0 476 + 07: x86: Support relocation of FDT on start-up 477 + x86: + coreboot-x86 478 + 08: x86: Add error checking to x86 relocation code 479 + 09: x86: Adjust link device tree include file 480 + 10: x86: Enable CONFIG_OF_CONTROL on coreboot 481 + 482 + 483 + You can see that image size only changed on x86, which is good because this 484 + series is not supposed to change any other board. From commit 7 onwards the 485 + build fails so we don't get code size numbers. The numbers are fractional 486 + because they are an average of all boards for that architecture. The 487 + intention is to allow you to quickly find image size problems introduced by 488 + your commits. 489 + 490 + Note that the 'text' region and 'rodata' are split out. You should add the 491 + two together to get the total read-only size (reported as the first column 492 + in the output from binutil's 'size' utility). 493 + 494 + A useful option is --step which lets you skip some commits. For example 495 + --step 2 will show the image sizes for only every 2nd commit (so it will 496 + compare the image sizes of the 1st, 3rd, 5th... commits). You can also use 497 + --step 0 which will compare only the first and last commits. This is useful 498 + for an overview of how your entire series affects code size. 499 + 500 + You can also use -d to see a detailed size breakdown for each board. This 501 + list is sorted in order from largest growth to largest reduction. 502 + 503 + It is possible to go a little further with the -B option (--bloat). This 504 + shows where U-Boot has bloted, breaking the size change down to the function 505 + level. Example output is below: 506 + 507 + $ ./tools/buildman/buildman -b us-mem4 -sSdB 508 + ... 509 + 19: Roll crc32 into hash infrastructure 510 + arm: (for 10/10 boards) all -143.4 bss +1.2 data -4.8 rodata -48.2 text -91.6 511 + paz00 : all +23 bss -4 rodata -29 text +56 512 + u-boot: add: 1/0, grow: 3/-2 bytes: 168/-104 (64) 513 + function old new delta 514 + hash_command 80 160 +80 515 + crc32_wd_buf - 56 +56 516 + ext4fs_read_file 540 568 +28 517 + insert_var_value_sub 688 692 +4 518 + run_list_real 1996 1992 -4 519 + do_mem_crc 168 68 -100 520 + trimslice : all -9 bss +16 rodata -29 text +4 521 + u-boot: add: 1/0, grow: 1/-3 bytes: 136/-124 (12) 522 + function old new delta 523 + hash_command 80 160 +80 524 + crc32_wd_buf - 56 +56 525 + ext4fs_iterate_dir 672 668 -4 526 + ext4fs_read_file 568 548 -20 527 + do_mem_crc 168 68 -100 528 + whistler : all -9 bss +16 rodata -29 text +4 529 + u-boot: add: 1/0, grow: 1/-3 bytes: 136/-124 (12) 530 + function old new delta 531 + hash_command 80 160 +80 532 + crc32_wd_buf - 56 +56 533 + ext4fs_iterate_dir 672 668 -4 534 + ext4fs_read_file 568 548 -20 535 + do_mem_crc 168 68 -100 536 + seaboard : all -9 bss -28 rodata -29 text +48 537 + u-boot: add: 1/0, grow: 3/-2 bytes: 160/-104 (56) 538 + function old new delta 539 + hash_command 80 160 +80 540 + crc32_wd_buf - 56 +56 541 + ext4fs_read_file 548 568 +20 542 + run_list_real 1996 2000 +4 543 + do_nandboot 760 756 -4 544 + do_mem_crc 168 68 -100 545 + colibri_t20_iris: all -9 rodata -29 text +20 546 + u-boot: add: 1/0, grow: 2/-3 bytes: 140/-112 (28) 547 + function old new delta 548 + hash_command 80 160 +80 549 + crc32_wd_buf - 56 +56 550 + read_abs_bbt 204 208 +4 551 + do_nandboot 760 756 -4 552 + ext4fs_read_file 576 568 -8 553 + do_mem_crc 168 68 -100 554 + ventana : all -37 bss -12 rodata -29 text +4 555 + u-boot: add: 1/0, grow: 1/-3 bytes: 136/-124 (12) 556 + function old new delta 557 + hash_command 80 160 +80 558 + crc32_wd_buf - 56 +56 559 + ext4fs_iterate_dir 672 668 -4 560 + ext4fs_read_file 568 548 -20 561 + do_mem_crc 168 68 -100 562 + harmony : all -37 bss -16 rodata -29 text +8 563 + u-boot: add: 1/0, grow: 2/-3 bytes: 140/-124 (16) 564 + function old new delta 565 + hash_command 80 160 +80 566 + crc32_wd_buf - 56 +56 567 + nand_write_oob_syndrome 428 432 +4 568 + ext4fs_iterate_dir 672 668 -4 569 + ext4fs_read_file 568 548 -20 570 + do_mem_crc 168 68 -100 571 + medcom-wide : all -417 bss +28 data -16 rodata -93 text -336 572 + u-boot: add: 1/-1, grow: 1/-2 bytes: 88/-376 (-288) 573 + function old new delta 574 + crc32_wd_buf - 56 +56 575 + do_fat_read_at 2872 2904 +32 576 + hash_algo 16 - -16 577 + do_mem_crc 168 68 -100 578 + hash_command 420 160 -260 579 + tec : all -449 bss -4 data -16 rodata -93 text -336 580 + u-boot: add: 1/-1, grow: 1/-2 bytes: 88/-376 (-288) 581 + function old new delta 582 + crc32_wd_buf - 56 +56 583 + do_fat_read_at 2872 2904 +32 584 + hash_algo 16 - -16 585 + do_mem_crc 168 68 -100 586 + hash_command 420 160 -260 587 + plutux : all -481 bss +16 data -16 rodata -93 text -388 588 + u-boot: add: 1/-1, grow: 1/-3 bytes: 68/-408 (-340) 589 + function old new delta 590 + crc32_wd_buf - 56 +56 591 + do_load_serial_bin 1688 1700 +12 592 + hash_algo 16 - -16 593 + do_fat_read_at 2904 2872 -32 594 + do_mem_crc 168 68 -100 595 + hash_command 420 160 -260 596 + powerpc: (for 5/5 boards) all +37.4 data -3.2 rodata -41.8 text +82.4 597 + MPC8610HPCD : all +55 rodata -29 text +84 598 + u-boot: add: 1/0, grow: 0/-1 bytes: 176/-96 (80) 599 + function old new delta 600 + hash_command - 176 +176 601 + do_mem_crc 184 88 -96 602 + MPC8641HPCN : all +55 rodata -29 text +84 603 + u-boot: add: 1/0, grow: 0/-1 bytes: 176/-96 (80) 604 + function old new delta 605 + hash_command - 176 +176 606 + do_mem_crc 184 88 -96 607 + MPC8641HPCN_36BIT: all +55 rodata -29 text +84 608 + u-boot: add: 1/0, grow: 0/-1 bytes: 176/-96 (80) 609 + function old new delta 610 + hash_command - 176 +176 611 + do_mem_crc 184 88 -96 612 + sbc8641d : all +55 rodata -29 text +84 613 + u-boot: add: 1/0, grow: 0/-1 bytes: 176/-96 (80) 614 + function old new delta 615 + hash_command - 176 +176 616 + do_mem_crc 184 88 -96 617 + xpedite517x : all -33 data -16 rodata -93 text +76 618 + u-boot: add: 1/-1, grow: 0/-1 bytes: 176/-112 (64) 619 + function old new delta 620 + hash_command - 176 +176 621 + hash_algo 16 - -16 622 + do_mem_crc 184 88 -96 623 + ... 624 + 625 + 626 + This shows that commit 19 has increased text size for arm (although only one 627 + board was built) and by 96 bytes for powerpc. This increase was offset in both 628 + cases by reductions in rodata and data/bss. 629 + 630 + Shown below the summary lines is the sizes for each board. Below each board 631 + is the sizes for each function. This information starts with: 632 + 633 + add - number of functions added / removed 634 + grow - number of functions which grew / shrunk 635 + bytes - number of bytes of code added to / removed from all functions, 636 + plus the total byte change in brackets 637 + 638 + The change seems to be that hash_command() has increased by more than the 639 + do_mem_crc() function has decreased. The function sizes typically add up to 640 + roughly the text area size, but note that every read-only section except 641 + rodata is included in 'text', so the function total does not exactly 642 + correspond. 643 + 644 + It is common when refactoring code for the rodata to decrease as the text size 645 + increases, and vice versa. 646 + 647 + 648 + Other options 649 + ============= 650 + 651 + Buildman has various other command line options. Try --help to see them. 652 + 653 + 654 + TODO 655 + ==== 656 + 657 + This has mostly be written in my spare time as a response to my difficulties 658 + in testing large series of patches. Apart from tidying up there is quite a 659 + bit of scope for improvement. Things like better error diffs, easier access 660 + to log files, error display while building. Also it would be nice it buildman 661 + could 'hunt' for problems, perhaps by building a few boards for each arch, 662 + or checking commits for changed files and building only boards which use 663 + those files. 664 + 665 + 666 + Credits 667 + ======= 668 + 669 + Thanks to Grant Grundler <grundler@chromium.org> for his ideas for improving 670 + the build speed by building all commits for a board instead of the other 671 + way around. 672 + 673 + 674 + 675 + Simon Glass 676 + sjg@chromium.org 677 + Halloween 2012 678 + Updated 12-12-12 679 + Updated 23-02-13
+167
tools/buildman/board.py
··· 1 + # Copyright (c) 2012 The Chromium OS Authors. 2 + # 3 + # See file CREDITS for list of people who contributed to this 4 + # project. 5 + # 6 + # This program is free software; you can redistribute it and/or 7 + # modify it under the terms of the GNU General Public License as 8 + # published by the Free Software Foundation; either version 2 of 9 + # the License, or (at your option) any later version. 10 + # 11 + # This program is distributed in the hope that it will be useful, 12 + # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + # GNU General Public License for more details. 15 + # 16 + # You should have received a copy of the GNU General Public License 17 + # along with this program; if not, write to the Free Software 18 + # Foundation, Inc., 59 Temple Place, Suite 330, Boston, 19 + # MA 02111-1307 USA 20 + # 21 + 22 + class Board: 23 + """A particular board that we can build""" 24 + def __init__(self, target, arch, cpu, board_name, vendor, soc, options): 25 + """Create a new board type. 26 + 27 + Args: 28 + target: Target name (use make <target>_config to configure) 29 + arch: Architecture name (e.g. arm) 30 + cpu: Cpu name (e.g. arm1136) 31 + board_name: Name of board (e.g. integrator) 32 + vendor: Name of vendor (e.g. armltd) 33 + soc: Name of SOC, or '' if none (e.g. mx31) 34 + options: board-specific options (e.g. integratorcp:CM1136) 35 + """ 36 + self.target = target 37 + self.arch = arch 38 + self.cpu = cpu 39 + self.board_name = board_name 40 + self.vendor = vendor 41 + self.soc = soc 42 + self.props = [self.target, self.arch, self.cpu, self.board_name, 43 + self.vendor, self.soc] 44 + self.options = options 45 + self.build_it = False 46 + 47 + 48 + class Boards: 49 + """Manage a list of boards.""" 50 + def __init__(self): 51 + # Use a simple list here, sinc OrderedDict requires Python 2.7 52 + self._boards = [] 53 + 54 + def AddBoard(self, board): 55 + """Add a new board to the list. 56 + 57 + The board's target member must not already exist in the board list. 58 + 59 + Args: 60 + board: board to add 61 + """ 62 + self._boards.append(board) 63 + 64 + def ReadBoards(self, fname): 65 + """Read a list of boards from a board file. 66 + 67 + Create a board object for each and add it to our _boards list. 68 + 69 + Args: 70 + fname: Filename of boards.cfg file 71 + """ 72 + with open(fname, 'r') as fd: 73 + for line in fd: 74 + if line[0] == '#': 75 + continue 76 + fields = line.split() 77 + if not fields: 78 + continue 79 + for upto in range(len(fields)): 80 + if fields[upto] == '-': 81 + fields[upto] = '' 82 + while len(fields) < 7: 83 + fields.append('') 84 + 85 + board = Board(*fields) 86 + self.AddBoard(board) 87 + 88 + 89 + def GetList(self): 90 + """Return a list of available boards. 91 + 92 + Returns: 93 + List of Board objects 94 + """ 95 + return self._boards 96 + 97 + def GetDict(self): 98 + """Build a dictionary containing all the boards. 99 + 100 + Returns: 101 + Dictionary: 102 + key is board.target 103 + value is board 104 + """ 105 + board_dict = {} 106 + for board in self._boards: 107 + board_dict[board.target] = board 108 + return board_dict 109 + 110 + def GetSelectedDict(self): 111 + """Return a dictionary containing the selected boards 112 + 113 + Returns: 114 + List of Board objects that are marked selected 115 + """ 116 + board_dict = {} 117 + for board in self._boards: 118 + if board.build_it: 119 + board_dict[board.target] = board 120 + return board_dict 121 + 122 + def GetSelected(self): 123 + """Return a list of selected boards 124 + 125 + Returns: 126 + List of Board objects that are marked selected 127 + """ 128 + return [board for board in self._boards if board.build_it] 129 + 130 + def GetSelectedNames(self): 131 + """Return a list of selected boards 132 + 133 + Returns: 134 + List of board names that are marked selected 135 + """ 136 + return [board.target for board in self._boards if board.build_it] 137 + 138 + def SelectBoards(self, args): 139 + """Mark boards selected based on args 140 + 141 + Args: 142 + List of strings specifying boards to include, either named, or 143 + by their target, architecture, cpu, vendor or soc. If empty, all 144 + boards are selected. 145 + 146 + Returns: 147 + Dictionary which holds the number of boards which were selected 148 + due to each argument, arranged by argument. 149 + """ 150 + result = {} 151 + for arg in args: 152 + result[arg] = 0 153 + result['all'] = 0 154 + 155 + for board in self._boards: 156 + if args: 157 + for arg in args: 158 + if arg in board.props: 159 + if not board.build_it: 160 + board.build_it = True 161 + result[arg] += 1 162 + result['all'] += 1 163 + else: 164 + board.build_it = True 165 + result['all'] += 1 166 + 167 + return result
+60
tools/buildman/bsettings.py
··· 1 + # Copyright (c) 2012 The Chromium OS Authors. 2 + # 3 + # See file CREDITS for list of people who contributed to this 4 + # project. 5 + # 6 + # This program is free software; you can redistribute it and/or 7 + # modify it under the terms of the GNU General Public License as 8 + # published by the Free Software Foundation; either version 2 of 9 + # the License, or (at your option) any later version. 10 + # 11 + # This program is distributed in the hope that it will be useful, 12 + # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + # GNU General Public License for more details. 15 + # 16 + # You should have received a copy of the GNU General Public License 17 + # along with this program; if not, write to the Free Software 18 + # Foundation, Inc., 59 Temple Place, Suite 330, Boston, 19 + # MA 02111-1307 USA 20 + # 21 + 22 + import ConfigParser 23 + import os 24 + 25 + 26 + def Setup(fname=''): 27 + """Set up the buildman settings module by reading config files 28 + 29 + Args: 30 + config_fname: Config filename to read ('' for default) 31 + """ 32 + global settings 33 + global config_fname 34 + 35 + settings = ConfigParser.SafeConfigParser() 36 + config_fname = fname 37 + if config_fname == '': 38 + config_fname = '%s/.buildman' % os.getenv('HOME') 39 + if config_fname: 40 + settings.read(config_fname) 41 + 42 + def GetItems(section): 43 + """Get the items from a section of the config. 44 + 45 + Args: 46 + section: name of section to retrieve 47 + 48 + Returns: 49 + List of (name, value) tuples for the section 50 + """ 51 + try: 52 + return settings.items(section) 53 + except ConfigParser.NoSectionError as e: 54 + print e 55 + print ("Warning: No tool chains - please add a [toolchain] section " 56 + "to your buildman config file %s. See README for details" % 57 + config_fname) 58 + return [] 59 + except: 60 + raise
+1445
tools/buildman/builder.py
··· 1 + # Copyright (c) 2013 The Chromium OS Authors. 2 + # 3 + # Bloat-o-meter code used here Copyright 2004 Matt Mackall <mpm@selenic.com> 4 + # 5 + # See file CREDITS for list of people who contributed to this 6 + # project. 7 + # 8 + # This program is free software; you can redistribute it and/or 9 + # modify it under the terms of the GNU General Public License as 10 + # published by the Free Software Foundation; either version 2 of 11 + # the License, or (at your option) any later version. 12 + # 13 + # This program is distributed in the hope that it will be useful, 14 + # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 + # GNU General Public License for more details. 17 + # 18 + # You should have received a copy of the GNU General Public License 19 + # along with this program; if not, write to the Free Software 20 + # Foundation, Inc., 59 Temple Place, Suite 330, Boston, 21 + # MA 02111-1307 USA 22 + # 23 + 24 + import collections 25 + import errno 26 + from datetime import datetime, timedelta 27 + import glob 28 + import os 29 + import re 30 + import Queue 31 + import shutil 32 + import string 33 + import sys 34 + import threading 35 + import time 36 + 37 + import command 38 + import gitutil 39 + import terminal 40 + import toolchain 41 + 42 + 43 + """ 44 + Theory of Operation 45 + 46 + Please see README for user documentation, and you should be familiar with 47 + that before trying to make sense of this. 48 + 49 + Buildman works by keeping the machine as busy as possible, building different 50 + commits for different boards on multiple CPUs at once. 51 + 52 + The source repo (self.git_dir) contains all the commits to be built. Each 53 + thread works on a single board at a time. It checks out the first commit, 54 + configures it for that board, then builds it. Then it checks out the next 55 + commit and builds it (typically without re-configuring). When it runs out 56 + of commits, it gets another job from the builder and starts again with that 57 + board. 58 + 59 + Clearly the builder threads could work either way - they could check out a 60 + commit and then built it for all boards. Using separate directories for each 61 + commit/board pair they could leave their build product around afterwards 62 + also. 63 + 64 + The intent behind building a single board for multiple commits, is to make 65 + use of incremental builds. Since each commit is built incrementally from 66 + the previous one, builds are faster. Reconfiguring for a different board 67 + removes all intermediate object files. 68 + 69 + Many threads can be working at once, but each has its own working directory. 70 + When a thread finishes a build, it puts the output files into a result 71 + directory. 72 + 73 + The base directory used by buildman is normally '../<branch>', i.e. 74 + a directory higher than the source repository and named after the branch 75 + being built. 76 + 77 + Within the base directory, we have one subdirectory for each commit. Within 78 + that is one subdirectory for each board. Within that is the build output for 79 + that commit/board combination. 80 + 81 + Buildman also create working directories for each thread, in a .bm-work/ 82 + subdirectory in the base dir. 83 + 84 + As an example, say we are building branch 'us-net' for boards 'sandbox' and 85 + 'seaboard', and say that us-net has two commits. We will have directories 86 + like this: 87 + 88 + us-net/ base directory 89 + 01_of_02_g4ed4ebc_net--Add-tftp-speed-/ 90 + sandbox/ 91 + u-boot.bin 92 + seaboard/ 93 + u-boot.bin 94 + 02_of_02_g4ed4ebc_net--Check-tftp-comp/ 95 + sandbox/ 96 + u-boot.bin 97 + seaboard/ 98 + u-boot.bin 99 + .bm-work/ 100 + 00/ working directory for thread 0 (contains source checkout) 101 + build/ build output 102 + 01/ working directory for thread 1 103 + build/ build output 104 + ... 105 + u-boot/ source directory 106 + .git/ repository 107 + """ 108 + 109 + # Possible build outcomes 110 + OUTCOME_OK, OUTCOME_WARNING, OUTCOME_ERROR, OUTCOME_UNKNOWN = range(4) 111 + 112 + # Translate a commit subject into a valid filename 113 + trans_valid_chars = string.maketrans("/: ", "---") 114 + 115 + 116 + def Mkdir(dirname): 117 + """Make a directory if it doesn't already exist. 118 + 119 + Args: 120 + dirname: Directory to create 121 + """ 122 + try: 123 + os.mkdir(dirname) 124 + except OSError as err: 125 + if err.errno == errno.EEXIST: 126 + pass 127 + else: 128 + raise 129 + 130 + class BuilderJob: 131 + """Holds information about a job to be performed by a thread 132 + 133 + Members: 134 + board: Board object to build 135 + commits: List of commit options to build. 136 + """ 137 + def __init__(self): 138 + self.board = None 139 + self.commits = [] 140 + 141 + 142 + class ResultThread(threading.Thread): 143 + """This thread processes results from builder threads. 144 + 145 + It simply passes the results on to the builder. There is only one 146 + result thread, and this helps to serialise the build output. 147 + """ 148 + def __init__(self, builder): 149 + """Set up a new result thread 150 + 151 + Args: 152 + builder: Builder which will be sent each result 153 + """ 154 + threading.Thread.__init__(self) 155 + self.builder = builder 156 + 157 + def run(self): 158 + """Called to start up the result thread. 159 + 160 + We collect the next result job and pass it on to the build. 161 + """ 162 + while True: 163 + result = self.builder.out_queue.get() 164 + self.builder.ProcessResult(result) 165 + self.builder.out_queue.task_done() 166 + 167 + 168 + class BuilderThread(threading.Thread): 169 + """This thread builds U-Boot for a particular board. 170 + 171 + An input queue provides each new job. We run 'make' to build U-Boot 172 + and then pass the results on to the output queue. 173 + 174 + Members: 175 + builder: The builder which contains information we might need 176 + thread_num: Our thread number (0-n-1), used to decide on a 177 + temporary directory 178 + """ 179 + def __init__(self, builder, thread_num): 180 + """Set up a new builder thread""" 181 + threading.Thread.__init__(self) 182 + self.builder = builder 183 + self.thread_num = thread_num 184 + 185 + def Make(self, commit, brd, stage, cwd, *args, **kwargs): 186 + """Run 'make' on a particular commit and board. 187 + 188 + The source code will already be checked out, so the 'commit' 189 + argument is only for information. 190 + 191 + Args: 192 + commit: Commit object that is being built 193 + brd: Board object that is being built 194 + stage: Stage of the build. Valid stages are: 195 + distclean - can be called to clean source 196 + config - called to configure for a board 197 + build - the main make invocation - it does the build 198 + args: A list of arguments to pass to 'make' 199 + kwargs: A list of keyword arguments to pass to command.RunPipe() 200 + 201 + Returns: 202 + CommandResult object 203 + """ 204 + return self.builder.do_make(commit, brd, stage, cwd, *args, 205 + **kwargs) 206 + 207 + def RunCommit(self, commit_upto, brd, work_dir, do_config, force_build): 208 + """Build a particular commit. 209 + 210 + If the build is already done, and we are not forcing a build, we skip 211 + the build and just return the previously-saved results. 212 + 213 + Args: 214 + commit_upto: Commit number to build (0...n-1) 215 + brd: Board object to build 216 + work_dir: Directory to which the source will be checked out 217 + do_config: True to run a make <board>_config on the source 218 + force_build: Force a build even if one was previously done 219 + 220 + Returns: 221 + tuple containing: 222 + - CommandResult object containing the results of the build 223 + - boolean indicating whether 'make config' is still needed 224 + """ 225 + # Create a default result - it will be overwritte by the call to 226 + # self.Make() below, in the event that we do a build. 227 + result = command.CommandResult() 228 + result.return_code = 0 229 + out_dir = os.path.join(work_dir, 'build') 230 + 231 + # Check if the job was already completed last time 232 + done_file = self.builder.GetDoneFile(commit_upto, brd.target) 233 + result.already_done = os.path.exists(done_file) 234 + if result.already_done and not force_build: 235 + # Get the return code from that build and use it 236 + with open(done_file, 'r') as fd: 237 + result.return_code = int(fd.readline()) 238 + err_file = self.builder.GetErrFile(commit_upto, brd.target) 239 + if os.path.exists(err_file) and os.stat(err_file).st_size: 240 + result.stderr = 'bad' 241 + else: 242 + # We are going to have to build it. First, get a toolchain 243 + if not self.toolchain: 244 + try: 245 + self.toolchain = self.builder.toolchains.Select(brd.arch) 246 + except ValueError as err: 247 + result.return_code = 10 248 + result.stdout = '' 249 + result.stderr = str(err) 250 + # TODO(sjg@chromium.org): This gets swallowed, but needs 251 + # to be reported. 252 + 253 + if self.toolchain: 254 + # Checkout the right commit 255 + if commit_upto is not None: 256 + commit = self.builder.commits[commit_upto] 257 + if self.builder.checkout: 258 + git_dir = os.path.join(work_dir, '.git') 259 + gitutil.Checkout(commit.hash, git_dir, work_dir, 260 + force=True) 261 + else: 262 + commit = self.builder.commit # Ick, fix this for BuildCommits() 263 + 264 + # Set up the environment and command line 265 + env = self.toolchain.MakeEnvironment() 266 + Mkdir(out_dir) 267 + args = ['O=build', '-s'] 268 + if self.builder.num_jobs is not None: 269 + args.extend(['-j', str(self.builder.num_jobs)]) 270 + config_args = ['%s_config' % brd.target] 271 + config_out = '' 272 + 273 + # If we need to reconfigure, do that now 274 + if do_config: 275 + result = self.Make(commit, brd, 'distclean', work_dir, 276 + 'distclean', *args, env=env) 277 + result = self.Make(commit, brd, 'config', work_dir, 278 + *(args + config_args), env=env) 279 + config_out = result.combined 280 + do_config = False # No need to configure next time 281 + if result.return_code == 0: 282 + result = self.Make(commit, brd, 'build', work_dir, *args, 283 + env=env) 284 + result.stdout = config_out + result.stdout 285 + else: 286 + result.return_code = 1 287 + result.stderr = 'No tool chain for %s\n' % brd.arch 288 + result.already_done = False 289 + 290 + result.toolchain = self.toolchain 291 + result.brd = brd 292 + result.commit_upto = commit_upto 293 + result.out_dir = out_dir 294 + return result, do_config 295 + 296 + def _WriteResult(self, result, keep_outputs): 297 + """Write a built result to the output directory. 298 + 299 + Args: 300 + result: CommandResult object containing result to write 301 + keep_outputs: True to store the output binaries, False 302 + to delete them 303 + """ 304 + # Fatal error 305 + if result.return_code < 0: 306 + return 307 + 308 + # Aborted? 309 + if result.stderr and 'No child processes' in result.stderr: 310 + return 311 + 312 + if result.already_done: 313 + return 314 + 315 + # Write the output and stderr 316 + output_dir = self.builder._GetOutputDir(result.commit_upto) 317 + Mkdir(output_dir) 318 + build_dir = self.builder.GetBuildDir(result.commit_upto, 319 + result.brd.target) 320 + Mkdir(build_dir) 321 + 322 + outfile = os.path.join(build_dir, 'log') 323 + with open(outfile, 'w') as fd: 324 + if result.stdout: 325 + fd.write(result.stdout) 326 + 327 + errfile = self.builder.GetErrFile(result.commit_upto, 328 + result.brd.target) 329 + if result.stderr: 330 + with open(errfile, 'w') as fd: 331 + fd.write(result.stderr) 332 + elif os.path.exists(errfile): 333 + os.remove(errfile) 334 + 335 + if result.toolchain: 336 + # Write the build result and toolchain information. 337 + done_file = self.builder.GetDoneFile(result.commit_upto, 338 + result.brd.target) 339 + with open(done_file, 'w') as fd: 340 + fd.write('%s' % result.return_code) 341 + with open(os.path.join(build_dir, 'toolchain'), 'w') as fd: 342 + print >>fd, 'gcc', result.toolchain.gcc 343 + print >>fd, 'path', result.toolchain.path 344 + print >>fd, 'cross', result.toolchain.cross 345 + print >>fd, 'arch', result.toolchain.arch 346 + fd.write('%s' % result.return_code) 347 + 348 + with open(os.path.join(build_dir, 'toolchain'), 'w') as fd: 349 + print >>fd, 'gcc', result.toolchain.gcc 350 + print >>fd, 'path', result.toolchain.path 351 + 352 + # Write out the image and function size information and an objdump 353 + env = result.toolchain.MakeEnvironment() 354 + lines = [] 355 + for fname in ['u-boot', 'spl/u-boot-spl']: 356 + cmd = ['%snm' % self.toolchain.cross, '--size-sort', fname] 357 + nm_result = command.RunPipe([cmd], capture=True, 358 + capture_stderr=True, cwd=result.out_dir, 359 + raise_on_error=False, env=env) 360 + if nm_result.stdout: 361 + nm = self.builder.GetFuncSizesFile(result.commit_upto, 362 + result.brd.target, fname) 363 + with open(nm, 'w') as fd: 364 + print >>fd, nm_result.stdout, 365 + 366 + cmd = ['%sobjdump' % self.toolchain.cross, '-h', fname] 367 + dump_result = command.RunPipe([cmd], capture=True, 368 + capture_stderr=True, cwd=result.out_dir, 369 + raise_on_error=False, env=env) 370 + rodata_size = '' 371 + if dump_result.stdout: 372 + objdump = self.builder.GetObjdumpFile(result.commit_upto, 373 + result.brd.target, fname) 374 + with open(objdump, 'w') as fd: 375 + print >>fd, dump_result.stdout, 376 + for line in dump_result.stdout.splitlines(): 377 + fields = line.split() 378 + if len(fields) > 5 and fields[1] == '.rodata': 379 + rodata_size = fields[2] 380 + 381 + cmd = ['%ssize' % self.toolchain.cross, fname] 382 + size_result = command.RunPipe([cmd], capture=True, 383 + capture_stderr=True, cwd=result.out_dir, 384 + raise_on_error=False, env=env) 385 + if size_result.stdout: 386 + lines.append(size_result.stdout.splitlines()[1] + ' ' + 387 + rodata_size) 388 + 389 + # Write out the image sizes file. This is similar to the output 390 + # of binutil's 'size' utility, but it omits the header line and 391 + # adds an additional hex value at the end of each line for the 392 + # rodata size 393 + if len(lines): 394 + sizes = self.builder.GetSizesFile(result.commit_upto, 395 + result.brd.target) 396 + with open(sizes, 'w') as fd: 397 + print >>fd, '\n'.join(lines) 398 + 399 + # Now write the actual build output 400 + if keep_outputs: 401 + patterns = ['u-boot', '*.bin', 'u-boot.dtb', '*.map', 402 + 'include/autoconf.mk', 'spl/u-boot-spl', 403 + 'spl/u-boot-spl.bin'] 404 + for pattern in patterns: 405 + file_list = glob.glob(os.path.join(result.out_dir, pattern)) 406 + for fname in file_list: 407 + shutil.copy(fname, build_dir) 408 + 409 + 410 + def RunJob(self, job): 411 + """Run a single job 412 + 413 + A job consists of a building a list of commits for a particular board. 414 + 415 + Args: 416 + job: Job to build 417 + """ 418 + brd = job.board 419 + work_dir = self.builder.GetThreadDir(self.thread_num) 420 + self.toolchain = None 421 + if job.commits: 422 + # Run 'make board_config' on the first commit 423 + do_config = True 424 + commit_upto = 0 425 + force_build = False 426 + for commit_upto in range(0, len(job.commits), job.step): 427 + result, request_config = self.RunCommit(commit_upto, brd, 428 + work_dir, do_config, 429 + force_build or self.builder.force_build) 430 + failed = result.return_code or result.stderr 431 + if failed and not do_config: 432 + # If our incremental build failed, try building again 433 + # with a reconfig. 434 + if self.builder.force_config_on_failure: 435 + result, request_config = self.RunCommit(commit_upto, 436 + brd, work_dir, True, True) 437 + do_config = request_config 438 + 439 + # If we built that commit, then config is done. But if we got 440 + # an warning, reconfig next time to force it to build the same 441 + # files that created warnings this time. Otherwise an 442 + # incremental build may not build the same file, and we will 443 + # think that the warning has gone away. 444 + # We could avoid this by using -Werror everywhere... 445 + # For errors, the problem doesn't happen, since presumably 446 + # the build stopped and didn't generate output, so will retry 447 + # that file next time. So we could detect warnings and deal 448 + # with them specially here. For now, we just reconfigure if 449 + # anything goes work. 450 + # Of course this is substantially slower if there are build 451 + # errors/warnings (e.g. 2-3x slower even if only 10% of builds 452 + # have problems). 453 + if (failed and not result.already_done and not do_config and 454 + self.builder.force_config_on_failure): 455 + # If this build failed, try the next one with a 456 + # reconfigure. 457 + # Sometimes if the board_config.h file changes it can mess 458 + # with dependencies, and we get: 459 + # make: *** No rule to make target `include/autoconf.mk', 460 + # needed by `depend'. 461 + do_config = True 462 + force_build = True 463 + else: 464 + force_build = False 465 + if self.builder.force_config_on_failure: 466 + if failed: 467 + do_config = True 468 + result.commit_upto = commit_upto 469 + if result.return_code < 0: 470 + raise ValueError('Interrupt') 471 + 472 + # We have the build results, so output the result 473 + self._WriteResult(result, job.keep_outputs) 474 + self.builder.out_queue.put(result) 475 + else: 476 + # Just build the currently checked-out build 477 + result = self.RunCommit(None, True) 478 + result.commit_upto = self.builder.upto 479 + self.builder.out_queue.put(result) 480 + 481 + def run(self): 482 + """Our thread's run function 483 + 484 + This thread picks a job from the queue, runs it, and then goes to the 485 + next job. 486 + """ 487 + alive = True 488 + while True: 489 + job = self.builder.queue.get() 490 + try: 491 + if self.builder.active and alive: 492 + self.RunJob(job) 493 + except Exception as err: 494 + alive = False 495 + print err 496 + self.builder.queue.task_done() 497 + 498 + 499 + class Builder: 500 + """Class for building U-Boot for a particular commit. 501 + 502 + Public members: (many should ->private) 503 + active: True if the builder is active and has not been stopped 504 + already_done: Number of builds already completed 505 + base_dir: Base directory to use for builder 506 + checkout: True to check out source, False to skip that step. 507 + This is used for testing. 508 + col: terminal.Color() object 509 + count: Number of commits to build 510 + do_make: Method to call to invoke Make 511 + fail: Number of builds that failed due to error 512 + force_build: Force building even if a build already exists 513 + force_config_on_failure: If a commit fails for a board, disable 514 + incremental building for the next commit we build for that 515 + board, so that we will see all warnings/errors again. 516 + git_dir: Git directory containing source repository 517 + last_line_len: Length of the last line we printed (used for erasing 518 + it with new progress information) 519 + num_jobs: Number of jobs to run at once (passed to make as -j) 520 + num_threads: Number of builder threads to run 521 + out_queue: Queue of results to process 522 + re_make_err: Compiled regular expression for ignore_lines 523 + queue: Queue of jobs to run 524 + threads: List of active threads 525 + toolchains: Toolchains object to use for building 526 + upto: Current commit number we are building (0.count-1) 527 + warned: Number of builds that produced at least one warning 528 + 529 + Private members: 530 + _base_board_dict: Last-summarised Dict of boards 531 + _base_err_lines: Last-summarised list of errors 532 + _build_period_us: Time taken for a single build (float object). 533 + _complete_delay: Expected delay until completion (timedelta) 534 + _next_delay_update: Next time we plan to display a progress update 535 + (datatime) 536 + _show_unknown: Show unknown boards (those not built) in summary 537 + _timestamps: List of timestamps for the completion of the last 538 + last _timestamp_count builds. Each is a datetime object. 539 + _timestamp_count: Number of timestamps to keep in our list. 540 + _working_dir: Base working directory containing all threads 541 + """ 542 + class Outcome: 543 + """Records a build outcome for a single make invocation 544 + 545 + Public Members: 546 + rc: Outcome value (OUTCOME_...) 547 + err_lines: List of error lines or [] if none 548 + sizes: Dictionary of image size information, keyed by filename 549 + - Each value is itself a dictionary containing 550 + values for 'text', 'data' and 'bss', being the integer 551 + size in bytes of each section. 552 + func_sizes: Dictionary keyed by filename - e.g. 'u-boot'. Each 553 + value is itself a dictionary: 554 + key: function name 555 + value: Size of function in bytes 556 + """ 557 + def __init__(self, rc, err_lines, sizes, func_sizes): 558 + self.rc = rc 559 + self.err_lines = err_lines 560 + self.sizes = sizes 561 + self.func_sizes = func_sizes 562 + 563 + def __init__(self, toolchains, base_dir, git_dir, num_threads, num_jobs, 564 + checkout=True, show_unknown=True, step=1): 565 + """Create a new Builder object 566 + 567 + Args: 568 + toolchains: Toolchains object to use for building 569 + base_dir: Base directory to use for builder 570 + git_dir: Git directory containing source repository 571 + num_threads: Number of builder threads to run 572 + num_jobs: Number of jobs to run at once (passed to make as -j) 573 + checkout: True to check out source, False to skip that step. 574 + This is used for testing. 575 + show_unknown: Show unknown boards (those not built) in summary 576 + step: 1 to process every commit, n to process every nth commit 577 + """ 578 + self.toolchains = toolchains 579 + self.base_dir = base_dir 580 + self._working_dir = os.path.join(base_dir, '.bm-work') 581 + self.threads = [] 582 + self.active = True 583 + self.do_make = self.Make 584 + self.checkout = checkout 585 + self.num_threads = num_threads 586 + self.num_jobs = num_jobs 587 + self.already_done = 0 588 + self.force_build = False 589 + self.git_dir = git_dir 590 + self._show_unknown = show_unknown 591 + self._timestamp_count = 10 592 + self._build_period_us = None 593 + self._complete_delay = None 594 + self._next_delay_update = datetime.now() 595 + self.force_config_on_failure = True 596 + self._step = step 597 + 598 + self.col = terminal.Color() 599 + 600 + self.queue = Queue.Queue() 601 + self.out_queue = Queue.Queue() 602 + for i in range(self.num_threads): 603 + t = BuilderThread(self, i) 604 + t.setDaemon(True) 605 + t.start() 606 + self.threads.append(t) 607 + 608 + self.last_line_len = 0 609 + t = ResultThread(self) 610 + t.setDaemon(True) 611 + t.start() 612 + self.threads.append(t) 613 + 614 + ignore_lines = ['(make.*Waiting for unfinished)', '(Segmentation fault)'] 615 + self.re_make_err = re.compile('|'.join(ignore_lines)) 616 + 617 + def __del__(self): 618 + """Get rid of all threads created by the builder""" 619 + for t in self.threads: 620 + del t 621 + 622 + def _AddTimestamp(self): 623 + """Add a new timestamp to the list and record the build period. 624 + 625 + The build period is the length of time taken to perform a single 626 + build (one board, one commit). 627 + """ 628 + now = datetime.now() 629 + self._timestamps.append(now) 630 + count = len(self._timestamps) 631 + delta = self._timestamps[-1] - self._timestamps[0] 632 + seconds = delta.total_seconds() 633 + 634 + # If we have enough data, estimate build period (time taken for a 635 + # single build) and therefore completion time. 636 + if count > 1 and self._next_delay_update < now: 637 + self._next_delay_update = now + timedelta(seconds=2) 638 + if seconds > 0: 639 + self._build_period = float(seconds) / count 640 + todo = self.count - self.upto 641 + self._complete_delay = timedelta(microseconds= 642 + self._build_period * todo * 1000000) 643 + # Round it 644 + self._complete_delay -= timedelta( 645 + microseconds=self._complete_delay.microseconds) 646 + 647 + if seconds > 60: 648 + self._timestamps.popleft() 649 + count -= 1 650 + 651 + def ClearLine(self, length): 652 + """Clear any characters on the current line 653 + 654 + Make way for a new line of length 'length', by outputting enough 655 + spaces to clear out the old line. Then remember the new length for 656 + next time. 657 + 658 + Args: 659 + length: Length of new line, in characters 660 + """ 661 + if length < self.last_line_len: 662 + print ' ' * (self.last_line_len - length), 663 + print '\r', 664 + self.last_line_len = length 665 + sys.stdout.flush() 666 + 667 + def SelectCommit(self, commit, checkout=True): 668 + """Checkout the selected commit for this build 669 + """ 670 + self.commit = commit 671 + if checkout and self.checkout: 672 + gitutil.Checkout(commit.hash) 673 + 674 + def Make(self, commit, brd, stage, cwd, *args, **kwargs): 675 + """Run make 676 + 677 + Args: 678 + commit: Commit object that is being built 679 + brd: Board object that is being built 680 + stage: Stage that we are at (distclean, config, build) 681 + cwd: Directory where make should be run 682 + args: Arguments to pass to make 683 + kwargs: Arguments to pass to command.RunPipe() 684 + """ 685 + cmd = ['make'] + list(args) 686 + result = command.RunPipe([cmd], capture=True, capture_stderr=True, 687 + cwd=cwd, raise_on_error=False, **kwargs) 688 + return result 689 + 690 + def ProcessResult(self, result): 691 + """Process the result of a build, showing progress information 692 + 693 + Args: 694 + result: A CommandResult object 695 + """ 696 + col = terminal.Color() 697 + if result: 698 + target = result.brd.target 699 + 700 + if result.return_code < 0: 701 + self.active = False 702 + command.StopAll() 703 + return 704 + 705 + self.upto += 1 706 + if result.return_code != 0: 707 + self.fail += 1 708 + elif result.stderr: 709 + self.warned += 1 710 + if result.already_done: 711 + self.already_done += 1 712 + else: 713 + target = '(starting)' 714 + 715 + # Display separate counts for ok, warned and fail 716 + ok = self.upto - self.warned - self.fail 717 + line = '\r' + self.col.Color(self.col.GREEN, '%5d' % ok) 718 + line += self.col.Color(self.col.YELLOW, '%5d' % self.warned) 719 + line += self.col.Color(self.col.RED, '%5d' % self.fail) 720 + 721 + name = ' /%-5d ' % self.count 722 + 723 + # Add our current completion time estimate 724 + self._AddTimestamp() 725 + if self._complete_delay: 726 + name += '%s : ' % self._complete_delay 727 + # When building all boards for a commit, we can print a commit 728 + # progress message. 729 + if result and result.commit_upto is None: 730 + name += 'commit %2d/%-3d' % (self.commit_upto + 1, 731 + self.commit_count) 732 + 733 + name += target 734 + print line + name, 735 + length = 13 + len(name) 736 + self.ClearLine(length) 737 + 738 + def _GetOutputDir(self, commit_upto): 739 + """Get the name of the output directory for a commit number 740 + 741 + The output directory is typically .../<branch>/<commit>. 742 + 743 + Args: 744 + commit_upto: Commit number to use (0..self.count-1) 745 + """ 746 + commit = self.commits[commit_upto] 747 + subject = commit.subject.translate(trans_valid_chars) 748 + commit_dir = ('%02d_of_%02d_g%s_%s' % (commit_upto + 1, 749 + self.commit_count, commit.hash, subject[:20])) 750 + output_dir = os.path.join(self.base_dir, commit_dir) 751 + return output_dir 752 + 753 + def GetBuildDir(self, commit_upto, target): 754 + """Get the name of the build directory for a commit number 755 + 756 + The build directory is typically .../<branch>/<commit>/<target>. 757 + 758 + Args: 759 + commit_upto: Commit number to use (0..self.count-1) 760 + target: Target name 761 + """ 762 + output_dir = self._GetOutputDir(commit_upto) 763 + return os.path.join(output_dir, target) 764 + 765 + def GetDoneFile(self, commit_upto, target): 766 + """Get the name of the done file for a commit number 767 + 768 + Args: 769 + commit_upto: Commit number to use (0..self.count-1) 770 + target: Target name 771 + """ 772 + return os.path.join(self.GetBuildDir(commit_upto, target), 'done') 773 + 774 + def GetSizesFile(self, commit_upto, target): 775 + """Get the name of the sizes file for a commit number 776 + 777 + Args: 778 + commit_upto: Commit number to use (0..self.count-1) 779 + target: Target name 780 + """ 781 + return os.path.join(self.GetBuildDir(commit_upto, target), 'sizes') 782 + 783 + def GetFuncSizesFile(self, commit_upto, target, elf_fname): 784 + """Get the name of the funcsizes file for a commit number and ELF file 785 + 786 + Args: 787 + commit_upto: Commit number to use (0..self.count-1) 788 + target: Target name 789 + elf_fname: Filename of elf image 790 + """ 791 + return os.path.join(self.GetBuildDir(commit_upto, target), 792 + '%s.sizes' % elf_fname.replace('/', '-')) 793 + 794 + def GetObjdumpFile(self, commit_upto, target, elf_fname): 795 + """Get the name of the objdump file for a commit number and ELF file 796 + 797 + Args: 798 + commit_upto: Commit number to use (0..self.count-1) 799 + target: Target name 800 + elf_fname: Filename of elf image 801 + """ 802 + return os.path.join(self.GetBuildDir(commit_upto, target), 803 + '%s.objdump' % elf_fname.replace('/', '-')) 804 + 805 + def GetErrFile(self, commit_upto, target): 806 + """Get the name of the err file for a commit number 807 + 808 + Args: 809 + commit_upto: Commit number to use (0..self.count-1) 810 + target: Target name 811 + """ 812 + output_dir = self.GetBuildDir(commit_upto, target) 813 + return os.path.join(output_dir, 'err') 814 + 815 + def FilterErrors(self, lines): 816 + """Filter out errors in which we have no interest 817 + 818 + We should probably use map(). 819 + 820 + Args: 821 + lines: List of error lines, each a string 822 + Returns: 823 + New list with only interesting lines included 824 + """ 825 + out_lines = [] 826 + for line in lines: 827 + if not self.re_make_err.search(line): 828 + out_lines.append(line) 829 + return out_lines 830 + 831 + def ReadFuncSizes(self, fname, fd): 832 + """Read function sizes from the output of 'nm' 833 + 834 + Args: 835 + fd: File containing data to read 836 + fname: Filename we are reading from (just for errors) 837 + 838 + Returns: 839 + Dictionary containing size of each function in bytes, indexed by 840 + function name. 841 + """ 842 + sym = {} 843 + for line in fd.readlines(): 844 + try: 845 + size, type, name = line[:-1].split() 846 + except: 847 + print "Invalid line in file '%s': '%s'" % (fname, line[:-1]) 848 + continue 849 + if type in 'tTdDbB': 850 + # function names begin with '.' on 64-bit powerpc 851 + if '.' in name[1:]: 852 + name = 'static.' + name.split('.')[0] 853 + sym[name] = sym.get(name, 0) + int(size, 16) 854 + return sym 855 + 856 + def GetBuildOutcome(self, commit_upto, target, read_func_sizes): 857 + """Work out the outcome of a build. 858 + 859 + Args: 860 + commit_upto: Commit number to check (0..n-1) 861 + target: Target board to check 862 + read_func_sizes: True to read function size information 863 + 864 + Returns: 865 + Outcome object 866 + """ 867 + done_file = self.GetDoneFile(commit_upto, target) 868 + sizes_file = self.GetSizesFile(commit_upto, target) 869 + sizes = {} 870 + func_sizes = {} 871 + if os.path.exists(done_file): 872 + with open(done_file, 'r') as fd: 873 + return_code = int(fd.readline()) 874 + err_lines = [] 875 + err_file = self.GetErrFile(commit_upto, target) 876 + if os.path.exists(err_file): 877 + with open(err_file, 'r') as fd: 878 + err_lines = self.FilterErrors(fd.readlines()) 879 + 880 + # Decide whether the build was ok, failed or created warnings 881 + if return_code: 882 + rc = OUTCOME_ERROR 883 + elif len(err_lines): 884 + rc = OUTCOME_WARNING 885 + else: 886 + rc = OUTCOME_OK 887 + 888 + # Convert size information to our simple format 889 + if os.path.exists(sizes_file): 890 + with open(sizes_file, 'r') as fd: 891 + for line in fd.readlines(): 892 + values = line.split() 893 + rodata = 0 894 + if len(values) > 6: 895 + rodata = int(values[6], 16) 896 + size_dict = { 897 + 'all' : int(values[0]) + int(values[1]) + 898 + int(values[2]), 899 + 'text' : int(values[0]) - rodata, 900 + 'data' : int(values[1]), 901 + 'bss' : int(values[2]), 902 + 'rodata' : rodata, 903 + } 904 + sizes[values[5]] = size_dict 905 + 906 + if read_func_sizes: 907 + pattern = self.GetFuncSizesFile(commit_upto, target, '*') 908 + for fname in glob.glob(pattern): 909 + with open(fname, 'r') as fd: 910 + dict_name = os.path.basename(fname).replace('.sizes', 911 + '') 912 + func_sizes[dict_name] = self.ReadFuncSizes(fname, fd) 913 + 914 + return Builder.Outcome(rc, err_lines, sizes, func_sizes) 915 + 916 + return Builder.Outcome(OUTCOME_UNKNOWN, [], {}, {}) 917 + 918 + def GetResultSummary(self, boards_selected, commit_upto, read_func_sizes): 919 + """Calculate a summary of the results of building a commit. 920 + 921 + Args: 922 + board_selected: Dict containing boards to summarise 923 + commit_upto: Commit number to summarize (0..self.count-1) 924 + read_func_sizes: True to read function size information 925 + 926 + Returns: 927 + Tuple: 928 + Dict containing boards which passed building this commit. 929 + keyed by board.target 930 + List containing a summary of error/warning lines 931 + """ 932 + board_dict = {} 933 + err_lines_summary = [] 934 + 935 + for board in boards_selected.itervalues(): 936 + outcome = self.GetBuildOutcome(commit_upto, board.target, 937 + read_func_sizes) 938 + board_dict[board.target] = outcome 939 + for err in outcome.err_lines: 940 + if err and not err.rstrip() in err_lines_summary: 941 + err_lines_summary.append(err.rstrip()) 942 + return board_dict, err_lines_summary 943 + 944 + def AddOutcome(self, board_dict, arch_list, changes, char, color): 945 + """Add an output to our list of outcomes for each architecture 946 + 947 + This simple function adds failing boards (changes) to the 948 + relevant architecture string, so we can print the results out 949 + sorted by architecture. 950 + 951 + Args: 952 + board_dict: Dict containing all boards 953 + arch_list: Dict keyed by arch name. Value is a string containing 954 + a list of board names which failed for that arch. 955 + changes: List of boards to add to arch_list 956 + color: terminal.Colour object 957 + """ 958 + done_arch = {} 959 + for target in changes: 960 + if target in board_dict: 961 + arch = board_dict[target].arch 962 + else: 963 + arch = 'unknown' 964 + str = self.col.Color(color, ' ' + target) 965 + if not arch in done_arch: 966 + str = self.col.Color(color, char) + ' ' + str 967 + done_arch[arch] = True 968 + if not arch in arch_list: 969 + arch_list[arch] = str 970 + else: 971 + arch_list[arch] += str 972 + 973 + 974 + def ColourNum(self, num): 975 + color = self.col.RED if num > 0 else self.col.GREEN 976 + if num == 0: 977 + return '0' 978 + return self.col.Color(color, str(num)) 979 + 980 + def ResetResultSummary(self, board_selected): 981 + """Reset the results summary ready for use. 982 + 983 + Set up the base board list to be all those selected, and set the 984 + error lines to empty. 985 + 986 + Following this, calls to PrintResultSummary() will use this 987 + information to work out what has changed. 988 + 989 + Args: 990 + board_selected: Dict containing boards to summarise, keyed by 991 + board.target 992 + """ 993 + self._base_board_dict = {} 994 + for board in board_selected: 995 + self._base_board_dict[board] = Builder.Outcome(0, [], [], {}) 996 + self._base_err_lines = [] 997 + 998 + def PrintFuncSizeDetail(self, fname, old, new): 999 + grow, shrink, add, remove, up, down = 0, 0, 0, 0, 0, 0 1000 + delta, common = [], {} 1001 + 1002 + for a in old: 1003 + if a in new: 1004 + common[a] = 1 1005 + 1006 + for name in old: 1007 + if name not in common: 1008 + remove += 1 1009 + down += old[name] 1010 + delta.append([-old[name], name]) 1011 + 1012 + for name in new: 1013 + if name not in common: 1014 + add += 1 1015 + up += new[name] 1016 + delta.append([new[name], name]) 1017 + 1018 + for name in common: 1019 + diff = new.get(name, 0) - old.get(name, 0) 1020 + if diff > 0: 1021 + grow, up = grow + 1, up + diff 1022 + elif diff < 0: 1023 + shrink, down = shrink + 1, down - diff 1024 + delta.append([diff, name]) 1025 + 1026 + delta.sort() 1027 + delta.reverse() 1028 + 1029 + args = [add, -remove, grow, -shrink, up, -down, up - down] 1030 + if max(args) == 0: 1031 + return 1032 + args = [self.ColourNum(x) for x in args] 1033 + indent = ' ' * 15 1034 + print ('%s%s: add: %s/%s, grow: %s/%s bytes: %s/%s (%s)' % 1035 + tuple([indent, self.col.Color(self.col.YELLOW, fname)] + args)) 1036 + print '%s %-38s %7s %7s %+7s' % (indent, 'function', 'old', 'new', 1037 + 'delta') 1038 + for diff, name in delta: 1039 + if diff: 1040 + color = self.col.RED if diff > 0 else self.col.GREEN 1041 + msg = '%s %-38s %7s %7s %+7d' % (indent, name, 1042 + old.get(name, '-'), new.get(name,'-'), diff) 1043 + print self.col.Color(color, msg) 1044 + 1045 + 1046 + def PrintSizeDetail(self, target_list, show_bloat): 1047 + """Show details size information for each board 1048 + 1049 + Args: 1050 + target_list: List of targets, each a dict containing: 1051 + 'target': Target name 1052 + 'total_diff': Total difference in bytes across all areas 1053 + <part_name>: Difference for that part 1054 + show_bloat: Show detail for each function 1055 + """ 1056 + targets_by_diff = sorted(target_list, reverse=True, 1057 + key=lambda x: x['_total_diff']) 1058 + for result in targets_by_diff: 1059 + printed_target = False 1060 + for name in sorted(result): 1061 + diff = result[name] 1062 + if name.startswith('_'): 1063 + continue 1064 + if diff != 0: 1065 + color = self.col.RED if diff > 0 else self.col.GREEN 1066 + msg = ' %s %+d' % (name, diff) 1067 + if not printed_target: 1068 + print '%10s %-15s:' % ('', result['_target']), 1069 + printed_target = True 1070 + print self.col.Color(color, msg), 1071 + if printed_target: 1072 + print 1073 + if show_bloat: 1074 + target = result['_target'] 1075 + outcome = result['_outcome'] 1076 + base_outcome = self._base_board_dict[target] 1077 + for fname in outcome.func_sizes: 1078 + self.PrintFuncSizeDetail(fname, 1079 + base_outcome.func_sizes[fname], 1080 + outcome.func_sizes[fname]) 1081 + 1082 + 1083 + def PrintSizeSummary(self, board_selected, board_dict, show_detail, 1084 + show_bloat): 1085 + """Print a summary of image sizes broken down by section. 1086 + 1087 + The summary takes the form of one line per architecture. The 1088 + line contains deltas for each of the sections (+ means the section 1089 + got bigger, - means smaller). The nunmbers are the average number 1090 + of bytes that a board in this section increased by. 1091 + 1092 + For example: 1093 + powerpc: (622 boards) text -0.0 1094 + arm: (285 boards) text -0.0 1095 + nds32: (3 boards) text -8.0 1096 + 1097 + Args: 1098 + board_selected: Dict containing boards to summarise, keyed by 1099 + board.target 1100 + board_dict: Dict containing boards for which we built this 1101 + commit, keyed by board.target. The value is an Outcome object. 1102 + show_detail: Show detail for each board 1103 + show_bloat: Show detail for each function 1104 + """ 1105 + arch_list = {} 1106 + arch_count = {} 1107 + 1108 + # Calculate changes in size for different image parts 1109 + # The previous sizes are in Board.sizes, for each board 1110 + for target in board_dict: 1111 + if target not in board_selected: 1112 + continue 1113 + base_sizes = self._base_board_dict[target].sizes 1114 + outcome = board_dict[target] 1115 + sizes = outcome.sizes 1116 + 1117 + # Loop through the list of images, creating a dict of size 1118 + # changes for each image/part. We end up with something like 1119 + # {'target' : 'snapper9g45, 'data' : 5, 'u-boot-spl:text' : -4} 1120 + # which means that U-Boot data increased by 5 bytes and SPL 1121 + # text decreased by 4. 1122 + err = {'_target' : target} 1123 + for image in sizes: 1124 + if image in base_sizes: 1125 + base_image = base_sizes[image] 1126 + # Loop through the text, data, bss parts 1127 + for part in sorted(sizes[image]): 1128 + diff = sizes[image][part] - base_image[part] 1129 + col = None 1130 + if diff: 1131 + if image == 'u-boot': 1132 + name = part 1133 + else: 1134 + name = image + ':' + part 1135 + err[name] = diff 1136 + arch = board_selected[target].arch 1137 + if not arch in arch_count: 1138 + arch_count[arch] = 1 1139 + else: 1140 + arch_count[arch] += 1 1141 + if not sizes: 1142 + pass # Only add to our list when we have some stats 1143 + elif not arch in arch_list: 1144 + arch_list[arch] = [err] 1145 + else: 1146 + arch_list[arch].append(err) 1147 + 1148 + # We now have a list of image size changes sorted by arch 1149 + # Print out a summary of these 1150 + for arch, target_list in arch_list.iteritems(): 1151 + # Get total difference for each type 1152 + totals = {} 1153 + for result in target_list: 1154 + total = 0 1155 + for name, diff in result.iteritems(): 1156 + if name.startswith('_'): 1157 + continue 1158 + total += diff 1159 + if name in totals: 1160 + totals[name] += diff 1161 + else: 1162 + totals[name] = diff 1163 + result['_total_diff'] = total 1164 + result['_outcome'] = board_dict[result['_target']] 1165 + 1166 + count = len(target_list) 1167 + printed_arch = False 1168 + for name in sorted(totals): 1169 + diff = totals[name] 1170 + if diff: 1171 + # Display the average difference in this name for this 1172 + # architecture 1173 + avg_diff = float(diff) / count 1174 + color = self.col.RED if avg_diff > 0 else self.col.GREEN 1175 + msg = ' %s %+1.1f' % (name, avg_diff) 1176 + if not printed_arch: 1177 + print '%10s: (for %d/%d boards)' % (arch, count, 1178 + arch_count[arch]), 1179 + printed_arch = True 1180 + print self.col.Color(color, msg), 1181 + 1182 + if printed_arch: 1183 + print 1184 + if show_detail: 1185 + self.PrintSizeDetail(target_list, show_bloat) 1186 + 1187 + 1188 + def PrintResultSummary(self, board_selected, board_dict, err_lines, 1189 + show_sizes, show_detail, show_bloat): 1190 + """Compare results with the base results and display delta. 1191 + 1192 + Only boards mentioned in board_selected will be considered. This 1193 + function is intended to be called repeatedly with the results of 1194 + each commit. It therefore shows a 'diff' between what it saw in 1195 + the last call and what it sees now. 1196 + 1197 + Args: 1198 + board_selected: Dict containing boards to summarise, keyed by 1199 + board.target 1200 + board_dict: Dict containing boards for which we built this 1201 + commit, keyed by board.target. The value is an Outcome object. 1202 + err_lines: A list of errors for this commit, or [] if there is 1203 + none, or we don't want to print errors 1204 + show_sizes: Show image size deltas 1205 + show_detail: Show detail for each board 1206 + show_bloat: Show detail for each function 1207 + """ 1208 + better = [] # List of boards fixed since last commit 1209 + worse = [] # List of new broken boards since last commit 1210 + new = [] # List of boards that didn't exist last time 1211 + unknown = [] # List of boards that were not built 1212 + 1213 + for target in board_dict: 1214 + if target not in board_selected: 1215 + continue 1216 + 1217 + # If the board was built last time, add its outcome to a list 1218 + if target in self._base_board_dict: 1219 + base_outcome = self._base_board_dict[target].rc 1220 + outcome = board_dict[target] 1221 + if outcome.rc == OUTCOME_UNKNOWN: 1222 + unknown.append(target) 1223 + elif outcome.rc < base_outcome: 1224 + better.append(target) 1225 + elif outcome.rc > base_outcome: 1226 + worse.append(target) 1227 + else: 1228 + new.append(target) 1229 + 1230 + # Get a list of errors that have appeared, and disappeared 1231 + better_err = [] 1232 + worse_err = [] 1233 + for line in err_lines: 1234 + if line not in self._base_err_lines: 1235 + worse_err.append('+' + line) 1236 + for line in self._base_err_lines: 1237 + if line not in err_lines: 1238 + better_err.append('-' + line) 1239 + 1240 + # Display results by arch 1241 + if better or worse or unknown or new or worse_err or better_err: 1242 + arch_list = {} 1243 + self.AddOutcome(board_selected, arch_list, better, '', 1244 + self.col.GREEN) 1245 + self.AddOutcome(board_selected, arch_list, worse, '+', 1246 + self.col.RED) 1247 + self.AddOutcome(board_selected, arch_list, new, '*', self.col.BLUE) 1248 + if self._show_unknown: 1249 + self.AddOutcome(board_selected, arch_list, unknown, '?', 1250 + self.col.MAGENTA) 1251 + for arch, target_list in arch_list.iteritems(): 1252 + print '%10s: %s' % (arch, target_list) 1253 + if better_err: 1254 + print self.col.Color(self.col.GREEN, '\n'.join(better_err)) 1255 + if worse_err: 1256 + print self.col.Color(self.col.RED, '\n'.join(worse_err)) 1257 + 1258 + if show_sizes: 1259 + self.PrintSizeSummary(board_selected, board_dict, show_detail, 1260 + show_bloat) 1261 + 1262 + # Save our updated information for the next call to this function 1263 + self._base_board_dict = board_dict 1264 + self._base_err_lines = err_lines 1265 + 1266 + # Get a list of boards that did not get built, if needed 1267 + not_built = [] 1268 + for board in board_selected: 1269 + if not board in board_dict: 1270 + not_built.append(board) 1271 + if not_built: 1272 + print "Boards not built (%d): %s" % (len(not_built), 1273 + ', '.join(not_built)) 1274 + 1275 + 1276 + def ShowSummary(self, commits, board_selected, show_errors, show_sizes, 1277 + show_detail, show_bloat): 1278 + """Show a build summary for U-Boot for a given board list. 1279 + 1280 + Reset the result summary, then repeatedly call GetResultSummary on 1281 + each commit's results, then display the differences we see. 1282 + 1283 + Args: 1284 + commit: Commit objects to summarise 1285 + board_selected: Dict containing boards to summarise 1286 + show_errors: Show errors that occured 1287 + show_sizes: Show size deltas 1288 + show_detail: Show detail for each board 1289 + show_bloat: Show detail for each function 1290 + """ 1291 + self.commit_count = len(commits) 1292 + self.commits = commits 1293 + self.ResetResultSummary(board_selected) 1294 + 1295 + for commit_upto in range(0, self.commit_count, self._step): 1296 + board_dict, err_lines = self.GetResultSummary(board_selected, 1297 + commit_upto, read_func_sizes=show_bloat) 1298 + msg = '%02d: %s' % (commit_upto + 1, commits[commit_upto].subject) 1299 + print self.col.Color(self.col.BLUE, msg) 1300 + self.PrintResultSummary(board_selected, board_dict, 1301 + err_lines if show_errors else [], show_sizes, show_detail, 1302 + show_bloat) 1303 + 1304 + 1305 + def SetupBuild(self, board_selected, commits): 1306 + """Set up ready to start a build. 1307 + 1308 + Args: 1309 + board_selected: Selected boards to build 1310 + commits: Selected commits to build 1311 + """ 1312 + # First work out how many commits we will build 1313 + count = (len(commits) + self._step - 1) / self._step 1314 + self.count = len(board_selected) * count 1315 + self.upto = self.warned = self.fail = 0 1316 + self._timestamps = collections.deque() 1317 + 1318 + def BuildBoardsForCommit(self, board_selected, keep_outputs): 1319 + """Build all boards for a single commit""" 1320 + self.SetupBuild(board_selected) 1321 + self.count = len(board_selected) 1322 + for brd in board_selected.itervalues(): 1323 + job = BuilderJob() 1324 + job.board = brd 1325 + job.commits = None 1326 + job.keep_outputs = keep_outputs 1327 + self.queue.put(brd) 1328 + 1329 + self.queue.join() 1330 + self.out_queue.join() 1331 + print 1332 + self.ClearLine(0) 1333 + 1334 + def BuildCommits(self, commits, board_selected, show_errors, keep_outputs): 1335 + """Build all boards for all commits (non-incremental)""" 1336 + self.commit_count = len(commits) 1337 + 1338 + self.ResetResultSummary(board_selected) 1339 + for self.commit_upto in range(self.commit_count): 1340 + self.SelectCommit(commits[self.commit_upto]) 1341 + self.SelectOutputDir() 1342 + Mkdir(self.output_dir) 1343 + 1344 + self.BuildBoardsForCommit(board_selected, keep_outputs) 1345 + board_dict, err_lines = self.GetResultSummary() 1346 + self.PrintResultSummary(board_selected, board_dict, 1347 + err_lines if show_errors else []) 1348 + 1349 + if self.already_done: 1350 + print '%d builds already done' % self.already_done 1351 + 1352 + def GetThreadDir(self, thread_num): 1353 + """Get the directory path to the working dir for a thread. 1354 + 1355 + Args: 1356 + thread_num: Number of thread to check. 1357 + """ 1358 + return os.path.join(self._working_dir, '%02d' % thread_num) 1359 + 1360 + def _PrepareThread(self, thread_num): 1361 + """Prepare the working directory for a thread. 1362 + 1363 + This clones or fetches the repo into the thread's work directory. 1364 + 1365 + Args: 1366 + thread_num: Thread number (0, 1, ...) 1367 + """ 1368 + thread_dir = self.GetThreadDir(thread_num) 1369 + Mkdir(thread_dir) 1370 + git_dir = os.path.join(thread_dir, '.git') 1371 + 1372 + # Clone the repo if it doesn't already exist 1373 + # TODO(sjg@chromium): Perhaps some git hackery to symlink instead, so 1374 + # we have a private index but uses the origin repo's contents? 1375 + if self.git_dir: 1376 + src_dir = os.path.abspath(self.git_dir) 1377 + if os.path.exists(git_dir): 1378 + gitutil.Fetch(git_dir, thread_dir) 1379 + else: 1380 + print 'Cloning repo for thread %d' % thread_num 1381 + gitutil.Clone(src_dir, thread_dir) 1382 + 1383 + def _PrepareWorkingSpace(self, max_threads): 1384 + """Prepare the working directory for use. 1385 + 1386 + Set up the git repo for each thread. 1387 + 1388 + Args: 1389 + max_threads: Maximum number of threads we expect to need. 1390 + """ 1391 + Mkdir(self._working_dir) 1392 + for thread in range(max_threads): 1393 + self._PrepareThread(thread) 1394 + 1395 + def _PrepareOutputSpace(self): 1396 + """Get the output directories ready to receive files. 1397 + 1398 + We delete any output directories which look like ones we need to 1399 + create. Having left over directories is confusing when the user wants 1400 + to check the output manually. 1401 + """ 1402 + dir_list = [] 1403 + for commit_upto in range(self.commit_count): 1404 + dir_list.append(self._GetOutputDir(commit_upto)) 1405 + 1406 + for dirname in glob.glob(os.path.join(self.base_dir, '*')): 1407 + if dirname not in dir_list: 1408 + shutil.rmtree(dirname) 1409 + 1410 + def BuildBoards(self, commits, board_selected, show_errors, keep_outputs): 1411 + """Build all commits for a list of boards 1412 + 1413 + Args: 1414 + commits: List of commits to be build, each a Commit object 1415 + boards_selected: Dict of selected boards, key is target name, 1416 + value is Board object 1417 + show_errors: True to show summarised error/warning info 1418 + keep_outputs: True to save build output files 1419 + """ 1420 + self.commit_count = len(commits) 1421 + self.commits = commits 1422 + 1423 + self.ResetResultSummary(board_selected) 1424 + Mkdir(self.base_dir) 1425 + self._PrepareWorkingSpace(min(self.num_threads, len(board_selected))) 1426 + self._PrepareOutputSpace() 1427 + self.SetupBuild(board_selected, commits) 1428 + self.ProcessResult(None) 1429 + 1430 + # Create jobs to build all commits for each board 1431 + for brd in board_selected.itervalues(): 1432 + job = BuilderJob() 1433 + job.board = brd 1434 + job.commits = commits 1435 + job.keep_outputs = keep_outputs 1436 + job.step = self._step 1437 + self.queue.put(job) 1438 + 1439 + # Wait until all jobs are started 1440 + self.queue.join() 1441 + 1442 + # Wait until we have processed all output 1443 + self.out_queue.join() 1444 + print 1445 + self.ClearLine(0)
+1
tools/buildman/buildman
··· 1 + buildman.py
+126
tools/buildman/buildman.py
··· 1 + #!/usr/bin/python 2 + # 3 + # Copyright (c) 2012 The Chromium OS Authors. 4 + # 5 + # See file CREDITS for list of people who contributed to this 6 + # project. 7 + # 8 + # This program is free software; you can redistribute it and/or 9 + # modify it under the terms of the GNU General Public License as 10 + # published by the Free Software Foundation; either version 2 of 11 + # the License, or (at your option) any later version. 12 + # 13 + # This program is distributed in the hope that it will be useful, 14 + # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 + # GNU General Public License for more details. 17 + # 18 + # You should have received a copy of the GNU General Public License 19 + # along with this program; if not, write to the Free Software 20 + # Foundation, Inc., 59 Temple Place, Suite 330, Boston, 21 + # MA 02111-1307 USA 22 + # 23 + 24 + """See README for more information""" 25 + 26 + import multiprocessing 27 + from optparse import OptionParser 28 + import os 29 + import re 30 + import sys 31 + import unittest 32 + 33 + # Bring in the patman libraries 34 + our_path = os.path.dirname(os.path.realpath(__file__)) 35 + sys.path.append(os.path.join(our_path, '../patman')) 36 + 37 + # Our modules 38 + import board 39 + import builder 40 + import checkpatch 41 + import command 42 + import control 43 + import doctest 44 + import gitutil 45 + import patchstream 46 + import terminal 47 + import toolchain 48 + 49 + def RunTests(): 50 + import test 51 + 52 + sys.argv = [sys.argv[0]] 53 + suite = unittest.TestLoader().loadTestsFromTestCase(test.TestBuild) 54 + result = unittest.TestResult() 55 + suite.run(result) 56 + 57 + # TODO: Surely we can just 'print' result? 58 + print result 59 + for test, err in result.errors: 60 + print err 61 + for test, err in result.failures: 62 + print err 63 + 64 + 65 + parser = OptionParser() 66 + parser.add_option('-b', '--branch', type='string', 67 + help='Branch name to build') 68 + parser.add_option('-B', '--bloat', dest='show_bloat', 69 + action='store_true', default=False, 70 + help='Show changes in function code size for each board') 71 + parser.add_option('-c', '--count', dest='count', type='int', 72 + default=-1, help='Run build on the top n commits') 73 + parser.add_option('-e', '--show_errors', action='store_true', 74 + default=False, help='Show errors and warnings') 75 + parser.add_option('-f', '--force-build', dest='force_build', 76 + action='store_true', default=False, 77 + help='Force build of boards even if already built') 78 + parser.add_option('-d', '--detail', dest='show_detail', 79 + action='store_true', default=False, 80 + help='Show detailed information for each board in summary') 81 + parser.add_option('-g', '--git', type='string', 82 + help='Git repo containing branch to build', default='.') 83 + parser.add_option('-H', '--full-help', action='store_true', dest='full_help', 84 + default=False, help='Display the README file') 85 + parser.add_option('-j', '--jobs', dest='jobs', type='int', 86 + default=None, help='Number of jobs to run at once (passed to make)') 87 + parser.add_option('-k', '--keep-outputs', action='store_true', 88 + default=False, help='Keep all build output files (e.g. binaries)') 89 + parser.add_option('--list-tool-chains', action='store_true', default=False, 90 + help='List available tool chains') 91 + parser.add_option('-n', '--dry-run', action='store_true', dest='dry_run', 92 + default=False, help="Do a try run (describe actions, but no nothing)") 93 + parser.add_option('-Q', '--quick', action='store_true', 94 + default=False, help='Do a rough build, with limited warning resolution') 95 + parser.add_option('-s', '--summary', action='store_true', 96 + default=False, help='Show a build summary') 97 + parser.add_option('-S', '--show-sizes', action='store_true', 98 + default=False, help='Show image size variation in summary') 99 + parser.add_option('--step', type='int', 100 + default=1, help='Only build every n commits (0=just first and last)') 101 + parser.add_option('-t', '--test', action='store_true', dest='test', 102 + default=False, help='run tests') 103 + parser.add_option('-T', '--threads', type='int', 104 + default=None, help='Number of builder threads to use') 105 + parser.add_option('-u', '--show_unknown', action='store_true', 106 + default=False, help='Show boards with unknown build result') 107 + 108 + parser.usage = """buildman -b <branch> [options] 109 + 110 + Build U-Boot for all commits in a branch. Use -n to do a dry run""" 111 + 112 + (options, args) = parser.parse_args() 113 + 114 + # Run our meagre tests 115 + if options.test: 116 + RunTests() 117 + elif options.full_help: 118 + pager = os.getenv('PAGER') 119 + if not pager: 120 + pager = 'more' 121 + fname = os.path.join(os.path.dirname(sys.argv[0]), 'README') 122 + command.Run(pager, fname) 123 + 124 + # Build selected commits for selected boards 125 + else: 126 + control.DoBuildman(options, args)
+181
tools/buildman/control.py
··· 1 + # Copyright (c) 2013 The Chromium OS Authors. 2 + # 3 + # See file CREDITS for list of people who contributed to this 4 + # project. 5 + # 6 + # This program is free software; you can redistribute it and/or 7 + # modify it under the terms of the GNU General Public License as 8 + # published by the Free Software Foundation; either version 2 of 9 + # the License, or (at your option) any later version. 10 + # 11 + # This program is distributed in the hope that it will be useful, 12 + # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + # GNU General Public License for more details. 15 + # 16 + # You should have received a copy of the GNU General Public License 17 + # along with this program; if not, write to the Free Software 18 + # Foundation, Inc., 59 Temple Place, Suite 330, Boston, 19 + # MA 02111-1307 USA 20 + # 21 + 22 + import multiprocessing 23 + import os 24 + import sys 25 + 26 + import board 27 + import bsettings 28 + from builder import Builder 29 + import gitutil 30 + import patchstream 31 + import terminal 32 + import toolchain 33 + 34 + def GetPlural(count): 35 + """Returns a plural 's' if count is not 1""" 36 + return 's' if count != 1 else '' 37 + 38 + def GetActionSummary(is_summary, count, selected, options): 39 + """Return a string summarising the intended action. 40 + 41 + Returns: 42 + Summary string. 43 + """ 44 + count = (count + options.step - 1) / options.step 45 + str = '%s %d commit%s for %d boards' % ( 46 + 'Summary of' if is_summary else 'Building', count, GetPlural(count), 47 + len(selected)) 48 + str += ' (%d thread%s, %d job%s per thread)' % (options.threads, 49 + GetPlural(options.threads), options.jobs, GetPlural(options.jobs)) 50 + return str 51 + 52 + def ShowActions(series, why_selected, boards_selected, builder, options): 53 + """Display a list of actions that we would take, if not a dry run. 54 + 55 + Args: 56 + series: Series object 57 + why_selected: Dictionary where each key is a buildman argument 58 + provided by the user, and the value is the boards brought 59 + in by that argument. For example, 'arm' might bring in 60 + 400 boards, so in this case the key would be 'arm' and 61 + the value would be a list of board names. 62 + boards_selected: Dict of selected boards, key is target name, 63 + value is Board object 64 + builder: The builder that will be used to build the commits 65 + options: Command line options object 66 + """ 67 + col = terminal.Color() 68 + print 'Dry run, so not doing much. But I would do this:' 69 + print 70 + print GetActionSummary(False, len(series.commits), boards_selected, 71 + options) 72 + print 'Build directory: %s' % builder.base_dir 73 + for upto in range(0, len(series.commits), options.step): 74 + commit = series.commits[upto] 75 + print ' ', col.Color(col.YELLOW, commit.hash, bright=False), 76 + print commit.subject 77 + print 78 + for arg in why_selected: 79 + if arg != 'all': 80 + print arg, ': %d boards' % why_selected[arg] 81 + print ('Total boards to build for each commit: %d\n' % 82 + why_selected['all']) 83 + 84 + def DoBuildman(options, args): 85 + """The main control code for buildman 86 + 87 + Args: 88 + options: Command line options object 89 + args: Command line arguments (list of strings) 90 + """ 91 + gitutil.Setup() 92 + 93 + bsettings.Setup() 94 + options.git_dir = os.path.join(options.git, '.git') 95 + 96 + toolchains = toolchain.Toolchains() 97 + toolchains.Scan(options.list_tool_chains) 98 + if options.list_tool_chains: 99 + toolchains.List() 100 + print 101 + return 102 + 103 + # Work out how many commits to build. We want to build everything on the 104 + # branch. We also build the upstream commit as a control so we can see 105 + # problems introduced by the first commit on the branch. 106 + col = terminal.Color() 107 + count = options.count 108 + if count == -1: 109 + if not options.branch: 110 + str = 'Please use -b to specify a branch to build' 111 + print col.Color(col.RED, str) 112 + sys.exit(1) 113 + count = gitutil.CountCommitsInBranch(options.git_dir, options.branch) 114 + count += 1 # Build upstream commit also 115 + 116 + if not count: 117 + str = ("No commits found to process in branch '%s': " 118 + "set branch's upstream or use -c flag" % options.branch) 119 + print col.Color(col.RED, str) 120 + sys.exit(1) 121 + 122 + # Work out what subset of the boards we are building 123 + boards = board.Boards() 124 + boards.ReadBoards(os.path.join(options.git, 'boards.cfg')) 125 + why_selected = boards.SelectBoards(args) 126 + selected = boards.GetSelected() 127 + if not len(selected): 128 + print col.Color(col.RED, 'No matching boards found') 129 + sys.exit(1) 130 + 131 + # Read the metadata from the commits. First look at the upstream commit, 132 + # then the ones in the branch. We would like to do something like 133 + # upstream/master~..branch but that isn't possible if upstream/master is 134 + # a merge commit (it will list all the commits that form part of the 135 + # merge) 136 + range_expr = gitutil.GetRangeInBranch(options.git_dir, options.branch) 137 + upstream_commit = gitutil.GetUpstream(options.git_dir, options.branch) 138 + series = patchstream.GetMetaDataForList(upstream_commit, options.git_dir, 139 + 1) 140 + series = patchstream.GetMetaDataForList(range_expr, options.git_dir, None, 141 + series) 142 + 143 + # By default we have one thread per CPU. But if there are not enough jobs 144 + # we can have fewer threads and use a high '-j' value for make. 145 + if not options.threads: 146 + options.threads = min(multiprocessing.cpu_count(), len(selected)) 147 + if not options.jobs: 148 + options.jobs = max(1, (multiprocessing.cpu_count() + 149 + len(selected) - 1) / len(selected)) 150 + 151 + if not options.step: 152 + options.step = len(series.commits) - 1 153 + 154 + # Create a new builder with the selected options 155 + output_dir = os.path.join('..', options.branch) 156 + builder = Builder(toolchains, output_dir, options.git_dir, 157 + options.threads, options.jobs, checkout=True, 158 + show_unknown=options.show_unknown, step=options.step) 159 + builder.force_config_on_failure = not options.quick 160 + 161 + # For a dry run, just show our actions as a sanity check 162 + if options.dry_run: 163 + ShowActions(series, why_selected, selected, builder, options) 164 + else: 165 + builder.force_build = options.force_build 166 + 167 + # Work out which boards to build 168 + board_selected = boards.GetSelectedDict() 169 + 170 + print GetActionSummary(options.summary, count, board_selected, options) 171 + 172 + if options.summary: 173 + # We can't show function sizes without board details at present 174 + if options.show_bloat: 175 + options.show_detail = True 176 + builder.ShowSummary(series.commits, board_selected, 177 + options.show_errors, options.show_sizes, 178 + options.show_detail, options.show_bloat) 179 + else: 180 + builder.BuildBoards(series.commits, board_selected, 181 + options.show_errors, options.keep_outputs)
+185
tools/buildman/test.py
··· 1 + # 2 + # Copyright (c) 2012 The Chromium OS Authors. 3 + # 4 + # See file CREDITS for list of people who contributed to this 5 + # project. 6 + # 7 + # This program is free software; you can redistribute it and/or 8 + # modify it under the terms of the GNU General Public License as 9 + # published by the Free Software Foundation; either version 2 of 10 + # the License, or (at your option) any later version. 11 + # 12 + # This program is distributed in the hope that it will be useful, 13 + # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + # GNU General Public License for more details. 16 + # 17 + # You should have received a copy of the GNU General Public License 18 + # along with this program; if not, write to the Free Software 19 + # Foundation, Inc., 59 Temple Place, Suite 330, Boston, 20 + # MA 02111-1307 USA 21 + # 22 + 23 + import os 24 + import shutil 25 + import sys 26 + import tempfile 27 + import time 28 + import unittest 29 + 30 + # Bring in the patman libraries 31 + our_path = os.path.dirname(os.path.realpath(__file__)) 32 + sys.path.append(os.path.join(our_path, '../patman')) 33 + 34 + import board 35 + import bsettings 36 + import builder 37 + import control 38 + import command 39 + import commit 40 + import toolchain 41 + 42 + errors = [ 43 + '''main.c: In function 'main_loop': 44 + main.c:260:6: warning: unused variable 'joe' [-Wunused-variable] 45 + ''', 46 + '''main.c: In function 'main_loop': 47 + main.c:295:2: error: 'fred' undeclared (first use in this function) 48 + main.c:295:2: note: each undeclared identifier is reported only once for each function it appears in 49 + make[1]: *** [main.o] Error 1 50 + make: *** [common/libcommon.o] Error 2 51 + Make failed 52 + ''', 53 + '''main.c: In function 'main_loop': 54 + main.c:280:6: warning: unused variable 'mary' [-Wunused-variable] 55 + ''', 56 + '''powerpc-linux-ld: warning: dot moved backwards before `.bss' 57 + powerpc-linux-ld: warning: dot moved backwards before `.bss' 58 + powerpc-linux-ld: u-boot: section .text lma 0xfffc0000 overlaps previous sections 59 + powerpc-linux-ld: u-boot: section .rodata lma 0xfffef3ec overlaps previous sections 60 + powerpc-linux-ld: u-boot: section .reloc lma 0xffffa400 overlaps previous sections 61 + powerpc-linux-ld: u-boot: section .data lma 0xffffcd38 overlaps previous sections 62 + powerpc-linux-ld: u-boot: section .u_boot_cmd lma 0xffffeb40 overlaps previous sections 63 + powerpc-linux-ld: u-boot: section .bootpg lma 0xfffff198 overlaps previous sections 64 + ''' 65 + ] 66 + 67 + 68 + # hash, subject, return code, list of errors/warnings 69 + commits = [ 70 + ['1234', 'upstream/master, ok', 0, []], 71 + ['5678', 'Second commit, a warning', 0, errors[0:1]], 72 + ['9012', 'Third commit, error', 1, errors[0:2]], 73 + ['3456', 'Fourth commit, warning', 0, [errors[0], errors[2]]], 74 + ['7890', 'Fifth commit, link errors', 1, [errors[0], errors[3]]], 75 + ['abcd', 'Sixth commit, fixes all errors', 0, []] 76 + ] 77 + 78 + boards = [ 79 + ['board0', 'arm', 'armv7', 'ARM Board 1', 'Tester', '', ''], 80 + ['board1', 'arm', 'armv7', 'ARM Board 2', 'Tester', '', ''], 81 + ['board2', 'powerpc', 'powerpc', 'PowerPC board 1', 'Tester', '', ''], 82 + ['board3', 'powerpc', 'mpc5xx', 'PowerPC board 2', 'Tester', '', ''], 83 + ['board4', 'sandbox', 'sandbox', 'Sandbox board', 'Tester', '', ''] 84 + ] 85 + 86 + class Options: 87 + """Class that holds build options""" 88 + pass 89 + 90 + class TestBuild(unittest.TestCase): 91 + """Test buildman 92 + 93 + TODO: Write tests for the rest of the functionality 94 + """ 95 + def setUp(self): 96 + # Set up commits to build 97 + self.commits = [] 98 + sequence = 0 99 + for commit_info in commits: 100 + comm = commit.Commit(commit_info[0]) 101 + comm.subject = commit_info[1] 102 + comm.return_code = commit_info[2] 103 + comm.error_list = commit_info[3] 104 + comm.sequence = sequence 105 + sequence += 1 106 + self.commits.append(comm) 107 + 108 + # Set up boards to build 109 + self.boards = board.Boards() 110 + for brd in boards: 111 + self.boards.AddBoard(board.Board(*brd)) 112 + self.boards.SelectBoards([]) 113 + 114 + # Set up the toolchains 115 + bsettings.Setup() 116 + self.toolchains = toolchain.Toolchains() 117 + self.toolchains.Add('arm-linux-gcc', test=False) 118 + self.toolchains.Add('sparc-linux-gcc', test=False) 119 + self.toolchains.Add('powerpc-linux-gcc', test=False) 120 + self.toolchains.Add('gcc', test=False) 121 + 122 + def Make(self, commit, brd, stage, *args, **kwargs): 123 + result = command.CommandResult() 124 + boardnum = int(brd.target[-1]) 125 + result.return_code = 0 126 + result.stderr = '' 127 + result.stdout = ('This is the test output for board %s, commit %s' % 128 + (brd.target, commit.hash)) 129 + if boardnum >= 1 and boardnum >= commit.sequence: 130 + result.return_code = commit.return_code 131 + result.stderr = ''.join(commit.error_list) 132 + if stage == 'build': 133 + target_dir = None 134 + for arg in args: 135 + if arg.startswith('O='): 136 + target_dir = arg[2:] 137 + 138 + if not os.path.isdir(target_dir): 139 + os.mkdir(target_dir) 140 + #time.sleep(.2 + boardnum * .2) 141 + 142 + result.combined = result.stdout + result.stderr 143 + return result 144 + 145 + def testBasic(self): 146 + """Test basic builder operation""" 147 + output_dir = tempfile.mkdtemp() 148 + if not os.path.isdir(output_dir): 149 + os.mkdir(output_dir) 150 + build = builder.Builder(self.toolchains, output_dir, None, 1, 2, 151 + checkout=False, show_unknown=False) 152 + build.do_make = self.Make 153 + board_selected = self.boards.GetSelectedDict() 154 + 155 + #build.BuildCommits(self.commits, board_selected, False) 156 + build.BuildBoards(self.commits, board_selected, False, False) 157 + build.ShowSummary(self.commits, board_selected, True, False, 158 + False, False) 159 + 160 + def _testGit(self): 161 + """Test basic builder operation by building a branch""" 162 + base_dir = tempfile.mkdtemp() 163 + if not os.path.isdir(base_dir): 164 + os.mkdir(base_dir) 165 + options = Options() 166 + options.git = os.getcwd() 167 + options.summary = False 168 + options.jobs = None 169 + options.dry_run = False 170 + #options.git = os.path.join(base_dir, 'repo') 171 + options.branch = 'test-buildman' 172 + options.force_build = False 173 + options.list_tool_chains = False 174 + options.count = -1 175 + options.git_dir = None 176 + options.threads = None 177 + options.show_unknown = False 178 + options.quick = False 179 + options.show_errors = False 180 + options.keep_outputs = False 181 + args = ['tegra20'] 182 + control.DoBuildman(options, args) 183 + 184 + if __name__ == "__main__": 185 + unittest.main()
+185
tools/buildman/toolchain.py
··· 1 + # Copyright (c) 2012 The Chromium OS Authors. 2 + # 3 + # See file CREDITS for list of people who contributed to this 4 + # project. 5 + # 6 + # This program is free software; you can redistribute it and/or 7 + # modify it under the terms of the GNU General Public License as 8 + # published by the Free Software Foundation; either version 2 of 9 + # the License, or (at your option) any later version. 10 + # 11 + # This program is distributed in the hope that it will be useful, 12 + # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + # GNU General Public License for more details. 15 + # 16 + # You should have received a copy of the GNU General Public License 17 + # along with this program; if not, write to the Free Software 18 + # Foundation, Inc., 59 Temple Place, Suite 330, Boston, 19 + # MA 02111-1307 USA 20 + # 21 + 22 + import glob 23 + import os 24 + 25 + import bsettings 26 + import command 27 + 28 + class Toolchain: 29 + """A single toolchain 30 + 31 + Public members: 32 + gcc: Full path to C compiler 33 + path: Directory path containing C compiler 34 + cross: Cross compile string, e.g. 'arm-linux-' 35 + arch: Architecture of toolchain as determined from the first 36 + component of the filename. E.g. arm-linux-gcc becomes arm 37 + """ 38 + 39 + def __init__(self, fname, test, verbose=False): 40 + """Create a new toolchain object. 41 + 42 + Args: 43 + fname: Filename of the gcc component 44 + test: True to run the toolchain to test it 45 + """ 46 + self.gcc = fname 47 + self.path = os.path.dirname(fname) 48 + self.cross = os.path.basename(fname)[:-3] 49 + pos = self.cross.find('-') 50 + self.arch = self.cross[:pos] if pos != -1 else 'sandbox' 51 + 52 + env = self.MakeEnvironment() 53 + 54 + # As a basic sanity check, run the C compiler with --version 55 + cmd = [fname, '--version'] 56 + if test: 57 + result = command.RunPipe([cmd], capture=True, env=env) 58 + self.ok = result.return_code == 0 59 + if verbose: 60 + print 'Tool chain test: ', 61 + if self.ok: 62 + print 'OK' 63 + else: 64 + print 'BAD' 65 + print 'Command: ', cmd 66 + print result.stdout 67 + print result.stderr 68 + else: 69 + self.ok = True 70 + self.priority = self.GetPriority(fname) 71 + 72 + def GetPriority(self, fname): 73 + """Return the priority of the toolchain. 74 + 75 + Toolchains are ranked according to their suitability by their 76 + filename prefix. 77 + 78 + Args: 79 + fname: Filename of toolchain 80 + Returns: 81 + Priority of toolchain, 0=highest, 20=lowest. 82 + """ 83 + priority_list = ['-elf', '-unknown-linux-gnu', '-linux', '-elf', 84 + '-none-linux-gnueabi', '-uclinux', '-none-eabi', 85 + '-gentoo-linux-gnu', '-linux-gnueabi', '-le-linux', '-uclinux'] 86 + for prio in range(len(priority_list)): 87 + if priority_list[prio] in fname: 88 + return prio 89 + return prio 90 + 91 + def MakeEnvironment(self): 92 + """Returns an environment for using the toolchain. 93 + 94 + Thie takes the current environment, adds CROSS_COMPILE and 95 + augments PATH so that the toolchain will operate correctly. 96 + """ 97 + env = dict(os.environ) 98 + env['CROSS_COMPILE'] = self.cross 99 + env['PATH'] += (':' + self.path) 100 + return env 101 + 102 + 103 + class Toolchains: 104 + """Manage a list of toolchains for building U-Boot 105 + 106 + We select one toolchain for each architecture type 107 + 108 + Public members: 109 + toolchains: Dict of Toolchain objects, keyed by architecture name 110 + paths: List of paths to check for toolchains (may contain wildcards) 111 + """ 112 + 113 + def __init__(self): 114 + self.toolchains = {} 115 + self.paths = [] 116 + for name, value in bsettings.GetItems('toolchain'): 117 + if '*' in value: 118 + self.paths += glob.glob(value) 119 + else: 120 + self.paths.append(value) 121 + 122 + 123 + def Add(self, fname, test=True, verbose=False): 124 + """Add a toolchain to our list 125 + 126 + We select the given toolchain as our preferred one for its 127 + architecture if it is a higher priority than the others. 128 + 129 + Args: 130 + fname: Filename of toolchain's gcc driver 131 + test: True to run the toolchain to test it 132 + """ 133 + toolchain = Toolchain(fname, test, verbose) 134 + add_it = toolchain.ok 135 + if toolchain.arch in self.toolchains: 136 + add_it = (toolchain.priority < 137 + self.toolchains[toolchain.arch].priority) 138 + if add_it: 139 + self.toolchains[toolchain.arch] = toolchain 140 + 141 + def Scan(self, verbose): 142 + """Scan for available toolchains and select the best for each arch. 143 + 144 + We look for all the toolchains we can file, figure out the 145 + architecture for each, and whether it works. Then we select the 146 + highest priority toolchain for each arch. 147 + 148 + Args: 149 + verbose: True to print out progress information 150 + """ 151 + if verbose: print 'Scanning for tool chains' 152 + for path in self.paths: 153 + if verbose: print " - scanning path '%s'" % path 154 + for subdir in ['.', 'bin', 'usr/bin']: 155 + dirname = os.path.join(path, subdir) 156 + if verbose: print " - looking in '%s'" % dirname 157 + for fname in glob.glob(dirname + '/*gcc'): 158 + if verbose: print " - found '%s'" % fname 159 + self.Add(fname, True, verbose) 160 + 161 + def List(self): 162 + """List out the selected toolchains for each architecture""" 163 + print 'List of available toolchains (%d):' % len(self.toolchains) 164 + if len(self.toolchains): 165 + for key, value in sorted(self.toolchains.iteritems()): 166 + print '%-10s: %s' % (key, value.gcc) 167 + else: 168 + print 'None' 169 + 170 + def Select(self, arch): 171 + """Returns the toolchain for a given architecture 172 + 173 + Args: 174 + args: Name of architecture (e.g. 'arm', 'ppc_8xx') 175 + 176 + returns: 177 + toolchain object, or None if none found 178 + """ 179 + for name, value in bsettings.GetItems('toolchain-alias'): 180 + if arch == name: 181 + arch = value 182 + 183 + if not arch in self.toolchains: 184 + raise ValueError, ("No tool chain found for arch '%s'" % arch) 185 + return self.toolchains[arch]