xref: /openbmc/u-boot/tools/buildman/buildman.py (revision 1a459660)
1fc3fe1c2SSimon Glass#!/usr/bin/python
2fc3fe1c2SSimon Glass#
3fc3fe1c2SSimon Glass# Copyright (c) 2012 The Chromium OS Authors.
4fc3fe1c2SSimon Glass#
5*1a459660SWolfgang Denk# SPDX-License-Identifier:	GPL-2.0+
6fc3fe1c2SSimon Glass#
7fc3fe1c2SSimon Glass
8fc3fe1c2SSimon Glass"""See README for more information"""
9fc3fe1c2SSimon Glass
10fc3fe1c2SSimon Glassimport multiprocessing
11fc3fe1c2SSimon Glassfrom optparse import OptionParser
12fc3fe1c2SSimon Glassimport os
13fc3fe1c2SSimon Glassimport re
14fc3fe1c2SSimon Glassimport sys
15fc3fe1c2SSimon Glassimport unittest
16fc3fe1c2SSimon Glass
17fc3fe1c2SSimon Glass# Bring in the patman libraries
18fc3fe1c2SSimon Glassour_path = os.path.dirname(os.path.realpath(__file__))
19fc3fe1c2SSimon Glasssys.path.append(os.path.join(our_path, '../patman'))
20fc3fe1c2SSimon Glass
21fc3fe1c2SSimon Glass# Our modules
22fc3fe1c2SSimon Glassimport board
23fc3fe1c2SSimon Glassimport builder
24fc3fe1c2SSimon Glassimport checkpatch
25fc3fe1c2SSimon Glassimport command
26fc3fe1c2SSimon Glassimport control
27fc3fe1c2SSimon Glassimport doctest
28fc3fe1c2SSimon Glassimport gitutil
29fc3fe1c2SSimon Glassimport patchstream
30fc3fe1c2SSimon Glassimport terminal
31fc3fe1c2SSimon Glassimport toolchain
32fc3fe1c2SSimon Glass
33fc3fe1c2SSimon Glassdef RunTests():
34fc3fe1c2SSimon Glass    import test
35fc3fe1c2SSimon Glass
36fc3fe1c2SSimon Glass    sys.argv = [sys.argv[0]]
37fc3fe1c2SSimon Glass    suite = unittest.TestLoader().loadTestsFromTestCase(test.TestBuild)
38fc3fe1c2SSimon Glass    result = unittest.TestResult()
39fc3fe1c2SSimon Glass    suite.run(result)
40fc3fe1c2SSimon Glass
41fc3fe1c2SSimon Glass    # TODO: Surely we can just 'print' result?
42fc3fe1c2SSimon Glass    print result
43fc3fe1c2SSimon Glass    for test, err in result.errors:
44fc3fe1c2SSimon Glass        print err
45fc3fe1c2SSimon Glass    for test, err in result.failures:
46fc3fe1c2SSimon Glass        print err
47fc3fe1c2SSimon Glass
48fc3fe1c2SSimon Glass
49fc3fe1c2SSimon Glassparser = OptionParser()
50fc3fe1c2SSimon Glassparser.add_option('-b', '--branch', type='string',
51fc3fe1c2SSimon Glass       help='Branch name to build')
52fc3fe1c2SSimon Glassparser.add_option('-B', '--bloat', dest='show_bloat',
53fc3fe1c2SSimon Glass       action='store_true', default=False,
54fc3fe1c2SSimon Glass       help='Show changes in function code size for each board')
55fc3fe1c2SSimon Glassparser.add_option('-c', '--count', dest='count', type='int',
56fc3fe1c2SSimon Glass       default=-1, help='Run build on the top n commits')
57fc3fe1c2SSimon Glassparser.add_option('-e', '--show_errors', action='store_true',
58fc3fe1c2SSimon Glass       default=False, help='Show errors and warnings')
59fc3fe1c2SSimon Glassparser.add_option('-f', '--force-build', dest='force_build',
60fc3fe1c2SSimon Glass       action='store_true', default=False,
61fc3fe1c2SSimon Glass       help='Force build of boards even if already built')
62fc3fe1c2SSimon Glassparser.add_option('-d', '--detail', dest='show_detail',
63fc3fe1c2SSimon Glass       action='store_true', default=False,
64fc3fe1c2SSimon Glass       help='Show detailed information for each board in summary')
65fc3fe1c2SSimon Glassparser.add_option('-g', '--git', type='string',
66fc3fe1c2SSimon Glass       help='Git repo containing branch to build', default='.')
67fc3fe1c2SSimon Glassparser.add_option('-H', '--full-help', action='store_true', dest='full_help',
68fc3fe1c2SSimon Glass       default=False, help='Display the README file')
69fc3fe1c2SSimon Glassparser.add_option('-j', '--jobs', dest='jobs', type='int',
70fc3fe1c2SSimon Glass       default=None, help='Number of jobs to run at once (passed to make)')
71fc3fe1c2SSimon Glassparser.add_option('-k', '--keep-outputs', action='store_true',
72fc3fe1c2SSimon Glass       default=False, help='Keep all build output files (e.g. binaries)')
73fc3fe1c2SSimon Glassparser.add_option('--list-tool-chains', action='store_true', default=False,
74fc3fe1c2SSimon Glass       help='List available tool chains')
75fc3fe1c2SSimon Glassparser.add_option('-n', '--dry-run', action='store_true', dest='dry_run',
76fc3fe1c2SSimon Glass       default=False, help="Do a try run (describe actions, but no nothing)")
77fc3fe1c2SSimon Glassparser.add_option('-Q', '--quick', action='store_true',
78fc3fe1c2SSimon Glass       default=False, help='Do a rough build, with limited warning resolution')
79fc3fe1c2SSimon Glassparser.add_option('-s', '--summary', action='store_true',
80fc3fe1c2SSimon Glass       default=False, help='Show a build summary')
81fc3fe1c2SSimon Glassparser.add_option('-S', '--show-sizes', action='store_true',
82fc3fe1c2SSimon Glass       default=False, help='Show image size variation in summary')
83fc3fe1c2SSimon Glassparser.add_option('--step', type='int',
84fc3fe1c2SSimon Glass       default=1, help='Only build every n commits (0=just first and last)')
85fc3fe1c2SSimon Glassparser.add_option('-t', '--test', action='store_true', dest='test',
86fc3fe1c2SSimon Glass                  default=False, help='run tests')
87fc3fe1c2SSimon Glassparser.add_option('-T', '--threads', type='int',
88fc3fe1c2SSimon Glass       default=None, help='Number of builder threads to use')
89fc3fe1c2SSimon Glassparser.add_option('-u', '--show_unknown', action='store_true',
90fc3fe1c2SSimon Glass       default=False, help='Show boards with unknown build result')
91fc3fe1c2SSimon Glass
92fc3fe1c2SSimon Glassparser.usage = """buildman -b <branch> [options]
93fc3fe1c2SSimon Glass
94fc3fe1c2SSimon GlassBuild U-Boot for all commits in a branch. Use -n to do a dry run"""
95fc3fe1c2SSimon Glass
96fc3fe1c2SSimon Glass(options, args) = parser.parse_args()
97fc3fe1c2SSimon Glass
98fc3fe1c2SSimon Glass# Run our meagre tests
99fc3fe1c2SSimon Glassif options.test:
100fc3fe1c2SSimon Glass    RunTests()
101fc3fe1c2SSimon Glasselif options.full_help:
102fc3fe1c2SSimon Glass    pager = os.getenv('PAGER')
103fc3fe1c2SSimon Glass    if not pager:
104fc3fe1c2SSimon Glass        pager = 'more'
105fc3fe1c2SSimon Glass    fname = os.path.join(os.path.dirname(sys.argv[0]), 'README')
106fc3fe1c2SSimon Glass    command.Run(pager, fname)
107fc3fe1c2SSimon Glass
108fc3fe1c2SSimon Glass# Build selected commits for selected boards
109fc3fe1c2SSimon Glasselse:
110fc3fe1c2SSimon Glass    control.DoBuildman(options, args)
111