blob: 845b47aa2ab66e76510adc66877eda8acaa91208 [file] [log] [blame] [view]
dprankefe4602312015-04-08 16:20:351# The MB (Meta-Build wrapper) user guide
2
3[TOC]
4
5## Introduction
6
Dirk Pranked181a1a2017-12-14 01:47:117`mb` is a simple python wrapper GN meta-build tool; it was originally
8written as part of the GYP->GN migration.
dprankefe4602312015-04-08 16:20:359
10It is intended to be used by bots to make it easier to manage the configuration
11each bot builds (i.e., the configurations can be changed from chromium
12commits), and to consolidate the list of all of the various configurations
13that Chromium is built in.
14
15Ideally this tool will no longer be needed after the migration is complete.
16
dprankea5a77ca2015-07-16 23:24:1717For more discussion of MB, see also [the design spec](design_spec.md).
dprankefe4602312015-04-08 16:20:3518
dprankea5a77ca2015-07-16 23:24:1719## MB subcommands
dprankefe4602312015-04-08 16:20:3520
Dirk Prankef24e6b22018-03-27 20:12:3021### mb analyze
dprankefe4602312015-04-08 16:20:3522
23`mb analyze` is reponsible for determining what targets are affected by
24a list of files (e.g., the list of files in a patch on a trybot):
25
26```
27mb analyze -c chromium_linux_rel //out/Release input.json output.json
28```
29
Ben Pastene74502492021-01-06 17:07:1530Either the `-c/--config` flag or the `--builder-group` and `-b/--builder` flags
dprankefe4602312015-04-08 16:20:3531must be specified so that `mb` can figure out which config to use.
32
dprankeee5b51f62015-04-09 00:03:2233The first positional argument must be a GN-style "source-absolute" path
34to the build directory.
dprankefe4602312015-04-08 16:20:3535
dprankeee5b51f62015-04-09 00:03:2236The second positional argument is a (normal) path to a JSON file containing
dpranke06de67be2015-11-12 22:10:0337a single object with the following fields:
dprankefe4602312015-04-08 16:20:3538
dpranke06de67be2015-11-12 22:10:0339 * `files`: an array of the modified filenames to check (as paths relative to
40 the checkout root).
41 * `test_targets`: an array of (ninja) build targets that needed to run the
42 tests we wish to run. An empty array will be treated as if there are
43 no tests that will be run.
44 * `additional_compile_targets`: an array of (ninja) build targets that
45 reflect the stuff we might want to build *in addition to* the list
Takuto Ikutaf91b4b282024-05-15 08:33:0846 passed in `test_targets`. Targets in this list will be treated
dpranke06de67be2015-11-12 22:10:0347 specially, in the following way: if a given target is a "meta"
Dirk Pranked181a1a2017-12-14 01:47:1148 (GN: group) target like 'blink_tests' or or even the
Thiago Farina511bb6d2017-06-30 22:24:1049 ninja-specific 'all' target, then only the *dependencies* of the
50 target that are affected by the modified files will be rebuilt
51 (not the target itself, which might also cause unaffected dependencies
52 to be rebuilt). An empty list will be treated as if there are no additional
53 targets to build.
dpranke06de67be2015-11-12 22:10:0354 Empty lists for both `test_targets` and `additional_compile_targets`
55 would cause no work to be done, so will result in an error.
56 * `targets`: a legacy field that resembled a union of `compile_targets`
57 and `test_targets`. Support for this field will be removed once the
58 bots have been updated to use compile_targets and test_targets instead.
dprankefe4602312015-04-08 16:20:3559
dprankeee5b51f62015-04-09 00:03:2260The third positional argument is a (normal) path to where mb will write
61the result, also as a JSON object. This object may contain the following
62fields:
dprankefe4602312015-04-08 16:20:3563
64 * `error`: this should only be present if something failed.
dpranke06de67be2015-11-12 22:10:0365 * `compile_targets`: the list of ninja targets that should be passed
66 directly to the corresponding ninja / compile.py invocation. This
67 list may contain entries that are *not* listed in the input (see
Takuto Ikutaf91b4b282024-05-15 08:33:0868 the description of `additional_compile_targets` above and
dpranke06de67be2015-11-12 22:10:0369 [design_spec.md](the design spec) for how this works).
70 * `invalid_targets`: a list of any targets that were passed in
71 either of the input lists that weren't actually found in the graph.
72 * `test_targets`: the subset of the input `test_targets` that are
73 potentially out of date, indicating that the matching test steps
74 should be re-run.
75 * `targets`: a legacy field that indicates the subset of the input `targets`
76 that depend on the input `files`.
77 * `build_targets`: a legacy field that indicates the minimal subset of
78 targets needed to build all of `targets` that were affected.
79 * `status`: a field containing one of three strings:
80
81 * `"Found dependency"` (build the `compile_targets`)
dprankefe4602312015-04-08 16:20:3582 * `"No dependency"` (i.e., no build needed)
dpranke06de67be2015-11-12 22:10:0383 * `"Found dependency (all)"` (`test_targets` is returned as-is;
84 `compile_targets` should contain the union of `test_targets` and
85 `additional_compile_targets`. In this case the targets do not
86 need to be pruned).
87
88See [design_spec.md](the design spec) for more details and examples; the
89differences can be subtle. We won't even go into how the `targets` and
90`build_targets` differ from each other or from `compile_targets` and
91`test_targets`.
dprankefe4602312015-04-08 16:20:3592
Ben Pastene74502492021-01-06 17:07:1593The `-b/--builder`, `-c/--config`, `-f/--config-file`, `--builder-group`,
dprankea5a77ca2015-07-16 23:24:1794`-q/--quiet`, and `-v/--verbose` flags work as documented for `mb gen`.
95
Dirk Prankef24e6b22018-03-27 20:12:3096### mb gen
dprankea5a77ca2015-07-16 23:24:1797
Dirk Pranked181a1a2017-12-14 01:47:1198`mb gen` is responsible for generating the Ninja files by invoking GN with
99the right sets of build args for the given bot. It takes arguments to
100specify a build config and a directory, then runs GN as appropriate:
dprankea5a77ca2015-07-16 23:24:17101
102```
103% mb gen -m tryserver.chromium.linux -b linux_rel //out/Release
104% mb gen -c linux_rel_trybot //out/Release
105```
106
Ben Pastene74502492021-01-06 17:07:15107Either the `-c/--config` flag or the `--builder-group` and `-b/--builder` flags
dprankeb9380a12016-07-21 21:44:09108must be specified so that `mb` can figure out which config to use. The
109`--phase` flag must also be used with builders that have multiple
110build/compile steps (and only with those builders).
dprankea5a77ca2015-07-16 23:24:17111
dprankee0f486f2015-11-19 23:42:00112By default, MB will look for a bot config file under `//ios/build/bots` (see
113[design_spec.md](the design spec) for details of how the bot config files
114work). If no matching one is found, will then look in
115`//tools/mb/mb_config.pyl` to look up the config information, but you can
116specify a custom config file using the `-f/--config-file` flag.
dprankea5a77ca2015-07-16 23:24:17117
118The path must be a GN-style "source-absolute" path (as above).
119
120You can pass the `-n/--dryrun` flag to mb gen to see what will happen without
121actually writing anything.
122
123You can pass the `-q/--quiet` flag to get mb to be silent unless there is an
124error, and pass the `-v/--verbose` flag to get mb to log all of the files
125that are read and written, and all the commands that are run.
126
Dirk Prankef24e6b22018-03-27 20:12:30127### mb help
dprankefe4602312015-04-08 16:20:35128
129Produces help output on the other subcommands
130
Dirk Prankef24e6b22018-03-27 20:12:30131### mb isolate
Dirk Pranke8cb6aa782017-12-16 02:31:33132
133Builds a given (ninja) target and produces an `.isolated` file suitable
134for then running the command either locally in an isolated environment,
135or remotely by uploading it to an isolate server and running it under
136swarming. See below for more information on isolates and swarming.
137
Dirk Prankef24e6b22018-03-27 20:12:30138### mb lookup
dprankefe4602312015-04-08 16:20:35139
140Prints what command will be run by `mb gen` (like `mb gen -n` but does
141not require you to specify a path).
142
Ben Pastene74502492021-01-06 17:07:15143The `-b/--builder`, `-c/--config`, `-f/--config-file`, `--builder-group`,
dprankeb9380a12016-07-21 21:44:09144`--phase`, `-q/--quiet`, and `-v/--verbose` flags work as documented for
145`mb gen`.
dprankea5a77ca2015-07-16 23:24:17146
Dirk Prankef24e6b22018-03-27 20:12:30147### mb run
Dirk Pranke8cb6aa782017-12-16 02:31:33148
149Builds and runs a given (ninja) target. By default the target will
150be run locally but isolated (i.e., outside of the source tree, just
151as it would be run under swarming). If the `-s/--swarming` flag is
152passed, the target will be built, run, uploaded to the isolate server,
153and run under swarming.
154
155By default, a set of dimensions appropriate for running the target in the
156default pool for the build will be provided. You can specify additional
157dimensions with the `-d/--dimension` flags, and you can skip the default
158dimensions with the `--no-default-dimensions` flag (which can be useful
159if you need to run on devices or in a different pool). See below for more
160information on isolates and swarming.
161
162In either case, any flags past `--` will be passed on to the command
163to be run inside the isolate.
164
Dirk Prankef24e6b22018-03-27 20:12:30165### mb validate
dprankefe4602312015-04-08 16:20:35166
167Does internal checking to make sure the config file is syntactically
168valid and that all of the entries are used properly. It does not validate
169that the flags make sense, or that the builder names are legal or
170comprehensive, but it does complain about configs and mixins that aren't
171used.
172
dprankea5a77ca2015-07-16 23:24:17173The `-f/--config-file` and `-q/--quiet` flags work as documented for
174`mb gen`.
175
dprankefe4602312015-04-08 16:20:35176This is mostly useful as a presubmit check and for verifying changes to
177the config file.
178
Dirk Prankef24e6b22018-03-27 20:12:30179### mb zip
180
181Builds and isolates a given (ninja) target like the `isolate` command does,
182and then takes all of the files in the isolate and writes them into a single
183zip file that can then easily be redistributed.
184
dprankea5a77ca2015-07-16 23:24:17185## Isolates and Swarming
186
187`mb gen` is also responsible for generating the `.isolate` and
188`.isolated.gen.json` files needed to run test executables through swarming
Dirk Pranked181a1a2017-12-14 01:47:11189in a GN build.
dprankea5a77ca2015-07-16 23:24:17190
191If you wish to generate the isolate files, pass `mb gen` the
192`--swarming-targets-file` command line argument; that arg should be a path
193to a file containing a list of ninja build targets to compute the runtime
194dependencies for (on Windows, use the ninja target name, not the file, so
195`base_unittests`, not `base_unittests.exe`).
196
197MB will take this file, translate each build target to the matching GN
198label (e.g., `base_unittests` -> `//base:base_unittests`, write that list
199to a file called `runtime_deps` in the build directory, and pass that to
200`gn gen $BUILD ... --runtime-deps-list-file=$BUILD/runtime_deps`.
201
202Once GN has computed the lists of runtime dependencies, MB will then
203look up the command line for each target (currently this is hard-coded
John Palmerab8812a2021-05-21 17:03:43204in [mb.py](https://source.chromium.org/chromium/chromium/src/+/main:tools/mb/mb.py;l=1370)), and write out the
dprankea5a77ca2015-07-16 23:24:17205matching `.isolate` and `.isolated.gen.json` files.
206
Dirk Prankef24e6b22018-03-27 20:12:30207## The mb_config.pyl config file
dprankefe4602312015-04-08 16:20:35208
209The `mb_config.pyl` config file is intended to enumerate all of the
210supported build configurations for Chromium. Generally speaking, you
211should never need to (or want to) build a configuration that isn't
212listed here, and so by using the configs in this file you can avoid
Dirk Pranked181a1a2017-12-14 01:47:11213having to juggle long lists of gn args by hand.
dprankefe4602312015-04-08 16:20:35214
215`mb_config.pyl` is structured as a file containing a single PYthon Literal
Ben Pastene74502492021-01-06 17:07:15216expression: a dictionary with three main keys, `builder_groups`, `configs` and
dprankefe4602312015-04-08 16:20:35217`mixins`.
218
Ben Pastene74502492021-01-06 17:07:15219The `builder_groups` key contains a nested series of dicts containing mappings
220of builder_group -> builder -> config . This allows us to isolate the builder
dprankeb9380a12016-07-21 21:44:09221recipes from the actual details of the configs. The config should either
222be a single string value representing a key in the `configs` dictionary,
223or a list of strings, each of which is a key in the `configs` dictionary;
224the latter case is for builders that do multiple compiles with different
225arguments in a single build, and must *only* be used for such builders
226(where a --phase argument must be supplied in each lookup or gen call).
dprankefe4602312015-04-08 16:20:35227
dprankeb9380a12016-07-21 21:44:09228The `configs` key points to a dictionary of named build configurations.
dprankefe4602312015-04-08 16:20:35229
230There should be an key in this dict for every supported configuration
231of Chromium, meaning every configuration we have a bot for, and every
232configuration commonly used by develpers but that we may not have a bot
233for.
234
235The value of each key is a list of "mixins" that will define what that
236build_config does. Each item in the list must be an entry in the dictionary
237value of the `mixins` key.
238
239Each mixin value is itself a dictionary that contains one or more of the
240following keys:
241
dprankefe4602312015-04-08 16:20:35242 * `gn_args`: a string containing a list of values passed to gn --args.
243 * `mixins`: a list of other mixins that should be included.
dprankefe4602312015-04-08 16:20:35244
245When `mb gen` or `mb analyze` executes, it takes a config name, looks it
246up in the 'configs' dict, and then does a left-to-right expansion of the
Dirk Pranked181a1a2017-12-14 01:47:11247mixins; gn_args values are concatenated.
dprankefe4602312015-04-08 16:20:35248
249For example, if you had:
250
251```
252{
253 'configs`: {
Dirk Pranked181a1a2017-12-14 01:47:11254 'linux_release_trybot': ['gn_release', 'trybot'],
dprankefe4602312015-04-08 16:20:35255 'gn_shared_debug': None,
256 }
257 'mixins': {
258 'bot': {
Takuto Ikutaf91b4b282024-05-15 08:33:08259 'gn_args': 'use_remoteexec=true dcheck_always_on=false',
dprankefe4602312015-04-08 16:20:35260 },
261 'debug': {
262 'gn_args': 'is_debug=true',
263 },
Dirk Pranked181a1a2017-12-14 01:47:11264 'gn_release': {
dprankefe4602312015-04-08 16:20:35265 'mixins': ['release'],
dprankefe4602312015-04-08 16:20:35266 },
267 'release': {
268 'gn_args': 'is_debug=false',
269 }
270 'shared': {
271 'gn_args': 'is_component_build=true',
dprankefe4602312015-04-08 16:20:35272 },
273 'trybot': {
dprankefe4602312015-04-08 16:20:35274 'gn_args': 'dcheck_always_on=true',
275 }
276 }
277}
martinissceaaa712015-10-23 22:45:26278```
dprankefe4602312015-04-08 16:20:35279
280and you ran `mb gen -c linux_release_trybot //out/Release`, it would
Takuto Ikutaf91b4b282024-05-15 08:33:08281translate into a call to `gn --args="use_remoteexec=true dcheck_always_on=false dcheck_always_on=true"`.
dprankefe4602312015-04-08 16:20:35282
283(From that you can see that mb is intentionally dumb and does not
Dirk Pranked181a1a2017-12-14 01:47:11284attempt to de-dup the flags, it lets GN do that).
dprankefe4602312015-04-08 16:20:35285
dprankea5a77ca2015-07-16 23:24:17286## Debugging MB
dprankefe4602312015-04-08 16:20:35287
288By design, MB should be simple enough that very little can go wrong.
289
290The most obvious issue is that you might see different commands being
291run than you expect; running `'mb -v'` will print what it's doing and
292run the commands; `'mb -n'` will print what it will do but *not* run
293the commands.
294
295If you hit weirder things than that, add some print statements to the
296python script, send a question to [email protected], or
297[file a bug](https://crbug.com/new) with the label
298'mb' and cc: [email protected].