1 # The MB (Meta-Build wrapper) user guide
7 `mb` is a simple python wrapper around the GYP and GN meta-build tools to
8 be used as part of the GYP->GN migration.
10 It is intended to be used by bots to make it easier to manage the configuration
11 each bot builds (i.e., the configurations can be changed from chromium
12 commits), and to consolidate the list of all of the various configurations
13 that Chromium is built in.
15 Ideally this tool will no longer be needed after the migration is complete.
17 For more discussion of MB, see also [the design spec](design_spec.md).
23 `mb analyze` is reponsible for determining what targets are affected by
24 a list of files (e.g., the list of files in a patch on a trybot):
27 mb analyze -c chromium_linux_rel //out/Release input.json output.json
30 Either the `-c/--config` flag or the `-m/--master` and `-b/--builder` flags
31 must be specified so that `mb` can figure out which config to use.
33 The first positional argument must be a GN-style "source-absolute" path
34 to the build directory.
36 The second positional argument is a (normal) path to a JSON file containing
37 a single object with two fields:
39 * `files`: an array of the modified filenames to check (as
40 paths relative to the checkout root).
41 * `targets`: an array of the unqualified target names to check.
43 The third positional argument is a (normal) path to where mb will write
44 the result, also as a JSON object. This object may contain the following
47 * `error`: this should only be present if something failed.
48 * `targets`: the subset of the input `targets` that depend on the
50 * `build_targets`: the minimal subset of targets needed to build all
51 of `targets` that were affected.
52 * `status`: one of three strings:
53 * `"Found dependency"` (build the `build_targets`)
54 * `"No dependency"` (i.e., no build needed)
55 * `"Found dependency (all)"` (build everything, in which case
56 `targets` and `build_targets` are not returned).
58 The `-b/--builder`, `-c/--config`, `-f/--config-file`, `-m/--master`,
59 `-q/--quiet`, and `-v/--verbose` flags work as documented for `mb gen`.
64 `mb gen` is responsible for generating the Ninja files by invoking either GYP
65 or GN as appropriate. It takes arguments to specify a build config and
66 a directory, then runs GYP or GN as appropriate:
69 % mb gen -m tryserver.chromium.linux -b linux_rel //out/Release
70 % mb gen -c linux_rel_trybot //out/Release
73 Either the `-c/--config` flag or the `-m/--master` and `-b/--builder` flags
74 must be specified so that `mb` can figure out which config to use.
76 By default, MB will look in `//tools/mb/mb_config.pyl` to look up the config
77 information, but you can specify a custom config file using the
78 `-f/--config-file` flag.
80 The path must be a GN-style "source-absolute" path (as above).
82 You can pass the `-n/--dryrun` flag to mb gen to see what will happen without
83 actually writing anything.
85 You can pass the `-q/--quiet` flag to get mb to be silent unless there is an
86 error, and pass the `-v/--verbose` flag to get mb to log all of the files
87 that are read and written, and all the commands that are run.
89 If the build config will use the Goma distributed-build system, you can pass
90 the path to your Goma client in the `-g/--goma-dir` flag, and it will be
91 incorporated into the appropriate flags for GYP or GN as needed.
93 If gen ends up using GYP, the path must have a valid GYP configuration as the
94 last component of the path (i.e., specify `//out/Release_x64`, not `//out`).
98 Produces help output on the other subcommands
102 Prints what command will be run by `mb gen` (like `mb gen -n` but does
103 not require you to specify a path).
105 The `-b/--builder`, `-c/--config`, `-f/--config-file`, `-m/--master`,
106 `-q/--quiet`, and `-v/--verbose` flags work as documented for `mb gen`.
110 Does internal checking to make sure the config file is syntactically
111 valid and that all of the entries are used properly. It does not validate
112 that the flags make sense, or that the builder names are legal or
113 comprehensive, but it does complain about configs and mixins that aren't
116 The `-f/--config-file` and `-q/--quiet` flags work as documented for
119 This is mostly useful as a presubmit check and for verifying changes to
122 ## Isolates and Swarming
124 `mb gen` is also responsible for generating the `.isolate` and
125 `.isolated.gen.json` files needed to run test executables through swarming
126 in a GN build (in a GYP build, this is done as part of the compile step).
128 If you wish to generate the isolate files, pass `mb gen` the
129 `--swarming-targets-file` command line argument; that arg should be a path
130 to a file containing a list of ninja build targets to compute the runtime
131 dependencies for (on Windows, use the ninja target name, not the file, so
132 `base_unittests`, not `base_unittests.exe`).
134 MB will take this file, translate each build target to the matching GN
135 label (e.g., `base_unittests` -> `//base:base_unittests`, write that list
136 to a file called `runtime_deps` in the build directory, and pass that to
137 `gn gen $BUILD ... --runtime-deps-list-file=$BUILD/runtime_deps`.
139 Once GN has computed the lists of runtime dependencies, MB will then
140 look up the command line for each target (currently this is hard-coded
141 in [mb.py](https://code.google.com/p/chromium/codesearch?q=mb.py#chromium/src/tools/mb/mb.py&q=mb.py%20GetIsolateCommand&sq=package:chromium&type=cs)), and write out the
142 matching `.isolate` and `.isolated.gen.json` files.
144 ## The `mb_config.pyl` config file
146 The `mb_config.pyl` config file is intended to enumerate all of the
147 supported build configurations for Chromium. Generally speaking, you
148 should never need to (or want to) build a configuration that isn't
149 listed here, and so by using the configs in this file you can avoid
150 having to juggle long lists of GYP_DEFINES and gn args by hand.
152 `mb_config.pyl` is structured as a file containing a single PYthon Literal
153 expression: a dictionary with three main keys, `masters`, `configs` and
156 The `masters` key contains a nested series of dicts containing mappings
157 of master -> builder -> config . This allows us to isolate the buildbot
158 recipes from the actual details of the configs.
160 The `configs` key points to a dictionary of named build
163 There should be an key in this dict for every supported configuration
164 of Chromium, meaning every configuration we have a bot for, and every
165 configuration commonly used by develpers but that we may not have a bot
168 The value of each key is a list of "mixins" that will define what that
169 build_config does. Each item in the list must be an entry in the dictionary
170 value of the `mixins` key.
172 Each mixin value is itself a dictionary that contains one or more of the
175 * `gyp_configs`: a list of the configurations to build, e.g.,
176 ['Release', 'Release_x64'].
177 * `gyp_defines`: a string containing a list of GYP_DEFINES.
178 * `gn_args`: a string containing a list of values passed to gn --args.
179 * `mixins`: a list of other mixins that should be included.
180 * `type`: a string with either the value `gyp` or `gn`;
181 setting this indicates which meta-build tool to use.
183 When `mb gen` or `mb analyze` executes, it takes a config name, looks it
184 up in the 'configs' dict, and then does a left-to-right expansion of the
185 mixins; gyp_defines and gn_args values are concatenated, and type and
186 gyp_configs values override each other.
188 For example, if you had:
193 'linux_release_trybot': ['gyp_release', 'trybot'],
194 'gn_shared_debug': None,
198 'gyp_defines': 'use_goma=1 dcheck_always_on=0',
199 'gn_args': 'use_goma=true dcheck_always_on=false',
202 'gn_args': 'is_debug=true',
204 'gn': {'type': 'gn'},
206 'gyp_config': 'Release'
207 'mixins': ['release'],
211 'gn_args': 'is_debug=false',
214 'gn_args': 'is_component_build=true',
215 'gyp_defines': 'component=shared_library',
218 'gyp_defines': 'dcheck_always_on=1',
219 'gn_args': 'dcheck_always_on=true',
224 and you ran `mb gen -c linux_release_trybot //out/Release`, it would
225 translate into a call to `gyp_chromium -G Release` with `GYP_DEFINES` set to
226 `"use_goma=true dcheck_always_on=false dcheck_always_on=true"`.
228 (From that you can see that mb is intentionally dumb and does not
229 attempt to de-dup the flags, it lets gyp do that).
233 By design, MB should be simple enough that very little can go wrong.
235 The most obvious issue is that you might see different commands being
236 run than you expect; running `'mb -v'` will print what it's doing and
237 run the commands; `'mb -n'` will print what it will do but *not* run
240 If you hit weirder things than that, add some print statements to the
241 python script, send a question to gn-dev@chromium.org, or
242 [file a bug](https://crbug.com/new) with the label
243 'mb' and cc: dpranke@chromium.org.