blob: 2d97e0ef14157fbb3551f73705213711bb627e08 [file] [log] [blame]
David Chen8fe82a32016-08-24 10:55:41 +00001---
2layout: documentation
Greg Estrenc0816752020-02-20 13:04:29 -08003title: User manual
David Chen8fe82a32016-08-24 10:55:41 +00004---
Greg Estrenc0816752020-02-20 13:04:29 -08005<h1>Commands and options</h1>
David Chen8fe82a32016-08-24 10:55:41 +00006
Greg Estrenc0816752020-02-20 13:04:29 -08007<h2 id='target-patterns'>Target syntax</h2>
laurentlbadf36072018-11-05 16:20:20 -08008
9Some commands, like <code>build</code> or <code>test</code>, can operate
10on a list of targets. They use a syntax more flexible than labels, which is
Googlerbb6ecd72020-05-28 12:52:28 -070011documented in the "<a href="guide.html#specifying-targets-to-build">Specifying
laurentlbadf36072018-11-05 16:20:20 -080012targets to build</a>" section of the User's Guide.
13
David Chen8fe82a32016-08-24 10:55:41 +000014<h2>Options</h2>
15
16<p>
17 The following sections describe the options available during a
18 build. When <code class='flag'>--long</code> is used on a help command, the on-line
19 help messages provide summary information about the meaning, type and
20 default value for each option.
21</p>
22
23<p>
24 Most options can only be specified once. When specified multiple times, the
25 last instance wins. Options that can be specified multiple times are
26 identified in the on-line help with the text 'may be used multiple times'.
27</p>
28
brandjoncf0390b2020-02-20 10:37:40 -080029<h3>Package location</h3>
David Chen8fe82a32016-08-24 10:55:41 +000030
David Chen8fe82a32016-08-24 10:55:41 +000031<h4 id='flag--package_path'><code class='flag'>--package_path</code></h4>
32<p>
33 This option specifies the set of directories that are searched to
34 find the BUILD file for a given package.
David Chen8fe82a32016-08-24 10:55:41 +000035</p>
36
David Chen8fe82a32016-08-24 10:55:41 +000037<p>
laurentlb15918182018-10-17 11:44:25 -070038 Bazel finds its packages by searching the package path. This is a colon
39 separated ordered list of bazel directories, each being the root of a
40 partial source tree.
David Chen8fe82a32016-08-24 10:55:41 +000041</p>
42
laurentlb15918182018-10-17 11:44:25 -070043<p>
44 <i>To specify a custom package path</i> using the
45 <code class='flag'>--package_path</code> option:
46</p>
47<pre>
48 % bazel build --package_path %workspace%:/some/other/root
49</pre>
50<p>
51Package path elements may be specified in three formats:
52</p>
53<ol>
54 <li>
55 If the first character is <code>/</code>, the path is absolute.
56 </li>
57 <li>
58 If the path starts with <code>%workspace%</code>, the path is taken relative
59 to the nearest enclosing bazel directory.<br>
60 For instance, if your working directory
61 is <code>/home/bob/clients/bob_client/bazel/foo</code>, then the
62 string <code>%workspace%</code> in the package-path is expanded
63 to <code>/home/bob/clients/bob_client/bazel</code>.
64 </li>
65 <li>
66 Anything else is taken relative to the working directory.<br> This is usually not what you mean to do,
67 and may behave unexpectedly if you use Bazel from directories below the bazel workspace.
68 For instance, if you use the package-path element <code>.</code>,
69 and then cd into the directory
70 <code>/home/bob/clients/bob_client/bazel/foo</code>, packages
71 will be resolved from the
72 <code>/home/bob/clients/bob_client/bazel/foo</code> directory.
73 </li>
74</ol>
75<p>
76 If you use a non-default package path, we recommend that you specify
Vladimir Chebotarev66885ff2018-12-04 14:08:16 -080077 it in your <a href='guide.html#bazelrc'>Bazel configuration file</a> for
laurentlb15918182018-10-17 11:44:25 -070078 convenience.
79</p>
80<p>
81 <i>Bazel doesn't require any packages to be in the
82 current directory</i>, so you can do a build from an empty bazel
83 workspace if all the necessary packages can be found somewhere else
84 on the package path.
85</p>
86<p>
87 <i>Example</i>: Building from an empty client
88</p>
89<pre>
90 % mkdir -p foo/bazel
91 % cd foo/bazel
92 % touch WORKSPACE
93 % bazel build --package_path /some/other/path //foo
94</pre>
brandjoncf0390b2020-02-20 10:37:40 -080095<h3 id='checking-options'>Error checking</h3>
David Chen8fe82a32016-08-24 10:55:41 +000096<p>
97 These options control Bazel's error-checking and/or warnings.
98</p>
99
100<h4 id='flag--check_constraint'><code class='flag'>--check_constraint <var>constraint</var></code></h4>
101<p>
102 This option takes an argument that specifies which constraint
103 should be checked.
104</p>
105<p>
106 Bazel performs special checks on each rule that is annotated with the
107 given constraint.
108</p>
109<p>
110 The supported constraints and their checks are as follows:
111</p>
112<ul>
113
114 <li><code>public</code>: Verify that all java_libraries marked with
115 <code>constraints = ['public']</code> only depend on java_libraries
116 that are marked as <code>constraints = ['public']</code> too. If bazel
117 finds a dependency that does not conform to this rule, bazel will issue
118 an error.
119 </li>
120</ul>
121
122<h4 id='flag--check_visibility'><code class='flag'>--[no]check_visibility</code></h4>
123<p>
124 If this option is set to false, visibility checks are demoted to warnings.
125 The default value of this option is true, so that by default, visibility
126 checking is done.
127
128</p>
David Chen8fe82a32016-08-24 10:55:41 +0000129<h4 id='flag--output_filter'><code class='flag'>--output_filter <var>regex</var></code></h4>
130<p>
131 The <code class='flag'>--output_filter</code> option will only show build and compilation
132 warnings for targets that match the regular expression. If a target does not
133 match the given regular expression and its execution succeeds, its standard
ulfjack171314b2017-06-02 09:09:43 +0200134 output and standard error are thrown away.
135</p>
136<p>
137 Here are some typical values for this option:
David Chen8fe82a32016-08-24 10:55:41 +0000138</p>
139<table>
140 <tr>
David Chen8fe82a32016-08-24 10:55:41 +0000141 <td><code class='flag'>--output_filter='^//(first/project|second/project):'</code></td>
142 <td>Show the output for the specified packages.</td>
143 </tr>
144 <tr>
145 <td><code class='flag'>--output_filter='^//((?!(first/bad_project|second/bad_project):).)*$'</code></td>
146 <td>Don't show output for the specified packages.</td>
147 </tr>
148 <tr>
ulfjack171314b2017-06-02 09:09:43 +0200149 <td><code class='flag'>--output_filter=</code></td>
Googler4da2f162017-07-17 21:36:56 +0200150 <td>Show everything.
ulfjack171314b2017-06-02 09:09:43 +0200151 </td>
152 </tr>
153 <tr>
David Chen8fe82a32016-08-24 10:55:41 +0000154 <td><code class='flag'>--output_filter=DONT_MATCH_ANYTHING</code></td>
ulfjack171314b2017-06-02 09:09:43 +0200155 <td>Show nothing.
156 </td>
David Chen8fe82a32016-08-24 10:55:41 +0000157 </tr>
158</table>
159
brandjoncf0390b2020-02-20 10:37:40 -0800160<h3 id='flags-options'>Tool flags</h3>
David Chen8fe82a32016-08-24 10:55:41 +0000161<p>
162 These options control which options Bazel will pass to other tools.
163</p>
164
Googler9cfa4cb2018-06-04 22:19:11 -0700165<h4 id='flag--copt'><code class='flag'>--copt <var>cc-option</var></code></h4>
David Chen8fe82a32016-08-24 10:55:41 +0000166<p>
Googler9cfa4cb2018-06-04 22:19:11 -0700167 This option takes an argument which is to be passed to the compiler.
168 The argument will be passed to the compiler whenever it is invoked
David Chen8fe82a32016-08-24 10:55:41 +0000169 for preprocessing, compiling, and/or assembling C, C++, or
170 assembler code. It will not be passed when linking.
171</p>
172<p>
173 This option can be used multiple times.
174 For example:
175</p>
176<pre>
177 % bazel build --copt="-g0" --copt="-fpic" //foo
178</pre>
179<p>
180 will compile the <code>foo</code> library without debug tables, generating
181 position-independent code.
182</p>
183<p>
184 Note that changing <code class='flag'>--copt</code> settings will force a recompilation
185 of all affected object files. Also note that copts values listed in specific
Googler9cfa4cb2018-06-04 22:19:11 -0700186 cc_library or cc_binary build rules will be placed on the compiler command line
David Chen8fe82a32016-08-24 10:55:41 +0000187 <em>after</em> these options.
188</p>
189<p>
190 Warning: C++-specific options (such as <code>-fno-implicit-templates</code>)
191 should be specified in <code class='flag'>--cxxopt</code>, not in
192 <code class='flag'>--copt</code>. Likewise, C-specific options (such as -Wstrict-prototypes)
193 should be specified in <code class='flag'>--conlyopt</code>, not in <code>copt</code>.
Googler9cfa4cb2018-06-04 22:19:11 -0700194 Similarly, compiler options that only have an
David Chen8fe82a32016-08-24 10:55:41 +0000195 effect at link time (such as <code>-l</code>) should be specified in
196 <code class='flag'>--linkopt</code>, not in <code class='flag'>--copt</code>.
197</p>
198
Googler9cfa4cb2018-06-04 22:19:11 -0700199<h4 id='flag--host_copt'><code class='flag'>--host_copt <var>cc-option</var></code></h4>
David Chen8fe82a32016-08-24 10:55:41 +0000200<p>
Googler9cfa4cb2018-06-04 22:19:11 -0700201 This option takes an argument which is to be passed to the compiler for source files
David Chen8fe82a32016-08-24 10:55:41 +0000202 that are compiled in the host configuration. This is analogous to
203 the <a href='#flag--copt'><code class='flag'>--copt</code></a> option, but applies only to the
204 host configuration.
205</p>
206
Googler9cfa4cb2018-06-04 22:19:11 -0700207<h4 id='flag--host_cxxopt'><code class='flag'>--host_cxxopt <var>cc-option</var></code></h4>
Marcel Hlopko4c1b1fd2017-02-24 12:54:17 +0000208<p>
Googler9cfa4cb2018-06-04 22:19:11 -0700209 This option takes an argument which is to be passed to the compiler for C++ source files
Marcel Hlopko4c1b1fd2017-02-24 12:54:17 +0000210 that are compiled in the host configuration. This is analogous to
211 the <a href='#flag--cxxopt'><code class='flag'>--cxxopt</code></a> option, but applies only to the
212 host configuration.
213</p>
214
Googler9cfa4cb2018-06-04 22:19:11 -0700215<h4 id='flag--conlyopt'><code class='flag'>--conlyopt <var>cc-option</var></code></h4>
David Chen8fe82a32016-08-24 10:55:41 +0000216<p>
Googler9cfa4cb2018-06-04 22:19:11 -0700217 This option takes an argument which is to be passed to the compiler when compiling C source files.
David Chen8fe82a32016-08-24 10:55:41 +0000218</p>
219<p>
220 This is similar to <code class='flag'>--copt</code>, but only applies to C compilation,
221 not to C++ compilation or linking. So you can pass C-specific options
222 (such as <code>-Wno-pointer-sign</code>) using <code class='flag'>--conlyopt</code>.
223</p>
224<p>
225 Note that copts parameters listed in specific cc_library or cc_binary build rules
Googler9cfa4cb2018-06-04 22:19:11 -0700226 will be placed on the compiler command line <em>after</em> these options.
David Chen8fe82a32016-08-24 10:55:41 +0000227</p>
228
Googler9cfa4cb2018-06-04 22:19:11 -0700229<h4 id='flag--cxxopt'><code class='flag'>--cxxopt <var>cc-option</var></code></h4>
David Chen8fe82a32016-08-24 10:55:41 +0000230<p>
Googler9cfa4cb2018-06-04 22:19:11 -0700231 This option takes an argument which is to be passed to the compiler when compiling C++ source
232 files.
David Chen8fe82a32016-08-24 10:55:41 +0000233</p>
234<p>
235 This is similar to <code class='flag'>--copt</code>, but only applies to C++ compilation,
236 not to C compilation or linking. So you can pass C++-specific options
237 (such as <code>-fpermissive</code> or <code>-fno-implicit-templates</code>) using <code class='flag'>--cxxopt</code>.
238 For example:
239</p>
240<pre>
241 % bazel build --cxxopt="-fpermissive" --cxxopt="-Wno-error" //foo/cruddy_code
242</pre>
243<p>
244 Note that copts parameters listed in specific cc_library or cc_binary build rules
Googler9cfa4cb2018-06-04 22:19:11 -0700245 will be placed on the compiler command line <em>after</em> these options.
David Chen8fe82a32016-08-24 10:55:41 +0000246</p>
247
248<h4 id='flag--linkopt'><code class='flag'>--linkopt <var>linker-option</var></code></h4>
249<p>
Googler9cfa4cb2018-06-04 22:19:11 -0700250 This option takes an argument which is to be passed to the compiler when linking.
David Chen8fe82a32016-08-24 10:55:41 +0000251</p>
252<p>
253 This is similar to <code class='flag'>--copt</code>, but only applies to linking,
Googler9cfa4cb2018-06-04 22:19:11 -0700254 not to compilation. So you can pass compiler options that only make sense
David Chen8fe82a32016-08-24 10:55:41 +0000255 at link time (such as <code>-lssp</code> or <code>-Wl,--wrap,abort</code>)
256 using <code class='flag'>--linkopt</code>. For example:
257</p>
258<pre>
259 % bazel build --copt="-fmudflap" --linkopt="-lmudflap" //foo/buggy_code
260</pre>
261<p>
262 Build rules can also specify link options in their attributes. This option's
263 settings always take precedence. Also see
264 <a href="be/c-cpp.html#cc_library.linkopts">cc_library.linkopts</a>.
265</p>
266
267<h4 id='flag--strip'><code class='flag'>--strip (always|never|sometimes)</code></h4>
268<p>
269 This option determines whether Bazel will strip debugging information from
270 all binaries and shared libraries, by invoking the linker with the <code>-Wl,--strip-debug</code> option.
271 <code class='flag'>--strip=always</code> means always strip debugging information.
272 <code class='flag'>--strip=never</code> means never strip debugging information.
Googler77e5b922019-10-23 12:09:20 -0700273 The default value of <code class='flag'>--strip=sometimes</code> means strip if the <code class='flag'>--compilation_mode</code>
David Chen8fe82a32016-08-24 10:55:41 +0000274 is <code>fastbuild</code>.
275</p>
276<pre>
277 % bazel build --strip=always //foo:bar
278</pre>
279<p>
280 will compile the target while stripping debugging information from all generated
281 binaries.
282</p>
283<p>
284 Note that if you want debugging information, it's not enough to disable stripping; you also need to make
285 sure that the debugging information was generated by the compiler, which you can do by using either
286 <code>-c dbg</code> or <code class='flag'>--copt -g</code>.
287</p>
288<p>
289 Note also that Bazel's <code class='flag'>--strip</code> option corresponds with ld's <code>--strip-debug</code> option:
290 it only strips debugging information. If for some reason you want to strip <em>all</em> symbols,
291 not just <em>debug</em> symbols, you would need to use ld's <code>--strip-all</code> option,
Googler87598722020-06-10 08:54:40 -0700292 which you can do by passing <code class='flag'>--linkopt=-Wl,--strip-all</code> to Bazel. Also be
293 aware that setting Bazel's <code class='flag'>--strip</code> flag will override
294 <code class='flag'>--linkopt=-Wl,--strip-all</code>, so you should only set one or the other.
David Chen8fe82a32016-08-24 10:55:41 +0000295</p>
296
297<h4 id='flag--stripopt'><code class='flag'>--stripopt <var>strip-option</var></code></h4>
298<p>
299 An additional option to pass to the <code>strip</code> command when generating
300 a <a href="be/c-cpp.html#cc_binary_implicit_outputs"><code>*.stripped</code>
301 binary</a>. The default is <code>-S -p</code>. This option can be used
302 multiple times.
303</p>
304<p>
305 Note that <code class='flag'>--stripopt</code> does not apply to the stripping of the main
306 binary with <code><a href='#flag--strip'>--strip</a>=(always|sometimes)</code>.
307</p>
308
309<h4 id='flag--fdo_instrument'><code class='flag'>--fdo_instrument <var>profile-output-dir</var></code></h4>
310<p>
311 The <code class='flag'>--fdo_instrument</code> option enables the generation of
312 FDO (feedback directed optimization) profile output when the
313 built C/C++ binary is executed. For GCC, the argument provided is used as a
314 directory prefix for a per-object file directory tree of .gcda files
315 containing profile information for each .o file.
316</p>
317<p>
318 Once the profile data tree has been generated, the profile tree
319 should be zipped up, and provided to the
320 <code class='flag'>--fdo_optimize=<var>profile-zip</var></code>
Googler66663572020-11-09 09:58:27 -0800321 Bazel option to enable the FDO-optimized compilation.
David Chen8fe82a32016-08-24 10:55:41 +0000322
323</p>
324<p>
325 For the LLVM compiler the argument is also the directory under which the raw LLVM profile
326 data file(s) is dumped, e.g.
327 <code class='flag'>--fdo_instrument=<var>/path/to/rawprof/dir/</var></code>.
328</p>
329<p>
330 The options <code class='flag'>--fdo_instrument</code> and <code class='flag'>--fdo_optimize</code>
331 cannot be used at the same time.
332</p>
333
Googler66663572020-11-09 09:58:27 -0800334
David Chen8fe82a32016-08-24 10:55:41 +0000335<h4 id='flag--fdo_optimize'><code class='flag'>--fdo_optimize <var>profile-zip</var></code></h4>
336<p>
337 The <code class='flag'>--fdo_optimize</code> option enables the use of the
338 per-object file profile information to perform FDO (feedback
339 directed optimization) optimizations when compiling. For GCC, the argument
340 provided is the zip file containing the previously-generated file tree
341 of .gcda files containing profile information for each .o file.
342</p>
343<p>
344 Alternatively, the argument provided can point to an auto profile
345 identified by the extension .afdo.
346
347</p>
348<p>
349 Note that this option also accepts labels that resolve to source files. You
350 may need to add an <code>exports_files</code> directive to the corresponding package to
351 make the file visible to Bazel.
352</p>
353<p>
354 For the LLVM compiler the argument provided should point to the indexed LLVM
355 profile output file prepared by the llvm-profdata tool, and should have a .profdata
356 extension.
357</p>
358<p>
359 The options <code class='flag'>--fdo_instrument</code> and <code class='flag'>
360 --fdo_optimize</code> cannot be used at the same time.
361</p>
362
David Chen8fe82a32016-08-24 10:55:41 +0000363
364<h4 id='flag--output_symbol_counts'><code class='flag'>--[no]output_symbol_counts</code></h4>
365<p>
Googlerd7273272017-05-02 18:56:29 +0200366 If enabled, each gold-invoked link of a C++ executable binary will output
David Chen8fe82a32016-08-24 10:55:41 +0000367 a <i>symbol counts</i> file (via the <code>--print-symbol-counts</code> gold
Googlerd7273272017-05-02 18:56:29 +0200368 option). For each linker input, the file logs the number of symbols that were
369 defined and the number of symbols that were used in the binary.
370 This information can be used to track unnecessary link dependencies.
371 The symbol counts file is written to the binary's output path with the name
David Chen8fe82a32016-08-24 10:55:41 +0000372 <code>[targetname].sc</code>.
373</p>
374<p>
375 This option is disabled by default.
376</p>
377
378<h4 id='flag--jvmopt'><code class='flag'>--jvmopt <var>jvm-option</var></code></h4>
379<p>
380 This option allows option arguments to be passed to the Java VM. It can be used
381 with one big argument, or multiple times with individual arguments. For example:
382</p>
383<pre>
384 % bazel build --jvmopt="-server -Xms256m" java/com/example/common/foo:all
385</pre>
386<p>
387 will use the server VM for launching all Java binaries and set the
388 startup heap size for the VM to 256 MB.
389</p>
390
391<h4 id='flag--javacopt'><code class='flag'>--javacopt <var>javac-option</var></code></h4>
392<p>
393 This option allows option arguments to be passed to javac. It can be used
394 with one big argument, or multiple times with individual arguments. For example:
395</p>
396<pre>
397 % bazel build --javacopt="-g:source,lines" //myprojects:prog
398</pre>
399<p>
400 will rebuild a java_binary with the javac default debug info
401 (instead of the bazel default).
402</p>
403<p>
404 The option is passed to javac after the Bazel built-in default options for
405 javac and before the per-rule options. The last specification of
406 any option to javac wins. The default options for javac are:
407</p>
408
409<pre>
410 -source 8 -target 8 -encoding UTF-8
411</pre>
412<p>
413 Note that changing <code class='flag'>--javacopt</code> settings will force a recompilation
414 of all affected classes. Also note that javacopts parameters listed in
415 specific java_library or java_binary build rules will be placed on the javac
416 command line <em>after</em> these options.
417</p>
418
419<h5 id='-extra_checks'><code>-extra_checks[:(off|on)]</code></h5>
420
421<p>
422 This javac option enables extra correctness checks. Any problems found will
423 be presented as errors.
424 Either <code>-extra_checks</code> or <code>-extra_checks:on</code> may be used
425 to force the checks to be turned on. <code>-extra_checks:off</code> completely
426 disables the analysis.
427 When this option is not specified, the default behavior is used.
428</p>
429
430<h4 id='flag--strict_java_deps'><code class='flag'>--strict_java_deps
431 (default|strict|off|warn|error)</code></h4>
432<p>
433 This option controls whether javac checks for missing direct dependencies.
434 Java targets must explicitly declare all directly used targets as
435 dependencies. This flag instructs javac to determine the jars actually used
436 for type checking each java file, and warn/error if they are not the output
437 of a direct dependency of the current target.
438</p>
439
440<ul>
441 <li> <code>off</code> means checking is disabled.
442 </li>
443 <li> <code>warn</code> means javac will generate standard java warnings of
444 type <code>[strict]</code> for each missing direct dependency.
445 </li>
446 <li> <code>default</code>, <code>strict</code> and <code>error</code> all
447 mean javac will generate errors instead of warnings, causing the current
448 target to fail to build if any missing direct dependencies are found.
449 This is also the default behavior when the flag is unspecified.
450 </li>
451</ul>
452
brandjoncf0390b2020-02-20 10:37:40 -0800453<h3 id='semantics-options'>Build semantics</h3>
David Chen8fe82a32016-08-24 10:55:41 +0000454<p>
455 These options affect the build commands and/or the output file contents.
456</p>
457
458<h4 id='flag--compilation_mode'><code class='flag'>--compilation_mode (fastbuild|opt|dbg)</code> (-c)</h4>
459<p>
Googlerd96e8db2020-07-09 20:38:37 -0700460 The <code class="flag">--compilation_mode</code> option (often shortened to <code>-c</code>,
461 especially <code>-c opt</code>) takes an argument of <code>fastbuild</code>, <code>dbg</code>
David Chen8fe82a32016-08-24 10:55:41 +0000462 or <code>opt</code>, and affects various C/C++ code-generation
463 options, such as the level of optimization and the completeness of
464 debug tables. Bazel uses a different output directory for each
465 different compilation mode, so you can switch between modes without
466 needing to do a full rebuild <i>every</i> time.
467</p>
468<ul>
469 <li> <code>fastbuild</code> means build as fast as possible:
470 generate minimal debugging information (<code>-gmlt
471 -Wl,-S</code>), and don't optimize. This is the
472 default. Note: <code>-DNDEBUG</code> will <b>not</b> be set.
473 </li>
474 <li> <code>dbg</code> means build with debugging enabled (<code>-g</code>),
475 so that you can use gdb (or another debugger).
476 </li>
477 <li> <code>opt</code> means build with optimization enabled and
478 with <code>assert()</code> calls disabled (<code>-O2 -DNDEBUG</code>).
479 Debugging information will not be generated in <code>opt</code> mode
480 unless you also pass <code class='flag'>--copt -g</code>.
481 </li>
482</ul>
483
484<h4 id='flag--cpu'><code class='flag'>--cpu <var>cpu</var></code></h4>
485<p>
486This option specifies the target CPU architecture to be used for
487the compilation of binaries during the build.
488</p>
489<p>
490
491</p>
Googlerf12e8022018-09-11 07:51:31 -0700492<p>
493 Note that a particular combination of crosstool version, compiler version,
494 and target CPU is allowed only if it has been specified in the currently
495 used CROSSTOOL file.
496</p>
497
jingwen38b1fee2020-05-11 09:19:25 -0700498<h4 id='flag--action_env'>
499 <code class='flag'>--action_env=<var>VAR=VALUE</var></code>
500</h4>
501<p>
502 Specifies the set of environment variables available during the execution of all actions.
503 Variables can be either specified by name, in which case the value will be taken from the
504 invocation environment, or by the `name=value` pair which sets the value independent of the
505 invocation environment.
506
507 This `--action_env` flag can be specified multiple times. If a value is assigned to the same
508 variable across multiple `--action_env` flags, the latest assignment wins.
509</p>
David Chen8fe82a32016-08-24 10:55:41 +0000510
Benjamin Peterson0b318542017-12-04 10:46:48 -0800511<h4 id='flag--experimental_action_listener'>
512 <code class='flag'>--experimental_action_listener=<var>label</var></code>
513</h4>
514<p>
515 The <code>experimental_action_listener</code> option instructs Bazel to use
516 details from the <a href="be/extra-actions.html#action_listener"
517 ><code>action_listener</code></a> rule specified by <var>label</var> to
518 insert <a href="be/extra-actions.html#extra_action"
519 ><code>extra_actions</code></a> into the build graph.
520</p>
521
522<h4 id='flag--experimental_extra_action_top_level_only'>
523 <code class='flag'>--[no]experimental_extra_action_top_level_only</code>
524</h4>
525<p>
526 If this option is set to true, extra actions specified by the
527 <a href='#flag--experimental_action_listener'> <code>
528 --experimental_action_listener</code></a> command line option will only be
529 scheduled for top level targets.
530</p>
531
532<h4 id='flag--experimental_extra_action_filter'>
533 <code class='flag'>--experimental_extra_action_filter=<var>regex</var></code>
534</h4>
535<p>
536 The <code>experimental_extra_action_filter</code> option instructs Bazel to
537 filter the set of targets to schedule <code>extra_actions</code> for.
538</p>
539<p>
540 This flag is only applicable in combination with the
541 <a href='#flag--experimental_action_listener'
542 ><code>--experimental_action_listener</code></a> flag.
543</p>
544<p>
545 By default all <code>extra_actions</code> in the transitive closure of the
546 requested targets-to-build get scheduled for execution.
547 <code>--experimental_extra_action_filter</code> will restrict scheduling to
548 <code>extra_actions</code> of which the owner's label matches the specified
549 regular expression.
550</p>
551<p>
552 The following example will limit scheduling of <code>extra_actions</code>
553 to only apply to actions of which the owner's label contains '/bar/':
554</p>
555<pre>% bazel build --experimental_action_listener=//test:al //foo/... \
556 --experimental_extra_action_filter=.*/bar/.*
557</pre>
558
David Chen8fe82a32016-08-24 10:55:41 +0000559<h4 id='flag--host_cpu'><code class='flag'>--host_cpu <var>cpu</var></code></h4>
560<p>
561 This option specifies the name of the CPU architecture that should be
562 used to build host tools.
563</p>
564
Alex Humesky105e6612017-01-06 19:03:10 +0000565<h4 id='flag--fat_apk_cpu'><code class='flag'>--fat_apk_cpu <var>cpu[,cpu]*</var></code></h4>
566<p>
567 The CPUs to build C/C++ libraries for in the transitive <code>deps</code> of
568 <code>android_binary</code>
569
570 rules. Other C/C++ rules are not affected. For example, if a <code>cc_library</code>
571 appears in the transitive <code>deps</code> of an <code>android_binary</code> rule and a
572 <code>cc_binary</code> rule, the <code>cc_library</code> will be built at least twice:
573 once for each CPU specified with <code class='flag'>--fat_apk_cpu</code> for the
574 <code>android_binary</code> rule, and once for the CPU specified with
575 <code class='flag'>--cpu</code> for the <code>cc_binary</code> rule.
576
577<p>
578The default is <code>armeabi-v7a</code>.
579</p>
580 <p>
581 One <code>.so</code> file will be created and packaged in the APK for
582 each CPU specified with <code class='flag'>--fat_apk_cpu</code>. The name of the <code>.so</code>
583 file will be the name of the <code>android_binary</code> rule prefixed with "lib", e.g., if the name
584 of the <code>android_binary</code> is "foo", then the file will be <code>libfoo.so</code>.
585 </p>
586
587 <p>
588 Note that an Android-compatible crosstool must be selected.
589 If an <code>android_ndk_repository</code> rule is defined in the
590 WORKSPACE file, an Android-compatible crosstool is automatically selected.
591 Otherwise, the crostool can be selected using the
592 <a href='#flag--android_crosstool_top'><code class='flag'>--android_crosstool_top</code></a>
593 or <a href='#flag--crosstool_top'><code class='flag'>--crosstool_top</code></a> flags.
594 </p>
595</p>
596
David Chen8fe82a32016-08-24 10:55:41 +0000597<h4 id='flag--per_file_copt'><code class='flag'>--per_file_copt
598 <var>[+-]regex[,[+-]regex]...@option[,option]...</var></code></h4>
599<p>
600 When present, any C++ file with a label or an execution path matching one of the inclusion regex
601 expressions and not matching any of the exclusion expressions will be built
602 with the given options. The label matching uses the canonical form of the label
603 (i.e //<code>package</code>:<code>label_name</code>).
604
605 The execution path is the relative path to your workspace directory including the base name
606 (including extension) of the C++ file. It also includes any platform dependent prefixes.
607 Note, that if only one of the label or the execution path matches the options will be used.
608</p>
609<p>
610 <b>Notes</b>:
611 To match the generated files (e.g. genrule outputs)
612 Bazel can only use the execution path. In this case the regexp shouldn't start with '//'
613 since that doesn't match any execution paths. Package names can be used like this:
614 <code class='flag'>--per_file_copt=base/.*\.pb\.cc@-g0</code>. This will match every
615 <code>.pb.cc</code> file under a directory called <code>base</code>.
616</p>
617<p>
618 This option can be used multiple times.
619</p>
620<p>
621 The option is applied regardless of the compilation mode used. I.e. it is possible
622 to compile with <code class='flag'>--compilation_mode=opt</code> and selectively compile some
623 files with stronger optimization turned on, or with optimization disabled.
624</p>
625<p>
626 <b>Caveat</b>: If some files are selectively compiled with debug symbols the symbols
627 might be stripped during linking. This can be prevented by setting
628 <code class='flag'>--strip=never</code>.
629</p>
630<p>
631 <b>Syntax</b>: <code>[+-]regex[,[+-]regex]...@option[,option]...</code> Where
632 <code>regex</code> stands for a regular expression that can be prefixed with
633 a <code>+</code> to identify include patterns and with <code>-</code> to identify
634 exclude patterns. <code>option</code> stands for an arbitrary option that is passed
635 to the C++ compiler. If an option contains a <code>,</code> it has to be quoted like so
636 <code>\,</code>. Options can also contain <code>@</code>, since only the first
637 <code>@</code> is used to separate regular expressions from options.
638</p>
639<p>
640 <b>Example</b>:
641 <code class='flag'>--per_file_copt=//foo:.*\.cc,-//foo:file\.cc@-O0,-fprofile-arcs</code>
642 adds the <code>-O0</code> and the <code>-fprofile-arcs</code> options to the command
643 line of the C++ compiler for all <code>.cc</code> files in <code>//foo/</code> except
644 <code>file.cc</code>.
645</p>
646<h4 id='flag--dynamic_mode'><code class='flag'>--dynamic_mode <var>mode</var></code></h4>
647<p>
648 Determines whether C++ binaries will be linked dynamically, interacting with
649 the <a href='be/c-cpp.html#cc_binary.linkstatic'>linkstatic
650 attribute</a> on build rules.
651</p>
652
653<p>
654 Modes:
655</p>
656<ul>
657 <li><code>auto</code>: Translates to a platform-dependent mode;
658 <code>default</code> for linux and <code>off</code> for cygwin.</li>
659 <li><code>default</code>: Allows bazel to choose whether to link dynamically.
660 See <a href='be/c-cpp.html#cc_binary.linkstatic'>linkstatic</a> for more
661 information.</li>
662 <li><code>fully</code>: Links all targets dynamically. This will speed up
663 linking time, and reduce the size of the resulting binaries.
664
665 </li>
666 <li><code>off</code>: Links all targets in
667 <a href='be/c-cpp.html#cc_binary.linkstatic'>mostly static</a> mode.
668 If <code>-static</code> is set in linkopts, targets will change to fully
669 static.</li>
670</ul>
671
672<h4 id='flag--fission'><code class='flag'>--fission (yes|no|[dbg][,opt][,fastbuild])</code></h4>
673<p>
674 Enables
675
676 <a href='https://gcc.gnu.org/wiki/DebugFission'>Fission</a>,
677 which writes C++ debug information to dedicated .dwo files instead of .o files, where it would
678 otherwise go. This substantially reduces the input size to links and can reduce link times.
679
680</p>
681<p>
682 When set to <code class='flag'>[dbg][,opt][,fastbuild]</code> (example:
683 <code class='flag'>--fission=dbg,fastbuild</code>), Fission is enabled
684 only for the specified set of compilation modes. This is useful for bazelrc
685 settings. When set to <code class='flag'>yes</code>, Fission is enabled
686 universally. When set to <code class='flag'>no</code>, Fission is disabled
687 universally. Default is <code class='flag'>dbg</code>.
688</p>
689
690<h4 id='flag--force_ignore_dash_static'><code class='flag'>--force_ignore_dash_static</code></h4>
691<p>
692 If this flag is set, any <code>-static</code> options in linkopts of
693 <code>cc_*</code> rules BUILD files are ignored. This is only intended as a
694 workaround for C++ hardening builds.
695</p>
696
697<h4 id='flag--force_pic'><code class='flag'>--[no]force_pic</code></h4>
698<p>
699 If enabled, all C++ compilations produce position-independent code ("-fPIC"),
700 links prefer PIC pre-built libraries over non-PIC libraries, and links produce
701 position-independent executables ("-pie"). Default is disabled.
702</p>
703<p>
704 Note that dynamically linked binaries (i.e. <code>--dynamic_mode fully</code>)
705 generate PIC code regardless of this flag's setting. So this flag is for cases
706 where users want PIC code explicitly generated for static links.
707</p>
708
Andrew Pellegrini8d2c1662017-01-26 16:04:12 +0000709<h4 id='flag--android_resource_shrinking'><code class='flag'>--android_resource_shrinking</code></h4>
710<p>
711 Selects whether to perform resource shrinking for android_binary rules. Sets the default for the
712 <a href='be/android.html#android_binary.shrink_resources'>shrink_resources attribute</a> on
713 android_binary rules; see the documentation for that rule for further details. Defaults to off.
714</p>
715
David Chen8fe82a32016-08-24 10:55:41 +0000716<h4 id='flag--custom_malloc'><code class='flag'>--custom_malloc <var>malloc-library-target</var></code></h4>
717<p>
718 When specified, always use the given malloc implementation, overriding all
719 <code>malloc="target"</code> attributes, including in those targets that use the
720 default (by not specifying any <code>malloc</code>).
721</p>
722
723<h4 id='flag--crosstool_top'><code class='flag'>--crosstool_top <var>label</var></code></h4>
724<p>
725 This option specifies the location of the crosstool compiler suite
726 to be used for all C++ compilation during a build. Bazel will look in that
727 location for a CROSSTOOL file and uses that to automatically determine
728 settings for
729
730 <code class='flag'>--compiler</code>.
731</p>
732
733<h4 id='flag--host_crosstool_top'><code class='flag'>--host_crosstool_top <var>label</var></code></h4>
734<p>
735 If not specified, bazel uses the value of <code class='flag'>--crosstool_top</code> to compile
736 code in the host configuration, i.e., tools run during the build. The main purpose of this flag
737 is to enable cross-compilation.
738</p>
739
Cal Peyserf1a15c02017-01-17 20:26:00 +0000740<h4 id='flag--apple_crosstool_top'><code class='flag'>--apple_crosstool_top <var>label</var></code></h4>
741<p>
742 The crosstool to use for compiling C/C++ rules in the transitive <code>deps</code> of
743 objc_*, ios__*, and apple_* rules. For those targets, this flag overwrites
744 <code class='flag'>--crosstool_top</code>.
745</p>
746
Alex Humesky105e6612017-01-06 19:03:10 +0000747<h4 id='flag--android_crosstool_top'><code class='flag'>--android_crosstool_top <var>label</var></code></h4>
748<p>
749 The crosstool to use for compiling C/C++ rules in the transitive <code>deps</code> of
750 <code>android_binary</code> rules. This is useful if other targets in the
751 build require a different crosstool. The default is to use the crosstool
752 generated by the <code>android_ndk_repository</code> rule in the WORKSPACE file.
753 See also <a href='#flag--fat_apk_cpu'><code class='flag'>--fat_apk_cpu</code></a>.
754</p>
David Chen8fe82a32016-08-24 10:55:41 +0000755<h4 id='flag--compiler'><code class='flag'>--compiler <var>version</var></code></h4>
756<p>
757 This option specifies the C/C++ compiler version (e.g. <code>gcc-4.1.0</code>)
758 to be used for the compilation of binaries during the build. If you want to
759 build with a custom crosstool, you should use a CROSSTOOL file instead of
760 specifying this flag.
761</p>
762<p>
763 Note that only certain combinations of crosstool version, compiler version,
rosica25ae1992018-06-04 10:41:53 -0700764 and target CPU are allowed.
David Chen8fe82a32016-08-24 10:55:41 +0000765</p>
766
Alex Humesky105e6612017-01-06 19:03:10 +0000767<h4 id='flag--android_sdk'><code class='flag'>--android_sdk <var>label</var></code></h4>
768<p>
769 This option specifies the Android SDK/platform toolchain
770 and Android runtime library that will be used to build any Android-related
771 rule.
772
773 The Android SDK will be automatically selected if an <code>android_sdk_repository</code>
774 rule is defined in the WORKSPACE file.
775</p>
776
David Chen8fe82a32016-08-24 10:55:41 +0000777<h4 id='flag--java_toolchain'><code class='flag'>--java_toolchain <var>label</var></code></h4>
778<p>
779 This option specifies the label of the java_toolchain used to compile Java
780 source files.
781</p>
782
cushon41375ac42017-10-30 17:03:18 -0400783<h4 id='flag--host_java_toolchain'><code class='flag'>--host_java_toolchain <var>label</var></code></h4>
784<p>
785 If not specified, bazel uses the value of <code class='flag'>--java_toolchain</code> to compile
786 code in the host configuration, i.e., tools run during the build. The main purpose of this flag
787 is to enable cross-compilation.
788</p>
789
Gregg Donovanfb915e82018-02-20 09:10:21 -0800790<h4 id='flag--javabase'><code class='flag'>--javabase (<var>label</var>)</code></h4>
David Chen8fe82a32016-08-24 10:55:41 +0000791<p>
cushon7d9596c2018-07-23 13:55:14 -0700792 This option sets the <i>label</i> of the base Java installation to use for <i>bazel run</i>,
793 <i>bazel test</i>, and for Java binaries built by <code>java_binary</code> and
794 <code>java_test</code> rules. The <code>JAVABASE</code> and <code>JAVA</code>
795 <a href='be/make-variables.html'>"Make" variables</a> are derived from this option.
David Chen8fe82a32016-08-24 10:55:41 +0000796</p>
797
cushon41375ac42017-10-30 17:03:18 -0400798<h4 id='flag--host_javabase'><code class='flag'>--host_javabase <var>label</var></code></h4>
799<p>
cushon2a8b6572018-07-25 10:33:40 -0700800 This option sets the <i>label</i> of the base Java installation to use in the host configuration,
cushon7d9596c2018-07-23 13:55:14 -0700801 for example for host build tools including JavaBuilder and Singlejar.
cushon41375ac42017-10-30 17:03:18 -0400802</p>
David Chen8fe82a32016-08-24 10:55:41 +0000803<p>
804 This does not select the Java compiler that is used to compile Java
805 source files. The compiler can be selected by settings the
806 <a href="#flag--java_toolchain"><code class='flag'>--java_toolchain</code></a>
807 option.
808</p>
809
brandjoncf0390b2020-02-20 10:37:40 -0800810<h3 id='strategy-options'>Execution strategy</h3>
David Chen8fe82a32016-08-24 10:55:41 +0000811<p>
812 These options affect how Bazel will execute the build.
813 They should not have any significant effect on the output files
814 generated by the build. Typically their main effect is on the
815 speed on the build.
816</p>
817
818<h4 id='flag--spawn_strategy'><code class='flag'>--spawn_strategy <var>strategy</var></code></h4>
819<p>
820 This option controls where and how commands are executed.
821</p>
822<ul>
823
824 <li>
ulfjacka42d1892019-02-12 08:34:30 -0800825 <code>standalone</code> causes commands to be executed as local subprocesses. This value is
826 deprecated. Please use <code>local</code> instead.
David Chen8fe82a32016-08-24 10:55:41 +0000827 </li>
828 <li>
829 <code>sandboxed</code> causes commands to be executed inside a sandbox on the local machine.
830 This requires that all input files, data dependencies and tools are listed as direct
831 dependencies in the <code>srcs</code>, <code>data</code> and <code>tools</code> attributes.
832 This is the default on systems that support sandboxed execution.
833 </li>
834
ulfjacka42d1892019-02-12 08:34:30 -0800835 <li>
836 <code>local</code> causes commands to be executed as local subprocesses.
837 </li>
838
ulfjacka42d1892019-02-12 08:34:30 -0800839 <li>
Dave Leebc67b362019-10-02 04:29:41 -0700840 <code>worker</code> causes commands to be executed using a persistent worker, if available.
841 </li>
842
843 <li>
ulfjacka42d1892019-02-12 08:34:30 -0800844 <code>docker</code> causes commands to be executed inside a docker sandbox on the local machine.
845 This requires that docker is installed.
846 </li>
847
848 <li>
849 <code>remote</code> causes commands to be executed remotely; this is only available if a
850 remote executor has been configured separately.
851 </li>
ulfjacka42d1892019-02-12 08:34:30 -0800852</ul>
853
854<h4 id='flag--strategy'><code class='flag'>--strategy <var>mnemonic</var>=<var>strategy</var></code></h4>
855<p>
856 This option controls where and how commands are executed, overriding the default setting on a
857 per-mnemonic basis. See
858 <code class='flag'><a href="#flag--spawn_strategy">--spawn_strategy</a></code> for the supported
859 strategies and their effects.
860</p>
861
862<h4 id='flag--strategy_regexp'><code class='flag'>--strategy_regexp <var>&lt;filter,filter,...&gt;=&lt;strategy&gt;</var></code></h4>
863<p>
864 This option specifies which strategy should be used to execute commands that have descriptions
865 matching a certain <code>regex_filter</code>. See
866 <code class='flag'><a href="#flag--per_file_copt">--per_file_copt</a></code> for details on
867 regex_filter matching. See
868 <code class='flag'><a href="#flag--spawn_strategy">--spawn_strategy</a></code> for the supported
869 strategies and their effects.
870</p>
871<p>
872The first <code>regex_filter</code> that matches the description is used. This option overrides
873other flags for specifying strategy.
874</p>
875<ul>
876 <li>
877 Example: <code>--strategy_regexp=//foo.*\\.cc,-//foo/bar=local</code> means to run actions using
878 <code>local</code> strategy if their descriptions match //foo.*.cc but not //foo/bar.
879 </li>
880 <li>
881 Example:
882 <code>--strategy_regexp='Compiling.*/bar=local' --strategy_regexp=Compiling=sandboxed</code>
883 will run 'Compiling //foo/bar/baz' with the <code>local</code> strategy, but reversing the order
884 would run it with <code>sandboxed</code>.
885 </li>
David Chen8fe82a32016-08-24 10:55:41 +0000886</ul>
887
888<h4 id='flag--genrule_strategy'><code class='flag'>--genrule_strategy <var>strategy</var></code></h4>
889<p>
ulfjacka42d1892019-02-12 08:34:30 -0800890 This is a deprecated short-hand for
891 <code class='flag'>--strategy=Genrule=<var>strategy</var></code>.
David Chen8fe82a32016-08-24 10:55:41 +0000892</p>
David Chen8fe82a32016-08-24 10:55:41 +0000893
David Chen8fe82a32016-08-24 10:55:41 +0000894<h4 id='flag--jobs'><code class='flag'>--jobs <var>n</var></code> (-j)</h4>
895<p>
896 This option, which takes an integer argument, specifies a limit on
897 the number of jobs that should be executed concurrently during the
Googlerb6857d52017-09-22 14:03:21 -0400898 execution phase of the build.
David Chen8fe82a32016-08-24 10:55:41 +0000899</p>
900<p>
901 Note that the number of concurrent jobs that Bazel will run
902 is determined not only by the <code class='flag'>--jobs</code> setting, but also
903 by Bazel's scheduler, which tries to avoid running concurrent jobs
904 that will use up more resources (RAM or CPU) than are available,
905 based on some (very crude) estimates of the resource consumption
906 of each job. The behavior of the scheduler can be controlled by
steinman7f530c82020-04-15 14:13:42 -0700907 the <code class='flag'>--local_ram_resources</code> option.
David Chen8fe82a32016-08-24 10:55:41 +0000908</p>
909
910<h4 id='flag--progress_report_interval'><code class='flag'>--progress_report_interval <var>n</var></code></h4>
911<p>
912
913 Bazel periodically prints a progress report on jobs that are not
914 finished yet (e.g. long running tests). This option sets the
915 reporting frequency, progress will be printed every <code>n</code>
916 seconds.
917</p>
918<p>
919 The default is 0, that means an incremental algorithm: the first
920 report will be printed after 10 seconds, then 30 seconds and after
921 that progress is reported once every minute.
922</p>
923
steinmancd1783d2019-03-08 08:09:42 -0800924<h4 id='flag--local_{ram,cpu}_resources'><code class='flag'>--local_{ram,cpu}_resources</code>
925 <var>resources or resource expression</var></h4>
David Chen8fe82a32016-08-24 10:55:41 +0000926<p>
steinmancd1783d2019-03-08 08:09:42 -0800927 These options specify the amount of local resources (RAM in MB and number of CPU logical cores)
928 that Bazel can take into consideration when scheduling build and test activities. They take
929 an integer, or a keyword (HOST_RAM or HOST_CPUS) optionally followed by [-|*<float>float</float>]
930 (for example, <code class='flag'>--local_cpu_resources=2</code>,
931 <code class='flag'>--local_ram_resources=HOST_RAM*.5</code>,
932 <code class='flag'>--local_cpu_resources=HOST_CPUS-1</code>).
933 The flags are independent; one or both may be set. By default Bazel will estimate amount of RAM
934 and number of CPU cores directly from system configuration.
David Chen8fe82a32016-08-24 10:55:41 +0000935</p>
David Chen8fe82a32016-08-24 10:55:41 +0000936
937<h4 id='flag--build_runfile_links'><code class='flag'>--[no]build_runfile_links</code></h4>
938<p>
Googler5a495842017-08-22 01:30:36 +0200939 This option, which is enabled by default, specifies whether the runfiles
940 symlinks for tests and binaries should be built in the output directory.
David Chen8fe82a32016-08-24 10:55:41 +0000941 Using <code class='flag'>--nobuild_runfile_links</code> can be useful
942 to validate if all targets compile without incurring the overhead
943 for building the runfiles trees.
944
David Chen8fe82a32016-08-24 10:55:41 +0000945</p>
946
947<p>
Googler5a495842017-08-22 01:30:36 +0200948 When tests (or applications) are executed, their run-time data
949 dependencies are gathered together in one place. Within Bazel's
950 output tree, this "runfiles" tree is typically rooted as a sibling of
951 the corresponding binary or test.
952 During test execution, runfiles may be accessed using paths of the form
David Chen8fe82a32016-08-24 10:55:41 +0000953 <code>$TEST_SRCDIR/workspace/<var>packagename</var>/<var>filename</var></code>.
Googler5a495842017-08-22 01:30:36 +0200954 The runfiles tree ensures that tests have access to all the files
David Chen8fe82a32016-08-24 10:55:41 +0000955 upon which they have a declared dependence, and nothing more. By
956 default, the runfiles tree is implemented by constructing a set of
957 symbolic links to the required files. As the set of links grows, so
958 does the cost of this operation, and for some large builds it can
959 contribute significantly to overall build time, particularly because
960 each individual test (or application) requires its own runfiles tree.
961</p>
David Chen8fe82a32016-08-24 10:55:41 +0000962
Googler01f659d2017-08-22 02:53:02 +0200963<h4 id='flag--build_runfile_manifests'><code class='flag'>--[no]build_runfile_manifests</code></h4>
964<p>
965 This option, which is enabled by default, specifies whether runfiles manifests
966 should be written to the output tree.
967 Disabling it implies <code class='flag'>--nobuild_runfile_links</code>.
968
Tobias Werth78e27f42019-08-12 00:49:58 -0700969 It can be disabled when executing tests remotely, as runfiles trees will
Googler01f659d2017-08-22 02:53:02 +0200970 be created remotely from in-memory manifests.
971
David Chen8fe82a32016-08-24 10:55:41 +0000972<h4 id='flag--discard_analysis_cache'>
973 <code class='flag'>--[no]discard_analysis_cache</code></h4>
974<p>
975 When this option is enabled, Bazel will discard the analysis cache
976 right before execution starts, thus freeing up additional memory
Googler59830672019-01-03 10:33:49 -0800977 (around 10%) for the <a href="guide.html#execution-phase">execution phase</a>.
janakr428c5e12019-05-06 15:35:54 -0700978 The drawback is that further incremental builds will be slower. See also
janakr69781dd52019-05-07 09:04:41 -0700979 <a href="/versions/{{ current_version }}/memory-saving-mode.html">
Googlera05b7f02019-05-21 08:13:04 -0700980memory-saving mode</a>.
David Chen8fe82a32016-08-24 10:55:41 +0000981</p>
982
983<h4 id='flag--keep_going'><code class='flag'>--[no]keep_going</code> (-k)</h4>
984<p>
985 As in GNU Make, the execution phase of a build stops when the first
986 error is encountered. Sometimes it is useful to try to build as
987 much as possible even in the face of errors. This option enables
988 that behavior, and when it is specified, the build will attempt to
989 build every target whose prerequisites were successfully built, but
990 will ignore errors.
991</p>
992<p>
993 While this option is usually associated with the execution phase of
994 a build, it also effects the analysis phase: if several targets are
995 specified in a build command, but only some of them can be
996 successfully analyzed, the build will stop with an error
997 unless <code class='flag'>--keep_going</code> is specified, in which case the
998 build will proceed to the execution phase, but only for the targets
999 that were successfully analyzed.
1000</p>
1001
David Chen8fe82a32016-08-24 10:55:41 +00001002<h4 id='flag--use_ijars'><code class='flag'>--[no]use_ijars</code></h4>
1003<p>
1004 This option changes the way <code>java_library</code> targets are
1005 compiled by Bazel. Instead of using the output of a
1006 <code>java_library</code> for compiling dependent
1007 <code>java_library</code> targets, Bazel will create interface jars
1008 that contain only the signatures of non-private members (public,
1009 protected, and default (package) access methods and fields) and use
1010 the interface jars to compile the dependent targets. This makes it
1011 possible to avoid recompilation when changes are only made to
1012 method bodies or private members of a class.
1013</p>
1014<p>
1015 Note that using <code class='flag'>--use_ijars</code> might give you a different
1016 error message when you are accidentally referring to a non visible
1017 member of another class: Instead of getting an error that the member
1018 is not visible you will get an error that the member does not exist.
1019</p>
1020<p>
1021 Note that changing the <code class='flag'>--use_ijars</code> setting will force
1022 a recompilation of all affected classes.
1023</p>
1024
1025<h4 id='flag--interface_shared_objects'>
1026 <code class='flag'>--[no]interface_shared_objects</code>
1027</h4>
1028<p>
1029 This option enables <i>interface shared objects</i>, which makes binaries and
1030 other shared libraries depend on the <i>interface</i> of a shared object,
1031 rather than its implementation. When only the implementation changes, Bazel
1032 can avoid rebuilding targets that depend on the changed shared library
1033 unnecessarily.
1034</p>
1035
brandjoncf0390b2020-02-20 10:37:40 -08001036<h3 id='output-selection-options'>Output selection</h3>
David Chen8fe82a32016-08-24 10:55:41 +00001037<p>
1038 These options determine what to build or test.
1039</p>
1040
1041<h4 id="nobuild"><code class='flag'>--[no]build</code></h4>
1042<p>
1043 This option causes the execution phase of the build to occur; it is
1044 on by default. When it is switched off, the execution phase is
1045 skipped, and only the first two phases, loading and analysis, occur.
1046</p>
1047<p>
1048 This option can be useful for validating BUILD files and detecting
1049 errors in the inputs, without actually building anything.
1050</p>
1051
1052<h4 id='flag--build_tests_only'><code class='flag'>--[no]build_tests_only</code></h4>
1053<p>
1054 If specified, Bazel will build only what is necessary to run the *_test
1055 and test_suite rules that were not filtered due to their
1056 <a href='#flag--test_size_filters'>size</a>,
1057 <a href='#flag--test_timeout_filters'>timeout</a>,
1058 <a href='#flag--test_tag_filters'>tag</a>, or
1059 <a href='#flag--test_lang_filters'>language</a>.
1060 If specified, Bazel will ignore other targets specified on the command line.
1061 By default, this option is disabled and Bazel will build everything
1062 requested, including *_test and test_suite rules that are filtered out from
1063 testing. This is useful because running
1064 <code>bazel test --build_tests_only foo/...</code> may not detect all build
1065 breakages in the <code>foo</code> tree.
1066</p>
1067
1068<h4 id='flag--check_up_to_date'><code class='flag'>--[no]check_up_to_date</code></h4>
1069<p>
1070 This option causes Bazel not to perform a build, but merely check
1071 whether all specified targets are up-to-date. If so, the build
1072 completes successfully, as usual. However, if any files are out of
1073 date, instead of being built, an error is reported and the build
1074 fails. This option may be useful to determine whether a build has
1075 been performed more recently than a source edit (e.g. for pre-submit
1076 checks) without incurring the cost of a build.
1077</p>
1078<p>
1079 See also <a href="#flag--check_tests_up_to_date"><code class='flag'>--check_tests_up_to_date</code></a>.
1080</p>
1081
1082<h4 id='flag--compile_one_dependency'><code class='flag'>--[no]compile_one_dependency</code></h4>
1083<p>
1084 Compile a single dependency of the argument files. This is useful for
1085 syntax checking source files in IDEs, for example, by rebuilding a single
1086 target that depends on the source file to detect errors as early as
1087 possible in the edit/build/test cycle. This argument affects the way all
1088 non-flag arguments are interpreted: for each source filename, one
1089 rule that depends on it will be built. For
1090
1091 C++ and Java
1092 sources, rules in the same language space are preferentially chosen. For
1093 multiple rules with the same preference, the one that appears first in the
1094 BUILD file is chosen. An explicitly named target pattern which does not
1095 reference a source file results in an error.
1096</p>
1097
1098<h4 id='flag--save_temps'><code class='flag'>--save_temps</code></h4>
1099<p>
Googler9cfa4cb2018-06-04 22:19:11 -07001100 The <code class='flag'>--save_temps</code> option causes temporary outputs from the compiler to be
1101 saved. These include .s files (assembler code), .i (preprocessed C) and .ii
David Chen8fe82a32016-08-24 10:55:41 +00001102 (preprocessed C++) files. These outputs are often useful for debugging. Temps will only be
1103 generated for the set of targets specified on the command line.
1104</p>
1105<p>
Googler9cfa4cb2018-06-04 22:19:11 -07001106 Note that our implementation of <code class='flag'>--save_temps</code> does not use the compiler's
David Chen8fe82a32016-08-24 10:55:41 +00001107 <code>-save-temps</code> flag. Instead, we do two passes, one with <code>-S</code>
1108 and one with <code>-E</code>. A consequence of this is that if your build fails,
1109 Bazel may not yet have produced the ".i" or ".ii" and ".s" files.
1110 If you're trying to use <code class='flag'>--save_temps</code> to debug a failed compilation,
1111 you may need to also use <code class='flag'>--keep_going</code> so that Bazel will still try to
1112 produce the preprocessed files after the compilation fails.
1113</p>
1114<p>
1115 The <code class='flag'>--save_temps</code> flag currently works only for cc_* rules.
1116</p>
1117<p>
1118 To ensure that Bazel prints the location of the additional output files, check that
1119 your <a href='#flag--show_result'><code class='flag'>--show_result <var>n</var></code></a>
1120 setting is high enough.
1121</p>
1122
Googlerd9db1692017-01-05 19:34:30 +00001123<h4 id='flag--build_tag_filters'><code class='flag'>--build_tag_filters <var>tag[,tag]*</var></code></h4>
1124<p>
1125 If specified, Bazel will build only targets that have at least one required tag
1126 (if any of them are specified) and does not have any excluded tags. Build tag
1127 filter is specified as comma delimited list of tag keywords, optionally
1128 preceded with '-' sign used to denote excluded tags. Required tags may also
1129 have a preceding '+' sign.
1130</p>
janakrc63128d2020-08-05 15:42:49 -07001131<p>
1132 When running tests, Bazel ignores <code class='flag'>--build_tag_filters</code> for test targets,
1133 which are built and run even if they do not match this filter. To avoid building them, filter
1134 test targets using <code class='flag'>--test_tag_filters</code> or by explicitly excluding them.
1135</p>
Googlerd9db1692017-01-05 19:34:30 +00001136
David Chen8fe82a32016-08-24 10:55:41 +00001137<h4 id='flag--test_size_filters'><code class='flag'>--test_size_filters <var>size[,size]*</var></code></h4>
1138<p>
1139 If specified, Bazel will test (or build if <code class='flag'>--build_tests_only</code>
1140 is also specified) only test targets with the given size. Test size filter
1141 is specified as comma delimited list of allowed test size values (small,
1142 medium, large or enormous), optionally preceded with '-' sign used to denote
1143 excluded test sizes. For example,
1144</p>
1145<pre>
1146 % bazel test --test_size_filters=small,medium //foo:all
1147</pre>
1148 and
1149<pre>
1150 % bazel test --test_size_filters=-large,-enormous //foo:all
1151</pre>
1152<p>
1153 will test only small and medium tests inside //foo.
1154</p>
1155<p>
1156 By default, test size filtering is not applied.
1157</p>
1158
1159<h4 id='flag--test_timeout_filters'><code class='flag'>--test_timeout_filters <var>timeout[,timeout]*</var></code></h4>
1160<p>
1161 If specified, Bazel will test (or build if <code class='flag'>--build_tests_only</code>
1162 is also specified) only test targets with the given timeout. Test timeout filter
1163 is specified as comma delimited list of allowed test timeout values (short,
1164 moderate, long or eternal), optionally preceded with '-' sign used to denote
1165 excluded test timeouts. See <a href='#flag--test_size_filters'>--test_size_filters</a>
1166 for example syntax.
1167</p>
1168<p>
1169 By default, test timeout filtering is not applied.
1170</p>
1171
1172
1173<h4 id='flag--test_tag_filters'><code class='flag'>--test_tag_filters <var>tag[,tag]*</var></code></h4>
1174<p>
1175 If specified, Bazel will test (or build if <code class='flag'>--build_tests_only</code>
1176 is also specified) only test targets that have at least one required tag
1177 (if any of them are specified) and does not have any excluded tags. Test tag
1178 filter is specified as comma delimited list of tag keywords, optionally
1179 preceded with '-' sign used to denote excluded tags. Required tags may also
1180 have a preceding '+' sign.
1181</p>
1182<p>
1183 For example,
1184<pre>
1185 % bazel test --test_tag_filters=performance,stress,-flaky //myproject:all
1186</pre>
1187<p>
1188 will test targets that are tagged with either <code>performance</code> or
1189 <code>stress</code> tag but are <b>not</b> tagged with the <code>flaky</code>
1190 tag.
1191</p>
1192<p>
1193 By default, test tag filtering is not applied. Note that you can also filter
1194 on test's <code>size</code> and <code>local</code> tags in
1195 this manner.
1196</p>
1197
1198<h4 id='flag--test_lang_filters'><code class='flag'>--test_lang_filters <var>lang[,lang]*</var></code></h4>
1199<p>
1200 Specifies a comma-separated list of test languages for languages with an official <code>*_test</code> rule the
1201 (see <a href="be/overview.html">build encyclopedia</a> for a full list of these). Each
1202 language can be optionally preceded with '-' to specify excluded
1203 languages. The name used for each language should be the same as
1204 the language prefix in the <code>*_test</code> rule, for example,
1205 <code>cc</code>, <code>java</code> or <code>sh</code>.
1206</p>
1207<p>
1208 If specified, Bazel will test (or build if <code class='flag'>--build_tests_only</code>
1209 is also specified) only test targets of the specified language(s).
1210</p>
1211<p>
1212 For example,
1213</p>
1214<pre>
1215 % bazel test --test_lang_filters=cc,java foo/...
1216</pre>
1217<p>
1218 will test only the C/C++ and Java tests (defined using
1219 <code>cc_test</code> and <code>java_test</code> rules, respectively)
1220 in <code>foo/...</code>, while
1221</p>
1222<pre>
1223 % bazel test --test_lang_filters=-sh,-java foo/...
1224</pre>
1225<p>
1226 will run all of the tests in <code>foo/...</code> except for the
1227 <code>sh_test</code> and <code>java_test</code> tests.
1228</p>
1229<p>
1230 By default, test language filtering is not applied.
1231</p>
1232
1233<h4 id="flag--test_filter"><code class='flag'>--test_filter=<var>filter-expression</var></code></h4>
1234<p>
1235 Specifies a filter that the test runner may use to pick a subset of tests for
michajlo20971eb2020-03-12 08:00:09 -07001236 running. All targets specified in the invocation are built, but depending on
David Chen8fe82a32016-08-24 10:55:41 +00001237 the expression only some of them may be executed; in some cases, only certain
1238 test methods are run.
1239</p>
1240<p>
1241 The particular interpretation of <var>filter-expression</var> is up to
1242 the test framework responsible for running the test. It may be a glob,
1243 substring, or regexp. <code class='flag'>--test_filter</code> is a convenience
1244 over passing different <code class='flag'>--test_arg</code> filter arguments,
1245 but not all frameworks support it.
1246</p>
1247
brandjoncf0390b2020-02-20 10:37:40 -08001248<h3 id='verbosity'>Verbosity</h3>
David Chen8fe82a32016-08-24 10:55:41 +00001249
1250These options control the verbosity of Bazel's output,
1251either to the terminal, or to additional log files.
1252
1253<h4 id='flag--explain'><code class='flag'>--explain <var>logfile</var></code></h4>
1254<p>
1255 This option, which requires a filename argument, causes the
1256 dependency checker in <code>bazel build</code>'s execution phase to
1257 explain, for each build step, either why it is being executed, or
1258 that it is up-to-date. The explanation is written
1259 to <i>logfile</i>.
1260</p>
1261<p>
1262 If you are encountering unexpected rebuilds, this option can help to
1263 understand the reason. Add it to your <code>.bazelrc</code> so that
1264 logging occurs for all subsequent builds, and then inspect the log
1265 when you see an execution step executed unexpectedly. This option
1266 may carry a small performance penalty, so you might want to remove
1267 it when it is no longer needed.
1268</p>
1269
1270<h4 id='flag--verbose_explanations'><code class='flag'>--verbose_explanations</code></h4>
1271<p>
1272 This option increases the verbosity of the explanations generated
1273 when the <a href='#flag--explain'>--explain</a> option is enabled.
1274</p>
1275<p>
1276 In particular, if verbose explanations are enabled,
1277 and an output file is rebuilt because the command used to
1278 build it has changed, then the output in the explanation file will
1279 include the full details of the new command (at least for most
1280 commands).
1281</p>
1282<p>
1283 Using this option may significantly increase the length of the
1284 generated explanation file and the performance penalty of using
1285 <code class='flag'>--explain</code>.
1286</p>
1287<p>
1288 If <code class='flag'>--explain</code> is not enabled, then
1289 <code class='flag'>--verbose_explanations</code> has no effect.
1290</p>
1291
1292<h4 id='flag--profile'><code class='flag'>--profile <var>file</var></code></h4>
1293<p>
1294 This option, which takes a filename argument, causes Bazel to write
1295 profiling data into a file. The data then can be analyzed or parsed using the
1296 <code>bazel analyze-profile</code> command. The Build profile can be useful in
1297 understanding where Bazel's <code>build</code> command is spending its time.
1298</p>
1299
1300<h4 id='flag--show_loading_progress'><code class='flag'>--[no]show_loading_progress</code></h4>
1301<p>
1302 This option causes Bazel to output package-loading progress
1303 messages. If it is disabled, the messages won't be shown.
1304</p>
1305
1306<h4 id='flag--show_progress'><code class='flag'>--[no]show_progress</code></h4>
1307<p>
1308 This option causes progress messages to be displayed; it is on by
1309 default. When disabled, progress messages are suppressed.
1310</p>
1311
1312<h4 id='flag--show_progress_rate_limit'><code class='flag'>--show_progress_rate_limit
1313 <var>n</var></code></h4>
1314<p>
1315 This option causes bazel to display only
1316 one progress message per <code>n</code> seconds, where <var>n</var> is a real number.
1317 If <code>n</code> is -1, all progress messages will be displayed. The default value for
1318 this option is 0.03, meaning bazel will limit the progress messages to one per every
1319 0.03 seconds.
1320</p>
1321
1322<h4 id='flag--show_result'><code class='flag'>--show_result <var>n</var></code></h4>
1323<p>
1324 This option controls the printing of result information at the end
1325 of a <code>bazel build</code> command. By default, if a single
1326 build target was specified, Bazel prints a message stating whether
1327 or not the target was successfully brought up-to-date, and if so,
1328 the list of output files that the target created. If multiple
1329 targets were specified, result information is not displayed.
1330</p>
1331<p>
1332 While the result information may be useful for builds of a single
1333 target or a few targets, for large builds (e.g. an entire top-level
1334 project tree), this information can be overwhelming and distracting;
1335 this option allows it to be controlled. <code class='flag'>--show_result</code>
1336 takes an integer argument, which is the maximum number of targets
1337 for which full result information should be printed. By default,
1338 the value is 1. Above this threshold, no result information is
1339 shown for individual targets. Thus zero causes the result
1340 information to be suppressed always, and a very large value causes
1341 the result to be printed always.
1342</p>
1343<p>
1344 Users may wish to choose a value in-between if they regularly
1345 alternate between building a small group of targets (for example,
1346 during the compile-edit-test cycle) and a large group of targets
1347 (for example, when establishing a new workspace or running
1348 regression tests). In the former case, the result information is
1349 very useful whereas in the latter case it is less so. As with all
1350 options, this can be specified implicitly via
Vladimir Chebotarev66885ff2018-12-04 14:08:16 -08001351 the <a href='guide.html#bazelrc'><code>.bazelrc</code></a> file.
David Chen8fe82a32016-08-24 10:55:41 +00001352</p>
1353<p>
1354 The files are printed so as to make it easy to copy and paste the
1355 filename to the shell, to run built executables. The "up-to-date"
1356 or "failed" messages for each target can be easily parsed by scripts
1357 which drive a build.
1358</p>
1359
1360<h4 id='flag--subcommands'><code class='flag'>--subcommands</code> (<code>-s</code>)</h4>
1361<p>
1362 This option causes Bazel's execution phase to print the full command line
1363 for each command prior to executing it.
1364</p>
1365
1366<pre>
1367 &gt;&gt;&gt;&gt;&gt; # //examples/cpp:hello-world [action 'Linking examples/cpp/hello-world']
lberkif071a232017-12-07 04:21:34 -08001368 (cd /home/johndoe/.cache/bazel/_bazel_johndoe/4c084335afceb392cfbe7c31afee3a9f/bazel && \
David Chen8fe82a32016-08-24 10:55:41 +00001369 exec env - \
lberkicbac3282017-12-07 05:47:43 -08001370 /usr/bin/gcc -o bazel-out/local-fastbuild/bin/examples/cpp/hello-world -B/usr/bin/ -Wl,-z,relro,-z,now -no-canonical-prefixes -pass-exit-codes -Wl,-S -Wl,@bazel-out/local_linux-fastbuild/bin/examples/cpp/hello-world-2.params)
David Chen8fe82a32016-08-24 10:55:41 +00001371</pre>
1372<p>
1373 Where possible, commands are printed in a Bourne shell compatible syntax,
1374 so that they can be easily copied and pasted to a shell command prompt.
1375 (The surrounding parentheses are provided to protect your shell from the
1376 <code>cd</code> and <code>exec</code> calls; be sure to copy them!)
1377 However some commands are implemented internally within Bazel, such as
1378 creating symlink trees. For these there's no command line to display.
1379
1380</p>
1381
1382<p>
ahumeskybe31bb82018-07-26 13:37:45 -07001383 <code class='flag'>--subcommands=pretty_print</code> may be passed to print
1384 the arguments of the command as a list rather than as a single line. This may
1385 help make long command lines more readable.
1386</p>
1387
1388<p>
David Chen8fe82a32016-08-24 10:55:41 +00001389 See also <a href="#flag--verbose_failures">--verbose_failures</a>, below.
1390</p>
1391
1392<h4 id='flag--verbose_failures'><code class='flag'>--verbose_failures</code></h4>
1393<p>
1394 This option causes Bazel's execution phase to print the full command line
1395 for commands that failed. This can be invaluable for debugging a
1396 failing build.
1397</p>
1398<p>
1399 Failing commands are printed in a Bourne shell compatible syntax, suitable
1400 for copying and pasting to a shell prompt.
1401</p>
1402
brandjoncf0390b2020-02-20 10:37:40 -08001403<h3 id='workspace_status'>Workspace status</h3>
laszlocsomor45a0ffe2018-02-05 00:48:35 -08001404
1405<p>
1406 Use these options to "stamp" Bazel-built binaries: to embed additional information into the
1407 binaries, such as the source control revision or other workspace-related information. You can use
1408 this mechanism with rules that support the <code>stamp</code> attribute, such as
1409 <code>genrule</code>, <code>cc_binary</code>, and more.
1410</p>
1411
1412<h4 id='flag--workspace_status_command'><code class='flag'>--workspace_status_command <var>program</var></code></h4>
1413<p>
1414 This flag lets you specify a binary that Bazel runs before each build. The program can report
1415 information about the status of the workspace, such as the current source control revision.
1416</p>
1417<p>
1418 The flag's value must be a path to a native program. On Linux/macOS this may be any executable.
1419 On Windows this must be a native binary, typically an ".exe", ".bat", or a ".cmd" file.
1420</p>
1421
1422<p>
1423 The program should print zero or more key/value pairs to standard output, one entry on each line,
1424 then exit with zero (otherwise the build fails). The key names can be anything but they may only
1425 use upper case letters and underscores. The first space after the key name separates it from the
jhorvitz2a5bf222020-11-30 14:05:02 -08001426 value. The value is the rest of the line (including additional whitespaces). Neither the key nor
1427 the value may span multiple lines. Keys must not be duplicated.
laszlocsomor45a0ffe2018-02-05 00:48:35 -08001428</p>
1429<p>
1430 Bazel partitions the keys into two buckets: "stable" and "volatile". (The names "stable" and
1431 "volatile" are a bit counter-intuitive, so don't think much about them.)
1432</p>
1433
1434<p>Bazel then writes the key-value pairs into two files:</p>
1435<ul>
1436 <li>
ahumesky5a6d8b62018-11-15 14:05:34 -08001437 <code>bazel-out/stable-status.txt</code>
1438 contains all keys and values where the key's name starts with <code>STABLE_</code>
laszlocsomor45a0ffe2018-02-05 00:48:35 -08001439 </li>
ahumesky5a6d8b62018-11-15 14:05:34 -08001440 <li>
1441 <code>bazel-out/volatile-status.txt</code>
1442 contains the rest of the keys and their values
1443 </li>
laszlocsomor45a0ffe2018-02-05 00:48:35 -08001444</ul>
1445
1446<p>The contract is:</p>
1447<ul>
1448 <li>
1449 <p>
1450 "stable" keys' values should change rarely, if possible. If the contents of
ahumesky5a6d8b62018-11-15 14:05:34 -08001451 <code>bazel-out/stable-status.txt</code>
1452 change, Bazel invalidates the actions that depend on them. In
1453 other words, if a stable key's value changes, Bazel will rerun stamped actions.
laszlocsomor45a0ffe2018-02-05 00:48:35 -08001454 Therefore the stable status should not contain things like timestamps, because they change all
ahumesky5a6d8b62018-11-15 14:05:34 -08001455 the time, and would make Bazel rerun stamped actions with each build.
laszlocsomor45a0ffe2018-02-05 00:48:35 -08001456 </p>
1457 <p>Bazel always outputs the following stable keys:</p>
1458 <ul>
1459 <li><code>BUILD_EMBED_LABEL</code>: value of <code class='flag'>--embed_label</code></li>
1460 <li><code>BUILD_HOST</code>: the name of the host machine that Bazel is running on</li>
1461 <li><code>BUILD_USER</code>: the name of the user that Bazel is running as</li>
1462 </ul>
1463 </li>
1464 <li>
1465 <p>
1466 "volatile" keys' values may change often. Bazel expects them to change all the time, like
ahumesky5a6d8b62018-11-15 14:05:34 -08001467 timestamps do, and duly updates the
David McNettfa388c32019-05-16 13:16:56 -07001468 <code>bazel-out/volatile-status.txt</code>
ahumesky5a6d8b62018-11-15 14:05:34 -08001469 file. In order to avoid
1470 rerunning stamped actions all the time though, <b>Bazel pretends that the volatile file never
1471 changes</b>. In other words, if the volatile status file is the only file whose contents has
1472 changed, Bazel will not invalidate actions that depend on it. If other inputs of the actions
1473 have changed, then Bazel reruns that action, and the action will see the updated volatile
laszlocsomor45a0ffe2018-02-05 00:48:35 -08001474 status, but just the volatile status changing alone will not invalidate the action.
1475 </p>
1476 <p>Bazel always outputs the following volatile keys:</p>
1477 <ul>
1478 <li>
lberki911c7c52018-04-25 07:56:27 -07001479 <code>BUILD_TIMESTAMP</code>: time of the build in seconds since the Unix Epoch (the value
1480 of <code>System.currentTimeMillis()</code> divided by a thousand)
laszlocsomor45a0ffe2018-02-05 00:48:35 -08001481 </li>
1482 </ul>
1483 </li>
1484</ul>
1485
1486<p>
1487 On Linux/macOS you can pass <code class='flag'>--workspace_status_command=/bin/true</code> to
Googler956ecf62018-11-26 10:15:05 -08001488 disable retrieving workspace status, because <code>true</code> does nothing, successfully (exits
laszlocsomor45a0ffe2018-02-05 00:48:35 -08001489 with zero) and prints no output. On Windows you can pass the path of MSYS's <code>true.exe</code>
1490 for the same effect.
1491</p>
1492
1493<p>If the workspace status command fails (exits non-zero) for any reason, the build will fail.</p>
1494
1495<p>Example program on Linux using Git:</p>
1496
1497<pre>
1498#!/bin/bash
1499echo "CURRENT_TIME $(date +%s)"
Googler98982a02020-07-29 10:16:10 -07001500echo "RANDOM_HASH $(cat /proc/sys/kernel/random/uuid)"
laszlocsomor45a0ffe2018-02-05 00:48:35 -08001501echo "STABLE_GIT_COMMIT $(git rev-parse HEAD)"
1502echo "STABLE_USER_NAME $USER"
1503</pre>
1504
1505<p>
1506 Pass this program's path with <code>--workspace_status_command</code>, and the stable status file
1507 will include the STABLE lines and the volatile status file will include the rest of the lines.
1508</p>
1509
David Chen8fe82a32016-08-24 10:55:41 +00001510<h4 id='flag--stamp'><code class='flag'>--[no]stamp</code></h4>
1511<p>
1512 This option controls whether stamping is enabled for
1513 rule types that support it. For most of the supported rule types stamping is
1514 enabled by default (e.g. <code>cc_binary</code>).
1515
1516 By default, stamping is disabled for all tests. Specifying
1517 <code class='flag'>--stamp</code> does not force affected targets to be rebuilt,
1518 if their dependencies have not changed.
1519</p>
1520
1521<p>
1522 Stamping can be enabled or disabled explicitly in BUILD using
1523 the <code>stamp</code> attribute of certain rule types, please refer to
1524 the <a href="be/overview.html">build encyclopedia</a> for details. For
1525 rules that are neither explicitly or implicitly configured as <code>stamp =
1526 0</code> or <code>stamp = 1</code>, the <code class='flag'>--[no]stamp</code> option
1527 selects whether stamping is enabled. Bazel never stamps binaries that are
1528 built for the host configuration, regardless of the stamp attribute.
1529</p>
1530
brandjoncf0390b2020-02-20 10:37:40 -08001531<h3 id='platform_build_options'>Platform</h3>
jcaterbf57a0a2018-06-13 10:16:31 -07001532
1533<p>
1534 Use these options to control the host and target platforms that configure how builds work, and to
1535 control what execution platforms and toolchains are available to Bazel rules.
1536</p>
1537
1538<p>
1539 Please see background information on
1540 <a href="platforms.html">Platforms</a> and <a href="toolchains.html">Toolchains</a>.
1541</p>
1542
1543<h4 id="flag--platforms"><code class='flag'>--platforms <var>labels</var></code></h4>
1544<p>
1545 The labels of the platform rules describing the target platforms for the
1546 current command.
1547</p>
1548
1549<h4 id="flag--host_platform"><code class='flag'>--host_platform <var>label</var></code></h4>
1550<p>
1551 The label of a platform rule that describes the host system.
1552</p>
1553
1554<h4 id="flag--extra_execution_platforms"><code class='flag'>--extra_execution_platforms <var>labels</var></code></h4>
1555<p>
1556 The platforms that are available as execution platforms to run actions.
1557 Platforms can be specified by exact target, or as a target pattern. These
1558 platforms will be considered before those declared in the WORKSPACE file by
Jingwen Chen0f4544d2018-12-14 16:28:16 -08001559 <a href="skylark/lib/globals.html#register_execution_platforms">
jcaterbf57a0a2018-06-13 10:16:31 -07001560 register_execution_platforms()</a>.
1561</p>
1562
1563<h4 id="flag--extra_toolchains"><code class='flag'>--extra_toolchains <var>labels</var></code></h4>
1564<p>
1565 The toolchain rules to be considered during toolchain resolution. Toolchains
1566 can be specified by exact target, or as a target pattern. These toolchains will
1567 be considered before those declared in the WORKSPACE file by
Jingwen Chen0f4544d2018-12-14 16:28:16 -08001568 <a href="skylark/lib/globals.html#register_toolchains">
jcaterbf57a0a2018-06-13 10:16:31 -07001569 register_toolchains()</a>.
1570</p>
1571
1572<h4 id="flag--toolchain_resolution_debug"><code class='flag'>--toolchain_resolution_debug=false</code></h4>
1573<p>
1574 Print debug information while finding toolchains for a rule. This might help
gregceca48e9a2020-04-14 08:54:38 -07001575 developers of Bazel or Starlark rules with debugging failures due to missing
jcaterbf57a0a2018-06-13 10:16:31 -07001576 toolchains.
1577</p>
1578
brandjoncf0390b2020-02-20 10:37:40 -08001579<h3 id='misc_build_options'>Miscellaneous</h3>
David Chen8fe82a32016-08-24 10:55:41 +00001580
warkahscott057ae962020-10-16 13:21:25 -07001581<h4 id='flag--flag_alias'><code class='flag'>--flag_alias <var>alias_name=target_path</var></code></h4>
1582<p>
1583 A convenience flag used to bind longer Starlark build settings to a shorter name. For more
1584 details, see the
1585 <a href=https://docs.bazel.build/versions/master/skylark/config.html#using-build-setting-aliases">Starlark Configurations</a>.
1586</p>
1587
David Chen8fe82a32016-08-24 10:55:41 +00001588<h4 id='flag--symlink_prefix'><code class='flag'>--symlink_prefix <var>string</var></code></h4>
1589<p>
1590 Changes the prefix of the generated convenience symlinks. The
1591 default value for the symlink prefix is <code>bazel-</code> which
1592 will create the symlinks <code>bazel-bin</code>, <code>bazel-testlogs</code>, and
1593 <code>bazel-genfiles</code>.
1594</p>
1595<p>
1596 If the symbolic links cannot be created for any reason, a warning is
1597 issued but the build is still considered a success. In particular,
1598 this allows you to build in a read-only directory or one that you have no
1599 permission to write into. Any paths printed in informational
1600 messages at the conclusion of a build will only use the
1601 symlink-relative short form if the symlinks point to the expected
1602 location; in other words, you can rely on the correctness of those
1603 paths, even if you cannot rely on the symlinks being created.
1604</p>
1605<p>
1606 Some common values of this option:
1607</p>
1608<ul>
1609
1610 <li>
1611 <p><b>Suppress symlink creation:</b>
1612 <code class='flag'>--symlink_prefix=/</code> will cause Bazel to not
1613 create or update any symlinks, including the <code>bazel-out</code> and
1614
1615 <code>bazel-&lt;workspace&gt;</code>
1616 symlinks. Use this option to suppress symlink creation entirely.
1617 </p>
1618 </li>
1619 <li>
1620 <p><b>Reduce clutter:</b>
1621 <code class='flag'>--symlink_prefix=.bazel/</code> will cause Bazel to create
1622 symlinks called <code>bin</code> (etc) inside a hidden directory <code>.bazel</code>.
1623 </p>
1624 </li>
1625</ul>
1626
1627<h4 id='flag--platform_suffix'><code class='flag'>--platform_suffix <var>string</var></code></h4>
1628<p>
1629 Adds a suffix to the configuration short name, which is used to determine the
1630 output directory. Setting this option to different values puts the files into
1631 different directories, for example to improve cache hit rates for builds that
1632 otherwise clobber each others output files, or to keep the output files around
1633 for comparisons.
1634</p>
1635
1636<h4 id='flag--default_visibility'><code class='flag'>--default_visibility=<var>(private|public)</var></code></h4>
1637<p>
1638 Temporary flag for testing bazel default visibility changes. Not intended for general use
1639 but documented for completeness' sake.
1640</p>
1641
Googler23471692017-06-02 11:26:16 -04001642<h4 id='flag--use_action_cache'><code class='flag'>--[no]use_action_cache</code></h4>
1643<p>
1644 This option is enabled by default. If disabled, Bazel will not use its local action cache.
1645 Disabling the local action cache saves memory and disk space for clean builds, but will make
1646 incremental builds slower.
1647</p>
1648
adonovan329ec6d2020-02-06 15:34:49 -08001649<h4 id='flag--starlark_cpu_profile'><code class='flag'>--starlark_cpu_profile=<i>file</i></code></h4>
1650<p>
1651 This flag, whose value is the name of a file, causes Bazel to gather
1652 statistics about CPU usage by all Starlark threads,
1653 and write the profile, in <a href='https://github.com/google/pprof'>pprof</a> format,
1654 to the named file.
1655
1656 Use this option to help identify Starlark functions that
1657 make loading and analysis slow due to excessive computation. For example:
1658</p>
1659<pre>
1660$ bazel build --nobuild --starlark_cpu_profile=/tmp/pprof.gz my/project/...
1661$ pprof /tmp/pprof.gz
1662(pprof) top
1663Type: CPU
1664Time: Feb 6, 2020 at 12:06pm (PST)
1665Duration: 5.26s, Total samples = 3.34s (63.55%)
1666Showing nodes accounting for 3.34s, 100% of 3.34s total
1667 flat flat% sum% cum cum%
1668 1.86s 55.69% 55.69% 1.86s 55.69% sort_source_files
1669 1.02s 30.54% 86.23% 1.02s 30.54% expand_all_combinations
1670 0.44s 13.17% 99.40% 0.44s 13.17% range
1671 0.02s 0.6% 100% 3.34s 100% sorted
1672 0 0% 100% 1.38s 41.32% my/project/main/BUILD
1673 0 0% 100% 1.96s 58.68% my/project/library.bzl
1674 0 0% 100% 3.34s 100% main
1675</pre>
1676<p>
1677 For different views of the same data, try the <code>pprof</code> commands <code>svg</code>,
1678 <code>web</code>, and <code>list</code>.
1679</p>
1680
David Chen8fe82a32016-08-24 10:55:41 +00001681<h2 id='bazel-releng'>Using Bazel for releases</h2>
1682<p>
1683 Bazel is used both by software engineers during the development
1684 cycle, and by release engineers when preparing binaries for deployment
1685 to production. This section provides a list of tips for release
1686 engineers using Bazel.
1687
1688</p>
1689
1690<h3>Significant options</h3>
1691
1692<p>
1693 When using Bazel for release builds, the same issues arise as for
1694 other scripts that perform a build, so you should read
Googler59830672019-01-03 10:33:49 -08001695 the <a href='guide.html#scripting'>scripting</a> section of this manual.
David Chen8fe82a32016-08-24 10:55:41 +00001696 In particular, the following options are strongly recommended:
1697</p>
1698<ul>
Vladimir Chebotarev66885ff2018-12-04 14:08:16 -08001699 <li><a href='guide.html#bazelrc'><code class='flag'>--bazelrc=/dev/null</code></a></li>
ccalvarinaf8b7722018-06-06 11:54:00 -07001700 <li><a href='#flag--keep_state_after_build'><code class='flag'>--nokeep_state_after_build</code></a></li>
David Chen8fe82a32016-08-24 10:55:41 +00001701</ul>
1702
1703<p>
brandjoncf0390b2020-02-20 10:37:40 -08001704 These options are also important:
David Chen8fe82a32016-08-24 10:55:41 +00001705</p>
1706
1707<ul>
1708
1709 <li><a href='#flag--package_path'><code class='flag'>--package_path</code></a></li>
1710 <li><a href='#flag--symlink_prefix'><code class='flag'>--symlink_prefix</code></a>:
1711 for managing builds for multiple configurations,
1712 it may be convenient to distinguish each build
1713 with a distinct identifier, e.g. "64bit" vs. "32bit". This option
1714 differentiates the <code>bazel-bin</code> (etc.) symlinks.
1715 </li>
1716</ul>
1717
brandjoncf0390b2020-02-20 10:37:40 -08001718<h2 id='test'>Running tests</h2>
David Chen8fe82a32016-08-24 10:55:41 +00001719<p>
1720 To build and run tests with bazel, type <code>bazel test</code> followed by
1721 the name of the test targets.
1722</p>
1723<p>
1724 By default, this command performs simultaneous build and test
1725 activity, building all specified targets (including any non-test
1726 targets specified on the command line) and testing
1727 <code>*_test</code> and <code>test_suite</code> targets as soon as
1728 their prerequisites are built, meaning that test execution is
1729 interleaved with building. Doing so usually results in significant
1730 speed gains.
1731
1732</p>
1733
1734<h3>Options for <code>bazel test</code></h3>
1735
1736<h4 id="flag--cache_test_results"><code class='flag'>--cache_test_results=(yes|no|auto)</code> (<code>-t</code>)</h4>
1737<p>
1738 If this option is set to 'auto' (the default) then Bazel will only rerun a test if any of the
1739 following conditions applies:
1740</p>
1741<ul>
1742 <li>Bazel detects changes in the test or its dependencies</li>
1743 <li>the test is marked as <code>external</code></li>
1744 <li>multiple test runs were requested with <code class='flag'>--runs_per_test</code></li>
1745 <li>the test failed.</li>
1746</ul>
1747<p>
1748 If 'no', all tests will be executed unconditionally.
1749</p>
1750<p>
1751 If 'yes', the caching behavior will be the same as auto
1752 except that it may cache test failures and test runs with
1753 <code class='flag'>--runs_per_test</code>.
1754</p>
1755<p>
1756 Note that test results are <em>always</em> saved in Bazel's output tree,
1757 regardless of whether this option is enabled, so
1758 you needn't have used <code class='flag'>--cache_test_results</code> on the
1759 prior run(s) of <code>bazel test</code> in order to get cache hits.
1760 The option only affects whether Bazel will <em>use</em> previously
1761 saved results, not whether it will save results of the current run.
1762</p>
1763<p>
1764 Users who have enabled this option by default in
1765 their <code>.bazelrc</code> file may find the
1766 abbreviations <code>-t</code> (on) or <code>-t-</code> (off)
1767 convenient for overriding the default on a particular run.
1768</p>
1769
1770<h4 id="flag--check_tests_up_to_date"><code class='flag'>--check_tests_up_to_date</code></h4>
1771<p>
1772 This option tells Bazel not to run the tests, but to merely check and report
1773 the cached test results. If there are any tests which have not been
1774 previously built and run, or whose tests results are out-of-date (e.g. because
1775 the source code or the build options have changed), then Bazel will report
1776 an error message ("test result is not up-to-date"), will record the test's
1777 status as "NO STATUS" (in red, if color output is enabled), and will return
1778 a non-zero exit code.
1779</p>
1780<p>
1781 This option also implies
1782 <code><a href="#flag--check_up_to_date">--check_up_to_date</a></code> behavior.
1783</p>
1784<p>
1785 This option may be useful for pre-submit checks.
1786</p>
1787
1788<h4 id="flag--test_verbose_timeout_warnings"><code class='flag'>--test_verbose_timeout_warnings</code></h4>
1789<p>
1790 This option tells Bazel to explicitly warn the user if a test's timeout is
Googler6d2bfa42018-09-21 10:25:21 -07001791significantly longer than the test's actual execution time. While a test's
David Chen8fe82a32016-08-24 10:55:41 +00001792timeout should be set such that it is not flaky, a test that has a highly
1793over-generous timeout can hide real problems that crop up unexpectedly.
1794</p>
1795<p>
1796For instance, a test that normally executes in a minute or two should not have
1797a timeout of ETERNAL or LONG as these are much, much too generous.
1798
1799 This option is useful to help users decide on a good timeout value or
1800 sanity check existing timeout values.
1801</p>
1802<p>
1803Note that each test shard is allotted the timeout of the entire
1804<code>XX_test</code> target. Using this option does not affect a test's timeout
1805value, merely warns if Bazel thinks the timeout could be restricted further.
1806</p>
1807
1808<h4 id='flag--test_keep_going'><code class='flag'>--[no]test_keep_going</code></h4>
1809<p>
1810 By default, all tests are run to completion. If this flag is disabled,
1811 however, the build is aborted on any non-passing test. Subsequent build steps
1812 and test invocations are not run, and in-flight invocations are canceled.
1813 Do not specify both <code class='flag'>--notest_keep_going</code> and
1814 <code class='flag'>--keep_going</code>.
1815</p>
1816
1817<h4 id='flag--flaky_test_attempts'><code class='flag'>--flaky_test_attempts <var>attempts</var></code></h4>
1818<p>
1819 This option specifies the maximum number of times a test should be attempted
1820 if it fails for any reason. A test that initially fails but eventually
1821 succeeds is reported as <code>FLAKY</code> on the test summary. It is,
1822 however, considered to be passed when it comes to identifying Bazel exit code
1823 or total number of passed tests. Tests that fail all allowed attempts are
1824 considered to be failed.
1825</p>
1826<p>
1827 By default (when this option is not specified, or when it is set to
1828 &quot;default&quot;), only a single attempt is allowed for regular tests, and
1829 3 for test rules with the <code>flaky</code> attribute set. You can specify
1830 an integer value to override the maximum limit of test attempts. Bazel allows
1831 a maximum of 10 test attempts in order to prevent abuse of the system.
1832</p>
1833
1834<h4 id='flag--runs_per_test'><code class='flag'>--runs_per_test <var>[regex@]number</var></code></h4>
1835<p>
1836 This option specifies the number of times each test should be executed. All
1837 test executions are treated as separate tests (e.g. fallback functionality
1838 will apply to each of them independently).
1839</p>
1840<p>
1841 The status of a target with failing runs depends on the value of the
1842 <code>--runs_per_test_detects_flakes</code> flag:
1843</p>
1844<ul>
1845 <li>If absent, any failing run causes the entire test to fail.</li>
1846 <li>If present and two runs from the same shard return PASS and FAIL, the test
1847 will receive a status of flaky (unless other failing runs cause it to
1848 fail).</li>
1849</ul>
1850
1851<p>
1852 If a single number is specified, all tests will run that many times.
1853 Alternatively, a regular expression may be specified using the syntax
1854 regex@number. This constrains the effect of --runs_per_test to targets
1855 which match the regex (e.g. "--runs_per_test=^//pizza:.*@4" runs all tests
1856 under //pizza/ 4 times).
1857 This form of --runs_per_test may be specified more than once.
1858</p>
1859
1860<h4 id='flag--runs_per_test_detects_flakes'><code
1861 class='flag'>--[no]runs_per_test_detects_flakes</code></h4>
1862<p>
1863 If this option is specified (by default it is not), Bazel will detect flaky
1864 test shards through --runs_per_test. If one or more runs for a single shard
1865 fail and one or more runs for the same shard pass, the target will be
1866 considered flaky with the flag. If unspecified, the target will report a
1867 failing status.
1868</p>
1869
1870<h4 id='flag--test_summary'><code class='flag'>--test_summary <var>output_style</var></code></h4>
1871<p>
1872 Specifies how the test result summary should be displayed.
1873</p>
1874<ul>
1875 <li><code>short</code> prints the results of each test along with the name of
1876 the file containing the test output if the test failed. This is the default
1877 value.
1878 </li>
1879 <li><code>terse</code> like <code>short</code>, but even shorter: only print
1880 information about tests which did not pass.
1881 </li>
1882 <li><code>detailed</code> prints each individual test case that failed, not
1883 only each test. The names of test output files are omitted.
1884 </li>
1885 <li><code>none</code> does not print test summary.
1886 </li>
1887</ul>
1888
1889<h4 id='flag--test_output'><code class='flag'>--test_output <var>output_style</var></code></h4>
1890<p>
1891 Specifies how test output should be displayed:
1892</p>
1893<ul>
1894 <li><code>summary</code> shows a summary of whether each test passed or
1895 failed. Also shows the output log file name for failed tests. The summary
1896 will be printed at the end of the build (during the build, one would see
1897 just simple progress messages when tests start, pass or fail).
1898 This is the default behavior.
1899 </li>
1900 <li><code>errors</code> sends combined stdout/stderr output from failed tests
1901 only into the stdout immediately after test is completed, ensuring that
1902 test output from simultaneous tests is not interleaved with each other.
1903 Prints a summary at the build as per summary output above.
1904 </li>
1905 <li><code>all</code> is similar to <code>errors</code> but prints output for
1906 all tests, including those which passed.
1907 </li>
1908 <li><code>streamed</code> streams stdout/stderr output from each test in
1909 real-time.
1910
1911 </li>
1912</ul>
1913
1914<h4 id='flag--java_debug'><code class='flag'>--java_debug</code></h4>
1915<p>
1916 This option causes the Java virtual machine of a java test to wait for a connection from a
1917 JDWP-compliant debugger before starting the test. This option implies --test_output=streamed.
1918</p>
1919
1920<h4 id='flag--verbose_test_summary'><code class='flag'>--[no]verbose_test_summary</code></h4>
1921<p>
1922 By default this option is enabled, causing test times and other additional
1923 information (such as test attempts) to be printed to the test summary. If
1924 <code class='flag'>--noverbose_test_summary</code> is specified, test summary will
1925 include only test name, test status and cached test indicator and will
1926 be formatted to stay within 80 characters when possible.
1927</p>
1928
1929<h4 id='flag--test_tmpdir'><code class='flag'>--test_tmpdir <var>path</var></code></h4>
1930<p>
1931 Specifies temporary directory for tests executed locally. Each test will be
1932 executed in a separate subdirectory inside this directory. The directory will
1933 be cleaned at the beginning of the each <code>bazel test</code> command.
1934 By default, bazel will place this directory under Bazel output base directory.
1935 Note that this is a directory for running tests, not storing test results
1936 (those are always stored under the <code>bazel-out</code> directory).
1937</p>
1938
1939<h4 id='flag--test_timeout'>
1940 <code class='flag'>--test_timeout
1941 <var>seconds</var></code>
1942 OR
1943 <code class='flag'>--test_timeout
1944 <var>seconds</var>,<var>seconds</var>,<var>seconds</var>,<var>seconds</var>
1945 </code>
1946</h4>
1947<p>
1948 Overrides the timeout value for all tests by using specified number of
1949 seconds as a new timeout value. If only one value is provided, then it will
1950 be used for all test timeout categories.
1951 </p>
1952 <p>
1953 Alternatively, four comma-separated values may be provided, specifying
1954 individual timeouts for short, moderate, long and eternal tests (in that
1955 order).
1956 In either form, zero or a negative value for any of the test sizes will
1957 be substituted by the default timeout for the given timeout categories as
1958 defined by the page
1959 <a href="test-encyclopedia.html">Writing Tests</a>.
1960 By default, Bazel will use these timeouts for all tests by
1961 inferring the timeout limit from the test's size whether the size is
1962 implicitly or explicitly set.
1963</p>
1964<p>
1965 Tests which explicitly state their timeout category as distinct from their
1966 size will receive the same value as if that timeout had been implicitly set by
1967 the size tag. So a test of size 'small' which declares a 'long' timeout will
1968 have the same effective timeout that a 'large' tests has with no explicit
1969 timeout.
1970</p>
1971
1972<h4 id='flag--test_arg'><code class='flag'>--test_arg <var>arg</var></code></h4>
1973<p>
Michael Staib3df106e2017-02-23 23:08:40 +00001974 Passes command-line options/flags/arguments to each test process. This
David Chen8fe82a32016-08-24 10:55:41 +00001975 option can be used multiple times to pass several arguments, e.g.
1976 <code class='flag'>--test_arg=--logtostderr --test_arg=--v=3</code>.
1977</p>
1978
1979<h4 id='flag--test_env'><code class='flag'>--test_env <var>variable</var>=<i>value</i></code>
1980 OR
1981 <code class='flag'>--test_env <var>variable</var></code></h4>
1982<p>
1983 Specifies additional variables that must be injected into the test
1984 environment for each test. If <var>value</var> is not specified it will be
1985 inherited from the shell environment used to start the <code>bazel test</code>
1986 command.
1987</p>
1988<p>
1989 The environment can be accessed from within a test by using
1990 <code>System.getenv("var")</code> (Java),
1991 <code>getenv("var")</code> (C or C++),
1992
1993</p>
1994
1995<h4 id="flag--run_under"><code class='flag'>--run_under=<var>command-prefix</var></code></h4>
1996<p>
1997 This specifies a prefix that the test runner will insert in front
1998 of the test command before running it. The
1999 <var>command-prefix</var> is split into words using Bourne shell
2000 tokenization rules, and then the list of words is prepended to the
2001 command that will be executed.
2002</p>
2003<p>
Googlera0f79b12018-11-29 06:31:16 -08002004 If the first word is a fully-qualified label (i.e. starts with
David Chen8fe82a32016-08-24 10:55:41 +00002005 <code>//</code>) it is built. Then the label is substituted by the
2006 corresponding executable location that is prepended to the command
2007 that will be executed along with the other words.
2008</p>
2009
2010<p>
2011Some caveats apply:
2012</p>
2013<ul>
2014 <li>
2015 The PATH used for running tests may be different than the PATH in your environment,
2016 so you may need to use an <b>absolute path</b> for the <code class='flag'>--run_under</code>
2017 command (the first word in <var>command-prefix</var>).
2018 </li>
2019 <li>
2020 <b><code>stdin</code> is not connected</b>, so <code class='flag'>--run_under</code>
2021 can't be used for interactive commands.
2022 </li>
2023
2024</ul>
2025<p>
2026Examples:
2027</p>
2028<pre>
David Chen8fe82a32016-08-24 10:55:41 +00002029 --run_under=/usr/bin/strace
2030 --run_under='/usr/bin/strace -c'
ckennellyaee19e12020-04-15 10:15:47 -07002031 --run_under=/usr/bin/valgrind
David Chen8fe82a32016-08-24 10:55:41 +00002032 --run_under='/usr/bin/valgrind --quiet --num-callers=20'
David Chen8fe82a32016-08-24 10:55:41 +00002033</pre>
2034
2035<h4>Test selection</h4>
2036<p>
2037 As documented under <a href='#output-selection-options'>Output selection options</a>,
2038 you can filter tests by <a href='#flag--test_size_filters'>size</a>,
2039 <a href='#flag--test_timeout_filters'>timeout</a>,
2040 <a href='#flag--test_tag_filters'>tag</a>, or
2041 <a href='#flag--test_lang_filters'>language</a>. A convenience
2042 <a href='#flag--test_filter'>general name filter</a> can forward particular
2043 filter args to the test runner.
2044</p>
2045
kchodorowfae5c742017-03-28 16:53:24 +00002046<h4 id="other_options_for_bazel_test">Other options for <code>bazel test</code></h4>
David Chen8fe82a32016-08-24 10:55:41 +00002047<p>
2048 The syntax and the remaining options are exactly like
Googler59830672019-01-03 10:33:49 -08002049 <a href='guide.html#build'>bazel build</a>.
David Chen8fe82a32016-08-24 10:55:41 +00002050</p>
2051
2052
brandjoncf0390b2020-02-20 10:37:40 -08002053<h3 id='clean'>Cleaning build outputs</h3>
laurentlbc85de9c2018-11-05 08:30:36 -08002054
2055<h4>The <code>clean</code> command</h4>
2056
2057<p>
2058 Bazel has a <code>clean</code> command, analogous to that of Make.
2059 It deletes the output directories for all build configurations performed
2060 by this Bazel instance, or the entire working tree created by this
2061 Bazel instance, and resets internal caches. If executed without any
2062 command-line options, then the output directory for all configurations
2063 will be cleaned.
2064</p>
2065
2066<p>Recall that each Bazel instance is associated with a single workspace, thus the
2067 <code>clean</code> command will delete all outputs from all builds you've done
2068 with that Bazel instance in that workspace.
2069</p>
2070<p>
2071 To completely remove the entire working tree created by a Bazel
2072 instance, you can specify the <code class='flag'>--expunge</code> option. When
2073 executed with <code class='flag'>--expunge</code>, the clean command simply
2074 removes the entire output base tree which, in addition to the build
2075 output, contains all temp files created by Bazel. It also
2076 stops the Bazel server after the clean, equivalent to the <a
2077 href='#shutdown'><code>shutdown</code></a> command. For example, to
2078 clean up all disk and memory traces of a Bazel instance, you could
2079 specify:
2080</p>
2081<pre>
2082 % bazel clean --expunge
2083</pre>
2084<p>
2085 Alternatively, you can expunge in the background by using
2086 <code class='flag'>--expunge_async</code>. It is safe to invoke a Bazel command
2087 in the same client while the asynchronous expunge continues to run.
2088 Note, however, that this may introduce IO contention.
2089</p>
2090
2091<p>
2092 The <code>clean</code> command is provided primarily as a means of
2093 reclaiming disk space for workspaces that are no longer needed.
2094 However, we recognize that Bazel's incremental rebuilds might not be
2095 perfect; <code>clean</code> may be used to recover a consistent
2096 state when problems arise.
2097</p>
2098<p>
2099 Bazel's design is such that these problems are fixable; we consider
2100 such bugs a high priority, and will do our best fix them. If you
2101 ever find an incorrect incremental build, please file a bug report.
2102 We encourage developers to get out of the habit of
2103 using <code>clean</code> and into that of reporting bugs in the
2104 tools.
2105</p>
2106
David Chen8fe82a32016-08-24 10:55:41 +00002107
brandjoncf0390b2020-02-20 10:37:40 -08002108<h2 id='run'>Running executables</h2>
David Chen8fe82a32016-08-24 10:55:41 +00002109<p>
2110 The <code>bazel run</code> command is similar to <code>bazel build</code>, except
diamondme42913a2019-01-24 16:11:30 -08002111 it is used to build <em>and run</em> a single target. Here is a typical session:
David Chen8fe82a32016-08-24 10:55:41 +00002112</p>
2113<pre>
2114 % bazel run -- java/myapp:myapp --arg1 --arg2
2115 Welcome to Bazel
2116 INFO: Loading package: java/myapp
2117 INFO: Loading package: foo/bar
2118 INFO: Loading complete. Analyzing...
2119 INFO: Found 1 target...
2120 ...
2121 Target //java/myapp:myapp up-to-date:
2122 bazel-bin/java/myapp:myapp
2123 INFO: Elapsed time: 0.638s, Critical Path: 0.34s
2124
2125 INFO: Running command line: bazel-bin/java/myapp:myapp --arg1 --arg2
2126 Hello there
2127 $EXEC_ROOT/java/myapp/myapp
2128 --arg1
2129 --arg2
2130</pre>
2131
2132<p>
David Chen8fe82a32016-08-24 10:55:41 +00002133 Note the use of the <code>--</code>. This is needed so that Bazel
2134 does not interpret <code>--arg1</code> and <code>--arg2</code> as
2135 Bazel options, but rather as part of the command line for running the binary.
2136 (The program being run simply says hello and prints out its args.)
2137</p>
2138
diamondme42913a2019-01-24 16:11:30 -08002139<p><code>bazel run</code> is similar, but not identical, to directly invoking
lberki749e8052019-02-12 04:23:43 -08002140the binary built by Bazel and its behavior is different depending on whether the
2141binary to be invoked is a test or not.
2142
2143When the binary is not a test, the current working directory will be the
2144runfiles tree of the binary.
2145
2146When the binary is a test, the current working directory will be the exec root
2147and a good-faith attempt is made to replicate the environment tests are usually
2148run in. The emulation is not perfect, though, and tests that have multiple
2149shards cannot be run this way (the
2150<code>--test_sharding_strategy=disabled</code> command line option can be used
2151to work around this)
2152
2153The following extra environment variables are also available to the binary:
2154<ul>
2155 <li>
2156 <code>BUILD_WORKSPACE_DIRECTORY</code>: the root of the workspace where the
2157 build was run.
2158 </li>
2159 <li>
2160 <code>BUILD_WORKING_DIRECTORY</code>: the current working directory where
2161 Bazel was run from.
2162 </li>
2163</ul>
2164
2165These can be used, for example, to interpret file names on the command line in
2166a user-friendly way.
diamondme42913a2019-01-24 16:11:30 -08002167
David Chen8fe82a32016-08-24 10:55:41 +00002168<h3>Options for <code>bazel run</code></h3>
2169
2170<h4 id='flag--run_under_run'><code class='flag'>--run_under=<var>command-prefix</var></code></h4>
2171<p>
2172 This has the same effect as the <code class='flag'>--run_under</code> option for
2173 <code>bazel test</code> (<a href='#flag--run_under'>see above</a>),
2174 except that it applies to the command being run by <code>bazel
2175 run</code> rather than to the tests being run by <code>bazel test</code>
2176 and cannot run under label.
2177</p>
2178
2179<h3>Executing tests</h3>
2180
2181<p>
2182 <code>bazel run</code> can also execute test binaries, which has the effect of
lberki5a2238d2018-05-18 03:15:32 -07002183 running the test in a close approximation of the environment described at
2184 <a href='test-encyclopedia.html'>Writing Tests</a>. Note that none of the
Googlere5197f72020-02-25 16:38:17 -08002185 <code>--test_*</code> arguments have an effect when running a test in this manner except
lberki5a2238d2018-05-18 03:15:32 -07002186 <code>--test_arg</code> .
David Chen8fe82a32016-08-24 10:55:41 +00002187</p>
2188
brandjoncf0390b2020-02-20 10:37:40 -08002189<h2 id='query'>Querying the dependency graph</h2>
David Chen8fe82a32016-08-24 10:55:41 +00002190
2191<p>
2192 Bazel includes a query language for asking questions about the
juliexxiaa8082fc2018-03-15 09:58:51 -07002193 dependency graph used during the build. The query language is used
2194 by two commands: query and cquery. The major difference between the
Googler59830672019-01-03 10:33:49 -08002195 two commands is that query runs after the <a href='guide.html#loading-phase'>loading phase</a>
2196 and cquery runs after the <a href='guide.html#analysis-phase'>analysis phase</a>. These tools are an
David Chen8fe82a32016-08-24 10:55:41 +00002197 invaluable aid to many software engineering tasks.
2198</p>
2199<p>
2200 The query language is based on the idea of
2201 algebraic operations over graphs; it is documented in detail in
2202
2203 <a href="query.html">Bazel Query Reference</a>.
2204 Please refer to that document for reference, for
2205 examples, and for query-specific command-line options.
2206</p>
2207
2208<p>
2209 The query tool accepts several command-line
2210 option. <code class='flag'>--output</code> selects the output format.
2211 <code class='flag'>--[no]keep_going</code> (disabled by default) causes the query
2212 tool to continue to make progress upon errors; this behavior may be
2213 disabled if an incomplete result is not acceptable in case of errors.
2214</p>
2215<p>
wtroberts5a0cf9b2019-09-06 07:55:15 -07002216 The <code class='flag'>--[no]tool_deps</code> option,
2217 enabled by default, causes dependencies in non-target configurations to be included in the
2218 dependency graph over which the query operates.
David Chen8fe82a32016-08-24 10:55:41 +00002219
2220</p>
2221<p>
2222 The <code class='flag'>--[no]implicit_deps</code> option, enabled by default, causes
2223 implicit dependencies to be included in the dependency graph over which the query operates. An
2224 implicit dependency is one that is not explicitly specified in the BUILD file
2225 but added by bazel.
2226</p>
2227<p>
2228 Example: "Show the locations of the definitions (in BUILD files) of
2229 all genrules required to build all the tests in the PEBL tree."
2230</p>
2231<pre>
2232 bazel query --output location 'kind(genrule, deps(kind(".*_test rule", foo/bar/pebl/...)))'
2233</pre>
2234
brandjoncf0390b2020-02-20 10:37:40 -08002235<h2 id='aquery'>Querying the action graph</h2>
twerthe7fcab32018-08-09 08:03:41 -07002236
2237<b>Caution</b>: The aquery command is still experimental and its API will change.
2238
2239<p>
2240 The <code>aquery</code> command allows you to query for actions in your build graph.
2241 It operates on the post-analysis configured target graph and exposes
2242 information about actions, artifacts and their relationships.
2243</p>
2244
2245<p>
2246 The tool accepts several command-line options.
twerth420b9532018-12-14 06:16:58 -08002247 <code class='flag'>--output</code> selects the output format. The default output format
2248 (<code>text</code>) is human-readable, use <code>proto</code> or <code>textproto</code> for
2249 machine-readable format.
twerthe7fcab32018-08-09 08:03:41 -07002250 Notably, the aquery command runs on top of a regular Bazel build and inherits
2251 the set of options available during a build.
2252</p>
2253
2254<p>
2255 It supports the same set of functions that is also available to traditional
2256 <code>query</code> but <code>siblings</code>, <code>buildfiles</code> and
2257 <code>tests</code>.
2258</p>
David Chen8fe82a32016-08-24 10:55:41 +00002259
leba367d42d2019-01-10 02:30:47 -08002260<p>
2261 More details on aquery can be found <a href="aquery.html">here</a>.
2262</p>
2263
brandjoncf0390b2020-02-20 10:37:40 -08002264<h2 id='misc'>Miscellaneous commands and options</h2>
David Chen8fe82a32016-08-24 10:55:41 +00002265
brandjoncf0390b2020-02-20 10:37:40 -08002266<h3 id='help'><code>help</code></h3>
David Chen8fe82a32016-08-24 10:55:41 +00002267
2268<p>
2269 The <code>help</code> command provides on-line help. By default, it
2270 shows a summary of available commands and help topics, as shown in
Googler59830672019-01-03 10:33:49 -08002271 the <a href='guide.html#overview'><i>Bazel overview</i></a> section above.
David Chen8fe82a32016-08-24 10:55:41 +00002272 Specifying an argument displays detailed help for a particular
2273 topic. Most topics are Bazel commands, e.g. <code>build</code>
2274 or <code>query</code>, but there are some additional help topics
2275 that do not correspond to commands.
2276</p>
2277
2278<h4 id='flag--long'><code class='flag'>--[no]long</code> (<code>-l</code>)</h4>
2279<p>
2280 By default, <code>bazel help [<var>topic</var>]</code> prints only a
2281 summary of the relevant options for a topic. If
2282 the <code class='flag'>--long</code> option is specified, the type, default value
2283 and full description of each option is also printed.
2284</p>
2285
brandjoncf0390b2020-02-20 10:37:40 -08002286<h3 id='shutdown'><code>shutdown</code></h3>
David Chen8fe82a32016-08-24 10:55:41 +00002287
2288<p>
Googler59830672019-01-03 10:33:49 -08002289 Bazel server processes (see <a href='guide.html#client/server'>Client/server
David Chen8fe82a32016-08-24 10:55:41 +00002290 implementation</a>) may be stopped by using the <code>shutdown</code>
2291 command. This command causes the Bazel server to exit as soon as it
2292 becomes idle (i.e. after the completion of any builds or other
2293 commands that are currently in progress).
2294
2295 Bazel servers stop themselves after an idle timeout, so this command
2296 is rarely necessary; however, it can be useful in scripts when it is
2297 known that no further builds will occur in a given workspace.
2298</p>
2299<p>
2300 <code>shutdown</code> accepts one
2301 option, <code class='flag'>--iff_heap_size_greater_than <i>n</i></code>, which
2302 requires an integer argument (in MB). If specified, this makes the shutdown
2303 conditional on the amount of memory already consumed. This is
2304 useful for scripts that initiate a lot of builds, as any memory
2305 leaks in the Bazel server could cause it to crash spuriously on
2306 occasion; performing a conditional restart preempts this condition.
2307</p>
2308
brandjoncf0390b2020-02-20 10:37:40 -08002309<h3 id='info'><code>info</code></h3>
David Chen8fe82a32016-08-24 10:55:41 +00002310
2311<p>
2312 The <code>info</code> command prints various values associated with
2313 the Bazel server instance, or with a specific build configuration.
2314 (These may be used by scripts that drive a build.)
2315</p>
2316
2317<p>
2318 The <code>info</code> command also permits a single (optional)
2319 argument, which is the name of one of the keys in the list below.
2320 In this case, <code>bazel info <var>key</var></code> will print only
2321 the value for that one key. (This is especially convenient when
2322 scripting Bazel, as it avoids the need to pipe the result
2323 through <code>sed -ne /key:/s/key://p</code>:
2324</p>
2325
2326<h4>Configuration-independent data</h4>
2327<ul>
2328 <li><code>release</code>: the release label for this Bazel
2329 instance, or "development version" if this is not a released
2330 binary.
2331 </li>
2332 <li><code>workspace</code> the absolute path to the base workspace
2333 directory.
2334 </li>
2335 <li><code>install_base</code>: the absolute path to the installation
2336 directory used by this Bazel instance for the current user. Bazel
2337 installs its internally required executables below this directory.
2338
2339 </li>
2340 <li><code>output_base</code>: the absolute path to the base output
2341 directory used by this Bazel instance for the current user and
2342 workspace combination. Bazel puts all of its scratch and build
2343 output below this directory.
2344 </li>
2345 <li><code>execution_root</code>: the absolute path to the execution
2346 root directory under output_base. This directory is the root for all files
2347 accessible to commands executed during the build, and is the working
2348 directory for those commands. If the workspace directory is writable, a
2349 symlink named
2350
2351 <code>bazel-&lt;workspace&gt;</code>
2352 is placed there pointing to this directory.
2353 </li>
2354 <li><code>output_path</code>: the absolute path to the output
2355 directory beneath the execution root used for all files actually
2356 generated as a result of build commands. If the workspace directory is
2357 writable, a symlink named <code>bazel-out</code> is placed there pointing
2358 to this directory.
nharmataa3a7dad2020-03-30 10:42:05 -07002359 </li>
David Chen8fe82a32016-08-24 10:55:41 +00002360 <li><code>server_pid</code>: the process ID of the Bazel server
nharmataa3a7dad2020-03-30 10:42:05 -07002361 process.
2362 </li>
2363 <li><code>server_log</code>: the absolute path to the Bazel server's debug log file.
2364 This file contains debugging information for all commands over the lifetime of the
2365 Bazel server, and is intended for human consumption by Bazel developers and power users.
2366 </li>
David Chen8fe82a32016-08-24 10:55:41 +00002367 <li><code>command_log</code>: the absolute path to the command log file;
2368 this contains the interleaved stdout and stderr streams of the most recent
2369 Bazel command. Note that running <code>bazel info</code> will overwrite the
2370 contents of this file, since it then becomes the most recent Bazel command.
2371 However, the location of the command log file will not change unless you
2372 change the setting of the <code class='flag'>--output_base</code> or
2373 <code class='flag'>--output_user_root</code> options.
2374 </li>
2375
2376 <li><code>used-heap-size</code>,
Googler82085c42018-08-16 08:01:39 -07002377 <code>committed-heap-size</code>,
David Chen8fe82a32016-08-24 10:55:41 +00002378 <code>max-heap-size</code>: reports various JVM heap size
2379 parameters. Respectively: memory currently used, memory currently
2380 guaranteed to be available to the JVM from the system, maximum
2381 possible allocation.
2382 </li>
2383 <li><code>gc-count</code>, <code>gc-time</code>: The cumulative count of
2384 garbage collections since the start of this Bazel server and the time spent
2385 to perform them. Note that these values are not reset at the start of every
2386 build.
2387 </li>
2388 <li><code>package_path</code>: A colon-separated list of paths which would be
2389 searched for packages by bazel. Has the same format as the
2390 <code class='flag'>--package_path</code> build command line argument.
2391 </li>
2392</ul>
2393<p>
2394 Example: the process ID of the Bazel server.
2395</p>
2396<pre>% bazel info server_pid
23971285
2398</pre>
2399
2400<h4>Configuration-specific data</h4>
2401<p>
2402 These data may be affected by the configuration options passed
2403 to <code>bazel info</code>, for
2404 example <code class='flag'>--cpu</code>, <code class='flag'>--compilation_mode</code>,
2405 etc. The <code>info</code> command accepts all
2406 the <a href='#analysis-options'>options that control dependency
2407 analysis</a>, since some of these determine the location of the
2408 output directory of a build, the choice of compiler, etc.
2409</p>
2410<ul>
2411 <li>
2412 <code>bazel-bin</code>, <code>bazel-testlogs</code>,
2413 <code>bazel-genfiles</code>: reports the absolute path to
2414 the <code>bazel-*</code> directories in which programs generated by the
2415 build are located. This is usually, though not always, the same as
2416 the <code>bazel-*</code> symlinks created in the base workspace directory after a
2417 successful build. However, if the workspace directory is read-only,
2418 no <code>bazel-*</code> symlinks can be created. Scripts that use
2419 the value reported by <code>bazel info</code>, instead of assuming the
2420 existence of the symlink, will be more robust.
2421 </li>
2422 <li>
2423 The complete
2424 <a href='be/make-variables.html'
2425 >"Make" environment</a>. If the <code class='flag'>--show_make_env</code> flag is
2426 specified, all variables in the current configuration's "Make" environment
2427 are also displayed (e.g. <code>CC</code>, <code>GLIBC_VERSION</code>, etc).
2428 These are the variables accessed using the <code>$(CC)</code>
2429 or <code>varref("CC")</code> syntax inside BUILD files.
2430 </li>
2431</ul>
2432
2433<p>
2434 Example: the C++ compiler for the current configuration.
2435 This is the <code>$(CC)</code> variable in the "Make" environment,
2436 so the <code class='flag'>--show_make_env</code> flag is needed.
2437</p>
2438
2439<pre>
Ulf Adamse0437b12016-08-29 14:48:47 +00002440 % bazel info --show_make_env -c opt COMPILATION_MODE
2441 opt
David Chen8fe82a32016-08-24 10:55:41 +00002442</pre>
2443
2444<p>
2445 Example: the <code>bazel-bin</code> output directory for the current
2446 configuration. This is guaranteed to be correct even in cases where
2447 the <code>bazel-bin</code> symlink cannot be created for some reason
2448 (e.g. you are building from a read-only directory).
2449</p>
2450
gregce29bc5802020-05-18 11:13:41 -07002451<pre>% bazel info --cpu=piii bazel-bin
2452/var/tmp/_bazel_johndoe/fbd0e8a34f61ce5d491e3da69d959fe6/execroot/io_bazel/bazel-out/piii-opt/bin
2453% bazel info --cpu=k8 bazel-bin
2454/var/tmp/_bazel_johndoe/fbd0e8a34f61ce5d491e3da69d959fe6/execroot/io_bazel/bazel-out/k8-opt/bin
gregce2083aad2020-05-18 15:49:30 -07002455</pre>
brandjoncf0390b2020-02-20 10:37:40 -08002456<h3 id='version'><code>version</code> and <code>--version</code></h3>
David Chen8fe82a32016-08-24 10:55:41 +00002457
2458<p>
2459 The version command prints version details about the built Bazel
2460 binary, including the changelist at which it was built and the date.
2461 These are particularly useful in determining if you have the latest
2462 Bazel, or if you are reporting bugs. Some of the interesting values
2463 are:
2464</p>
2465<ul>
2466 <li><code>changelist</code>: the changelist at which this version of
2467 Bazel was released.
2468 </li>
2469 <li><code>label</code>: the release label for this Bazel
2470 instance, or "development version" if this is not a released
2471 binary. Very useful when reporting bugs.
2472 </li>
2473</ul>
2474
michajlo52a0bcf2019-08-29 08:55:21 -07002475<p>
2476 <code>bazel --version</code>, with no other args, will emit the same output as
2477 <code>bazel version --gnu_format</code>, except without the side-effect of potentially starting
brandjoncf0390b2020-02-20 10:37:40 -08002478 a Bazel server or unpacking the server archive. <code>bazel --version</code> can be run from
2479 anywhere - it does not require a workspace directory.
michajlo52a0bcf2019-08-29 08:55:21 -07002480</p>
2481
brandjoncf0390b2020-02-20 10:37:40 -08002482<h3 id='mobile-install'><code>mobile-install</code></h3>
David Chen8fe82a32016-08-24 10:55:41 +00002483<p>
2484 The <code>mobile-install</code> command installs apps to mobile devices.
2485 Currently only Android devices running ART are supported.
Alex Humesky105e6612017-01-06 19:03:10 +00002486
2487 See <a href="mobile-install.html">bazel mobile-install</a>
2488 for more information.
David Chen8fe82a32016-08-24 10:55:41 +00002489</p>
2490<p>
2491 Note that this command does not install the same thing that
2492 <code>bazel build</code> produces: Bazel tweaks the app so that it can be
2493 built, installed and re-installed quickly. This should, however, be mostly
2494 transparent to the app.
2495</p>
2496<p>
2497 The following options are supported:
2498</p>
2499<h4 id='flag--incremental'><code class='flag'>--incremental</code></h4>
2500<p>
2501 If set, Bazel tries to install the app incrementally, that is, only those
2502 parts that have changed since the last build. This cannot update resources
2503 referenced from <code>AndroidManifest.xml</code>, native code or Java
2504 resources (i.e. ones referenced by <code>Class.getResource()</code>). If these
2505 things change, this option must be omitted. Contrary to the spirit of Bazel
2506 and due to limitations of the Android platform, it is the
2507 <b>responsibility of the user</b> to know when this command is good enough and
Alex Humesky105e6612017-01-06 19:03:10 +00002508 when a full install is needed.
2509
2510 If you are using a device with Marshmallow or later, consider the
2511 <a href='#flag--split_apks'><code class='flag'>--split_apks</code></a> flag.
David Chen8fe82a32016-08-24 10:55:41 +00002512</p>
Alex Humesky105e6612017-01-06 19:03:10 +00002513<h4 id='flag--split_apks'><code class='flag'>--split_apks</code></h4>
David Chen8fe82a32016-08-24 10:55:41 +00002514<p>
Alex Humesky105e6612017-01-06 19:03:10 +00002515 Whether to use split apks to install and update the application on the device.
2516 Works only with devices with Marshmallow or later. Note that the
2517 <a href='#flag--incremental'><code class='flag'>--incremental</code></a> flag
2518 is not necessary when using <code class='flag'>--split_apks</code>.
David Chen8fe82a32016-08-24 10:55:41 +00002519</p>
Alex Humesky105e6612017-01-06 19:03:10 +00002520<h4 id='flag--start_app'><code class='flag'>--start_app</code></h4>
2521<p>
2522 Starts the app in a clean state after installing. Equivalent to
2523 <code>--start=COLD</code>.
2524</p>
Googler2b88f622017-03-16 21:52:14 +00002525<h4 id='flag--debug_app'><code class='flag'>--debug_app</code></h4>
Alex Humesky105e6612017-01-06 19:03:10 +00002526<p>
Googler2b88f622017-03-16 21:52:14 +00002527 Waits for debugger to be attached before starting the app in a clean state after installing.
2528 Equivalent to <code>--start=DEBUG</code>.
2529</p>
2530<h4 id='flag--start'><code class='flag'>--start=<i>start_type</i></code></h4>
2531<p>
2532 How the app should be started after installing it. Supported <i>start_type</i>s are:
2533 <ul>
2534 <li><code>NO</code> Does not start the app. This is the default.</li>
2535 <li><code>COLD</code> Starts the app from a clean state after install.</li>
2536 <li><code>WARM</code> Preserves and restores the application state on incremental installs.</li>
2537 <li><code>DEBUG</code> Waits for the debugger before starting the app in a clean state after install.</li>
2538 </ul>
2539 Note that if more than one of <code class='flag'>--start=<i>start_type</i></code>,
2540 <code class='flag'>--start_app</code> or
2541 <code class='flag'>--debug_app</code> is set, the last value will be used.
Alex Humesky105e6612017-01-06 19:03:10 +00002542</p>
2543<h4 id='flag--adb'><code class='flag'>--adb <var>path</var></code></h4>
2544<p>
2545 Indicates the <code>adb</code> binary to be used.
2546
2547 The default is to use the adb in the Android SDK specified by
2548 <a href='#flag--android_sdk'><code class='flag'>--android_sdk</code></a>.
2549
2550</p>
2551<h4 id='flag--adb_arg'><code class='flag'>--adb_arg <var>arg</var></code></h4>
David Chen8fe82a32016-08-24 10:55:41 +00002552<p>
2553 Extra arguments to <code>adb</code>. These come before the subcommand in the
2554 command line and are typically used to specify which device to install to.
Alex Humesky105e6612017-01-06 19:03:10 +00002555 For example, to select the Android device or emulator to use:
David Chen8fe82a32016-08-24 10:55:41 +00002556<pre>% bazel mobile-install --adb_arg=-s --adb_arg=deadbeef
2557</pre>
2558will invoke <code>adb</code> as
2559<pre>
2560adb -s deadbeef install ...
2561</pre>
Alex Humesky105e6612017-01-06 19:03:10 +00002562</p>
Alex Humesky105e6612017-01-06 19:03:10 +00002563<h4 id='flag--incremental_install_verbosity'><code class='flag'>--incremental_install_verbosity <var>number</var></code></h4>
2564<p>
2565 The verbosity for incremental install. Set to 1 for debug logging to be
2566 printed to the console.
David Chen8fe82a32016-08-24 10:55:41 +00002567</p>
2568
gregceca8ee232018-03-08 11:35:22 -08002569
brandjoncf0390b2020-02-20 10:37:40 -08002570<h3 id='dump'><code>dump</code></h3>
gregceca8ee232018-03-08 11:35:22 -08002571
2572<p>
2573 The <code>dump</code> command prints to stdout a dump of the
2574 internal state of the Bazel server. This command is intended
2575 primarily for use by Bazel developers, so the output of this command
2576 is not specified, and is subject to change.
2577</p>
2578
tomlu72642a22017-10-18 06:23:14 +02002579<p>
2580 By default, command will just print help message outlining possible
2581 options to dump specific areas of the Bazel state. In order to dump
2582 internal state, at least one of the options must be specified.
2583</p>
2584<p>
2585 Following options are supported:
2586</p>
2587<ul>
2588 <li><code class='flag'>--action_cache</code> dumps action cache content.</li>
2589 <li><code class='flag'>--packages</code> dumps package cache content.</li>
tomlu72642a22017-10-18 06:23:14 +02002590 <li><code class='flag'>--skyframe</code> dumps state of internal Bazel dependency graph.</li>
2591 <li><code class='flag'>--rules</code> dumps rule summary for each rule and aspect class,
gregceca48e9a2020-04-14 08:54:38 -07002592 including counts and action counts. This includes both native and Starlark rules.
tomlu72642a22017-10-18 06:23:14 +02002593 If memory tracking is enabled, then the rules' memory consumption is also printed.</li>
2594 <li><code class='flag'>--skylark_memory</code> dumps a
2595 <href a=https://github.com/google/pprof>pprof</href> compatible .gz file to the specified path.
2596 You must enable memory tracking for this to work.</li>
twerth700bc132018-03-05 01:32:50 -08002597 <li><code class='flag'>--action_graph=/path/to/file</code> dumps the state of
2598 the internal Bazel action graph in proto format to
2599 <code>/path/to/file</code>. You have to run (at least) the analysis phase
2600 for the targets you are interested in (for example, <code>bazel build --nobuild
2601 //foo:bar</code>). Note that this feature is still experimental, subject to
2602 change and will probably be integrated into <code>cquery</code> in the
2603 future.
2604 <li><code class='flag'>--action_graph:targets=target1,target2,...</code>
2605 filters the actions to the comma-separated list of targets when dumping the
2606 action graph.</li>
ahumeskya0f3a652018-09-17 09:23:44 -07002607 <li><code class='flag'>--action_graph:include_cmdline</code> Include the command lines of actions
2608 in the action graph dump.</li>
tomlu72642a22017-10-18 06:23:14 +02002609</ul>
2610
tomlu5af61382017-10-30 18:01:48 -04002611 <h4 id='memory-tracking'>Memory tracking</h4>
2612 <p>
2613 Some <code>dump</code> commands require memory tracking. To turn this on, you have to pass
2614 startup flags to Bazel:
2615 </p>
2616 <ul>
2617 <li><code>--host_jvm_args=-javaagent:$BAZEL/third_party/allocation_instrumenter/java-allocation-instrumenter-3.0.1.jar</code></li>
tomlu4cad14a2017-10-31 09:08:32 -04002618 <li><code>--host_jvm_args=-DRULE_MEMORY_TRACKER=1</code></li>
tomlu5af61382017-10-30 18:01:48 -04002619 </ul>
2620 <p>
Googlerbc321af2020-11-30 14:49:00 -08002621 The java-agent is checked into Bazel at
tomlu5af61382017-10-30 18:01:48 -04002622 third_party/allocation_instrumenter/java-allocation-instrumenter-3.0.1.jar, so make
Googlerbc321af2020-11-30 14:49:00 -08002623 sure you adjust <code>$BAZEL</code> for where you keep your Bazel repository.
tomlu72642a22017-10-18 06:23:14 +02002624
tomlu5af61382017-10-30 18:01:48 -04002625 Do not forget to keep passing these options to Bazel for every command or the server will
2626 restart.
2627 </p>
2628 <p>Example:</p>
2629 <pre>
2630 % bazel --host_jvm_args=-javaagent:$BAZEL/third_party/allocation_instrumenter/java-allocation-instrumenter-3.0.1.jar \
2631 --host_jvm_args=-DRULE_MEMORY_TRACKER=1 \
2632 build --nobuild &lt;targets&gt;
tomlu72642a22017-10-18 06:23:14 +02002633
tomlu5af61382017-10-30 18:01:48 -04002634 # Dump rules
2635 % bazel --host_jvm_args=-javaagent:$BAZEL/third_party/allocation_instrumenter/java-allocation-instrumenter-3.0.1.jar \
2636 --host_jvm_args=-DRULE_MEMORY_TRACKER=1 \
2637 dump --rules
tomlu72642a22017-10-18 06:23:14 +02002638
gregceca48e9a2020-04-14 08:54:38 -07002639 # Dump Starlark heap and analyze it with pprof
tomlu5af61382017-10-30 18:01:48 -04002640 % bazel --host_jvm_args=-javaagent:$BAZEL/third_party/allocation_instrumenter/java-allocation-instrumenter-3.0.1.jar \
2641 --host_jvm_args=-DRULE_MEMORY_TRACKER=1 \
2642 dump --skylark_memory=$HOME/prof.gz
2643 % pprof -flame $HOME/prof.gz
2644 </pre>
brandjoncf0390b2020-02-20 10:37:40 -08002645<h3 id='analyze-profile'><code>analyze-profile</code></h3>
tomlu72642a22017-10-18 06:23:14 +02002646
2647<p>
2648 The <code>analyze-profile</code> command analyzes data previously gathered
2649 during the build using <code class='flag'>--profile</code> option. It provides several
2650 options to either perform analysis of the build execution or export data in
2651 the specified format.
2652
2653</p>
2654<p>
2655 The following options are supported:
2656</p>
2657<ul>
Eric Cousineau334925f2020-10-14 07:12:30 -07002658 <li><code id='flag--dump'>--dump</code> displays all gathered data in a
2659 <a href='guide.html#dump-text-format'>human-readable format</a>. However,
2660 this it does not support other formats yet.</li>
tomlu72642a22017-10-18 06:23:14 +02002661</ul>
2662
2663<p>
Googler59830672019-01-03 10:33:49 -08002664 See the section on <a href='guide.html#profiling'>Troubleshooting performance by profiling</a> for
tomlu72642a22017-10-18 06:23:14 +02002665 format details and usage help.
2666
David Chen8fe82a32016-08-24 10:55:41 +00002667</p>
2668
brandjoncf0390b2020-02-20 10:37:40 -08002669<h3 id='canonicalize'><code>canonicalize-flags</code></h3>
David Chen8fe82a32016-08-24 10:55:41 +00002670
2671<p>
Eric Cousineaubb99f9d2020-10-19 18:07:27 -07002672 The <a href="https://docs.bazel.build/command-line-reference.html#canonicalize-flags-options">
2673 <code>canonicalize-flags</code></a> command, which takes a list of options for
David Chen8fe82a32016-08-24 10:55:41 +00002674 a Bazel command and returns a list of options that has the same effect. The
2675 new list of options is canonical, i.e., two lists of options with the same
2676 effect are canonicalized to the same new list.
2677</p>
2678<p>
2679 The <code class='flag'>--for_command</code> option can be used to select between different
2680 commands. At this time, only <code>build</code> and <code>test</code> are
2681 supported. Options that the given command does not support cause an error.
2682</p>
2683<p>
2684 Note that a small number of options cannot be reordered, because Bazel cannot
Eric Cousineaubb99f9d2020-10-19 18:07:27 -07002685 ensure that the effect is identical. Also note that this command
2686 <i>does not</i> expand flags from <code>--config</code>.
David Chen8fe82a32016-08-24 10:55:41 +00002687</p>
Eric Cousineaubb99f9d2020-10-19 18:07:27 -07002688<p>
2689 As an example:
2690</p>
2691<pre>
2692 % bazel canonicalize-flags -- --config=any_name --test_tag_filters="-lint"
2693 --config=any_name
2694 --test_tag_filters=-lint
2695</pre>
David Chen8fe82a32016-08-24 10:55:41 +00002696
brandjoncf0390b2020-02-20 10:37:40 -08002697<h3 id='startup_options'>Startup options</h3>
David Chen8fe82a32016-08-24 10:55:41 +00002698
2699<p>
2700 The options described in this section affect the startup of the Java
2701 virtual machine used by Bazel server process, and they apply to all
2702 subsequent commands handled by that server. If there is an already
2703 running Bazel server and the startup options do not match, it will
2704 be restarted.
2705</p>
2706<p>
2707 All of the options described in this section must be specified using the
2708 <code class='flag'>--key=value</code> or <code class='flag'>--key value</code>
2709 syntax. Also, these options must appear <i>before</i> the name of the Bazel
2710 command.
2711</p>
2712
2713<h4 id='flag--output_base'><code class='flag'>--output_base=<var>dir</var></code></h4>
2714<p>
2715 This option requires a path argument, which must specify a
2716 writable directory. Bazel will use this location to write all its
2717 output. The output base is also the key by which the client locates
2718 the Bazel server. By changing the output base, you change the server
2719 which will handle the command.
2720</p>
2721<p>
2722 By default, the output base is derived from the user's login name,
2723 and the name of the workspace directory (actually, its MD5 digest),
2724 so a typical value looks like:
2725
lberkif071a232017-12-07 04:21:34 -08002726 <code>/var/tmp/google/_bazel_johndoe/d41d8cd98f00b204e9800998ecf8427e</code>.
David Chen8fe82a32016-08-24 10:55:41 +00002727 Note that the client uses the output base to find the Bazel server
2728 instance, so if you specify a different output base in a Bazel
2729 command, a different server will be found (or started) to handle the
2730 request. It's possible to perform two concurrent builds in the same
2731 workspace directory by varying the output base.
2732</p>
2733
2734<p>For example:</p>
sxlijin90f244f2020-05-12 06:08:15 -07002735<pre><code>
2736 OUTPUT_BASE=/var/tmp/google/_bazel_johndoe/custom_output_base
laurentlbdad21ed2020-05-13 16:00:41 -07002737 % bazel --output_base $OUTPUT_BASE build //foo &amp; bazel --output_base $OUTPUT_BASE build //bar
2738</code></pre>
2739<p>
2740 In this command, the two Bazel commands run concurrently (because of
2741 the shell <code>&amp;</code> operator), each using a different Bazel
2742 server instance (because of the different output bases).
2743 In contrast, if the default output base was used in both commands,
2744 then both requests would be sent to the same server, which would
2745 handle them sequentially: building <code>//foo</code> first, followed
2746 by an incremental build of <code>//bar</code>.
2747</p>
2748<p>
2749 We recommend you do not use NFS locations for the output base, as
2750 the higher access latency of NFS will cause noticeably slower
2751 builds.
2752</p>
2753
David Chen8fe82a32016-08-24 10:55:41 +00002754<h4 id='flag--output_user_root'><code class='flag'>--output_user_root=<var>dir</var></code></h4>
2755<p>
jmmv0f8cecf2020-05-15 07:54:17 -07002756 Points to the root directory where output bases are created unless
2757 overriden with <code class='flag'>--output_base</code>. The directory
2758 must either not exist or be owned by the calling user. In the past,
2759 this was allowed to point to a directory shared among various users
2760 but it's not allowed any longer. (We can reconsider allowing this once
2761 <a href='https://github.com/bazelbuild/bazel/issues/11100'>#11100</a>
2762 is addressed.)
David Chen8fe82a32016-08-24 10:55:41 +00002763</p>
2764<p>
2765 If the <code class='flag'>--output_base</code> option is specified, it overrides
2766 using <code class='flag'>--output_user_root</code> to calculate the output base.
2767</p>
2768<p>
2769 The install base location is also calculated based on
2770 <code class='flag'>--output_user_root</code>, plus the MD5 identity of the Bazel embedded
2771 binaries.
2772</p>
2773<p>
2774 You can also use the <code class='flag'>--output_user_root</code> option to choose an
2775 alternate base location for all of Bazel's output (install base and output
2776 base) if there is a better location in your filesystem layout.
2777</p>
2778
cushon2a8b6572018-07-25 10:33:40 -07002779<a name="startup_flag--host_javabase"></a>
2780<h4 id='startup_flag--server_javabase'><code class='flag'>--server_javabase=<var>dir</var></code></h4>
Googlerba66e722017-12-04 12:15:36 -08002781<p>
2782 Specifies the Java virtual machine in which <i>Bazel itself</i> runs. The value must be a path to
2783 the directory containing a JDK or JRE. It should not be a label.
Googlera37711b2018-09-11 10:25:01 -07002784 This option should appear before any Bazel command, for example:
Googlerba66e722017-12-04 12:15:36 -08002785</p>
2786<pre>
Googler1523e3b2020-04-17 09:31:34 -07002787 % bazel --server_javabase=/usr/local/buildtools/java/jdk11 build //foo
Googlerba66e722017-12-04 12:15:36 -08002788</pre>
2789<p>
2790 This flag does <i>not</i> affect the JVMs used by Bazel subprocesses such as applications, tests,
2791 tools, and so on. Use build options <a href='#flag--javabase'>--javabase</a> or
2792 <a href='#flag--host_javabase'>--host_javabase</a> instead.
2793</p>
cushon2a8b6572018-07-25 10:33:40 -07002794<p>
2795 This flag was previously named <code>--host_javabase</code> (sometimes referred to as the
2796 'left-hand side' <code>--host_javabase</code>), but was renamed to avoid confusion with the
2797 build flag <a href='#flag--host_javabase'>--host_javabase</a> (sometimes referred to as the
2798 'right-hand side' <code>--host_javabase</code>).
2799</p>
Googlerba66e722017-12-04 12:15:36 -08002800
David Chen8fe82a32016-08-24 10:55:41 +00002801<h4 id='flag--host_jvm_args'><code class='flag'>--host_jvm_args=<var>string</var></code></h4>
2802<p>
2803 Specifies a startup option to be passed to the Java virtual machine in which <i>Bazel itself</i>
2804 runs. This can be used to set the stack size, for example:
2805</p>
2806<pre>
2807 % bazel --host_jvm_args="-Xss256K" build //foo
2808</pre>
2809<p>
2810 This option can be used multiple times with individual arguments. Note that
2811 setting this flag should rarely be needed. You can also pass a space-separated list of strings,
2812 each of which will be interpreted as a separate JVM argument, but this feature will soon be
2813 deprecated.
2814
2815</p>
2816<p>
2817 That this does <i>not</i> affect any JVMs used by
ccalvarinaf8b7722018-06-06 11:54:00 -07002818 subprocesses of Bazel: applications, tests, tools, and so on. To pass
David Chen8fe82a32016-08-24 10:55:41 +00002819 JVM options to executable Java programs, whether run by <code>bazel
2820 run</code> or on the command-line, you should use
2821 the <code>--jvm_flags</code> argument which
2822 all <code>java_binary</code> and <code>java_test</code> programs
2823 support. Alternatively for tests, use <code>bazel
2824 test --test_arg=--jvm_flags=foo ...</code>.
2825</p>
2826
2827<h4 id='flag--host_jvm_debug'><code class='flag'>--host_jvm_debug</code></h4>
2828<p>
2829 This option causes the Java virtual machine to wait for a connection
2830 from a JDWP-compliant debugger before
2831 calling the main method of <i>Bazel itself</i>. This is primarily
2832 intended for use by Bazel developers.
2833</p>
2834<p>
2835 (Please note that this does <i>not</i> affect any JVMs used by
2836 subprocesses of Bazel: applications, tests, tools, etc.)
2837</p>
2838
2839<h4 id='flag--batch'><code class='flag'>--batch</code></h4>
ccalvarinaf8b7722018-06-06 11:54:00 -07002840
David Chen8fe82a32016-08-24 10:55:41 +00002841<p>
ccalvarinaf8b7722018-06-06 11:54:00 -07002842 Batch mode causes Bazel to not use the standard client/server mode described
Googler59830672019-01-03 10:33:49 -08002843 <a href='guide.html#client/server'>above</a>, instead running a bazel java process for a
ccalvarinaf8b7722018-06-06 11:54:00 -07002844 single command, which has been used for more predictable semantics with respect
2845 to signal handling, job control, and environment variable inheritance, and is
2846 necessary for running bazel in a chroot jail.
David Chen8fe82a32016-08-24 10:55:41 +00002847</p>
2848
2849<p>
2850 Batch mode retains proper queueing semantics within the same output_base.
2851 That is, simultaneous invocations will be processed in order, without overlap.
ccalvarinaf8b7722018-06-06 11:54:00 -07002852 If a batch mode Bazel is run on a client with a running server, it first
David Chen8fe82a32016-08-24 10:55:41 +00002853 kills the server before processing the command.
2854</p>
2855
2856<p>
ccalvarinaf8b7722018-06-06 11:54:00 -07002857 Bazel will run slower in batch mode, or with the alternatives described above.
2858 This is because, among other things, the build file cache is memory-resident, so it is not
David Chen8fe82a32016-08-24 10:55:41 +00002859 preserved between sequential batch invocations.
2860 Therefore, using batch mode often makes more sense in cases where performance
2861 is less critical, such as continuous builds.
2862</p>
2863
michajlod72eb8d2019-11-19 10:58:53 -08002864<p>
2865 <i>WARNING:</i> <code class='flag'>--batch</code> is sufficiently slower than standard
2866 client/server mode. Additionally it might not support all of the features and optimizations which
2867 are made possible by a persistent Bazel server. If you're using <code class='flag'>--batch</code>
2868 for the purpose of build isolation, we recommend using the command option
2869 <code class='flag'>--nokeep_state_after_build</code>, which guarantees that no incremental
2870 in-memory state is kept between builds. In order to restart the Bazel server and JVM after a
2871 build, please explicitly do so using the "shutdown" command.
2872</p>
2873
2874
David Chen8fe82a32016-08-24 10:55:41 +00002875<h4 id='flag--max_idle_secs'><code class='flag'>--max_idle_secs <var>n</var></code></h4>
2876<p>
2877 This option specifies how long, in seconds, the Bazel server process
2878 should wait after the last client request, before it exits. The
dchaicf988cd2019-08-23 06:35:03 -07002879 default value is 10800 (3 hours). <code class='flag'>--max_idle_secs=0</code> will cause the
diamondm2decd3e2020-07-21 16:54:59 -07002880 Bazel server process to persist indefinitely. <i>NOTE:</i> this flag is only read if Bazel needs
2881 to start a new server. Changing this option will not cause the server to restart.
David Chen8fe82a32016-08-24 10:55:41 +00002882</p>
2883<p>
2884 This option may be used by scripts that invoke Bazel to ensure that
2885 they do not leave Bazel server processes on a user's machine when they
2886 would not be running otherwise.
2887 For example, a presubmit script might wish to
2888 invoke <code>bazel query</code> to ensure that a user's pending
2889 change does not introduce unwanted dependencies. However, if the
2890 user has not done a recent build in that workspace, it would be
2891 undesirable for the presubmit script to start a Bazel server just
2892 for it to remain idle for the rest of the day.
2893 By specifying a small value of <code class='flag'>--max_idle_secs</code> in the
2894 query request, the script can ensure that <i>if</i> it caused a new
2895 server to start, that server will exit promptly, but if instead
2896 there was already a server running, that server will continue to run
2897 until it has been idle for the usual time. Of course, the existing
2898 server's idle timer will be reset.
2899</p>
shreyax5f2d5642018-10-29 15:01:24 -07002900<h4 id='flag--shutdown_on_low_sys_mem'><code class='flag'>--[no]shutdown_on_low_sys_mem</code></h4>
2901<p>
2902 If enabled and <code class='flag'>--max_idle_secs</code> is set to a positive duration,
2903 after the build server has been idle for a while, shut down the server when the system is
2904 low on memory. Linux only.
2905</p>
2906<p>
2907 In addition to running an idle check corresponding to max_idle_secs, the build server will
2908 starts monitoring available system memory after the server has been idle for some time.
2909 If the available system memory becomes critically low, the server will exit.
2910</p>
David Chen8fe82a32016-08-24 10:55:41 +00002911
2912<h4 id='flag--block_for_lock'><code class='flag'>--[no]block_for_lock</code></h4>
2913<p>
2914 If enabled, Bazel will wait for other Bazel commands holding the
2915 server lock to complete before progressing. If disabled, Bazel will
2916 exit in error if it cannot immediately acquire the lock and
2917 proceed.
2918
2919 Developers might use this in presubmit checks to avoid long waits caused
2920 by another Bazel command in the same client.
2921</p>
2922
2923<h4 id='flag--io_nice_level'><code class='flag'>--io_nice_level <var>n</var></code></h4>
2924<p>
2925 Sets a level from 0-7 for best-effort IO scheduling. 0 is highest priority,
2926 7 is lowest. The anticipatory scheduler may only honor up to priority 4.
2927 Negative values are ignored.
2928</p>
2929
2930<h4 id='flag--batch_cpu_scheduling'><code class='flag'>--batch_cpu_scheduling</code></h4>
2931<p>
2932 Use <code>batch</code> CPU scheduling for Bazel. This policy is useful for
2933 workloads that are non-interactive, but do not want to lower their nice value.
2934 See 'man 2 sched_setscheduler'. This policy may provide for better system
2935 interactivity at the expense of Bazel throughput.
2936</p>
2937
2938<h3 id='misc_options'>Miscellaneous options</h3>
2939
2940<h4 id='flag--announce_rc'><code class='flag'>--[no]announce_rc</code></h4>
2941<p>
2942 Controls whether Bazel announces command options read from the bazelrc file when
2943 starting up. (Startup options are unconditionally announced.)
2944</p>
2945
2946<h4 id='flag--color'><code class='flag'>--color (yes|no|auto)</code></h4>
2947<p>
2948 This option determines whether Bazel will use colors to highlight
2949 its output on the screen.
2950</p>
2951<p>
2952 If this option is set to <code>yes</code>, color output is enabled.
2953 If this option is set to <code>auto</code>, Bazel will use color output only if
2954 the output is being sent to a terminal and the TERM environment variable
2955 is set to a value other than <code>dumb</code>, <code>emacs</code>, or <code>xterm-mono</code>.
2956 If this option is set to <code>no</code>, color output is disabled,
2957 regardless of whether the output is going to a terminal and regardless
2958 of the setting of the TERM environment variable.
2959</p>
2960
2961<h4 id='flag--config'><code class='flag'>--config <var>name</var></code></h4>
2962<p>
2963 Selects additional config section from the rc files; for the current
2964 <code>command</code>, it also pulls in the options from
Googlerc848bf32017-02-14 12:15:42 +00002965 <code>command:name</code> if such a section exists. Can be specified multiple
2966 times to add flags from several config sections. Expansions can refer to other
2967 definitions (i.e. expansions can be chained).
David Chen8fe82a32016-08-24 10:55:41 +00002968</p>
2969
2970<h4 id='flag--curses'><code class='flag'>--curses (yes|no|auto)</code></h4>
2971<p>
2972 This option determines whether Bazel will use cursor controls
2973 in its screen output. This results in less scrolling data, and a more
2974 compact, easy-to-read stream of output from Bazel. This works well with
2975 <code class='flag'>--color</code>.
2976</p>
2977<p>
2978 If this option is set to <code>yes</code>, use of cursor controls is enabled.
2979 If this option is set to <code>no</code>, use of cursor controls is disabled.
2980 If this option is set to <code>auto</code>, use of cursor controls will be
2981 enabled under the same conditions as for <code class='flag'>--color=auto</code>.
2982</p>
2983
2984<h4 id='flag--show_timestamps'><code class='flag'>--[no]show_timestamps</code></h4>
2985<p>
2986 If specified, a timestamp is added to each message generated by
2987 Bazel specifying the time at which the message was displayed.
2988</p>