1 # Copyright (c) 2013 The Chromium OS Authors.
3 # See file CREDITS for list of people who contributed to this
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.
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.
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,
22 import multiprocessing
28 from builder import Builder
35 """Returns a plural 's' if count is not 1"""
36 return 's' if count != 1 else ''
38 def GetActionSummary(is_summary, count, selected, options):
39 """Return a string summarising the intended action.
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),
48 str += ' (%d thread%s, %d job%s per thread)' % (options.threads,
49 GetPlural(options.threads), options.jobs, GetPlural(options.jobs))
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.
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,
64 builder: The builder that will be used to build the commits
65 options: Command line options object
67 col = terminal.Color()
68 print 'Dry run, so not doing much. But I would do this:'
70 print GetActionSummary(False, len(series.commits), boards_selected,
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),
78 for arg in why_selected:
80 print arg, ': %d boards' % why_selected[arg]
81 print ('Total boards to build for each commit: %d\n' %
84 def DoBuildman(options, args):
85 """The main control code for buildman
88 options: Command line options object
89 args: Command line arguments (list of strings)
94 options.git_dir = os.path.join(options.git, '.git')
96 toolchains = toolchain.Toolchains()
97 toolchains.Scan(options.list_tool_chains)
98 if options.list_tool_chains:
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
109 if not options.branch:
110 str = 'Please use -b to specify a branch to build'
111 print col.Color(col.RED, str)
113 count = gitutil.CountCommitsInBranch(options.git_dir, options.branch)
114 count += 1 # Build upstream commit also
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)
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')
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
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,
140 # Conflicting tags are not a problem for buildman, since it does not use
141 # them. For example, Series-version is not useful for buildman. On the
142 # other hand conflicting tags will cause an error. So allow later tags
143 # to overwrite earlier ones.
144 series.allow_overwrite = True
145 series = patchstream.GetMetaDataForList(range_expr, options.git_dir, None,
148 # By default we have one thread per CPU. But if there are not enough jobs
149 # we can have fewer threads and use a high '-j' value for make.
150 if not options.threads:
151 options.threads = min(multiprocessing.cpu_count(), len(selected))
153 options.jobs = max(1, (multiprocessing.cpu_count() +
154 len(selected) - 1) / len(selected))
157 options.step = len(series.commits) - 1
159 # Create a new builder with the selected options
160 output_dir = os.path.join('..', options.branch)
161 builder = Builder(toolchains, output_dir, options.git_dir,
162 options.threads, options.jobs, checkout=True,
163 show_unknown=options.show_unknown, step=options.step)
164 builder.force_config_on_failure = not options.quick
166 # For a dry run, just show our actions as a sanity check
168 ShowActions(series, why_selected, selected, builder, options)
170 builder.force_build = options.force_build
172 # Work out which boards to build
173 board_selected = boards.GetSelectedDict()
175 print GetActionSummary(options.summary, count, board_selected, options)
178 # We can't show function sizes without board details at present
179 if options.show_bloat:
180 options.show_detail = True
181 builder.ShowSummary(series.commits, board_selected,
182 options.show_errors, options.show_sizes,
183 options.show_detail, options.show_bloat)
185 builder.BuildBoards(series.commits, board_selected,
186 options.show_errors, options.keep_outputs)