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