Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 2 | # Copyright (c) 2013 The Chromium OS Authors. |
| 3 | # |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 4 | |
| 5 | import multiprocessing |
| 6 | import os |
Simon Glass | 883a321 | 2014-09-05 19:00:18 -0600 | [diff] [blame] | 7 | import shutil |
Simon Glass | 0ede00f | 2020-04-17 18:09:02 -0600 | [diff] [blame] | 8 | import subprocess |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 9 | import sys |
| 10 | |
Simon Glass | 0ede00f | 2020-04-17 18:09:02 -0600 | [diff] [blame] | 11 | from buildman import board |
| 12 | from buildman import bsettings |
| 13 | from buildman import toolchain |
| 14 | from buildman.builder import Builder |
Simon Glass | bf77667 | 2020-04-17 18:09:04 -0600 | [diff] [blame] | 15 | from patman import command |
| 16 | from patman import gitutil |
| 17 | from patman import patchstream |
| 18 | from patman import terminal |
Paul Barker | 5fe50f9 | 2021-09-08 12:38:01 +0100 | [diff] [blame] | 19 | from patman import tools |
Simon Glass | bf77667 | 2020-04-17 18:09:04 -0600 | [diff] [blame] | 20 | from patman.terminal import Print |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 21 | |
| 22 | def GetPlural(count): |
| 23 | """Returns a plural 's' if count is not 1""" |
| 24 | return 's' if count != 1 else '' |
| 25 | |
Simon Glass | fea5858 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 26 | def GetActionSummary(is_summary, commits, selected, options): |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 27 | """Return a string summarising the intended action. |
| 28 | |
| 29 | Returns: |
| 30 | Summary string. |
| 31 | """ |
Simon Glass | fea5858 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 32 | if commits: |
| 33 | count = len(commits) |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 34 | count = (count + options.step - 1) // options.step |
Simon Glass | fea5858 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 35 | commit_str = '%d commit%s' % (count, GetPlural(count)) |
| 36 | else: |
| 37 | commit_str = 'current source' |
| 38 | str = '%s %s for %d boards' % ( |
| 39 | 'Summary of' if is_summary else 'Building', commit_str, |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 40 | len(selected)) |
| 41 | str += ' (%d thread%s, %d job%s per thread)' % (options.threads, |
| 42 | GetPlural(options.threads), options.jobs, GetPlural(options.jobs)) |
| 43 | return str |
| 44 | |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 45 | def ShowActions(series, why_selected, boards_selected, builder, options, |
| 46 | board_warnings): |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 47 | """Display a list of actions that we would take, if not a dry run. |
| 48 | |
| 49 | Args: |
| 50 | series: Series object |
| 51 | why_selected: Dictionary where each key is a buildman argument |
Simon Glass | 8d7523c | 2017-01-23 05:38:56 -0700 | [diff] [blame] | 52 | provided by the user, and the value is the list of boards |
| 53 | brought in by that argument. For example, 'arm' might bring |
| 54 | in 400 boards, so in this case the key would be 'arm' and |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 55 | the value would be a list of board names. |
| 56 | boards_selected: Dict of selected boards, key is target name, |
| 57 | value is Board object |
| 58 | builder: The builder that will be used to build the commits |
| 59 | options: Command line options object |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 60 | board_warnings: List of warnings obtained from board selected |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 61 | """ |
| 62 | col = terminal.Color() |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 63 | print('Dry run, so not doing much. But I would do this:') |
| 64 | print() |
Simon Glass | fea5858 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 65 | if series: |
| 66 | commits = series.commits |
| 67 | else: |
| 68 | commits = None |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 69 | print(GetActionSummary(False, commits, boards_selected, |
| 70 | options)) |
| 71 | print('Build directory: %s' % builder.base_dir) |
Simon Glass | fea5858 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 72 | if commits: |
| 73 | for upto in range(0, len(series.commits), options.step): |
| 74 | commit = series.commits[upto] |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 75 | print(' ', col.Color(col.YELLOW, commit.hash[:8], bright=False), end=' ') |
| 76 | print(commit.subject) |
| 77 | print() |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 78 | for arg in why_selected: |
| 79 | if arg != 'all': |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 80 | print(arg, ': %d boards' % len(why_selected[arg])) |
Simon Glass | 8d7523c | 2017-01-23 05:38:56 -0700 | [diff] [blame] | 81 | if options.verbose: |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 82 | print(' %s' % ' '.join(why_selected[arg])) |
| 83 | print(('Total boards to build for each commit: %d\n' % |
| 84 | len(why_selected['all']))) |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 85 | if board_warnings: |
| 86 | for warning in board_warnings: |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 87 | print(col.Color(col.YELLOW, warning)) |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 88 | |
Simon Glass | 4e9162d | 2020-03-18 09:42:47 -0600 | [diff] [blame] | 89 | def ShowToolchainPrefix(boards, toolchains): |
Simon Glass | 57cb9d5 | 2019-12-05 15:59:14 -0700 | [diff] [blame] | 90 | """Show information about a the tool chain used by one or more boards |
| 91 | |
Simon Glass | 4e9162d | 2020-03-18 09:42:47 -0600 | [diff] [blame] | 92 | The function checks that all boards use the same toolchain, then prints |
| 93 | the correct value for CROSS_COMPILE. |
Simon Glass | 57cb9d5 | 2019-12-05 15:59:14 -0700 | [diff] [blame] | 94 | |
| 95 | Args: |
| 96 | boards: Boards object containing selected boards |
| 97 | toolchains: Toolchains object containing available toolchains |
Simon Glass | 57cb9d5 | 2019-12-05 15:59:14 -0700 | [diff] [blame] | 98 | |
| 99 | Return: |
| 100 | None on success, string error message otherwise |
| 101 | """ |
| 102 | boards = boards.GetSelectedDict() |
| 103 | tc_set = set() |
| 104 | for brd in boards.values(): |
| 105 | tc_set.add(toolchains.Select(brd.arch)) |
| 106 | if len(tc_set) != 1: |
| 107 | return 'Supplied boards must share one toolchain' |
| 108 | return False |
| 109 | tc = tc_set.pop() |
Simon Glass | 4e9162d | 2020-03-18 09:42:47 -0600 | [diff] [blame] | 110 | print(tc.GetEnvArgs(toolchain.VAR_CROSS_COMPILE)) |
Simon Glass | 57cb9d5 | 2019-12-05 15:59:14 -0700 | [diff] [blame] | 111 | return None |
| 112 | |
Simon Glass | 883a321 | 2014-09-05 19:00:18 -0600 | [diff] [blame] | 113 | def DoBuildman(options, args, toolchains=None, make_func=None, boards=None, |
Simon Glass | 8116c78 | 2021-04-11 16:27:27 +1200 | [diff] [blame] | 114 | clean_dir=False, test_thread_exceptions=False): |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 115 | """The main control code for buildman |
| 116 | |
| 117 | Args: |
| 118 | options: Command line options object |
| 119 | args: Command line arguments (list of strings) |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 120 | toolchains: Toolchains to use - this should be a Toolchains() |
| 121 | object. If None, then it will be created and scanned |
| 122 | make_func: Make function to use for the builder. This is called |
| 123 | to execute 'make'. If this is None, the normal function |
| 124 | will be used, which calls the 'make' tool with suitable |
| 125 | arguments. This setting is useful for tests. |
Simon Glass | 823e60b | 2014-09-05 19:00:16 -0600 | [diff] [blame] | 126 | board: Boards() object to use, containing a list of available |
| 127 | boards. If this is None it will be created and scanned. |
Simon Glass | 2499331 | 2021-04-11 16:27:25 +1200 | [diff] [blame] | 128 | clean_dir: Used for tests only, indicates that the existing output_dir |
| 129 | should be removed before starting the build |
Simon Glass | 8116c78 | 2021-04-11 16:27:27 +1200 | [diff] [blame] | 130 | test_thread_exceptions: Uses for tests only, True to make the threads |
| 131 | raise an exception instead of reporting their result. This simulates |
| 132 | a failure in the code somewhere |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 133 | """ |
Simon Glass | 883a321 | 2014-09-05 19:00:18 -0600 | [diff] [blame] | 134 | global builder |
| 135 | |
Simon Glass | 48ba585 | 2014-09-05 19:00:11 -0600 | [diff] [blame] | 136 | if options.full_help: |
Paul Barker | 5fe50f9 | 2021-09-08 12:38:01 +0100 | [diff] [blame] | 137 | tools.PrintFullHelp( |
| 138 | os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), 'README') |
| 139 | ) |
Simon Glass | 48ba585 | 2014-09-05 19:00:11 -0600 | [diff] [blame] | 140 | return 0 |
| 141 | |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 142 | gitutil.Setup() |
Simon Glass | 713bea3 | 2016-07-27 20:33:02 -0600 | [diff] [blame] | 143 | col = terminal.Color() |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 144 | |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 145 | options.git_dir = os.path.join(options.git, '.git') |
| 146 | |
Simon Glass | 7e92e46 | 2016-07-27 20:33:04 -0600 | [diff] [blame] | 147 | no_toolchains = toolchains is None |
| 148 | if no_toolchains: |
Simon Glass | 00beb24 | 2019-01-07 16:44:20 -0700 | [diff] [blame] | 149 | toolchains = toolchain.Toolchains(options.override_toolchain) |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 150 | |
Simon Glass | 827e37b | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 151 | if options.fetch_arch: |
| 152 | if options.fetch_arch == 'list': |
| 153 | sorted_list = toolchains.ListArchs() |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 154 | print(col.Color(col.BLUE, 'Available architectures: %s\n' % |
| 155 | ' '.join(sorted_list))) |
Simon Glass | 827e37b | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 156 | return 0 |
| 157 | else: |
| 158 | fetch_arch = options.fetch_arch |
| 159 | if fetch_arch == 'all': |
| 160 | fetch_arch = ','.join(toolchains.ListArchs()) |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 161 | print(col.Color(col.CYAN, '\nDownloading toolchains: %s' % |
| 162 | fetch_arch)) |
Simon Glass | 827e37b | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 163 | for arch in fetch_arch.split(','): |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 164 | print() |
Simon Glass | 827e37b | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 165 | ret = toolchains.FetchAndInstall(arch) |
| 166 | if ret: |
| 167 | return ret |
| 168 | return 0 |
| 169 | |
Simon Glass | 7e92e46 | 2016-07-27 20:33:04 -0600 | [diff] [blame] | 170 | if no_toolchains: |
| 171 | toolchains.GetSettings() |
Simon Glass | 40232c9 | 2018-11-06 16:02:10 -0700 | [diff] [blame] | 172 | toolchains.Scan(options.list_tool_chains and options.verbose) |
Simon Glass | 7e92e46 | 2016-07-27 20:33:04 -0600 | [diff] [blame] | 173 | if options.list_tool_chains: |
| 174 | toolchains.List() |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 175 | print() |
Simon Glass | 7e92e46 | 2016-07-27 20:33:04 -0600 | [diff] [blame] | 176 | return 0 |
| 177 | |
Simon Glass | eb70a2c | 2020-04-09 15:08:51 -0600 | [diff] [blame] | 178 | if options.incremental: |
| 179 | print(col.Color(col.RED, |
| 180 | 'Warning: -I has been removed. See documentation')) |
Simon Glass | 88daaef | 2020-04-17 17:51:32 -0600 | [diff] [blame] | 181 | if not options.output_dir: |
| 182 | if options.work_in_output: |
| 183 | sys.exit(col.Color(col.RED, '-w requires that you specify -o')) |
| 184 | options.output_dir = '..' |
Simon Glass | eb70a2c | 2020-04-09 15:08:51 -0600 | [diff] [blame] | 185 | |
Simon Glass | 7c66ead | 2019-12-05 15:59:13 -0700 | [diff] [blame] | 186 | # Work out what subset of the boards we are building |
| 187 | if not boards: |
| 188 | if not os.path.exists(options.output_dir): |
| 189 | os.makedirs(options.output_dir) |
| 190 | board_file = os.path.join(options.output_dir, 'boards.cfg') |
Simon Glass | 5a910b9 | 2020-07-19 09:59:49 -0600 | [diff] [blame] | 191 | our_path = os.path.dirname(os.path.realpath(__file__)) |
| 192 | genboardscfg = os.path.join(our_path, '../genboardscfg.py') |
| 193 | if not os.path.exists(genboardscfg): |
| 194 | genboardscfg = os.path.join(options.git, 'tools/genboardscfg.py') |
Simon Glass | 7c66ead | 2019-12-05 15:59:13 -0700 | [diff] [blame] | 195 | status = subprocess.call([genboardscfg, '-q', '-o', board_file]) |
| 196 | if status != 0: |
Simon Glass | 5a910b9 | 2020-07-19 09:59:49 -0600 | [diff] [blame] | 197 | # Older versions don't support -q |
| 198 | status = subprocess.call([genboardscfg, '-o', board_file]) |
| 199 | if status != 0: |
| 200 | sys.exit("Failed to generate boards.cfg") |
Simon Glass | 7c66ead | 2019-12-05 15:59:13 -0700 | [diff] [blame] | 201 | |
| 202 | boards = board.Boards() |
| 203 | boards.ReadBoards(board_file) |
| 204 | |
| 205 | exclude = [] |
| 206 | if options.exclude: |
| 207 | for arg in options.exclude: |
| 208 | exclude += arg.split(',') |
| 209 | |
| 210 | if options.boards: |
| 211 | requested_boards = [] |
| 212 | for b in options.boards: |
| 213 | requested_boards += b.split(',') |
| 214 | else: |
| 215 | requested_boards = None |
| 216 | why_selected, board_warnings = boards.SelectBoards(args, exclude, |
| 217 | requested_boards) |
| 218 | selected = boards.GetSelected() |
| 219 | if not len(selected): |
| 220 | sys.exit(col.Color(col.RED, 'No matching boards found')) |
| 221 | |
Simon Glass | 4e9162d | 2020-03-18 09:42:47 -0600 | [diff] [blame] | 222 | if options.print_prefix: |
Simon Glass | 97944d3 | 2020-04-17 17:51:31 -0600 | [diff] [blame] | 223 | err = ShowToolchainPrefix(boards, toolchains) |
Simon Glass | 57cb9d5 | 2019-12-05 15:59:14 -0700 | [diff] [blame] | 224 | if err: |
| 225 | sys.exit(col.Color(col.RED, err)) |
| 226 | return 0 |
| 227 | |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 228 | # Work out how many commits to build. We want to build everything on the |
| 229 | # branch. We also build the upstream commit as a control so we can see |
| 230 | # problems introduced by the first commit on the branch. |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 231 | count = options.count |
Simon Glass | 5abab20 | 2014-12-01 17:33:57 -0700 | [diff] [blame] | 232 | has_range = options.branch and '..' in options.branch |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 233 | if count == -1: |
| 234 | if not options.branch: |
Simon Glass | fea5858 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 235 | count = 1 |
| 236 | else: |
Simon Glass | 5abab20 | 2014-12-01 17:33:57 -0700 | [diff] [blame] | 237 | if has_range: |
| 238 | count, msg = gitutil.CountCommitsInRange(options.git_dir, |
| 239 | options.branch) |
| 240 | else: |
| 241 | count, msg = gitutil.CountCommitsInBranch(options.git_dir, |
| 242 | options.branch) |
Simon Glass | fea5858 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 243 | if count is None: |
Simon Glass | 2a9e2c6 | 2014-12-01 17:33:54 -0700 | [diff] [blame] | 244 | sys.exit(col.Color(col.RED, msg)) |
Simon Glass | 5abab20 | 2014-12-01 17:33:57 -0700 | [diff] [blame] | 245 | elif count == 0: |
| 246 | sys.exit(col.Color(col.RED, "Range '%s' has no commits" % |
| 247 | options.branch)) |
Simon Glass | 2a9e2c6 | 2014-12-01 17:33:54 -0700 | [diff] [blame] | 248 | if msg: |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 249 | print(col.Color(col.YELLOW, msg)) |
Simon Glass | fea5858 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 250 | count += 1 # Build upstream commit also |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 251 | |
| 252 | if not count: |
| 253 | str = ("No commits found to process in branch '%s': " |
| 254 | "set branch's upstream or use -c flag" % options.branch) |
Masahiro Yamada | 31e2141 | 2014-08-16 00:59:26 +0900 | [diff] [blame] | 255 | sys.exit(col.Color(col.RED, str)) |
Simon Glass | d829f12 | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 256 | if options.work_in_output: |
| 257 | if len(selected) != 1: |
| 258 | sys.exit(col.Color(col.RED, |
| 259 | '-w can only be used with a single board')) |
| 260 | if count != 1: |
| 261 | sys.exit(col.Color(col.RED, |
| 262 | '-w can only be used with a single commit')) |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 263 | |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 264 | # Read the metadata from the commits. First look at the upstream commit, |
| 265 | # then the ones in the branch. We would like to do something like |
| 266 | # upstream/master~..branch but that isn't possible if upstream/master is |
| 267 | # a merge commit (it will list all the commits that form part of the |
| 268 | # merge) |
Simon Glass | 950a231 | 2014-09-05 19:00:23 -0600 | [diff] [blame] | 269 | # Conflicting tags are not a problem for buildman, since it does not use |
| 270 | # them. For example, Series-version is not useful for buildman. On the |
| 271 | # other hand conflicting tags will cause an error. So allow later tags |
| 272 | # to overwrite earlier ones by setting allow_overwrite=True |
Simon Glass | fea5858 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 273 | if options.branch: |
Simon Glass | 3b74ba5 | 2014-08-09 15:33:09 -0600 | [diff] [blame] | 274 | if count == -1: |
Simon Glass | 5abab20 | 2014-12-01 17:33:57 -0700 | [diff] [blame] | 275 | if has_range: |
| 276 | range_expr = options.branch |
| 277 | else: |
| 278 | range_expr = gitutil.GetRangeInBranch(options.git_dir, |
| 279 | options.branch) |
Simon Glass | 3b74ba5 | 2014-08-09 15:33:09 -0600 | [diff] [blame] | 280 | upstream_commit = gitutil.GetUpstream(options.git_dir, |
| 281 | options.branch) |
Simon Glass | d93720e | 2020-10-29 21:46:19 -0600 | [diff] [blame] | 282 | series = patchstream.get_metadata_for_list(upstream_commit, |
Simon Glass | 950a231 | 2014-09-05 19:00:23 -0600 | [diff] [blame] | 283 | options.git_dir, 1, series=None, allow_overwrite=True) |
Simon Glass | fea5858 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 284 | |
Simon Glass | d93720e | 2020-10-29 21:46:19 -0600 | [diff] [blame] | 285 | series = patchstream.get_metadata_for_list(range_expr, |
Simon Glass | 950a231 | 2014-09-05 19:00:23 -0600 | [diff] [blame] | 286 | options.git_dir, None, series, allow_overwrite=True) |
Simon Glass | 3b74ba5 | 2014-08-09 15:33:09 -0600 | [diff] [blame] | 287 | else: |
| 288 | # Honour the count |
Simon Glass | d93720e | 2020-10-29 21:46:19 -0600 | [diff] [blame] | 289 | series = patchstream.get_metadata_for_list(options.branch, |
Simon Glass | 950a231 | 2014-09-05 19:00:23 -0600 | [diff] [blame] | 290 | options.git_dir, count, series=None, allow_overwrite=True) |
Simon Glass | fea5858 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 291 | else: |
| 292 | series = None |
Simon Glass | 8d7523c | 2017-01-23 05:38:56 -0700 | [diff] [blame] | 293 | if not options.dry_run: |
| 294 | options.verbose = True |
| 295 | if not options.summary: |
| 296 | options.show_errors = True |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 297 | |
| 298 | # By default we have one thread per CPU. But if there are not enough jobs |
| 299 | # we can have fewer threads and use a high '-j' value for make. |
Simon Glass | b82492b | 2021-01-30 22:17:46 -0700 | [diff] [blame] | 300 | if options.threads is None: |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 301 | options.threads = min(multiprocessing.cpu_count(), len(selected)) |
| 302 | if not options.jobs: |
| 303 | options.jobs = max(1, (multiprocessing.cpu_count() + |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 304 | len(selected) - 1) // len(selected)) |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 305 | |
| 306 | if not options.step: |
| 307 | options.step = len(series.commits) - 1 |
| 308 | |
Masahiro Yamada | 9979692 | 2014-07-22 11:19:09 +0900 | [diff] [blame] | 309 | gnu_make = command.Output(os.path.join(options.git, |
Simon Glass | 785f154 | 2016-07-25 18:59:00 -0600 | [diff] [blame] | 310 | 'scripts/show-gnu-make'), raise_on_error=False).rstrip() |
Masahiro Yamada | 9979692 | 2014-07-22 11:19:09 +0900 | [diff] [blame] | 311 | if not gnu_make: |
Masahiro Yamada | 31e2141 | 2014-08-16 00:59:26 +0900 | [diff] [blame] | 312 | sys.exit('GNU Make not found') |
Masahiro Yamada | 9979692 | 2014-07-22 11:19:09 +0900 | [diff] [blame] | 313 | |
Simon Glass | 05c96b1 | 2014-12-01 17:33:52 -0700 | [diff] [blame] | 314 | # Create a new builder with the selected options. |
| 315 | output_dir = options.output_dir |
Simon Glass | fea5858 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 316 | if options.branch: |
Simon Glass | f7582ce | 2014-09-05 19:00:22 -0600 | [diff] [blame] | 317 | dirname = options.branch.replace('/', '_') |
Simon Glass | 5971ab5 | 2014-12-01 17:33:55 -0700 | [diff] [blame] | 318 | # As a special case allow the board directory to be placed in the |
| 319 | # output directory itself rather than any subdirectory. |
| 320 | if not options.no_subdirs: |
| 321 | output_dir = os.path.join(options.output_dir, dirname) |
Lothar Waßmann | 409fc02 | 2018-04-08 05:14:11 -0600 | [diff] [blame] | 322 | if clean_dir and os.path.exists(output_dir): |
| 323 | shutil.rmtree(output_dir) |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 324 | builder = Builder(toolchains, output_dir, options.git_dir, |
Masahiro Yamada | 9979692 | 2014-07-22 11:19:09 +0900 | [diff] [blame] | 325 | options.threads, options.jobs, gnu_make=gnu_make, checkout=True, |
Simon Glass | 5971ab5 | 2014-12-01 17:33:55 -0700 | [diff] [blame] | 326 | show_unknown=options.show_unknown, step=options.step, |
Simon Glass | d2ce658 | 2014-12-01 17:34:07 -0700 | [diff] [blame] | 327 | no_subdirs=options.no_subdirs, full_path=options.full_path, |
Stephen Warren | f79f1e0 | 2016-04-11 10:48:44 -0600 | [diff] [blame] | 328 | verbose_build=options.verbose_build, |
Simon Glass | eb70a2c | 2020-04-09 15:08:51 -0600 | [diff] [blame] | 329 | mrproper=options.mrproper, |
Simon Glass | b50113f | 2016-11-13 14:25:51 -0700 | [diff] [blame] | 330 | per_board_out_dir=options.per_board_out_dir, |
Simon Glass | b464f8e | 2016-11-13 14:25:53 -0700 | [diff] [blame] | 331 | config_only=options.config_only, |
Daniel Schwierzeck | 2371d1b | 2018-01-26 16:31:05 +0100 | [diff] [blame] | 332 | squash_config_y=not options.preserve_config_y, |
Simon Glass | d829f12 | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 333 | warnings_as_errors=options.warnings_as_errors, |
Simon Glass | 8116c78 | 2021-04-11 16:27:27 +1200 | [diff] [blame] | 334 | work_in_output=options.work_in_output, |
| 335 | test_thread_exceptions=test_thread_exceptions) |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 336 | builder.force_config_on_failure = not options.quick |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 337 | if make_func: |
| 338 | builder.do_make = make_func |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 339 | |
| 340 | # For a dry run, just show our actions as a sanity check |
| 341 | if options.dry_run: |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 342 | ShowActions(series, why_selected, selected, builder, options, |
| 343 | board_warnings) |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 344 | else: |
| 345 | builder.force_build = options.force_build |
Simon Glass | 4266dc2 | 2014-07-13 12:22:31 -0600 | [diff] [blame] | 346 | builder.force_build_failures = options.force_build_failures |
Simon Glass | 97e9152 | 2014-07-14 17:51:02 -0600 | [diff] [blame] | 347 | builder.force_reconfig = options.force_reconfig |
Simon Glass | 189a496 | 2014-07-14 17:51:03 -0600 | [diff] [blame] | 348 | builder.in_tree = options.in_tree |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 349 | |
| 350 | # Work out which boards to build |
| 351 | board_selected = boards.GetSelectedDict() |
| 352 | |
Simon Glass | fea5858 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 353 | if series: |
| 354 | commits = series.commits |
Simon Glass | 883a321 | 2014-09-05 19:00:18 -0600 | [diff] [blame] | 355 | # Number the commits for test purposes |
| 356 | for commit in range(len(commits)): |
| 357 | commits[commit].sequence = commit |
Simon Glass | fea5858 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 358 | else: |
| 359 | commits = None |
| 360 | |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 361 | Print(GetActionSummary(options.summary, commits, board_selected, |
Simon Glass | 174592b | 2020-04-09 15:08:52 -0600 | [diff] [blame] | 362 | options)) |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 363 | |
Simon Glass | 7798e22 | 2014-09-14 20:23:16 -0600 | [diff] [blame] | 364 | # We can't show function sizes without board details at present |
| 365 | if options.show_bloat: |
| 366 | options.show_detail = True |
Simon Glass | 174592b | 2020-04-09 15:08:52 -0600 | [diff] [blame] | 367 | builder.SetDisplayOptions( |
| 368 | options.show_errors, options.show_sizes, options.show_detail, |
| 369 | options.show_bloat, options.list_error_boards, options.show_config, |
Simon Glass | 113a8a5 | 2020-04-09 15:08:53 -0600 | [diff] [blame] | 370 | options.show_environment, options.filter_dtb_warnings, |
| 371 | options.filter_migration_warnings) |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 372 | if options.summary: |
Simon Glass | b2ea7ab | 2014-08-09 15:33:02 -0600 | [diff] [blame] | 373 | builder.ShowSummary(commits, board_selected) |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 374 | else: |
Simon Glass | 8116c78 | 2021-04-11 16:27:27 +1200 | [diff] [blame] | 375 | fail, warned, excs = builder.BuildBoards( |
| 376 | commits, board_selected, options.keep_outputs, options.verbose) |
| 377 | if excs: |
| 378 | return 102 |
| 379 | elif fail: |
Simon Glass | b1e5e6d | 2020-04-09 10:49:45 -0600 | [diff] [blame] | 380 | return 100 |
Simon Glass | 7beb43c | 2020-03-18 09:42:44 -0600 | [diff] [blame] | 381 | elif warned and not options.ignore_warnings: |
Simon Glass | b1e5e6d | 2020-04-09 10:49:45 -0600 | [diff] [blame] | 382 | return 101 |
Simon Glass | 2c3deb9 | 2014-08-28 09:43:39 -0600 | [diff] [blame] | 383 | return 0 |