Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 2 | # Copyright (c) 2013 The Chromium OS Authors. |
| 3 | # |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 4 | |
| 5 | import multiprocessing |
| 6 | import os |
Simon Glass | a10ebe1 | 2014-09-05 19:00:18 -0600 | [diff] [blame] | 7 | import shutil |
Simon Glass | f0d9c10 | 2020-04-17 18:09:02 -0600 | [diff] [blame] | 8 | import subprocess |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 9 | import sys |
| 10 | |
Simon Glass | f0d9c10 | 2020-04-17 18:09:02 -0600 | [diff] [blame] | 11 | from buildman import board |
| 12 | from buildman import bsettings |
Simon Glass | e5650a8 | 2022-01-22 05:07:33 -0700 | [diff] [blame] | 13 | from buildman import cfgutil |
Simon Glass | f0d9c10 | 2020-04-17 18:09:02 -0600 | [diff] [blame] | 14 | from buildman import toolchain |
| 15 | from buildman.builder import Builder |
Simon Glass | a997ea5 | 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 | 25ecd97 | 2021-09-08 12:38:01 +0100 | [diff] [blame] | 20 | from patman import tools |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame^] | 21 | from patman.terminal import tprint |
Simon Glass | c05694f | 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 | d326ad7 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 27 | def GetActionSummary(is_summary, commits, selected, options): |
Simon Glass | c05694f | 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 | d326ad7 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 33 | if commits: |
| 34 | count = len(commits) |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 35 | count = (count + options.step - 1) // options.step |
Simon Glass | d326ad7 | 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 | c05694f | 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 | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 46 | def ShowActions(series, why_selected, boards_selected, builder, options, |
| 47 | board_warnings): |
Simon Glass | c05694f | 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 | 6af145f | 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 | c05694f | 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 | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 61 | board_warnings: List of warnings obtained from board selected |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 62 | """ |
| 63 | col = terminal.Color() |
Simon Glass | c78ed66 | 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 | d326ad7 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 66 | if series: |
| 67 | commits = series.commits |
| 68 | else: |
| 69 | commits = None |
Simon Glass | c78ed66 | 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 | d326ad7 | 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 | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 76 | print(' ', col.build(col.YELLOW, commit.hash[:8], bright=False), end=' ') |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 77 | print(commit.subject) |
| 78 | print() |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 79 | for arg in why_selected: |
| 80 | if arg != 'all': |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 81 | print(arg, ': %d boards' % len(why_selected[arg])) |
Simon Glass | 6af145f | 2017-01-23 05:38:56 -0700 | [diff] [blame] | 82 | if options.verbose: |
Simon Glass | c78ed66 | 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 | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 86 | if board_warnings: |
| 87 | for warning in board_warnings: |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 88 | print(col.build(col.YELLOW, warning)) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 89 | |
Simon Glass | 2df44be | 2020-03-18 09:42:47 -0600 | [diff] [blame] | 90 | def ShowToolchainPrefix(boards, toolchains): |
Simon Glass | 48ac42e | 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 | 2df44be | 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 | 48ac42e | 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 | 48ac42e | 2019-12-05 15:59:14 -0700 | [diff] [blame] | 99 | |
| 100 | Return: |
| 101 | None on success, string error message otherwise |
| 102 | """ |
| 103 | boards = boards.GetSelectedDict() |
| 104 | tc_set = set() |
| 105 | for brd in boards.values(): |
| 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 | 2df44be | 2020-03-18 09:42:47 -0600 | [diff] [blame] | 111 | print(tc.GetEnvArgs(toolchain.VAR_CROSS_COMPILE)) |
Simon Glass | 48ac42e | 2019-12-05 15:59:14 -0700 | [diff] [blame] | 112 | return None |
| 113 | |
Simon Glass | a10ebe1 | 2014-09-05 19:00:18 -0600 | [diff] [blame] | 114 | def DoBuildman(options, args, toolchains=None, make_func=None, boards=None, |
Simon Glass | 9bf9a72 | 2021-04-11 16:27:27 +1200 | [diff] [blame] | 115 | clean_dir=False, test_thread_exceptions=False): |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 116 | """The main control code for buildman |
| 117 | |
| 118 | Args: |
| 119 | options: Command line options object |
| 120 | args: Command line arguments (list of strings) |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 121 | toolchains: Toolchains to use - this should be a Toolchains() |
| 122 | object. If None, then it will be created and scanned |
| 123 | make_func: Make function to use for the builder. This is called |
| 124 | to execute 'make'. If this is None, the normal function |
| 125 | will be used, which calls the 'make' tool with suitable |
| 126 | arguments. This setting is useful for tests. |
Simon Glass | cbd3658 | 2014-09-05 19:00:16 -0600 | [diff] [blame] | 127 | board: Boards() object to use, containing a list of available |
| 128 | boards. If this is None it will be created and scanned. |
Simon Glass | a29b3ea | 2021-04-11 16:27:25 +1200 | [diff] [blame] | 129 | clean_dir: Used for tests only, indicates that the existing output_dir |
| 130 | should be removed before starting the build |
Simon Glass | 9bf9a72 | 2021-04-11 16:27:27 +1200 | [diff] [blame] | 131 | test_thread_exceptions: Uses for tests only, True to make the threads |
| 132 | raise an exception instead of reporting their result. This simulates |
| 133 | a failure in the code somewhere |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 134 | """ |
Simon Glass | a10ebe1 | 2014-09-05 19:00:18 -0600 | [diff] [blame] | 135 | global builder |
| 136 | |
Simon Glass | ca9b06e | 2014-09-05 19:00:11 -0600 | [diff] [blame] | 137 | if options.full_help: |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 138 | tools.print_full_help( |
Paul Barker | 25ecd97 | 2021-09-08 12:38:01 +0100 | [diff] [blame] | 139 | os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), 'README') |
| 140 | ) |
Simon Glass | ca9b06e | 2014-09-05 19:00:11 -0600 | [diff] [blame] | 141 | return 0 |
| 142 | |
Simon Glass | 761648b | 2022-01-29 14:14:11 -0700 | [diff] [blame] | 143 | gitutil.setup() |
Simon Glass | 9f1ba0f | 2016-07-27 20:33:02 -0600 | [diff] [blame] | 144 | col = terminal.Color() |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 145 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 146 | options.git_dir = os.path.join(options.git, '.git') |
| 147 | |
Simon Glass | a3d9b4f | 2016-07-27 20:33:04 -0600 | [diff] [blame] | 148 | no_toolchains = toolchains is None |
| 149 | if no_toolchains: |
Simon Glass | f77ca5b | 2019-01-07 16:44:20 -0700 | [diff] [blame] | 150 | toolchains = toolchain.Toolchains(options.override_toolchain) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 151 | |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 152 | if options.fetch_arch: |
| 153 | if options.fetch_arch == 'list': |
| 154 | sorted_list = toolchains.ListArchs() |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 155 | print(col.build(col.BLUE, 'Available architectures: %s\n' % |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 156 | ' '.join(sorted_list))) |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 157 | return 0 |
| 158 | else: |
| 159 | fetch_arch = options.fetch_arch |
| 160 | if fetch_arch == 'all': |
| 161 | fetch_arch = ','.join(toolchains.ListArchs()) |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 162 | print(col.build(col.CYAN, '\nDownloading toolchains: %s' % |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 163 | fetch_arch)) |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 164 | for arch in fetch_arch.split(','): |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 165 | print() |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 166 | ret = toolchains.FetchAndInstall(arch) |
| 167 | if ret: |
| 168 | return ret |
| 169 | return 0 |
| 170 | |
Simon Glass | a3d9b4f | 2016-07-27 20:33:04 -0600 | [diff] [blame] | 171 | if no_toolchains: |
| 172 | toolchains.GetSettings() |
Simon Glass | 74579fc | 2018-11-06 16:02:10 -0700 | [diff] [blame] | 173 | toolchains.Scan(options.list_tool_chains and options.verbose) |
Simon Glass | a3d9b4f | 2016-07-27 20:33:04 -0600 | [diff] [blame] | 174 | if options.list_tool_chains: |
| 175 | toolchains.List() |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 176 | print() |
Simon Glass | a3d9b4f | 2016-07-27 20:33:04 -0600 | [diff] [blame] | 177 | return 0 |
| 178 | |
Simon Glass | 6029af1 | 2020-04-09 15:08:51 -0600 | [diff] [blame] | 179 | if options.incremental: |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 180 | print(col.build(col.RED, |
Simon Glass | 6029af1 | 2020-04-09 15:08:51 -0600 | [diff] [blame] | 181 | 'Warning: -I has been removed. See documentation')) |
Simon Glass | d9c9863 | 2020-04-17 17:51:32 -0600 | [diff] [blame] | 182 | if not options.output_dir: |
| 183 | if options.work_in_output: |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 184 | sys.exit(col.build(col.RED, '-w requires that you specify -o')) |
Simon Glass | d9c9863 | 2020-04-17 17:51:32 -0600 | [diff] [blame] | 185 | options.output_dir = '..' |
Simon Glass | 6029af1 | 2020-04-09 15:08:51 -0600 | [diff] [blame] | 186 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 187 | # Work out what subset of the boards we are building |
Simon Glass | cbd3658 | 2014-09-05 19:00:16 -0600 | [diff] [blame] | 188 | if not boards: |
Tom Rini | 6ef6b3f | 2019-11-19 15:14:33 -0500 | [diff] [blame] | 189 | if not os.path.exists(options.output_dir): |
| 190 | os.makedirs(options.output_dir) |
Bin Meng | 0733e20 | 2019-10-28 07:24:59 -0700 | [diff] [blame] | 191 | board_file = os.path.join(options.output_dir, 'boards.cfg') |
Simon Glass | 952109b | 2020-07-19 09:59:49 -0600 | [diff] [blame] | 192 | our_path = os.path.dirname(os.path.realpath(__file__)) |
| 193 | genboardscfg = os.path.join(our_path, '../genboardscfg.py') |
| 194 | if not os.path.exists(genboardscfg): |
| 195 | genboardscfg = os.path.join(options.git, 'tools/genboardscfg.py') |
Simon Glass | aa26d47 | 2019-12-05 15:59:12 -0700 | [diff] [blame] | 196 | status = subprocess.call([genboardscfg, '-q', '-o', board_file]) |
Simon Glass | cbd3658 | 2014-09-05 19:00:16 -0600 | [diff] [blame] | 197 | if status != 0: |
Simon Glass | 952109b | 2020-07-19 09:59:49 -0600 | [diff] [blame] | 198 | # Older versions don't support -q |
| 199 | status = subprocess.call([genboardscfg, '-o', board_file]) |
| 200 | if status != 0: |
| 201 | sys.exit("Failed to generate boards.cfg") |
Masahiro Yamada | e9bc8d2 | 2014-07-30 14:08:22 +0900 | [diff] [blame] | 202 | |
Simon Glass | cbd3658 | 2014-09-05 19:00:16 -0600 | [diff] [blame] | 203 | boards = board.Boards() |
Bin Meng | 0733e20 | 2019-10-28 07:24:59 -0700 | [diff] [blame] | 204 | boards.ReadBoards(board_file) |
Simon Glass | 924c73a | 2014-08-28 09:43:41 -0600 | [diff] [blame] | 205 | |
| 206 | exclude = [] |
| 207 | if options.exclude: |
| 208 | for arg in options.exclude: |
| 209 | exclude += arg.split(',') |
| 210 | |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 211 | if options.boards: |
| 212 | requested_boards = [] |
| 213 | for b in options.boards: |
| 214 | requested_boards += b.split(',') |
| 215 | else: |
| 216 | requested_boards = None |
| 217 | why_selected, board_warnings = boards.SelectBoards(args, exclude, |
| 218 | requested_boards) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 219 | selected = boards.GetSelected() |
| 220 | if not len(selected): |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 221 | sys.exit(col.build(col.RED, 'No matching boards found')) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 222 | |
Simon Glass | 2df44be | 2020-03-18 09:42:47 -0600 | [diff] [blame] | 223 | if options.print_prefix: |
Simon Glass | f4c0072 | 2020-04-17 17:51:31 -0600 | [diff] [blame] | 224 | err = ShowToolchainPrefix(boards, toolchains) |
Simon Glass | 48ac42e | 2019-12-05 15:59:14 -0700 | [diff] [blame] | 225 | if err: |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 226 | sys.exit(col.build(col.RED, err)) |
Simon Glass | 48ac42e | 2019-12-05 15:59:14 -0700 | [diff] [blame] | 227 | return 0 |
| 228 | |
Simon Glass | 9b55091 | 2019-12-05 15:59:13 -0700 | [diff] [blame] | 229 | # Work out how many commits to build. We want to build everything on the |
| 230 | # branch. We also build the upstream commit as a control so we can see |
| 231 | # problems introduced by the first commit on the branch. |
| 232 | count = options.count |
| 233 | has_range = options.branch and '..' in options.branch |
| 234 | if count == -1: |
| 235 | if not options.branch: |
| 236 | count = 1 |
| 237 | else: |
| 238 | if has_range: |
Simon Glass | 761648b | 2022-01-29 14:14:11 -0700 | [diff] [blame] | 239 | count, msg = gitutil.count_commits_in_range(options.git_dir, |
Simon Glass | 9b55091 | 2019-12-05 15:59:13 -0700 | [diff] [blame] | 240 | options.branch) |
| 241 | else: |
Simon Glass | 761648b | 2022-01-29 14:14:11 -0700 | [diff] [blame] | 242 | count, msg = gitutil.count_commits_in_branch(options.git_dir, |
Simon Glass | 9b55091 | 2019-12-05 15:59:13 -0700 | [diff] [blame] | 243 | options.branch) |
| 244 | if count is None: |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 245 | sys.exit(col.build(col.RED, msg)) |
Simon Glass | 9b55091 | 2019-12-05 15:59:13 -0700 | [diff] [blame] | 246 | elif count == 0: |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 247 | sys.exit(col.build(col.RED, "Range '%s' has no commits" % |
Simon Glass | 9b55091 | 2019-12-05 15:59:13 -0700 | [diff] [blame] | 248 | options.branch)) |
| 249 | if msg: |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 250 | print(col.build(col.YELLOW, msg)) |
Simon Glass | 9b55091 | 2019-12-05 15:59:13 -0700 | [diff] [blame] | 251 | count += 1 # Build upstream commit also |
| 252 | |
| 253 | if not count: |
| 254 | str = ("No commits found to process in branch '%s': " |
| 255 | "set branch's upstream or use -c flag" % options.branch) |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 256 | sys.exit(col.build(col.RED, str)) |
Simon Glass | b6eb8cf | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 257 | if options.work_in_output: |
| 258 | if len(selected) != 1: |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 259 | sys.exit(col.build(col.RED, |
Simon Glass | b6eb8cf | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 260 | '-w can only be used with a single board')) |
| 261 | if count != 1: |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 262 | sys.exit(col.build(col.RED, |
Simon Glass | b6eb8cf | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 263 | '-w can only be used with a single commit')) |
Simon Glass | 9b55091 | 2019-12-05 15:59:13 -0700 | [diff] [blame] | 264 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 265 | # Read the metadata from the commits. First look at the upstream commit, |
| 266 | # then the ones in the branch. We would like to do something like |
| 267 | # upstream/master~..branch but that isn't possible if upstream/master is |
| 268 | # a merge commit (it will list all the commits that form part of the |
| 269 | # merge) |
Simon Glass | 359b55a6 | 2014-09-05 19:00:23 -0600 | [diff] [blame] | 270 | # Conflicting tags are not a problem for buildman, since it does not use |
| 271 | # them. For example, Series-version is not useful for buildman. On the |
| 272 | # other hand conflicting tags will cause an error. So allow later tags |
| 273 | # to overwrite earlier ones by setting allow_overwrite=True |
Simon Glass | d326ad7 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 274 | if options.branch: |
Simon Glass | 16a5288 | 2014-08-09 15:33:09 -0600 | [diff] [blame] | 275 | if count == -1: |
Simon Glass | 5eeef46 | 2014-12-01 17:33:57 -0700 | [diff] [blame] | 276 | if has_range: |
| 277 | range_expr = options.branch |
| 278 | else: |
Simon Glass | 761648b | 2022-01-29 14:14:11 -0700 | [diff] [blame] | 279 | range_expr = gitutil.get_range_in_branch(options.git_dir, |
Simon Glass | 5eeef46 | 2014-12-01 17:33:57 -0700 | [diff] [blame] | 280 | options.branch) |
Simon Glass | 761648b | 2022-01-29 14:14:11 -0700 | [diff] [blame] | 281 | upstream_commit = gitutil.get_upstream(options.git_dir, |
Simon Glass | 16a5288 | 2014-08-09 15:33:09 -0600 | [diff] [blame] | 282 | options.branch) |
Simon Glass | 93f61c0 | 2020-10-29 21:46:19 -0600 | [diff] [blame] | 283 | series = patchstream.get_metadata_for_list(upstream_commit, |
Simon Glass | 359b55a6 | 2014-09-05 19:00:23 -0600 | [diff] [blame] | 284 | options.git_dir, 1, series=None, allow_overwrite=True) |
Simon Glass | d326ad7 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 285 | |
Simon Glass | 93f61c0 | 2020-10-29 21:46:19 -0600 | [diff] [blame] | 286 | series = patchstream.get_metadata_for_list(range_expr, |
Simon Glass | 359b55a6 | 2014-09-05 19:00:23 -0600 | [diff] [blame] | 287 | options.git_dir, None, series, allow_overwrite=True) |
Simon Glass | 16a5288 | 2014-08-09 15:33:09 -0600 | [diff] [blame] | 288 | else: |
| 289 | # Honour the count |
Simon Glass | 93f61c0 | 2020-10-29 21:46:19 -0600 | [diff] [blame] | 290 | series = patchstream.get_metadata_for_list(options.branch, |
Simon Glass | 359b55a6 | 2014-09-05 19:00:23 -0600 | [diff] [blame] | 291 | options.git_dir, count, series=None, allow_overwrite=True) |
Simon Glass | d326ad7 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 292 | else: |
| 293 | series = None |
Simon Glass | 6af145f | 2017-01-23 05:38:56 -0700 | [diff] [blame] | 294 | if not options.dry_run: |
| 295 | options.verbose = True |
| 296 | if not options.summary: |
| 297 | options.show_errors = True |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 298 | |
| 299 | # By default we have one thread per CPU. But if there are not enough jobs |
| 300 | # we can have fewer threads and use a high '-j' value for make. |
Simon Glass | c635d89 | 2021-01-30 22:17:46 -0700 | [diff] [blame] | 301 | if options.threads is None: |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 302 | options.threads = min(multiprocessing.cpu_count(), len(selected)) |
| 303 | if not options.jobs: |
| 304 | options.jobs = max(1, (multiprocessing.cpu_count() + |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 305 | len(selected) - 1) // len(selected)) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 306 | |
| 307 | if not options.step: |
| 308 | options.step = len(series.commits) - 1 |
| 309 | |
Simon Glass | 840be73 | 2022-01-29 14:14:05 -0700 | [diff] [blame] | 310 | gnu_make = command.output(os.path.join(options.git, |
Simon Glass | c55e056 | 2016-07-25 18:59:00 -0600 | [diff] [blame] | 311 | 'scripts/show-gnu-make'), raise_on_error=False).rstrip() |
Masahiro Yamada | 1fe610d | 2014-07-22 11:19:09 +0900 | [diff] [blame] | 312 | if not gnu_make: |
Masahiro Yamada | 880828d | 2014-08-16 00:59:26 +0900 | [diff] [blame] | 313 | sys.exit('GNU Make not found') |
Masahiro Yamada | 1fe610d | 2014-07-22 11:19:09 +0900 | [diff] [blame] | 314 | |
Simon Glass | dbc01c7 | 2014-12-01 17:33:52 -0700 | [diff] [blame] | 315 | # Create a new builder with the selected options. |
| 316 | output_dir = options.output_dir |
Simon Glass | d326ad7 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 317 | if options.branch: |
Simon Glass | 4aeceb9 | 2014-09-05 19:00:22 -0600 | [diff] [blame] | 318 | dirname = options.branch.replace('/', '_') |
Simon Glass | e87bde1 | 2014-12-01 17:33:55 -0700 | [diff] [blame] | 319 | # As a special case allow the board directory to be placed in the |
| 320 | # output directory itself rather than any subdirectory. |
| 321 | if not options.no_subdirs: |
| 322 | output_dir = os.path.join(options.output_dir, dirname) |
Lothar Waßmann | ce6df92 | 2018-04-08 05:14:11 -0600 | [diff] [blame] | 323 | if clean_dir and os.path.exists(output_dir): |
| 324 | shutil.rmtree(output_dir) |
Simon Glass | e5650a8 | 2022-01-22 05:07:33 -0700 | [diff] [blame] | 325 | adjust_cfg = cfgutil.convert_list_to_dict(options.adjust_cfg) |
| 326 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 327 | builder = Builder(toolchains, output_dir, options.git_dir, |
Masahiro Yamada | 1fe610d | 2014-07-22 11:19:09 +0900 | [diff] [blame] | 328 | options.threads, options.jobs, gnu_make=gnu_make, checkout=True, |
Simon Glass | e87bde1 | 2014-12-01 17:33:55 -0700 | [diff] [blame] | 329 | show_unknown=options.show_unknown, step=options.step, |
Simon Glass | 655b610 | 2014-12-01 17:34:07 -0700 | [diff] [blame] | 330 | no_subdirs=options.no_subdirs, full_path=options.full_path, |
Stephen Warren | 97c9690 | 2016-04-11 10:48:44 -0600 | [diff] [blame] | 331 | verbose_build=options.verbose_build, |
Simon Glass | 6029af1 | 2020-04-09 15:08:51 -0600 | [diff] [blame] | 332 | mrproper=options.mrproper, |
Simon Glass | 739e851 | 2016-11-13 14:25:51 -0700 | [diff] [blame] | 333 | per_board_out_dir=options.per_board_out_dir, |
Simon Glass | cde5c30 | 2016-11-13 14:25:53 -0700 | [diff] [blame] | 334 | config_only=options.config_only, |
Daniel Schwierzeck | 20e2ea9 | 2018-01-26 16:31:05 +0100 | [diff] [blame] | 335 | squash_config_y=not options.preserve_config_y, |
Simon Glass | b6eb8cf | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 336 | warnings_as_errors=options.warnings_as_errors, |
Simon Glass | 9bf9a72 | 2021-04-11 16:27:27 +1200 | [diff] [blame] | 337 | work_in_output=options.work_in_output, |
Simon Glass | e5650a8 | 2022-01-22 05:07:33 -0700 | [diff] [blame] | 338 | test_thread_exceptions=test_thread_exceptions, |
| 339 | adjust_cfg=adjust_cfg) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 340 | builder.force_config_on_failure = not options.quick |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 341 | if make_func: |
| 342 | builder.do_make = make_func |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 343 | |
| 344 | # For a dry run, just show our actions as a sanity check |
| 345 | if options.dry_run: |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 346 | ShowActions(series, why_selected, selected, builder, options, |
| 347 | board_warnings) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 348 | else: |
| 349 | builder.force_build = options.force_build |
Simon Glass | 7041c39 | 2014-07-13 12:22:31 -0600 | [diff] [blame] | 350 | builder.force_build_failures = options.force_build_failures |
Simon Glass | f3018b7a | 2014-07-14 17:51:02 -0600 | [diff] [blame] | 351 | builder.force_reconfig = options.force_reconfig |
Simon Glass | 38df2e2 | 2014-07-14 17:51:03 -0600 | [diff] [blame] | 352 | builder.in_tree = options.in_tree |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 353 | |
| 354 | # Work out which boards to build |
| 355 | board_selected = boards.GetSelectedDict() |
| 356 | |
Simon Glass | d326ad7 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 357 | if series: |
| 358 | commits = series.commits |
Simon Glass | a10ebe1 | 2014-09-05 19:00:18 -0600 | [diff] [blame] | 359 | # Number the commits for test purposes |
| 360 | for commit in range(len(commits)): |
| 361 | commits[commit].sequence = commit |
Simon Glass | d326ad7 | 2014-08-09 15:32:59 -0600 | [diff] [blame] | 362 | else: |
| 363 | commits = None |
| 364 | |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame^] | 365 | tprint(GetActionSummary(options.summary, commits, board_selected, |
Simon Glass | 9ea9381 | 2020-04-09 15:08:52 -0600 | [diff] [blame] | 366 | options)) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 367 | |
Simon Glass | 232d850 | 2014-09-14 20:23:16 -0600 | [diff] [blame] | 368 | # We can't show function sizes without board details at present |
| 369 | if options.show_bloat: |
| 370 | options.show_detail = True |
Simon Glass | 9ea9381 | 2020-04-09 15:08:52 -0600 | [diff] [blame] | 371 | builder.SetDisplayOptions( |
| 372 | options.show_errors, options.show_sizes, options.show_detail, |
| 373 | options.show_bloat, options.list_error_boards, options.show_config, |
Simon Glass | f4ebfba | 2020-04-09 15:08:53 -0600 | [diff] [blame] | 374 | options.show_environment, options.filter_dtb_warnings, |
| 375 | options.filter_migration_warnings) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 376 | if options.summary: |
Simon Glass | eb48bbc | 2014-08-09 15:33:02 -0600 | [diff] [blame] | 377 | builder.ShowSummary(commits, board_selected) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 378 | else: |
Simon Glass | 9bf9a72 | 2021-04-11 16:27:27 +1200 | [diff] [blame] | 379 | fail, warned, excs = builder.BuildBoards( |
| 380 | commits, board_selected, options.keep_outputs, options.verbose) |
| 381 | if excs: |
| 382 | return 102 |
| 383 | elif fail: |
Simon Glass | e4cd506 | 2020-04-09 10:49:45 -0600 | [diff] [blame] | 384 | return 100 |
Simon Glass | 35e7d38 | 2020-03-18 09:42:44 -0600 | [diff] [blame] | 385 | elif warned and not options.ignore_warnings: |
Simon Glass | e4cd506 | 2020-04-09 10:49:45 -0600 | [diff] [blame] | 386 | return 101 |
Simon Glass | c2f9107 | 2014-08-28 09:43:39 -0600 | [diff] [blame] | 387 | return 0 |