blob: c2072a56767cfef1c6ce3806e3dc681bb56e609e [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
11documented in the "<a href="guide.html#target-patterns">Specifying
12targets 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,
292 which you can do by passing <code class='flag'>--linkopt=-Wl,--strip-all</code> to Bazel.
293</p>
294
295<h4 id='flag--stripopt'><code class='flag'>--stripopt <var>strip-option</var></code></h4>
296<p>
297 An additional option to pass to the <code>strip</code> command when generating
298 a <a href="be/c-cpp.html#cc_binary_implicit_outputs"><code>*.stripped</code>
299 binary</a>. The default is <code>-S -p</code>. This option can be used
300 multiple times.
301</p>
302<p>
303 Note that <code class='flag'>--stripopt</code> does not apply to the stripping of the main
304 binary with <code><a href='#flag--strip'>--strip</a>=(always|sometimes)</code>.
305</p>
306
307<h4 id='flag--fdo_instrument'><code class='flag'>--fdo_instrument <var>profile-output-dir</var></code></h4>
308<p>
309 The <code class='flag'>--fdo_instrument</code> option enables the generation of
310 FDO (feedback directed optimization) profile output when the
311 built C/C++ binary is executed. For GCC, the argument provided is used as a
312 directory prefix for a per-object file directory tree of .gcda files
313 containing profile information for each .o file.
314</p>
315<p>
316 Once the profile data tree has been generated, the profile tree
317 should be zipped up, and provided to the
318 <code class='flag'>--fdo_optimize=<var>profile-zip</var></code>
319 Bazel option to enable the FDO optimized compilation.
320
321</p>
322<p>
323 For the LLVM compiler the argument is also the directory under which the raw LLVM profile
324 data file(s) is dumped, e.g.
325 <code class='flag'>--fdo_instrument=<var>/path/to/rawprof/dir/</var></code>.
326</p>
327<p>
328 The options <code class='flag'>--fdo_instrument</code> and <code class='flag'>--fdo_optimize</code>
329 cannot be used at the same time.
330</p>
331
332<h4 id='flag--fdo_optimize'><code class='flag'>--fdo_optimize <var>profile-zip</var></code></h4>
333<p>
334 The <code class='flag'>--fdo_optimize</code> option enables the use of the
335 per-object file profile information to perform FDO (feedback
336 directed optimization) optimizations when compiling. For GCC, the argument
337 provided is the zip file containing the previously-generated file tree
338 of .gcda files containing profile information for each .o file.
339</p>
340<p>
341 Alternatively, the argument provided can point to an auto profile
342 identified by the extension .afdo.
343
344</p>
345<p>
346 Note that this option also accepts labels that resolve to source files. You
347 may need to add an <code>exports_files</code> directive to the corresponding package to
348 make the file visible to Bazel.
349</p>
350<p>
351 For the LLVM compiler the argument provided should point to the indexed LLVM
352 profile output file prepared by the llvm-profdata tool, and should have a .profdata
353 extension.
354</p>
355<p>
356 The options <code class='flag'>--fdo_instrument</code> and <code class='flag'>
357 --fdo_optimize</code> cannot be used at the same time.
358</p>
359
David Chen8fe82a32016-08-24 10:55:41 +0000360
361<h4 id='flag--output_symbol_counts'><code class='flag'>--[no]output_symbol_counts</code></h4>
362<p>
Googlerd7273272017-05-02 18:56:29 +0200363 If enabled, each gold-invoked link of a C++ executable binary will output
David Chen8fe82a32016-08-24 10:55:41 +0000364 a <i>symbol counts</i> file (via the <code>--print-symbol-counts</code> gold
Googlerd7273272017-05-02 18:56:29 +0200365 option). For each linker input, the file logs the number of symbols that were
366 defined and the number of symbols that were used in the binary.
367 This information can be used to track unnecessary link dependencies.
368 The symbol counts file is written to the binary's output path with the name
David Chen8fe82a32016-08-24 10:55:41 +0000369 <code>[targetname].sc</code>.
370</p>
371<p>
372 This option is disabled by default.
373</p>
374
375<h4 id='flag--jvmopt'><code class='flag'>--jvmopt <var>jvm-option</var></code></h4>
376<p>
377 This option allows option arguments to be passed to the Java VM. It can be used
378 with one big argument, or multiple times with individual arguments. For example:
379</p>
380<pre>
381 % bazel build --jvmopt="-server -Xms256m" java/com/example/common/foo:all
382</pre>
383<p>
384 will use the server VM for launching all Java binaries and set the
385 startup heap size for the VM to 256 MB.
386</p>
387
388<h4 id='flag--javacopt'><code class='flag'>--javacopt <var>javac-option</var></code></h4>
389<p>
390 This option allows option arguments to be passed to javac. It can be used
391 with one big argument, or multiple times with individual arguments. For example:
392</p>
393<pre>
394 % bazel build --javacopt="-g:source,lines" //myprojects:prog
395</pre>
396<p>
397 will rebuild a java_binary with the javac default debug info
398 (instead of the bazel default).
399</p>
400<p>
401 The option is passed to javac after the Bazel built-in default options for
402 javac and before the per-rule options. The last specification of
403 any option to javac wins. The default options for javac are:
404</p>
405
406<pre>
407 -source 8 -target 8 -encoding UTF-8
408</pre>
409<p>
410 Note that changing <code class='flag'>--javacopt</code> settings will force a recompilation
411 of all affected classes. Also note that javacopts parameters listed in
412 specific java_library or java_binary build rules will be placed on the javac
413 command line <em>after</em> these options.
414</p>
415
416<h5 id='-extra_checks'><code>-extra_checks[:(off|on)]</code></h5>
417
418<p>
419 This javac option enables extra correctness checks. Any problems found will
420 be presented as errors.
421 Either <code>-extra_checks</code> or <code>-extra_checks:on</code> may be used
422 to force the checks to be turned on. <code>-extra_checks:off</code> completely
423 disables the analysis.
424 When this option is not specified, the default behavior is used.
425</p>
426
427<h4 id='flag--strict_java_deps'><code class='flag'>--strict_java_deps
428 (default|strict|off|warn|error)</code></h4>
429<p>
430 This option controls whether javac checks for missing direct dependencies.
431 Java targets must explicitly declare all directly used targets as
432 dependencies. This flag instructs javac to determine the jars actually used
433 for type checking each java file, and warn/error if they are not the output
434 of a direct dependency of the current target.
435</p>
436
437<ul>
438 <li> <code>off</code> means checking is disabled.
439 </li>
440 <li> <code>warn</code> means javac will generate standard java warnings of
441 type <code>[strict]</code> for each missing direct dependency.
442 </li>
443 <li> <code>default</code>, <code>strict</code> and <code>error</code> all
444 mean javac will generate errors instead of warnings, causing the current
445 target to fail to build if any missing direct dependencies are found.
446 This is also the default behavior when the flag is unspecified.
447 </li>
448</ul>
449
brandjoncf0390b2020-02-20 10:37:40 -0800450<h3 id='semantics-options'>Build semantics</h3>
David Chen8fe82a32016-08-24 10:55:41 +0000451<p>
452 These options affect the build commands and/or the output file contents.
453</p>
454
455<h4 id='flag--compilation_mode'><code class='flag'>--compilation_mode (fastbuild|opt|dbg)</code> (-c)</h4>
456<p>
457 This option takes an argument of <code>fastbuild</code>, <code>dbg</code>
458 or <code>opt</code>, and affects various C/C++ code-generation
459 options, such as the level of optimization and the completeness of
460 debug tables. Bazel uses a different output directory for each
461 different compilation mode, so you can switch between modes without
462 needing to do a full rebuild <i>every</i> time.
463</p>
464<ul>
465 <li> <code>fastbuild</code> means build as fast as possible:
466 generate minimal debugging information (<code>-gmlt
467 -Wl,-S</code>), and don't optimize. This is the
468 default. Note: <code>-DNDEBUG</code> will <b>not</b> be set.
469 </li>
470 <li> <code>dbg</code> means build with debugging enabled (<code>-g</code>),
471 so that you can use gdb (or another debugger).
472 </li>
473 <li> <code>opt</code> means build with optimization enabled and
474 with <code>assert()</code> calls disabled (<code>-O2 -DNDEBUG</code>).
475 Debugging information will not be generated in <code>opt</code> mode
476 unless you also pass <code class='flag'>--copt -g</code>.
477 </li>
478</ul>
479
480<h4 id='flag--cpu'><code class='flag'>--cpu <var>cpu</var></code></h4>
481<p>
482This option specifies the target CPU architecture to be used for
483the compilation of binaries during the build.
484</p>
485<p>
486
487</p>
Googlerf12e8022018-09-11 07:51:31 -0700488<p>
489 Note that a particular combination of crosstool version, compiler version,
490 and target CPU is allowed only if it has been specified in the currently
491 used CROSSTOOL file.
492</p>
493
jingwen38b1fee2020-05-11 09:19:25 -0700494<h4 id='flag--action_env'>
495 <code class='flag'>--action_env=<var>VAR=VALUE</var></code>
496</h4>
497<p>
498 Specifies the set of environment variables available during the execution of all actions.
499 Variables can be either specified by name, in which case the value will be taken from the
500 invocation environment, or by the `name=value` pair which sets the value independent of the
501 invocation environment.
502
503 This `--action_env` flag can be specified multiple times. If a value is assigned to the same
504 variable across multiple `--action_env` flags, the latest assignment wins.
505</p>
David Chen8fe82a32016-08-24 10:55:41 +0000506
Benjamin Peterson0b318542017-12-04 10:46:48 -0800507<h4 id='flag--experimental_action_listener'>
508 <code class='flag'>--experimental_action_listener=<var>label</var></code>
509</h4>
510<p>
511 The <code>experimental_action_listener</code> option instructs Bazel to use
512 details from the <a href="be/extra-actions.html#action_listener"
513 ><code>action_listener</code></a> rule specified by <var>label</var> to
514 insert <a href="be/extra-actions.html#extra_action"
515 ><code>extra_actions</code></a> into the build graph.
516</p>
517
518<h4 id='flag--experimental_extra_action_top_level_only'>
519 <code class='flag'>--[no]experimental_extra_action_top_level_only</code>
520</h4>
521<p>
522 If this option is set to true, extra actions specified by the
523 <a href='#flag--experimental_action_listener'> <code>
524 --experimental_action_listener</code></a> command line option will only be
525 scheduled for top level targets.
526</p>
527
528<h4 id='flag--experimental_extra_action_filter'>
529 <code class='flag'>--experimental_extra_action_filter=<var>regex</var></code>
530</h4>
531<p>
532 The <code>experimental_extra_action_filter</code> option instructs Bazel to
533 filter the set of targets to schedule <code>extra_actions</code> for.
534</p>
535<p>
536 This flag is only applicable in combination with the
537 <a href='#flag--experimental_action_listener'
538 ><code>--experimental_action_listener</code></a> flag.
539</p>
540<p>
541 By default all <code>extra_actions</code> in the transitive closure of the
542 requested targets-to-build get scheduled for execution.
543 <code>--experimental_extra_action_filter</code> will restrict scheduling to
544 <code>extra_actions</code> of which the owner's label matches the specified
545 regular expression.
546</p>
547<p>
548 The following example will limit scheduling of <code>extra_actions</code>
549 to only apply to actions of which the owner's label contains '/bar/':
550</p>
551<pre>% bazel build --experimental_action_listener=//test:al //foo/... \
552 --experimental_extra_action_filter=.*/bar/.*
553</pre>
554
David Chen8fe82a32016-08-24 10:55:41 +0000555<h4 id='flag--host_cpu'><code class='flag'>--host_cpu <var>cpu</var></code></h4>
556<p>
557 This option specifies the name of the CPU architecture that should be
558 used to build host tools.
559</p>
560
Alex Humesky105e6612017-01-06 19:03:10 +0000561<h4 id='flag--fat_apk_cpu'><code class='flag'>--fat_apk_cpu <var>cpu[,cpu]*</var></code></h4>
562<p>
563 The CPUs to build C/C++ libraries for in the transitive <code>deps</code> of
564 <code>android_binary</code>
565
566 rules. Other C/C++ rules are not affected. For example, if a <code>cc_library</code>
567 appears in the transitive <code>deps</code> of an <code>android_binary</code> rule and a
568 <code>cc_binary</code> rule, the <code>cc_library</code> will be built at least twice:
569 once for each CPU specified with <code class='flag'>--fat_apk_cpu</code> for the
570 <code>android_binary</code> rule, and once for the CPU specified with
571 <code class='flag'>--cpu</code> for the <code>cc_binary</code> rule.
572
573<p>
574The default is <code>armeabi-v7a</code>.
575</p>
576 <p>
577 One <code>.so</code> file will be created and packaged in the APK for
578 each CPU specified with <code class='flag'>--fat_apk_cpu</code>. The name of the <code>.so</code>
579 file will be the name of the <code>android_binary</code> rule prefixed with "lib", e.g., if the name
580 of the <code>android_binary</code> is "foo", then the file will be <code>libfoo.so</code>.
581 </p>
582
583 <p>
584 Note that an Android-compatible crosstool must be selected.
585 If an <code>android_ndk_repository</code> rule is defined in the
586 WORKSPACE file, an Android-compatible crosstool is automatically selected.
587 Otherwise, the crostool can be selected using the
588 <a href='#flag--android_crosstool_top'><code class='flag'>--android_crosstool_top</code></a>
589 or <a href='#flag--crosstool_top'><code class='flag'>--crosstool_top</code></a> flags.
590 </p>
591</p>
592
David Chen8fe82a32016-08-24 10:55:41 +0000593<h4 id='flag--per_file_copt'><code class='flag'>--per_file_copt
594 <var>[+-]regex[,[+-]regex]...@option[,option]...</var></code></h4>
595<p>
596 When present, any C++ file with a label or an execution path matching one of the inclusion regex
597 expressions and not matching any of the exclusion expressions will be built
598 with the given options. The label matching uses the canonical form of the label
599 (i.e //<code>package</code>:<code>label_name</code>).
600
601 The execution path is the relative path to your workspace directory including the base name
602 (including extension) of the C++ file. It also includes any platform dependent prefixes.
603 Note, that if only one of the label or the execution path matches the options will be used.
604</p>
605<p>
606 <b>Notes</b>:
607 To match the generated files (e.g. genrule outputs)
608 Bazel can only use the execution path. In this case the regexp shouldn't start with '//'
609 since that doesn't match any execution paths. Package names can be used like this:
610 <code class='flag'>--per_file_copt=base/.*\.pb\.cc@-g0</code>. This will match every
611 <code>.pb.cc</code> file under a directory called <code>base</code>.
612</p>
613<p>
614 This option can be used multiple times.
615</p>
616<p>
617 The option is applied regardless of the compilation mode used. I.e. it is possible
618 to compile with <code class='flag'>--compilation_mode=opt</code> and selectively compile some
619 files with stronger optimization turned on, or with optimization disabled.
620</p>
621<p>
622 <b>Caveat</b>: If some files are selectively compiled with debug symbols the symbols
623 might be stripped during linking. This can be prevented by setting
624 <code class='flag'>--strip=never</code>.
625</p>
626<p>
627 <b>Syntax</b>: <code>[+-]regex[,[+-]regex]...@option[,option]...</code> Where
628 <code>regex</code> stands for a regular expression that can be prefixed with
629 a <code>+</code> to identify include patterns and with <code>-</code> to identify
630 exclude patterns. <code>option</code> stands for an arbitrary option that is passed
631 to the C++ compiler. If an option contains a <code>,</code> it has to be quoted like so
632 <code>\,</code>. Options can also contain <code>@</code>, since only the first
633 <code>@</code> is used to separate regular expressions from options.
634</p>
635<p>
636 <b>Example</b>:
637 <code class='flag'>--per_file_copt=//foo:.*\.cc,-//foo:file\.cc@-O0,-fprofile-arcs</code>
638 adds the <code>-O0</code> and the <code>-fprofile-arcs</code> options to the command
639 line of the C++ compiler for all <code>.cc</code> files in <code>//foo/</code> except
640 <code>file.cc</code>.
641</p>
642<h4 id='flag--dynamic_mode'><code class='flag'>--dynamic_mode <var>mode</var></code></h4>
643<p>
644 Determines whether C++ binaries will be linked dynamically, interacting with
645 the <a href='be/c-cpp.html#cc_binary.linkstatic'>linkstatic
646 attribute</a> on build rules.
647</p>
648
649<p>
650 Modes:
651</p>
652<ul>
653 <li><code>auto</code>: Translates to a platform-dependent mode;
654 <code>default</code> for linux and <code>off</code> for cygwin.</li>
655 <li><code>default</code>: Allows bazel to choose whether to link dynamically.
656 See <a href='be/c-cpp.html#cc_binary.linkstatic'>linkstatic</a> for more
657 information.</li>
658 <li><code>fully</code>: Links all targets dynamically. This will speed up
659 linking time, and reduce the size of the resulting binaries.
660
661 </li>
662 <li><code>off</code>: Links all targets in
663 <a href='be/c-cpp.html#cc_binary.linkstatic'>mostly static</a> mode.
664 If <code>-static</code> is set in linkopts, targets will change to fully
665 static.</li>
666</ul>
667
668<h4 id='flag--fission'><code class='flag'>--fission (yes|no|[dbg][,opt][,fastbuild])</code></h4>
669<p>
670 Enables
671
672 <a href='https://gcc.gnu.org/wiki/DebugFission'>Fission</a>,
673 which writes C++ debug information to dedicated .dwo files instead of .o files, where it would
674 otherwise go. This substantially reduces the input size to links and can reduce link times.
675
676</p>
677<p>
678 When set to <code class='flag'>[dbg][,opt][,fastbuild]</code> (example:
679 <code class='flag'>--fission=dbg,fastbuild</code>), Fission is enabled
680 only for the specified set of compilation modes. This is useful for bazelrc
681 settings. When set to <code class='flag'>yes</code>, Fission is enabled
682 universally. When set to <code class='flag'>no</code>, Fission is disabled
683 universally. Default is <code class='flag'>dbg</code>.
684</p>
685
686<h4 id='flag--force_ignore_dash_static'><code class='flag'>--force_ignore_dash_static</code></h4>
687<p>
688 If this flag is set, any <code>-static</code> options in linkopts of
689 <code>cc_*</code> rules BUILD files are ignored. This is only intended as a
690 workaround for C++ hardening builds.
691</p>
692
693<h4 id='flag--force_pic'><code class='flag'>--[no]force_pic</code></h4>
694<p>
695 If enabled, all C++ compilations produce position-independent code ("-fPIC"),
696 links prefer PIC pre-built libraries over non-PIC libraries, and links produce
697 position-independent executables ("-pie"). Default is disabled.
698</p>
699<p>
700 Note that dynamically linked binaries (i.e. <code>--dynamic_mode fully</code>)
701 generate PIC code regardless of this flag's setting. So this flag is for cases
702 where users want PIC code explicitly generated for static links.
703</p>
704
Andrew Pellegrini8d2c1662017-01-26 16:04:12 +0000705<h4 id='flag--android_resource_shrinking'><code class='flag'>--android_resource_shrinking</code></h4>
706<p>
707 Selects whether to perform resource shrinking for android_binary rules. Sets the default for the
708 <a href='be/android.html#android_binary.shrink_resources'>shrink_resources attribute</a> on
709 android_binary rules; see the documentation for that rule for further details. Defaults to off.
710</p>
711
David Chen8fe82a32016-08-24 10:55:41 +0000712<h4 id='flag--custom_malloc'><code class='flag'>--custom_malloc <var>malloc-library-target</var></code></h4>
713<p>
714 When specified, always use the given malloc implementation, overriding all
715 <code>malloc="target"</code> attributes, including in those targets that use the
716 default (by not specifying any <code>malloc</code>).
717</p>
718
719<h4 id='flag--crosstool_top'><code class='flag'>--crosstool_top <var>label</var></code></h4>
720<p>
721 This option specifies the location of the crosstool compiler suite
722 to be used for all C++ compilation during a build. Bazel will look in that
723 location for a CROSSTOOL file and uses that to automatically determine
724 settings for
725
726 <code class='flag'>--compiler</code>.
727</p>
728
729<h4 id='flag--host_crosstool_top'><code class='flag'>--host_crosstool_top <var>label</var></code></h4>
730<p>
731 If not specified, bazel uses the value of <code class='flag'>--crosstool_top</code> to compile
732 code in the host configuration, i.e., tools run during the build. The main purpose of this flag
733 is to enable cross-compilation.
734</p>
735
Cal Peyserf1a15c02017-01-17 20:26:00 +0000736<h4 id='flag--apple_crosstool_top'><code class='flag'>--apple_crosstool_top <var>label</var></code></h4>
737<p>
738 The crosstool to use for compiling C/C++ rules in the transitive <code>deps</code> of
739 objc_*, ios__*, and apple_* rules. For those targets, this flag overwrites
740 <code class='flag'>--crosstool_top</code>.
741</p>
742
Alex Humesky105e6612017-01-06 19:03:10 +0000743<h4 id='flag--android_crosstool_top'><code class='flag'>--android_crosstool_top <var>label</var></code></h4>
744<p>
745 The crosstool to use for compiling C/C++ rules in the transitive <code>deps</code> of
746 <code>android_binary</code> rules. This is useful if other targets in the
747 build require a different crosstool. The default is to use the crosstool
748 generated by the <code>android_ndk_repository</code> rule in the WORKSPACE file.
749 See also <a href='#flag--fat_apk_cpu'><code class='flag'>--fat_apk_cpu</code></a>.
750</p>
David Chen8fe82a32016-08-24 10:55:41 +0000751<h4 id='flag--compiler'><code class='flag'>--compiler <var>version</var></code></h4>
752<p>
753 This option specifies the C/C++ compiler version (e.g. <code>gcc-4.1.0</code>)
754 to be used for the compilation of binaries during the build. If you want to
755 build with a custom crosstool, you should use a CROSSTOOL file instead of
756 specifying this flag.
757</p>
758<p>
759 Note that only certain combinations of crosstool version, compiler version,
rosica25ae1992018-06-04 10:41:53 -0700760 and target CPU are allowed.
David Chen8fe82a32016-08-24 10:55:41 +0000761</p>
762
Alex Humesky105e6612017-01-06 19:03:10 +0000763<h4 id='flag--android_sdk'><code class='flag'>--android_sdk <var>label</var></code></h4>
764<p>
765 This option specifies the Android SDK/platform toolchain
766 and Android runtime library that will be used to build any Android-related
767 rule.
768
769 The Android SDK will be automatically selected if an <code>android_sdk_repository</code>
770 rule is defined in the WORKSPACE file.
771</p>
772
David Chen8fe82a32016-08-24 10:55:41 +0000773<h4 id='flag--java_toolchain'><code class='flag'>--java_toolchain <var>label</var></code></h4>
774<p>
775 This option specifies the label of the java_toolchain used to compile Java
776 source files.
777</p>
778
cushon41375ac42017-10-30 17:03:18 -0400779<h4 id='flag--host_java_toolchain'><code class='flag'>--host_java_toolchain <var>label</var></code></h4>
780<p>
781 If not specified, bazel uses the value of <code class='flag'>--java_toolchain</code> to compile
782 code in the host configuration, i.e., tools run during the build. The main purpose of this flag
783 is to enable cross-compilation.
784</p>
785
Gregg Donovanfb915e82018-02-20 09:10:21 -0800786<h4 id='flag--javabase'><code class='flag'>--javabase (<var>label</var>)</code></h4>
David Chen8fe82a32016-08-24 10:55:41 +0000787<p>
cushon7d9596c2018-07-23 13:55:14 -0700788 This option sets the <i>label</i> of the base Java installation to use for <i>bazel run</i>,
789 <i>bazel test</i>, and for Java binaries built by <code>java_binary</code> and
790 <code>java_test</code> rules. The <code>JAVABASE</code> and <code>JAVA</code>
791 <a href='be/make-variables.html'>"Make" variables</a> are derived from this option.
David Chen8fe82a32016-08-24 10:55:41 +0000792</p>
793
cushon41375ac42017-10-30 17:03:18 -0400794<h4 id='flag--host_javabase'><code class='flag'>--host_javabase <var>label</var></code></h4>
795<p>
cushon2a8b6572018-07-25 10:33:40 -0700796 This option sets the <i>label</i> of the base Java installation to use in the host configuration,
cushon7d9596c2018-07-23 13:55:14 -0700797 for example for host build tools including JavaBuilder and Singlejar.
cushon41375ac42017-10-30 17:03:18 -0400798</p>
David Chen8fe82a32016-08-24 10:55:41 +0000799<p>
800 This does not select the Java compiler that is used to compile Java
801 source files. The compiler can be selected by settings the
802 <a href="#flag--java_toolchain"><code class='flag'>--java_toolchain</code></a>
803 option.
804</p>
805
brandjoncf0390b2020-02-20 10:37:40 -0800806<h3 id='strategy-options'>Execution strategy</h3>
David Chen8fe82a32016-08-24 10:55:41 +0000807<p>
808 These options affect how Bazel will execute the build.
809 They should not have any significant effect on the output files
810 generated by the build. Typically their main effect is on the
811 speed on the build.
812</p>
813
814<h4 id='flag--spawn_strategy'><code class='flag'>--spawn_strategy <var>strategy</var></code></h4>
815<p>
816 This option controls where and how commands are executed.
817</p>
818<ul>
819
820 <li>
ulfjacka42d1892019-02-12 08:34:30 -0800821 <code>standalone</code> causes commands to be executed as local subprocesses. This value is
822 deprecated. Please use <code>local</code> instead.
David Chen8fe82a32016-08-24 10:55:41 +0000823 </li>
824 <li>
825 <code>sandboxed</code> causes commands to be executed inside a sandbox on the local machine.
826 This requires that all input files, data dependencies and tools are listed as direct
827 dependencies in the <code>srcs</code>, <code>data</code> and <code>tools</code> attributes.
828 This is the default on systems that support sandboxed execution.
829 </li>
830
ulfjacka42d1892019-02-12 08:34:30 -0800831 <li>
832 <code>local</code> causes commands to be executed as local subprocesses.
833 </li>
834
ulfjacka42d1892019-02-12 08:34:30 -0800835 <li>
Dave Leebc67b362019-10-02 04:29:41 -0700836 <code>worker</code> causes commands to be executed using a persistent worker, if available.
837 </li>
838
839 <li>
ulfjacka42d1892019-02-12 08:34:30 -0800840 <code>docker</code> causes commands to be executed inside a docker sandbox on the local machine.
841 This requires that docker is installed.
842 </li>
843
844 <li>
845 <code>remote</code> causes commands to be executed remotely; this is only available if a
846 remote executor has been configured separately.
847 </li>
ulfjacka42d1892019-02-12 08:34:30 -0800848</ul>
849
850<h4 id='flag--strategy'><code class='flag'>--strategy <var>mnemonic</var>=<var>strategy</var></code></h4>
851<p>
852 This option controls where and how commands are executed, overriding the default setting on a
853 per-mnemonic basis. See
854 <code class='flag'><a href="#flag--spawn_strategy">--spawn_strategy</a></code> for the supported
855 strategies and their effects.
856</p>
857
858<h4 id='flag--strategy_regexp'><code class='flag'>--strategy_regexp <var>&lt;filter,filter,...&gt;=&lt;strategy&gt;</var></code></h4>
859<p>
860 This option specifies which strategy should be used to execute commands that have descriptions
861 matching a certain <code>regex_filter</code>. See
862 <code class='flag'><a href="#flag--per_file_copt">--per_file_copt</a></code> for details on
863 regex_filter matching. See
864 <code class='flag'><a href="#flag--spawn_strategy">--spawn_strategy</a></code> for the supported
865 strategies and their effects.
866</p>
867<p>
868The first <code>regex_filter</code> that matches the description is used. This option overrides
869other flags for specifying strategy.
870</p>
871<ul>
872 <li>
873 Example: <code>--strategy_regexp=//foo.*\\.cc,-//foo/bar=local</code> means to run actions using
874 <code>local</code> strategy if their descriptions match //foo.*.cc but not //foo/bar.
875 </li>
876 <li>
877 Example:
878 <code>--strategy_regexp='Compiling.*/bar=local' --strategy_regexp=Compiling=sandboxed</code>
879 will run 'Compiling //foo/bar/baz' with the <code>local</code> strategy, but reversing the order
880 would run it with <code>sandboxed</code>.
881 </li>
David Chen8fe82a32016-08-24 10:55:41 +0000882</ul>
883
884<h4 id='flag--genrule_strategy'><code class='flag'>--genrule_strategy <var>strategy</var></code></h4>
885<p>
ulfjacka42d1892019-02-12 08:34:30 -0800886 This is a deprecated short-hand for
887 <code class='flag'>--strategy=Genrule=<var>strategy</var></code>.
David Chen8fe82a32016-08-24 10:55:41 +0000888</p>
David Chen8fe82a32016-08-24 10:55:41 +0000889
David Chen8fe82a32016-08-24 10:55:41 +0000890<h4 id='flag--jobs'><code class='flag'>--jobs <var>n</var></code> (-j)</h4>
891<p>
892 This option, which takes an integer argument, specifies a limit on
893 the number of jobs that should be executed concurrently during the
Googlerb6857d52017-09-22 14:03:21 -0400894 execution phase of the build.
David Chen8fe82a32016-08-24 10:55:41 +0000895</p>
896<p>
897 Note that the number of concurrent jobs that Bazel will run
898 is determined not only by the <code class='flag'>--jobs</code> setting, but also
899 by Bazel's scheduler, which tries to avoid running concurrent jobs
900 that will use up more resources (RAM or CPU) than are available,
901 based on some (very crude) estimates of the resource consumption
902 of each job. The behavior of the scheduler can be controlled by
steinman7f530c82020-04-15 14:13:42 -0700903 the <code class='flag'>--local_ram_resources</code> option.
David Chen8fe82a32016-08-24 10:55:41 +0000904</p>
905
906<h4 id='flag--progress_report_interval'><code class='flag'>--progress_report_interval <var>n</var></code></h4>
907<p>
908
909 Bazel periodically prints a progress report on jobs that are not
910 finished yet (e.g. long running tests). This option sets the
911 reporting frequency, progress will be printed every <code>n</code>
912 seconds.
913</p>
914<p>
915 The default is 0, that means an incremental algorithm: the first
916 report will be printed after 10 seconds, then 30 seconds and after
917 that progress is reported once every minute.
918</p>
919
steinmancd1783d2019-03-08 08:09:42 -0800920<h4 id='flag--local_{ram,cpu}_resources'><code class='flag'>--local_{ram,cpu}_resources</code>
921 <var>resources or resource expression</var></h4>
David Chen8fe82a32016-08-24 10:55:41 +0000922<p>
steinmancd1783d2019-03-08 08:09:42 -0800923 These options specify the amount of local resources (RAM in MB and number of CPU logical cores)
924 that Bazel can take into consideration when scheduling build and test activities. They take
925 an integer, or a keyword (HOST_RAM or HOST_CPUS) optionally followed by [-|*<float>float</float>]
926 (for example, <code class='flag'>--local_cpu_resources=2</code>,
927 <code class='flag'>--local_ram_resources=HOST_RAM*.5</code>,
928 <code class='flag'>--local_cpu_resources=HOST_CPUS-1</code>).
929 The flags are independent; one or both may be set. By default Bazel will estimate amount of RAM
930 and number of CPU cores directly from system configuration.
David Chen8fe82a32016-08-24 10:55:41 +0000931</p>
David Chen8fe82a32016-08-24 10:55:41 +0000932
933<h4 id='flag--build_runfile_links'><code class='flag'>--[no]build_runfile_links</code></h4>
934<p>
Googler5a495842017-08-22 01:30:36 +0200935 This option, which is enabled by default, specifies whether the runfiles
936 symlinks for tests and binaries should be built in the output directory.
David Chen8fe82a32016-08-24 10:55:41 +0000937 Using <code class='flag'>--nobuild_runfile_links</code> can be useful
938 to validate if all targets compile without incurring the overhead
939 for building the runfiles trees.
940
David Chen8fe82a32016-08-24 10:55:41 +0000941</p>
942
943<p>
Googler5a495842017-08-22 01:30:36 +0200944 When tests (or applications) are executed, their run-time data
945 dependencies are gathered together in one place. Within Bazel's
946 output tree, this "runfiles" tree is typically rooted as a sibling of
947 the corresponding binary or test.
948 During test execution, runfiles may be accessed using paths of the form
David Chen8fe82a32016-08-24 10:55:41 +0000949 <code>$TEST_SRCDIR/workspace/<var>packagename</var>/<var>filename</var></code>.
Googler5a495842017-08-22 01:30:36 +0200950 The runfiles tree ensures that tests have access to all the files
David Chen8fe82a32016-08-24 10:55:41 +0000951 upon which they have a declared dependence, and nothing more. By
952 default, the runfiles tree is implemented by constructing a set of
953 symbolic links to the required files. As the set of links grows, so
954 does the cost of this operation, and for some large builds it can
955 contribute significantly to overall build time, particularly because
956 each individual test (or application) requires its own runfiles tree.
957</p>
David Chen8fe82a32016-08-24 10:55:41 +0000958
Googler01f659d2017-08-22 02:53:02 +0200959<h4 id='flag--build_runfile_manifests'><code class='flag'>--[no]build_runfile_manifests</code></h4>
960<p>
961 This option, which is enabled by default, specifies whether runfiles manifests
962 should be written to the output tree.
963 Disabling it implies <code class='flag'>--nobuild_runfile_links</code>.
964
Tobias Werth78e27f42019-08-12 00:49:58 -0700965 It can be disabled when executing tests remotely, as runfiles trees will
Googler01f659d2017-08-22 02:53:02 +0200966 be created remotely from in-memory manifests.
967
David Chen8fe82a32016-08-24 10:55:41 +0000968<h4 id='flag--discard_analysis_cache'>
969 <code class='flag'>--[no]discard_analysis_cache</code></h4>
970<p>
971 When this option is enabled, Bazel will discard the analysis cache
972 right before execution starts, thus freeing up additional memory
Googler59830672019-01-03 10:33:49 -0800973 (around 10%) for the <a href="guide.html#execution-phase">execution phase</a>.
janakr428c5e12019-05-06 15:35:54 -0700974 The drawback is that further incremental builds will be slower. See also
janakr69781dd52019-05-07 09:04:41 -0700975 <a href="/versions/{{ current_version }}/memory-saving-mode.html">
Googlera05b7f02019-05-21 08:13:04 -0700976memory-saving mode</a>.
David Chen8fe82a32016-08-24 10:55:41 +0000977</p>
978
979<h4 id='flag--keep_going'><code class='flag'>--[no]keep_going</code> (-k)</h4>
980<p>
981 As in GNU Make, the execution phase of a build stops when the first
982 error is encountered. Sometimes it is useful to try to build as
983 much as possible even in the face of errors. This option enables
984 that behavior, and when it is specified, the build will attempt to
985 build every target whose prerequisites were successfully built, but
986 will ignore errors.
987</p>
988<p>
989 While this option is usually associated with the execution phase of
990 a build, it also effects the analysis phase: if several targets are
991 specified in a build command, but only some of them can be
992 successfully analyzed, the build will stop with an error
993 unless <code class='flag'>--keep_going</code> is specified, in which case the
994 build will proceed to the execution phase, but only for the targets
995 that were successfully analyzed.
996</p>
997
David Chen8fe82a32016-08-24 10:55:41 +0000998<h4 id='flag--use_ijars'><code class='flag'>--[no]use_ijars</code></h4>
999<p>
1000 This option changes the way <code>java_library</code> targets are
1001 compiled by Bazel. Instead of using the output of a
1002 <code>java_library</code> for compiling dependent
1003 <code>java_library</code> targets, Bazel will create interface jars
1004 that contain only the signatures of non-private members (public,
1005 protected, and default (package) access methods and fields) and use
1006 the interface jars to compile the dependent targets. This makes it
1007 possible to avoid recompilation when changes are only made to
1008 method bodies or private members of a class.
1009</p>
1010<p>
1011 Note that using <code class='flag'>--use_ijars</code> might give you a different
1012 error message when you are accidentally referring to a non visible
1013 member of another class: Instead of getting an error that the member
1014 is not visible you will get an error that the member does not exist.
1015</p>
1016<p>
1017 Note that changing the <code class='flag'>--use_ijars</code> setting will force
1018 a recompilation of all affected classes.
1019</p>
1020
1021<h4 id='flag--interface_shared_objects'>
1022 <code class='flag'>--[no]interface_shared_objects</code>
1023</h4>
1024<p>
1025 This option enables <i>interface shared objects</i>, which makes binaries and
1026 other shared libraries depend on the <i>interface</i> of a shared object,
1027 rather than its implementation. When only the implementation changes, Bazel
1028 can avoid rebuilding targets that depend on the changed shared library
1029 unnecessarily.
1030</p>
1031
brandjoncf0390b2020-02-20 10:37:40 -08001032<h3 id='output-selection-options'>Output selection</h3>
David Chen8fe82a32016-08-24 10:55:41 +00001033<p>
1034 These options determine what to build or test.
1035</p>
1036
1037<h4 id="nobuild"><code class='flag'>--[no]build</code></h4>
1038<p>
1039 This option causes the execution phase of the build to occur; it is
1040 on by default. When it is switched off, the execution phase is
1041 skipped, and only the first two phases, loading and analysis, occur.
1042</p>
1043<p>
1044 This option can be useful for validating BUILD files and detecting
1045 errors in the inputs, without actually building anything.
1046</p>
1047
1048<h4 id='flag--build_tests_only'><code class='flag'>--[no]build_tests_only</code></h4>
1049<p>
1050 If specified, Bazel will build only what is necessary to run the *_test
1051 and test_suite rules that were not filtered due to their
1052 <a href='#flag--test_size_filters'>size</a>,
1053 <a href='#flag--test_timeout_filters'>timeout</a>,
1054 <a href='#flag--test_tag_filters'>tag</a>, or
1055 <a href='#flag--test_lang_filters'>language</a>.
1056 If specified, Bazel will ignore other targets specified on the command line.
1057 By default, this option is disabled and Bazel will build everything
1058 requested, including *_test and test_suite rules that are filtered out from
1059 testing. This is useful because running
1060 <code>bazel test --build_tests_only foo/...</code> may not detect all build
1061 breakages in the <code>foo</code> tree.
1062</p>
1063
1064<h4 id='flag--check_up_to_date'><code class='flag'>--[no]check_up_to_date</code></h4>
1065<p>
1066 This option causes Bazel not to perform a build, but merely check
1067 whether all specified targets are up-to-date. If so, the build
1068 completes successfully, as usual. However, if any files are out of
1069 date, instead of being built, an error is reported and the build
1070 fails. This option may be useful to determine whether a build has
1071 been performed more recently than a source edit (e.g. for pre-submit
1072 checks) without incurring the cost of a build.
1073</p>
1074<p>
1075 See also <a href="#flag--check_tests_up_to_date"><code class='flag'>--check_tests_up_to_date</code></a>.
1076</p>
1077
1078<h4 id='flag--compile_one_dependency'><code class='flag'>--[no]compile_one_dependency</code></h4>
1079<p>
1080 Compile a single dependency of the argument files. This is useful for
1081 syntax checking source files in IDEs, for example, by rebuilding a single
1082 target that depends on the source file to detect errors as early as
1083 possible in the edit/build/test cycle. This argument affects the way all
1084 non-flag arguments are interpreted: for each source filename, one
1085 rule that depends on it will be built. For
1086
1087 C++ and Java
1088 sources, rules in the same language space are preferentially chosen. For
1089 multiple rules with the same preference, the one that appears first in the
1090 BUILD file is chosen. An explicitly named target pattern which does not
1091 reference a source file results in an error.
1092</p>
1093
1094<h4 id='flag--save_temps'><code class='flag'>--save_temps</code></h4>
1095<p>
Googler9cfa4cb2018-06-04 22:19:11 -07001096 The <code class='flag'>--save_temps</code> option causes temporary outputs from the compiler to be
1097 saved. These include .s files (assembler code), .i (preprocessed C) and .ii
David Chen8fe82a32016-08-24 10:55:41 +00001098 (preprocessed C++) files. These outputs are often useful for debugging. Temps will only be
1099 generated for the set of targets specified on the command line.
1100</p>
1101<p>
Googler9cfa4cb2018-06-04 22:19:11 -07001102 Note that our implementation of <code class='flag'>--save_temps</code> does not use the compiler's
David Chen8fe82a32016-08-24 10:55:41 +00001103 <code>-save-temps</code> flag. Instead, we do two passes, one with <code>-S</code>
1104 and one with <code>-E</code>. A consequence of this is that if your build fails,
1105 Bazel may not yet have produced the ".i" or ".ii" and ".s" files.
1106 If you're trying to use <code class='flag'>--save_temps</code> to debug a failed compilation,
1107 you may need to also use <code class='flag'>--keep_going</code> so that Bazel will still try to
1108 produce the preprocessed files after the compilation fails.
1109</p>
1110<p>
1111 The <code class='flag'>--save_temps</code> flag currently works only for cc_* rules.
1112</p>
1113<p>
1114 To ensure that Bazel prints the location of the additional output files, check that
1115 your <a href='#flag--show_result'><code class='flag'>--show_result <var>n</var></code></a>
1116 setting is high enough.
1117</p>
1118
Googlerd9db1692017-01-05 19:34:30 +00001119<h4 id='flag--build_tag_filters'><code class='flag'>--build_tag_filters <var>tag[,tag]*</var></code></h4>
1120<p>
1121 If specified, Bazel will build only targets that have at least one required tag
1122 (if any of them are specified) and does not have any excluded tags. Build tag
1123 filter is specified as comma delimited list of tag keywords, optionally
1124 preceded with '-' sign used to denote excluded tags. Required tags may also
1125 have a preceding '+' sign.
1126</p>
1127
David Chen8fe82a32016-08-24 10:55:41 +00001128<h4 id='flag--test_size_filters'><code class='flag'>--test_size_filters <var>size[,size]*</var></code></h4>
1129<p>
1130 If specified, Bazel will test (or build if <code class='flag'>--build_tests_only</code>
1131 is also specified) only test targets with the given size. Test size filter
1132 is specified as comma delimited list of allowed test size values (small,
1133 medium, large or enormous), optionally preceded with '-' sign used to denote
1134 excluded test sizes. For example,
1135</p>
1136<pre>
1137 % bazel test --test_size_filters=small,medium //foo:all
1138</pre>
1139 and
1140<pre>
1141 % bazel test --test_size_filters=-large,-enormous //foo:all
1142</pre>
1143<p>
1144 will test only small and medium tests inside //foo.
1145</p>
1146<p>
1147 By default, test size filtering is not applied.
1148</p>
1149
1150<h4 id='flag--test_timeout_filters'><code class='flag'>--test_timeout_filters <var>timeout[,timeout]*</var></code></h4>
1151<p>
1152 If specified, Bazel will test (or build if <code class='flag'>--build_tests_only</code>
1153 is also specified) only test targets with the given timeout. Test timeout filter
1154 is specified as comma delimited list of allowed test timeout values (short,
1155 moderate, long or eternal), optionally preceded with '-' sign used to denote
1156 excluded test timeouts. See <a href='#flag--test_size_filters'>--test_size_filters</a>
1157 for example syntax.
1158</p>
1159<p>
1160 By default, test timeout filtering is not applied.
1161</p>
1162
1163
1164<h4 id='flag--test_tag_filters'><code class='flag'>--test_tag_filters <var>tag[,tag]*</var></code></h4>
1165<p>
1166 If specified, Bazel will test (or build if <code class='flag'>--build_tests_only</code>
1167 is also specified) only test targets that have at least one required tag
1168 (if any of them are specified) and does not have any excluded tags. Test tag
1169 filter is specified as comma delimited list of tag keywords, optionally
1170 preceded with '-' sign used to denote excluded tags. Required tags may also
1171 have a preceding '+' sign.
1172</p>
1173<p>
1174 For example,
1175<pre>
1176 % bazel test --test_tag_filters=performance,stress,-flaky //myproject:all
1177</pre>
1178<p>
1179 will test targets that are tagged with either <code>performance</code> or
1180 <code>stress</code> tag but are <b>not</b> tagged with the <code>flaky</code>
1181 tag.
1182</p>
1183<p>
1184 By default, test tag filtering is not applied. Note that you can also filter
1185 on test's <code>size</code> and <code>local</code> tags in
1186 this manner.
1187</p>
1188
1189<h4 id='flag--test_lang_filters'><code class='flag'>--test_lang_filters <var>lang[,lang]*</var></code></h4>
1190<p>
1191 Specifies a comma-separated list of test languages for languages with an official <code>*_test</code> rule the
1192 (see <a href="be/overview.html">build encyclopedia</a> for a full list of these). Each
1193 language can be optionally preceded with '-' to specify excluded
1194 languages. The name used for each language should be the same as
1195 the language prefix in the <code>*_test</code> rule, for example,
1196 <code>cc</code>, <code>java</code> or <code>sh</code>.
1197</p>
1198<p>
1199 If specified, Bazel will test (or build if <code class='flag'>--build_tests_only</code>
1200 is also specified) only test targets of the specified language(s).
1201</p>
1202<p>
1203 For example,
1204</p>
1205<pre>
1206 % bazel test --test_lang_filters=cc,java foo/...
1207</pre>
1208<p>
1209 will test only the C/C++ and Java tests (defined using
1210 <code>cc_test</code> and <code>java_test</code> rules, respectively)
1211 in <code>foo/...</code>, while
1212</p>
1213<pre>
1214 % bazel test --test_lang_filters=-sh,-java foo/...
1215</pre>
1216<p>
1217 will run all of the tests in <code>foo/...</code> except for the
1218 <code>sh_test</code> and <code>java_test</code> tests.
1219</p>
1220<p>
1221 By default, test language filtering is not applied.
1222</p>
1223
1224<h4 id="flag--test_filter"><code class='flag'>--test_filter=<var>filter-expression</var></code></h4>
1225<p>
1226 Specifies a filter that the test runner may use to pick a subset of tests for
michajlo20971eb2020-03-12 08:00:09 -07001227 running. All targets specified in the invocation are built, but depending on
David Chen8fe82a32016-08-24 10:55:41 +00001228 the expression only some of them may be executed; in some cases, only certain
1229 test methods are run.
1230</p>
1231<p>
1232 The particular interpretation of <var>filter-expression</var> is up to
1233 the test framework responsible for running the test. It may be a glob,
1234 substring, or regexp. <code class='flag'>--test_filter</code> is a convenience
1235 over passing different <code class='flag'>--test_arg</code> filter arguments,
1236 but not all frameworks support it.
1237</p>
1238
brandjoncf0390b2020-02-20 10:37:40 -08001239<h3 id='verbosity'>Verbosity</h3>
David Chen8fe82a32016-08-24 10:55:41 +00001240
1241These options control the verbosity of Bazel's output,
1242either to the terminal, or to additional log files.
1243
1244<h4 id='flag--explain'><code class='flag'>--explain <var>logfile</var></code></h4>
1245<p>
1246 This option, which requires a filename argument, causes the
1247 dependency checker in <code>bazel build</code>'s execution phase to
1248 explain, for each build step, either why it is being executed, or
1249 that it is up-to-date. The explanation is written
1250 to <i>logfile</i>.
1251</p>
1252<p>
1253 If you are encountering unexpected rebuilds, this option can help to
1254 understand the reason. Add it to your <code>.bazelrc</code> so that
1255 logging occurs for all subsequent builds, and then inspect the log
1256 when you see an execution step executed unexpectedly. This option
1257 may carry a small performance penalty, so you might want to remove
1258 it when it is no longer needed.
1259</p>
1260
1261<h4 id='flag--verbose_explanations'><code class='flag'>--verbose_explanations</code></h4>
1262<p>
1263 This option increases the verbosity of the explanations generated
1264 when the <a href='#flag--explain'>--explain</a> option is enabled.
1265</p>
1266<p>
1267 In particular, if verbose explanations are enabled,
1268 and an output file is rebuilt because the command used to
1269 build it has changed, then the output in the explanation file will
1270 include the full details of the new command (at least for most
1271 commands).
1272</p>
1273<p>
1274 Using this option may significantly increase the length of the
1275 generated explanation file and the performance penalty of using
1276 <code class='flag'>--explain</code>.
1277</p>
1278<p>
1279 If <code class='flag'>--explain</code> is not enabled, then
1280 <code class='flag'>--verbose_explanations</code> has no effect.
1281</p>
1282
1283<h4 id='flag--profile'><code class='flag'>--profile <var>file</var></code></h4>
1284<p>
1285 This option, which takes a filename argument, causes Bazel to write
1286 profiling data into a file. The data then can be analyzed or parsed using the
1287 <code>bazel analyze-profile</code> command. The Build profile can be useful in
1288 understanding where Bazel's <code>build</code> command is spending its time.
1289</p>
1290
1291<h4 id='flag--show_loading_progress'><code class='flag'>--[no]show_loading_progress</code></h4>
1292<p>
1293 This option causes Bazel to output package-loading progress
1294 messages. If it is disabled, the messages won't be shown.
1295</p>
1296
1297<h4 id='flag--show_progress'><code class='flag'>--[no]show_progress</code></h4>
1298<p>
1299 This option causes progress messages to be displayed; it is on by
1300 default. When disabled, progress messages are suppressed.
1301</p>
1302
1303<h4 id='flag--show_progress_rate_limit'><code class='flag'>--show_progress_rate_limit
1304 <var>n</var></code></h4>
1305<p>
1306 This option causes bazel to display only
1307 one progress message per <code>n</code> seconds, where <var>n</var> is a real number.
1308 If <code>n</code> is -1, all progress messages will be displayed. The default value for
1309 this option is 0.03, meaning bazel will limit the progress messages to one per every
1310 0.03 seconds.
1311</p>
1312
1313<h4 id='flag--show_result'><code class='flag'>--show_result <var>n</var></code></h4>
1314<p>
1315 This option controls the printing of result information at the end
1316 of a <code>bazel build</code> command. By default, if a single
1317 build target was specified, Bazel prints a message stating whether
1318 or not the target was successfully brought up-to-date, and if so,
1319 the list of output files that the target created. If multiple
1320 targets were specified, result information is not displayed.
1321</p>
1322<p>
1323 While the result information may be useful for builds of a single
1324 target or a few targets, for large builds (e.g. an entire top-level
1325 project tree), this information can be overwhelming and distracting;
1326 this option allows it to be controlled. <code class='flag'>--show_result</code>
1327 takes an integer argument, which is the maximum number of targets
1328 for which full result information should be printed. By default,
1329 the value is 1. Above this threshold, no result information is
1330 shown for individual targets. Thus zero causes the result
1331 information to be suppressed always, and a very large value causes
1332 the result to be printed always.
1333</p>
1334<p>
1335 Users may wish to choose a value in-between if they regularly
1336 alternate between building a small group of targets (for example,
1337 during the compile-edit-test cycle) and a large group of targets
1338 (for example, when establishing a new workspace or running
1339 regression tests). In the former case, the result information is
1340 very useful whereas in the latter case it is less so. As with all
1341 options, this can be specified implicitly via
Vladimir Chebotarev66885ff2018-12-04 14:08:16 -08001342 the <a href='guide.html#bazelrc'><code>.bazelrc</code></a> file.
David Chen8fe82a32016-08-24 10:55:41 +00001343</p>
1344<p>
1345 The files are printed so as to make it easy to copy and paste the
1346 filename to the shell, to run built executables. The "up-to-date"
1347 or "failed" messages for each target can be easily parsed by scripts
1348 which drive a build.
1349</p>
1350
1351<h4 id='flag--subcommands'><code class='flag'>--subcommands</code> (<code>-s</code>)</h4>
1352<p>
1353 This option causes Bazel's execution phase to print the full command line
1354 for each command prior to executing it.
1355</p>
1356
1357<pre>
1358 &gt;&gt;&gt;&gt;&gt; # //examples/cpp:hello-world [action 'Linking examples/cpp/hello-world']
lberkif071a232017-12-07 04:21:34 -08001359 (cd /home/johndoe/.cache/bazel/_bazel_johndoe/4c084335afceb392cfbe7c31afee3a9f/bazel && \
David Chen8fe82a32016-08-24 10:55:41 +00001360 exec env - \
lberkicbac3282017-12-07 05:47:43 -08001361 /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 +00001362</pre>
1363<p>
1364 Where possible, commands are printed in a Bourne shell compatible syntax,
1365 so that they can be easily copied and pasted to a shell command prompt.
1366 (The surrounding parentheses are provided to protect your shell from the
1367 <code>cd</code> and <code>exec</code> calls; be sure to copy them!)
1368 However some commands are implemented internally within Bazel, such as
1369 creating symlink trees. For these there's no command line to display.
1370
1371</p>
1372
1373<p>
ahumeskybe31bb82018-07-26 13:37:45 -07001374 <code class='flag'>--subcommands=pretty_print</code> may be passed to print
1375 the arguments of the command as a list rather than as a single line. This may
1376 help make long command lines more readable.
1377</p>
1378
1379<p>
David Chen8fe82a32016-08-24 10:55:41 +00001380 See also <a href="#flag--verbose_failures">--verbose_failures</a>, below.
1381</p>
1382
1383<h4 id='flag--verbose_failures'><code class='flag'>--verbose_failures</code></h4>
1384<p>
1385 This option causes Bazel's execution phase to print the full command line
1386 for commands that failed. This can be invaluable for debugging a
1387 failing build.
1388</p>
1389<p>
1390 Failing commands are printed in a Bourne shell compatible syntax, suitable
1391 for copying and pasting to a shell prompt.
1392</p>
1393
brandjoncf0390b2020-02-20 10:37:40 -08001394<h3 id='workspace_status'>Workspace status</h3>
laszlocsomor45a0ffe2018-02-05 00:48:35 -08001395
1396<p>
1397 Use these options to "stamp" Bazel-built binaries: to embed additional information into the
1398 binaries, such as the source control revision or other workspace-related information. You can use
1399 this mechanism with rules that support the <code>stamp</code> attribute, such as
1400 <code>genrule</code>, <code>cc_binary</code>, and more.
1401</p>
1402
1403<h4 id='flag--workspace_status_command'><code class='flag'>--workspace_status_command <var>program</var></code></h4>
1404<p>
1405 This flag lets you specify a binary that Bazel runs before each build. The program can report
1406 information about the status of the workspace, such as the current source control revision.
1407</p>
1408<p>
1409 The flag's value must be a path to a native program. On Linux/macOS this may be any executable.
1410 On Windows this must be a native binary, typically an ".exe", ".bat", or a ".cmd" file.
1411</p>
1412
1413<p>
1414 The program should print zero or more key/value pairs to standard output, one entry on each line,
1415 then exit with zero (otherwise the build fails). The key names can be anything but they may only
1416 use upper case letters and underscores. The first space after the key name separates it from the
1417 value. The value is the rest of the line (including additional whitespaces).
1418</p>
1419<p>
1420 Bazel partitions the keys into two buckets: "stable" and "volatile". (The names "stable" and
1421 "volatile" are a bit counter-intuitive, so don't think much about them.)
1422</p>
1423
1424<p>Bazel then writes the key-value pairs into two files:</p>
1425<ul>
1426 <li>
ahumesky5a6d8b62018-11-15 14:05:34 -08001427 <code>bazel-out/stable-status.txt</code>
1428 contains all keys and values where the key's name starts with <code>STABLE_</code>
laszlocsomor45a0ffe2018-02-05 00:48:35 -08001429 </li>
ahumesky5a6d8b62018-11-15 14:05:34 -08001430 <li>
1431 <code>bazel-out/volatile-status.txt</code>
1432 contains the rest of the keys and their values
1433 </li>
laszlocsomor45a0ffe2018-02-05 00:48:35 -08001434</ul>
1435
1436<p>The contract is:</p>
1437<ul>
1438 <li>
1439 <p>
1440 "stable" keys' values should change rarely, if possible. If the contents of
ahumesky5a6d8b62018-11-15 14:05:34 -08001441 <code>bazel-out/stable-status.txt</code>
1442 change, Bazel invalidates the actions that depend on them. In
1443 other words, if a stable key's value changes, Bazel will rerun stamped actions.
laszlocsomor45a0ffe2018-02-05 00:48:35 -08001444 Therefore the stable status should not contain things like timestamps, because they change all
ahumesky5a6d8b62018-11-15 14:05:34 -08001445 the time, and would make Bazel rerun stamped actions with each build.
laszlocsomor45a0ffe2018-02-05 00:48:35 -08001446 </p>
1447 <p>Bazel always outputs the following stable keys:</p>
1448 <ul>
1449 <li><code>BUILD_EMBED_LABEL</code>: value of <code class='flag'>--embed_label</code></li>
1450 <li><code>BUILD_HOST</code>: the name of the host machine that Bazel is running on</li>
1451 <li><code>BUILD_USER</code>: the name of the user that Bazel is running as</li>
1452 </ul>
1453 </li>
1454 <li>
1455 <p>
1456 "volatile" keys' values may change often. Bazel expects them to change all the time, like
ahumesky5a6d8b62018-11-15 14:05:34 -08001457 timestamps do, and duly updates the
David McNettfa388c32019-05-16 13:16:56 -07001458 <code>bazel-out/volatile-status.txt</code>
ahumesky5a6d8b62018-11-15 14:05:34 -08001459 file. In order to avoid
1460 rerunning stamped actions all the time though, <b>Bazel pretends that the volatile file never
1461 changes</b>. In other words, if the volatile status file is the only file whose contents has
1462 changed, Bazel will not invalidate actions that depend on it. If other inputs of the actions
1463 have changed, then Bazel reruns that action, and the action will see the updated volatile
laszlocsomor45a0ffe2018-02-05 00:48:35 -08001464 status, but just the volatile status changing alone will not invalidate the action.
1465 </p>
1466 <p>Bazel always outputs the following volatile keys:</p>
1467 <ul>
1468 <li>
lberki911c7c52018-04-25 07:56:27 -07001469 <code>BUILD_TIMESTAMP</code>: time of the build in seconds since the Unix Epoch (the value
1470 of <code>System.currentTimeMillis()</code> divided by a thousand)
laszlocsomor45a0ffe2018-02-05 00:48:35 -08001471 </li>
1472 </ul>
1473 </li>
1474</ul>
1475
1476<p>
1477 On Linux/macOS you can pass <code class='flag'>--workspace_status_command=/bin/true</code> to
Googler956ecf62018-11-26 10:15:05 -08001478 disable retrieving workspace status, because <code>true</code> does nothing, successfully (exits
laszlocsomor45a0ffe2018-02-05 00:48:35 -08001479 with zero) and prints no output. On Windows you can pass the path of MSYS's <code>true.exe</code>
1480 for the same effect.
1481</p>
1482
1483<p>If the workspace status command fails (exits non-zero) for any reason, the build will fail.</p>
1484
1485<p>Example program on Linux using Git:</p>
1486
1487<pre>
1488#!/bin/bash
1489echo "CURRENT_TIME $(date +%s)"
1490echo "RANDOM_HASH $(cat /dev/urandom | head -c16 | md5sum 2>/dev/null | cut -f1 -d' ')"
1491echo "STABLE_GIT_COMMIT $(git rev-parse HEAD)"
1492echo "STABLE_USER_NAME $USER"
1493</pre>
1494
1495<p>
1496 Pass this program's path with <code>--workspace_status_command</code>, and the stable status file
1497 will include the STABLE lines and the volatile status file will include the rest of the lines.
1498</p>
1499
David Chen8fe82a32016-08-24 10:55:41 +00001500<h4 id='flag--stamp'><code class='flag'>--[no]stamp</code></h4>
1501<p>
1502 This option controls whether stamping is enabled for
1503 rule types that support it. For most of the supported rule types stamping is
1504 enabled by default (e.g. <code>cc_binary</code>).
1505
1506 By default, stamping is disabled for all tests. Specifying
1507 <code class='flag'>--stamp</code> does not force affected targets to be rebuilt,
1508 if their dependencies have not changed.
1509</p>
1510
1511<p>
1512 Stamping can be enabled or disabled explicitly in BUILD using
1513 the <code>stamp</code> attribute of certain rule types, please refer to
1514 the <a href="be/overview.html">build encyclopedia</a> for details. For
1515 rules that are neither explicitly or implicitly configured as <code>stamp =
1516 0</code> or <code>stamp = 1</code>, the <code class='flag'>--[no]stamp</code> option
1517 selects whether stamping is enabled. Bazel never stamps binaries that are
1518 built for the host configuration, regardless of the stamp attribute.
1519</p>
1520
brandjoncf0390b2020-02-20 10:37:40 -08001521<h3 id='platform_build_options'>Platform</h3>
jcaterbf57a0a2018-06-13 10:16:31 -07001522
1523<p>
1524 Use these options to control the host and target platforms that configure how builds work, and to
1525 control what execution platforms and toolchains are available to Bazel rules.
1526</p>
1527
1528<p>
1529 Please see background information on
1530 <a href="platforms.html">Platforms</a> and <a href="toolchains.html">Toolchains</a>.
1531</p>
1532
1533<h4 id="flag--platforms"><code class='flag'>--platforms <var>labels</var></code></h4>
1534<p>
1535 The labels of the platform rules describing the target platforms for the
1536 current command.
1537</p>
1538
1539<h4 id="flag--host_platform"><code class='flag'>--host_platform <var>label</var></code></h4>
1540<p>
1541 The label of a platform rule that describes the host system.
1542</p>
1543
1544<h4 id="flag--extra_execution_platforms"><code class='flag'>--extra_execution_platforms <var>labels</var></code></h4>
1545<p>
1546 The platforms that are available as execution platforms to run actions.
1547 Platforms can be specified by exact target, or as a target pattern. These
1548 platforms will be considered before those declared in the WORKSPACE file by
Jingwen Chen0f4544d2018-12-14 16:28:16 -08001549 <a href="skylark/lib/globals.html#register_execution_platforms">
jcaterbf57a0a2018-06-13 10:16:31 -07001550 register_execution_platforms()</a>.
1551</p>
1552
1553<h4 id="flag--extra_toolchains"><code class='flag'>--extra_toolchains <var>labels</var></code></h4>
1554<p>
1555 The toolchain rules to be considered during toolchain resolution. Toolchains
1556 can be specified by exact target, or as a target pattern. These toolchains will
1557 be considered before those declared in the WORKSPACE file by
Jingwen Chen0f4544d2018-12-14 16:28:16 -08001558 <a href="skylark/lib/globals.html#register_toolchains">
jcaterbf57a0a2018-06-13 10:16:31 -07001559 register_toolchains()</a>.
1560</p>
1561
1562<h4 id="flag--toolchain_resolution_debug"><code class='flag'>--toolchain_resolution_debug=false</code></h4>
1563<p>
1564 Print debug information while finding toolchains for a rule. This might help
gregceca48e9a2020-04-14 08:54:38 -07001565 developers of Bazel or Starlark rules with debugging failures due to missing
jcaterbf57a0a2018-06-13 10:16:31 -07001566 toolchains.
1567</p>
1568
brandjoncf0390b2020-02-20 10:37:40 -08001569<h3 id='misc_build_options'>Miscellaneous</h3>
David Chen8fe82a32016-08-24 10:55:41 +00001570
1571<h4 id='flag--symlink_prefix'><code class='flag'>--symlink_prefix <var>string</var></code></h4>
1572<p>
1573 Changes the prefix of the generated convenience symlinks. The
1574 default value for the symlink prefix is <code>bazel-</code> which
1575 will create the symlinks <code>bazel-bin</code>, <code>bazel-testlogs</code>, and
1576 <code>bazel-genfiles</code>.
1577</p>
1578<p>
1579 If the symbolic links cannot be created for any reason, a warning is
1580 issued but the build is still considered a success. In particular,
1581 this allows you to build in a read-only directory or one that you have no
1582 permission to write into. Any paths printed in informational
1583 messages at the conclusion of a build will only use the
1584 symlink-relative short form if the symlinks point to the expected
1585 location; in other words, you can rely on the correctness of those
1586 paths, even if you cannot rely on the symlinks being created.
1587</p>
1588<p>
1589 Some common values of this option:
1590</p>
1591<ul>
1592
1593 <li>
1594 <p><b>Suppress symlink creation:</b>
1595 <code class='flag'>--symlink_prefix=/</code> will cause Bazel to not
1596 create or update any symlinks, including the <code>bazel-out</code> and
1597
1598 <code>bazel-&lt;workspace&gt;</code>
1599 symlinks. Use this option to suppress symlink creation entirely.
1600 </p>
1601 </li>
1602 <li>
1603 <p><b>Reduce clutter:</b>
1604 <code class='flag'>--symlink_prefix=.bazel/</code> will cause Bazel to create
1605 symlinks called <code>bin</code> (etc) inside a hidden directory <code>.bazel</code>.
1606 </p>
1607 </li>
1608</ul>
1609
1610<h4 id='flag--platform_suffix'><code class='flag'>--platform_suffix <var>string</var></code></h4>
1611<p>
1612 Adds a suffix to the configuration short name, which is used to determine the
1613 output directory. Setting this option to different values puts the files into
1614 different directories, for example to improve cache hit rates for builds that
1615 otherwise clobber each others output files, or to keep the output files around
1616 for comparisons.
1617</p>
1618
1619<h4 id='flag--default_visibility'><code class='flag'>--default_visibility=<var>(private|public)</var></code></h4>
1620<p>
1621 Temporary flag for testing bazel default visibility changes. Not intended for general use
1622 but documented for completeness' sake.
1623</p>
1624
Googler23471692017-06-02 11:26:16 -04001625<h4 id='flag--use_action_cache'><code class='flag'>--[no]use_action_cache</code></h4>
1626<p>
1627 This option is enabled by default. If disabled, Bazel will not use its local action cache.
1628 Disabling the local action cache saves memory and disk space for clean builds, but will make
1629 incremental builds slower.
1630</p>
1631
adonovan329ec6d2020-02-06 15:34:49 -08001632<h4 id='flag--starlark_cpu_profile'><code class='flag'>--starlark_cpu_profile=<i>file</i></code></h4>
1633<p>
1634 This flag, whose value is the name of a file, causes Bazel to gather
1635 statistics about CPU usage by all Starlark threads,
1636 and write the profile, in <a href='https://github.com/google/pprof'>pprof</a> format,
1637 to the named file.
1638
1639 Use this option to help identify Starlark functions that
1640 make loading and analysis slow due to excessive computation. For example:
1641</p>
1642<pre>
1643$ bazel build --nobuild --starlark_cpu_profile=/tmp/pprof.gz my/project/...
1644$ pprof /tmp/pprof.gz
1645(pprof) top
1646Type: CPU
1647Time: Feb 6, 2020 at 12:06pm (PST)
1648Duration: 5.26s, Total samples = 3.34s (63.55%)
1649Showing nodes accounting for 3.34s, 100% of 3.34s total
1650 flat flat% sum% cum cum%
1651 1.86s 55.69% 55.69% 1.86s 55.69% sort_source_files
1652 1.02s 30.54% 86.23% 1.02s 30.54% expand_all_combinations
1653 0.44s 13.17% 99.40% 0.44s 13.17% range
1654 0.02s 0.6% 100% 3.34s 100% sorted
1655 0 0% 100% 1.38s 41.32% my/project/main/BUILD
1656 0 0% 100% 1.96s 58.68% my/project/library.bzl
1657 0 0% 100% 3.34s 100% main
1658</pre>
1659<p>
1660 For different views of the same data, try the <code>pprof</code> commands <code>svg</code>,
1661 <code>web</code>, and <code>list</code>.
1662</p>
1663
David Chen8fe82a32016-08-24 10:55:41 +00001664<h2 id='bazel-releng'>Using Bazel for releases</h2>
1665<p>
1666 Bazel is used both by software engineers during the development
1667 cycle, and by release engineers when preparing binaries for deployment
1668 to production. This section provides a list of tips for release
1669 engineers using Bazel.
1670
1671</p>
1672
1673<h3>Significant options</h3>
1674
1675<p>
1676 When using Bazel for release builds, the same issues arise as for
1677 other scripts that perform a build, so you should read
Googler59830672019-01-03 10:33:49 -08001678 the <a href='guide.html#scripting'>scripting</a> section of this manual.
David Chen8fe82a32016-08-24 10:55:41 +00001679 In particular, the following options are strongly recommended:
1680</p>
1681<ul>
Vladimir Chebotarev66885ff2018-12-04 14:08:16 -08001682 <li><a href='guide.html#bazelrc'><code class='flag'>--bazelrc=/dev/null</code></a></li>
ccalvarinaf8b7722018-06-06 11:54:00 -07001683 <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 +00001684</ul>
1685
1686<p>
brandjoncf0390b2020-02-20 10:37:40 -08001687 These options are also important:
David Chen8fe82a32016-08-24 10:55:41 +00001688</p>
1689
1690<ul>
1691
1692 <li><a href='#flag--package_path'><code class='flag'>--package_path</code></a></li>
1693 <li><a href='#flag--symlink_prefix'><code class='flag'>--symlink_prefix</code></a>:
1694 for managing builds for multiple configurations,
1695 it may be convenient to distinguish each build
1696 with a distinct identifier, e.g. "64bit" vs. "32bit". This option
1697 differentiates the <code>bazel-bin</code> (etc.) symlinks.
1698 </li>
1699</ul>
1700
brandjoncf0390b2020-02-20 10:37:40 -08001701<h2 id='test'>Running tests</h2>
David Chen8fe82a32016-08-24 10:55:41 +00001702<p>
1703 To build and run tests with bazel, type <code>bazel test</code> followed by
1704 the name of the test targets.
1705</p>
1706<p>
1707 By default, this command performs simultaneous build and test
1708 activity, building all specified targets (including any non-test
1709 targets specified on the command line) and testing
1710 <code>*_test</code> and <code>test_suite</code> targets as soon as
1711 their prerequisites are built, meaning that test execution is
1712 interleaved with building. Doing so usually results in significant
1713 speed gains.
1714
1715</p>
1716
1717<h3>Options for <code>bazel test</code></h3>
1718
1719<h4 id="flag--cache_test_results"><code class='flag'>--cache_test_results=(yes|no|auto)</code> (<code>-t</code>)</h4>
1720<p>
1721 If this option is set to 'auto' (the default) then Bazel will only rerun a test if any of the
1722 following conditions applies:
1723</p>
1724<ul>
1725 <li>Bazel detects changes in the test or its dependencies</li>
1726 <li>the test is marked as <code>external</code></li>
1727 <li>multiple test runs were requested with <code class='flag'>--runs_per_test</code></li>
1728 <li>the test failed.</li>
1729</ul>
1730<p>
1731 If 'no', all tests will be executed unconditionally.
1732</p>
1733<p>
1734 If 'yes', the caching behavior will be the same as auto
1735 except that it may cache test failures and test runs with
1736 <code class='flag'>--runs_per_test</code>.
1737</p>
1738<p>
1739 Note that test results are <em>always</em> saved in Bazel's output tree,
1740 regardless of whether this option is enabled, so
1741 you needn't have used <code class='flag'>--cache_test_results</code> on the
1742 prior run(s) of <code>bazel test</code> in order to get cache hits.
1743 The option only affects whether Bazel will <em>use</em> previously
1744 saved results, not whether it will save results of the current run.
1745</p>
1746<p>
1747 Users who have enabled this option by default in
1748 their <code>.bazelrc</code> file may find the
1749 abbreviations <code>-t</code> (on) or <code>-t-</code> (off)
1750 convenient for overriding the default on a particular run.
1751</p>
1752
1753<h4 id="flag--check_tests_up_to_date"><code class='flag'>--check_tests_up_to_date</code></h4>
1754<p>
1755 This option tells Bazel not to run the tests, but to merely check and report
1756 the cached test results. If there are any tests which have not been
1757 previously built and run, or whose tests results are out-of-date (e.g. because
1758 the source code or the build options have changed), then Bazel will report
1759 an error message ("test result is not up-to-date"), will record the test's
1760 status as "NO STATUS" (in red, if color output is enabled), and will return
1761 a non-zero exit code.
1762</p>
1763<p>
1764 This option also implies
1765 <code><a href="#flag--check_up_to_date">--check_up_to_date</a></code> behavior.
1766</p>
1767<p>
1768 This option may be useful for pre-submit checks.
1769</p>
1770
1771<h4 id="flag--test_verbose_timeout_warnings"><code class='flag'>--test_verbose_timeout_warnings</code></h4>
1772<p>
1773 This option tells Bazel to explicitly warn the user if a test's timeout is
Googler6d2bfa42018-09-21 10:25:21 -07001774significantly longer than the test's actual execution time. While a test's
David Chen8fe82a32016-08-24 10:55:41 +00001775timeout should be set such that it is not flaky, a test that has a highly
1776over-generous timeout can hide real problems that crop up unexpectedly.
1777</p>
1778<p>
1779For instance, a test that normally executes in a minute or two should not have
1780a timeout of ETERNAL or LONG as these are much, much too generous.
1781
1782 This option is useful to help users decide on a good timeout value or
1783 sanity check existing timeout values.
1784</p>
1785<p>
1786Note that each test shard is allotted the timeout of the entire
1787<code>XX_test</code> target. Using this option does not affect a test's timeout
1788value, merely warns if Bazel thinks the timeout could be restricted further.
1789</p>
1790
1791<h4 id='flag--test_keep_going'><code class='flag'>--[no]test_keep_going</code></h4>
1792<p>
1793 By default, all tests are run to completion. If this flag is disabled,
1794 however, the build is aborted on any non-passing test. Subsequent build steps
1795 and test invocations are not run, and in-flight invocations are canceled.
1796 Do not specify both <code class='flag'>--notest_keep_going</code> and
1797 <code class='flag'>--keep_going</code>.
1798</p>
1799
1800<h4 id='flag--flaky_test_attempts'><code class='flag'>--flaky_test_attempts <var>attempts</var></code></h4>
1801<p>
1802 This option specifies the maximum number of times a test should be attempted
1803 if it fails for any reason. A test that initially fails but eventually
1804 succeeds is reported as <code>FLAKY</code> on the test summary. It is,
1805 however, considered to be passed when it comes to identifying Bazel exit code
1806 or total number of passed tests. Tests that fail all allowed attempts are
1807 considered to be failed.
1808</p>
1809<p>
1810 By default (when this option is not specified, or when it is set to
1811 &quot;default&quot;), only a single attempt is allowed for regular tests, and
1812 3 for test rules with the <code>flaky</code> attribute set. You can specify
1813 an integer value to override the maximum limit of test attempts. Bazel allows
1814 a maximum of 10 test attempts in order to prevent abuse of the system.
1815</p>
1816
1817<h4 id='flag--runs_per_test'><code class='flag'>--runs_per_test <var>[regex@]number</var></code></h4>
1818<p>
1819 This option specifies the number of times each test should be executed. All
1820 test executions are treated as separate tests (e.g. fallback functionality
1821 will apply to each of them independently).
1822</p>
1823<p>
1824 The status of a target with failing runs depends on the value of the
1825 <code>--runs_per_test_detects_flakes</code> flag:
1826</p>
1827<ul>
1828 <li>If absent, any failing run causes the entire test to fail.</li>
1829 <li>If present and two runs from the same shard return PASS and FAIL, the test
1830 will receive a status of flaky (unless other failing runs cause it to
1831 fail).</li>
1832</ul>
1833
1834<p>
1835 If a single number is specified, all tests will run that many times.
1836 Alternatively, a regular expression may be specified using the syntax
1837 regex@number. This constrains the effect of --runs_per_test to targets
1838 which match the regex (e.g. "--runs_per_test=^//pizza:.*@4" runs all tests
1839 under //pizza/ 4 times).
1840 This form of --runs_per_test may be specified more than once.
1841</p>
1842
1843<h4 id='flag--runs_per_test_detects_flakes'><code
1844 class='flag'>--[no]runs_per_test_detects_flakes</code></h4>
1845<p>
1846 If this option is specified (by default it is not), Bazel will detect flaky
1847 test shards through --runs_per_test. If one or more runs for a single shard
1848 fail and one or more runs for the same shard pass, the target will be
1849 considered flaky with the flag. If unspecified, the target will report a
1850 failing status.
1851</p>
1852
1853<h4 id='flag--test_summary'><code class='flag'>--test_summary <var>output_style</var></code></h4>
1854<p>
1855 Specifies how the test result summary should be displayed.
1856</p>
1857<ul>
1858 <li><code>short</code> prints the results of each test along with the name of
1859 the file containing the test output if the test failed. This is the default
1860 value.
1861 </li>
1862 <li><code>terse</code> like <code>short</code>, but even shorter: only print
1863 information about tests which did not pass.
1864 </li>
1865 <li><code>detailed</code> prints each individual test case that failed, not
1866 only each test. The names of test output files are omitted.
1867 </li>
1868 <li><code>none</code> does not print test summary.
1869 </li>
1870</ul>
1871
1872<h4 id='flag--test_output'><code class='flag'>--test_output <var>output_style</var></code></h4>
1873<p>
1874 Specifies how test output should be displayed:
1875</p>
1876<ul>
1877 <li><code>summary</code> shows a summary of whether each test passed or
1878 failed. Also shows the output log file name for failed tests. The summary
1879 will be printed at the end of the build (during the build, one would see
1880 just simple progress messages when tests start, pass or fail).
1881 This is the default behavior.
1882 </li>
1883 <li><code>errors</code> sends combined stdout/stderr output from failed tests
1884 only into the stdout immediately after test is completed, ensuring that
1885 test output from simultaneous tests is not interleaved with each other.
1886 Prints a summary at the build as per summary output above.
1887 </li>
1888 <li><code>all</code> is similar to <code>errors</code> but prints output for
1889 all tests, including those which passed.
1890 </li>
1891 <li><code>streamed</code> streams stdout/stderr output from each test in
1892 real-time.
1893
1894 </li>
1895</ul>
1896
1897<h4 id='flag--java_debug'><code class='flag'>--java_debug</code></h4>
1898<p>
1899 This option causes the Java virtual machine of a java test to wait for a connection from a
1900 JDWP-compliant debugger before starting the test. This option implies --test_output=streamed.
1901</p>
1902
1903<h4 id='flag--verbose_test_summary'><code class='flag'>--[no]verbose_test_summary</code></h4>
1904<p>
1905 By default this option is enabled, causing test times and other additional
1906 information (such as test attempts) to be printed to the test summary. If
1907 <code class='flag'>--noverbose_test_summary</code> is specified, test summary will
1908 include only test name, test status and cached test indicator and will
1909 be formatted to stay within 80 characters when possible.
1910</p>
1911
1912<h4 id='flag--test_tmpdir'><code class='flag'>--test_tmpdir <var>path</var></code></h4>
1913<p>
1914 Specifies temporary directory for tests executed locally. Each test will be
1915 executed in a separate subdirectory inside this directory. The directory will
1916 be cleaned at the beginning of the each <code>bazel test</code> command.
1917 By default, bazel will place this directory under Bazel output base directory.
1918 Note that this is a directory for running tests, not storing test results
1919 (those are always stored under the <code>bazel-out</code> directory).
1920</p>
1921
1922<h4 id='flag--test_timeout'>
1923 <code class='flag'>--test_timeout
1924 <var>seconds</var></code>
1925 OR
1926 <code class='flag'>--test_timeout
1927 <var>seconds</var>,<var>seconds</var>,<var>seconds</var>,<var>seconds</var>
1928 </code>
1929</h4>
1930<p>
1931 Overrides the timeout value for all tests by using specified number of
1932 seconds as a new timeout value. If only one value is provided, then it will
1933 be used for all test timeout categories.
1934 </p>
1935 <p>
1936 Alternatively, four comma-separated values may be provided, specifying
1937 individual timeouts for short, moderate, long and eternal tests (in that
1938 order).
1939 In either form, zero or a negative value for any of the test sizes will
1940 be substituted by the default timeout for the given timeout categories as
1941 defined by the page
1942 <a href="test-encyclopedia.html">Writing Tests</a>.
1943 By default, Bazel will use these timeouts for all tests by
1944 inferring the timeout limit from the test's size whether the size is
1945 implicitly or explicitly set.
1946</p>
1947<p>
1948 Tests which explicitly state their timeout category as distinct from their
1949 size will receive the same value as if that timeout had been implicitly set by
1950 the size tag. So a test of size 'small' which declares a 'long' timeout will
1951 have the same effective timeout that a 'large' tests has with no explicit
1952 timeout.
1953</p>
1954
1955<h4 id='flag--test_arg'><code class='flag'>--test_arg <var>arg</var></code></h4>
1956<p>
Michael Staib3df106e2017-02-23 23:08:40 +00001957 Passes command-line options/flags/arguments to each test process. This
David Chen8fe82a32016-08-24 10:55:41 +00001958 option can be used multiple times to pass several arguments, e.g.
1959 <code class='flag'>--test_arg=--logtostderr --test_arg=--v=3</code>.
1960</p>
1961
1962<h4 id='flag--test_env'><code class='flag'>--test_env <var>variable</var>=<i>value</i></code>
1963 OR
1964 <code class='flag'>--test_env <var>variable</var></code></h4>
1965<p>
1966 Specifies additional variables that must be injected into the test
1967 environment for each test. If <var>value</var> is not specified it will be
1968 inherited from the shell environment used to start the <code>bazel test</code>
1969 command.
1970</p>
1971<p>
1972 The environment can be accessed from within a test by using
1973 <code>System.getenv("var")</code> (Java),
1974 <code>getenv("var")</code> (C or C++),
1975
1976</p>
1977
1978<h4 id="flag--run_under"><code class='flag'>--run_under=<var>command-prefix</var></code></h4>
1979<p>
1980 This specifies a prefix that the test runner will insert in front
1981 of the test command before running it. The
1982 <var>command-prefix</var> is split into words using Bourne shell
1983 tokenization rules, and then the list of words is prepended to the
1984 command that will be executed.
1985</p>
1986<p>
Googlera0f79b12018-11-29 06:31:16 -08001987 If the first word is a fully-qualified label (i.e. starts with
David Chen8fe82a32016-08-24 10:55:41 +00001988 <code>//</code>) it is built. Then the label is substituted by the
1989 corresponding executable location that is prepended to the command
1990 that will be executed along with the other words.
1991</p>
1992
1993<p>
1994Some caveats apply:
1995</p>
1996<ul>
1997 <li>
1998 The PATH used for running tests may be different than the PATH in your environment,
1999 so you may need to use an <b>absolute path</b> for the <code class='flag'>--run_under</code>
2000 command (the first word in <var>command-prefix</var>).
2001 </li>
2002 <li>
2003 <b><code>stdin</code> is not connected</b>, so <code class='flag'>--run_under</code>
2004 can't be used for interactive commands.
2005 </li>
2006
2007</ul>
2008<p>
2009Examples:
2010</p>
2011<pre>
David Chen8fe82a32016-08-24 10:55:41 +00002012 --run_under=/usr/bin/strace
2013 --run_under='/usr/bin/strace -c'
ckennellyaee19e12020-04-15 10:15:47 -07002014 --run_under=/usr/bin/valgrind
David Chen8fe82a32016-08-24 10:55:41 +00002015 --run_under='/usr/bin/valgrind --quiet --num-callers=20'
David Chen8fe82a32016-08-24 10:55:41 +00002016</pre>
2017
2018<h4>Test selection</h4>
2019<p>
2020 As documented under <a href='#output-selection-options'>Output selection options</a>,
2021 you can filter tests by <a href='#flag--test_size_filters'>size</a>,
2022 <a href='#flag--test_timeout_filters'>timeout</a>,
2023 <a href='#flag--test_tag_filters'>tag</a>, or
2024 <a href='#flag--test_lang_filters'>language</a>. A convenience
2025 <a href='#flag--test_filter'>general name filter</a> can forward particular
2026 filter args to the test runner.
2027</p>
2028
kchodorowfae5c742017-03-28 16:53:24 +00002029<h4 id="other_options_for_bazel_test">Other options for <code>bazel test</code></h4>
David Chen8fe82a32016-08-24 10:55:41 +00002030<p>
2031 The syntax and the remaining options are exactly like
Googler59830672019-01-03 10:33:49 -08002032 <a href='guide.html#build'>bazel build</a>.
David Chen8fe82a32016-08-24 10:55:41 +00002033</p>
2034
2035
brandjoncf0390b2020-02-20 10:37:40 -08002036<h3 id='clean'>Cleaning build outputs</h3>
laurentlbc85de9c2018-11-05 08:30:36 -08002037
2038<h4>The <code>clean</code> command</h4>
2039
2040<p>
2041 Bazel has a <code>clean</code> command, analogous to that of Make.
2042 It deletes the output directories for all build configurations performed
2043 by this Bazel instance, or the entire working tree created by this
2044 Bazel instance, and resets internal caches. If executed without any
2045 command-line options, then the output directory for all configurations
2046 will be cleaned.
2047</p>
2048
2049<p>Recall that each Bazel instance is associated with a single workspace, thus the
2050 <code>clean</code> command will delete all outputs from all builds you've done
2051 with that Bazel instance in that workspace.
2052</p>
2053<p>
2054 To completely remove the entire working tree created by a Bazel
2055 instance, you can specify the <code class='flag'>--expunge</code> option. When
2056 executed with <code class='flag'>--expunge</code>, the clean command simply
2057 removes the entire output base tree which, in addition to the build
2058 output, contains all temp files created by Bazel. It also
2059 stops the Bazel server after the clean, equivalent to the <a
2060 href='#shutdown'><code>shutdown</code></a> command. For example, to
2061 clean up all disk and memory traces of a Bazel instance, you could
2062 specify:
2063</p>
2064<pre>
2065 % bazel clean --expunge
2066</pre>
2067<p>
2068 Alternatively, you can expunge in the background by using
2069 <code class='flag'>--expunge_async</code>. It is safe to invoke a Bazel command
2070 in the same client while the asynchronous expunge continues to run.
2071 Note, however, that this may introduce IO contention.
2072</p>
2073
2074<p>
2075 The <code>clean</code> command is provided primarily as a means of
2076 reclaiming disk space for workspaces that are no longer needed.
2077 However, we recognize that Bazel's incremental rebuilds might not be
2078 perfect; <code>clean</code> may be used to recover a consistent
2079 state when problems arise.
2080</p>
2081<p>
2082 Bazel's design is such that these problems are fixable; we consider
2083 such bugs a high priority, and will do our best fix them. If you
2084 ever find an incorrect incremental build, please file a bug report.
2085 We encourage developers to get out of the habit of
2086 using <code>clean</code> and into that of reporting bugs in the
2087 tools.
2088</p>
2089
David Chen8fe82a32016-08-24 10:55:41 +00002090
brandjoncf0390b2020-02-20 10:37:40 -08002091<h2 id='run'>Running executables</h2>
David Chen8fe82a32016-08-24 10:55:41 +00002092<p>
2093 The <code>bazel run</code> command is similar to <code>bazel build</code>, except
diamondme42913a2019-01-24 16:11:30 -08002094 it is used to build <em>and run</em> a single target. Here is a typical session:
David Chen8fe82a32016-08-24 10:55:41 +00002095</p>
2096<pre>
2097 % bazel run -- java/myapp:myapp --arg1 --arg2
2098 Welcome to Bazel
2099 INFO: Loading package: java/myapp
2100 INFO: Loading package: foo/bar
2101 INFO: Loading complete. Analyzing...
2102 INFO: Found 1 target...
2103 ...
2104 Target //java/myapp:myapp up-to-date:
2105 bazel-bin/java/myapp:myapp
2106 INFO: Elapsed time: 0.638s, Critical Path: 0.34s
2107
2108 INFO: Running command line: bazel-bin/java/myapp:myapp --arg1 --arg2
2109 Hello there
2110 $EXEC_ROOT/java/myapp/myapp
2111 --arg1
2112 --arg2
2113</pre>
2114
2115<p>
David Chen8fe82a32016-08-24 10:55:41 +00002116 Note the use of the <code>--</code>. This is needed so that Bazel
2117 does not interpret <code>--arg1</code> and <code>--arg2</code> as
2118 Bazel options, but rather as part of the command line for running the binary.
2119 (The program being run simply says hello and prints out its args.)
2120</p>
2121
diamondme42913a2019-01-24 16:11:30 -08002122<p><code>bazel run</code> is similar, but not identical, to directly invoking
lberki749e8052019-02-12 04:23:43 -08002123the binary built by Bazel and its behavior is different depending on whether the
2124binary to be invoked is a test or not.
2125
2126When the binary is not a test, the current working directory will be the
2127runfiles tree of the binary.
2128
2129When the binary is a test, the current working directory will be the exec root
2130and a good-faith attempt is made to replicate the environment tests are usually
2131run in. The emulation is not perfect, though, and tests that have multiple
2132shards cannot be run this way (the
2133<code>--test_sharding_strategy=disabled</code> command line option can be used
2134to work around this)
2135
2136The following extra environment variables are also available to the binary:
2137<ul>
2138 <li>
2139 <code>BUILD_WORKSPACE_DIRECTORY</code>: the root of the workspace where the
2140 build was run.
2141 </li>
2142 <li>
2143 <code>BUILD_WORKING_DIRECTORY</code>: the current working directory where
2144 Bazel was run from.
2145 </li>
2146</ul>
2147
2148These can be used, for example, to interpret file names on the command line in
2149a user-friendly way.
diamondme42913a2019-01-24 16:11:30 -08002150
David Chen8fe82a32016-08-24 10:55:41 +00002151<h3>Options for <code>bazel run</code></h3>
2152
2153<h4 id='flag--run_under_run'><code class='flag'>--run_under=<var>command-prefix</var></code></h4>
2154<p>
2155 This has the same effect as the <code class='flag'>--run_under</code> option for
2156 <code>bazel test</code> (<a href='#flag--run_under'>see above</a>),
2157 except that it applies to the command being run by <code>bazel
2158 run</code> rather than to the tests being run by <code>bazel test</code>
2159 and cannot run under label.
2160</p>
2161
2162<h3>Executing tests</h3>
2163
2164<p>
2165 <code>bazel run</code> can also execute test binaries, which has the effect of
lberki5a2238d2018-05-18 03:15:32 -07002166 running the test in a close approximation of the environment described at
2167 <a href='test-encyclopedia.html'>Writing Tests</a>. Note that none of the
Googlere5197f72020-02-25 16:38:17 -08002168 <code>--test_*</code> arguments have an effect when running a test in this manner except
lberki5a2238d2018-05-18 03:15:32 -07002169 <code>--test_arg</code> .
David Chen8fe82a32016-08-24 10:55:41 +00002170</p>
2171
brandjoncf0390b2020-02-20 10:37:40 -08002172<h2 id='query'>Querying the dependency graph</h2>
David Chen8fe82a32016-08-24 10:55:41 +00002173
2174<p>
2175 Bazel includes a query language for asking questions about the
juliexxiaa8082fc2018-03-15 09:58:51 -07002176 dependency graph used during the build. The query language is used
2177 by two commands: query and cquery. The major difference between the
Googler59830672019-01-03 10:33:49 -08002178 two commands is that query runs after the <a href='guide.html#loading-phase'>loading phase</a>
2179 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 +00002180 invaluable aid to many software engineering tasks.
2181</p>
2182<p>
2183 The query language is based on the idea of
2184 algebraic operations over graphs; it is documented in detail in
2185
2186 <a href="query.html">Bazel Query Reference</a>.
2187 Please refer to that document for reference, for
2188 examples, and for query-specific command-line options.
2189</p>
2190
2191<p>
2192 The query tool accepts several command-line
2193 option. <code class='flag'>--output</code> selects the output format.
2194 <code class='flag'>--[no]keep_going</code> (disabled by default) causes the query
2195 tool to continue to make progress upon errors; this behavior may be
2196 disabled if an incomplete result is not acceptable in case of errors.
2197</p>
2198<p>
wtroberts5a0cf9b2019-09-06 07:55:15 -07002199 The <code class='flag'>--[no]tool_deps</code> option,
2200 enabled by default, causes dependencies in non-target configurations to be included in the
2201 dependency graph over which the query operates.
David Chen8fe82a32016-08-24 10:55:41 +00002202
2203</p>
2204<p>
2205 The <code class='flag'>--[no]implicit_deps</code> option, enabled by default, causes
2206 implicit dependencies to be included in the dependency graph over which the query operates. An
2207 implicit dependency is one that is not explicitly specified in the BUILD file
2208 but added by bazel.
2209</p>
2210<p>
2211 Example: "Show the locations of the definitions (in BUILD files) of
2212 all genrules required to build all the tests in the PEBL tree."
2213</p>
2214<pre>
2215 bazel query --output location 'kind(genrule, deps(kind(".*_test rule", foo/bar/pebl/...)))'
2216</pre>
2217
brandjoncf0390b2020-02-20 10:37:40 -08002218<h2 id='aquery'>Querying the action graph</h2>
twerthe7fcab32018-08-09 08:03:41 -07002219
2220<b>Caution</b>: The aquery command is still experimental and its API will change.
2221
2222<p>
2223 The <code>aquery</code> command allows you to query for actions in your build graph.
2224 It operates on the post-analysis configured target graph and exposes
2225 information about actions, artifacts and their relationships.
2226</p>
2227
2228<p>
2229 The tool accepts several command-line options.
twerth420b9532018-12-14 06:16:58 -08002230 <code class='flag'>--output</code> selects the output format. The default output format
2231 (<code>text</code>) is human-readable, use <code>proto</code> or <code>textproto</code> for
2232 machine-readable format.
twerthe7fcab32018-08-09 08:03:41 -07002233 Notably, the aquery command runs on top of a regular Bazel build and inherits
2234 the set of options available during a build.
2235</p>
2236
2237<p>
2238 It supports the same set of functions that is also available to traditional
2239 <code>query</code> but <code>siblings</code>, <code>buildfiles</code> and
2240 <code>tests</code>.
2241</p>
David Chen8fe82a32016-08-24 10:55:41 +00002242
leba367d42d2019-01-10 02:30:47 -08002243<p>
2244 More details on aquery can be found <a href="aquery.html">here</a>.
2245</p>
2246
brandjoncf0390b2020-02-20 10:37:40 -08002247<h2 id='misc'>Miscellaneous commands and options</h2>
David Chen8fe82a32016-08-24 10:55:41 +00002248
brandjoncf0390b2020-02-20 10:37:40 -08002249<h3 id='help'><code>help</code></h3>
David Chen8fe82a32016-08-24 10:55:41 +00002250
2251<p>
2252 The <code>help</code> command provides on-line help. By default, it
2253 shows a summary of available commands and help topics, as shown in
Googler59830672019-01-03 10:33:49 -08002254 the <a href='guide.html#overview'><i>Bazel overview</i></a> section above.
David Chen8fe82a32016-08-24 10:55:41 +00002255 Specifying an argument displays detailed help for a particular
2256 topic. Most topics are Bazel commands, e.g. <code>build</code>
2257 or <code>query</code>, but there are some additional help topics
2258 that do not correspond to commands.
2259</p>
2260
2261<h4 id='flag--long'><code class='flag'>--[no]long</code> (<code>-l</code>)</h4>
2262<p>
2263 By default, <code>bazel help [<var>topic</var>]</code> prints only a
2264 summary of the relevant options for a topic. If
2265 the <code class='flag'>--long</code> option is specified, the type, default value
2266 and full description of each option is also printed.
2267</p>
2268
brandjoncf0390b2020-02-20 10:37:40 -08002269<h3 id='shutdown'><code>shutdown</code></h3>
David Chen8fe82a32016-08-24 10:55:41 +00002270
2271<p>
Googler59830672019-01-03 10:33:49 -08002272 Bazel server processes (see <a href='guide.html#client/server'>Client/server
David Chen8fe82a32016-08-24 10:55:41 +00002273 implementation</a>) may be stopped by using the <code>shutdown</code>
2274 command. This command causes the Bazel server to exit as soon as it
2275 becomes idle (i.e. after the completion of any builds or other
2276 commands that are currently in progress).
2277
2278 Bazel servers stop themselves after an idle timeout, so this command
2279 is rarely necessary; however, it can be useful in scripts when it is
2280 known that no further builds will occur in a given workspace.
2281</p>
2282<p>
2283 <code>shutdown</code> accepts one
2284 option, <code class='flag'>--iff_heap_size_greater_than <i>n</i></code>, which
2285 requires an integer argument (in MB). If specified, this makes the shutdown
2286 conditional on the amount of memory already consumed. This is
2287 useful for scripts that initiate a lot of builds, as any memory
2288 leaks in the Bazel server could cause it to crash spuriously on
2289 occasion; performing a conditional restart preempts this condition.
2290</p>
2291
brandjoncf0390b2020-02-20 10:37:40 -08002292<h3 id='info'><code>info</code></h3>
David Chen8fe82a32016-08-24 10:55:41 +00002293
2294<p>
2295 The <code>info</code> command prints various values associated with
2296 the Bazel server instance, or with a specific build configuration.
2297 (These may be used by scripts that drive a build.)
2298</p>
2299
2300<p>
2301 The <code>info</code> command also permits a single (optional)
2302 argument, which is the name of one of the keys in the list below.
2303 In this case, <code>bazel info <var>key</var></code> will print only
2304 the value for that one key. (This is especially convenient when
2305 scripting Bazel, as it avoids the need to pipe the result
2306 through <code>sed -ne /key:/s/key://p</code>:
2307</p>
2308
2309<h4>Configuration-independent data</h4>
2310<ul>
2311 <li><code>release</code>: the release label for this Bazel
2312 instance, or "development version" if this is not a released
2313 binary.
2314 </li>
2315 <li><code>workspace</code> the absolute path to the base workspace
2316 directory.
2317 </li>
2318 <li><code>install_base</code>: the absolute path to the installation
2319 directory used by this Bazel instance for the current user. Bazel
2320 installs its internally required executables below this directory.
2321
2322 </li>
2323 <li><code>output_base</code>: the absolute path to the base output
2324 directory used by this Bazel instance for the current user and
2325 workspace combination. Bazel puts all of its scratch and build
2326 output below this directory.
2327 </li>
2328 <li><code>execution_root</code>: the absolute path to the execution
2329 root directory under output_base. This directory is the root for all files
2330 accessible to commands executed during the build, and is the working
2331 directory for those commands. If the workspace directory is writable, a
2332 symlink named
2333
2334 <code>bazel-&lt;workspace&gt;</code>
2335 is placed there pointing to this directory.
2336 </li>
2337 <li><code>output_path</code>: the absolute path to the output
2338 directory beneath the execution root used for all files actually
2339 generated as a result of build commands. If the workspace directory is
2340 writable, a symlink named <code>bazel-out</code> is placed there pointing
2341 to this directory.
nharmataa3a7dad2020-03-30 10:42:05 -07002342 </li>
David Chen8fe82a32016-08-24 10:55:41 +00002343 <li><code>server_pid</code>: the process ID of the Bazel server
nharmataa3a7dad2020-03-30 10:42:05 -07002344 process.
2345 </li>
2346 <li><code>server_log</code>: the absolute path to the Bazel server's debug log file.
2347 This file contains debugging information for all commands over the lifetime of the
2348 Bazel server, and is intended for human consumption by Bazel developers and power users.
2349 </li>
David Chen8fe82a32016-08-24 10:55:41 +00002350 <li><code>command_log</code>: the absolute path to the command log file;
2351 this contains the interleaved stdout and stderr streams of the most recent
2352 Bazel command. Note that running <code>bazel info</code> will overwrite the
2353 contents of this file, since it then becomes the most recent Bazel command.
2354 However, the location of the command log file will not change unless you
2355 change the setting of the <code class='flag'>--output_base</code> or
2356 <code class='flag'>--output_user_root</code> options.
2357 </li>
2358
2359 <li><code>used-heap-size</code>,
Googler82085c42018-08-16 08:01:39 -07002360 <code>committed-heap-size</code>,
David Chen8fe82a32016-08-24 10:55:41 +00002361 <code>max-heap-size</code>: reports various JVM heap size
2362 parameters. Respectively: memory currently used, memory currently
2363 guaranteed to be available to the JVM from the system, maximum
2364 possible allocation.
2365 </li>
2366 <li><code>gc-count</code>, <code>gc-time</code>: The cumulative count of
2367 garbage collections since the start of this Bazel server and the time spent
2368 to perform them. Note that these values are not reset at the start of every
2369 build.
2370 </li>
2371 <li><code>package_path</code>: A colon-separated list of paths which would be
2372 searched for packages by bazel. Has the same format as the
2373 <code class='flag'>--package_path</code> build command line argument.
2374 </li>
2375</ul>
2376<p>
2377 Example: the process ID of the Bazel server.
2378</p>
2379<pre>% bazel info server_pid
23801285
2381</pre>
2382
2383<h4>Configuration-specific data</h4>
2384<p>
2385 These data may be affected by the configuration options passed
2386 to <code>bazel info</code>, for
2387 example <code class='flag'>--cpu</code>, <code class='flag'>--compilation_mode</code>,
2388 etc. The <code>info</code> command accepts all
2389 the <a href='#analysis-options'>options that control dependency
2390 analysis</a>, since some of these determine the location of the
2391 output directory of a build, the choice of compiler, etc.
2392</p>
2393<ul>
2394 <li>
2395 <code>bazel-bin</code>, <code>bazel-testlogs</code>,
2396 <code>bazel-genfiles</code>: reports the absolute path to
2397 the <code>bazel-*</code> directories in which programs generated by the
2398 build are located. This is usually, though not always, the same as
2399 the <code>bazel-*</code> symlinks created in the base workspace directory after a
2400 successful build. However, if the workspace directory is read-only,
2401 no <code>bazel-*</code> symlinks can be created. Scripts that use
2402 the value reported by <code>bazel info</code>, instead of assuming the
2403 existence of the symlink, will be more robust.
2404 </li>
2405 <li>
2406 The complete
2407 <a href='be/make-variables.html'
2408 >"Make" environment</a>. If the <code class='flag'>--show_make_env</code> flag is
2409 specified, all variables in the current configuration's "Make" environment
2410 are also displayed (e.g. <code>CC</code>, <code>GLIBC_VERSION</code>, etc).
2411 These are the variables accessed using the <code>$(CC)</code>
2412 or <code>varref("CC")</code> syntax inside BUILD files.
2413 </li>
2414</ul>
2415
2416<p>
2417 Example: the C++ compiler for the current configuration.
2418 This is the <code>$(CC)</code> variable in the "Make" environment,
2419 so the <code class='flag'>--show_make_env</code> flag is needed.
2420</p>
2421
2422<pre>
Ulf Adamse0437b12016-08-29 14:48:47 +00002423 % bazel info --show_make_env -c opt COMPILATION_MODE
2424 opt
David Chen8fe82a32016-08-24 10:55:41 +00002425</pre>
2426
2427<p>
2428 Example: the <code>bazel-bin</code> output directory for the current
2429 configuration. This is guaranteed to be correct even in cases where
2430 the <code>bazel-bin</code> symlink cannot be created for some reason
2431 (e.g. you are building from a read-only directory).
2432</p>
2433
brandjoncf0390b2020-02-20 10:37:40 -08002434<h3 id='version'><code>version</code> and <code>--version</code></h3>
David Chen8fe82a32016-08-24 10:55:41 +00002435
2436<p>
2437 The version command prints version details about the built Bazel
2438 binary, including the changelist at which it was built and the date.
2439 These are particularly useful in determining if you have the latest
2440 Bazel, or if you are reporting bugs. Some of the interesting values
2441 are:
2442</p>
2443<ul>
2444 <li><code>changelist</code>: the changelist at which this version of
2445 Bazel was released.
2446 </li>
2447 <li><code>label</code>: the release label for this Bazel
2448 instance, or "development version" if this is not a released
2449 binary. Very useful when reporting bugs.
2450 </li>
2451</ul>
2452
michajlo52a0bcf2019-08-29 08:55:21 -07002453<p>
2454 <code>bazel --version</code>, with no other args, will emit the same output as
2455 <code>bazel version --gnu_format</code>, except without the side-effect of potentially starting
brandjoncf0390b2020-02-20 10:37:40 -08002456 a Bazel server or unpacking the server archive. <code>bazel --version</code> can be run from
2457 anywhere - it does not require a workspace directory.
michajlo52a0bcf2019-08-29 08:55:21 -07002458</p>
2459
brandjoncf0390b2020-02-20 10:37:40 -08002460<h3 id='mobile-install'><code>mobile-install</code></h3>
David Chen8fe82a32016-08-24 10:55:41 +00002461<p>
2462 The <code>mobile-install</code> command installs apps to mobile devices.
2463 Currently only Android devices running ART are supported.
Alex Humesky105e6612017-01-06 19:03:10 +00002464
2465 See <a href="mobile-install.html">bazel mobile-install</a>
2466 for more information.
David Chen8fe82a32016-08-24 10:55:41 +00002467</p>
2468<p>
2469 Note that this command does not install the same thing that
2470 <code>bazel build</code> produces: Bazel tweaks the app so that it can be
2471 built, installed and re-installed quickly. This should, however, be mostly
2472 transparent to the app.
2473</p>
2474<p>
2475 The following options are supported:
2476</p>
2477<h4 id='flag--incremental'><code class='flag'>--incremental</code></h4>
2478<p>
2479 If set, Bazel tries to install the app incrementally, that is, only those
2480 parts that have changed since the last build. This cannot update resources
2481 referenced from <code>AndroidManifest.xml</code>, native code or Java
2482 resources (i.e. ones referenced by <code>Class.getResource()</code>). If these
2483 things change, this option must be omitted. Contrary to the spirit of Bazel
2484 and due to limitations of the Android platform, it is the
2485 <b>responsibility of the user</b> to know when this command is good enough and
Alex Humesky105e6612017-01-06 19:03:10 +00002486 when a full install is needed.
2487
2488 If you are using a device with Marshmallow or later, consider the
2489 <a href='#flag--split_apks'><code class='flag'>--split_apks</code></a> flag.
David Chen8fe82a32016-08-24 10:55:41 +00002490</p>
Alex Humesky105e6612017-01-06 19:03:10 +00002491<h4 id='flag--split_apks'><code class='flag'>--split_apks</code></h4>
David Chen8fe82a32016-08-24 10:55:41 +00002492<p>
Alex Humesky105e6612017-01-06 19:03:10 +00002493 Whether to use split apks to install and update the application on the device.
2494 Works only with devices with Marshmallow or later. Note that the
2495 <a href='#flag--incremental'><code class='flag'>--incremental</code></a> flag
2496 is not necessary when using <code class='flag'>--split_apks</code>.
David Chen8fe82a32016-08-24 10:55:41 +00002497</p>
Alex Humesky105e6612017-01-06 19:03:10 +00002498<h4 id='flag--start_app'><code class='flag'>--start_app</code></h4>
2499<p>
2500 Starts the app in a clean state after installing. Equivalent to
2501 <code>--start=COLD</code>.
2502</p>
Googler2b88f622017-03-16 21:52:14 +00002503<h4 id='flag--debug_app'><code class='flag'>--debug_app</code></h4>
Alex Humesky105e6612017-01-06 19:03:10 +00002504<p>
Googler2b88f622017-03-16 21:52:14 +00002505 Waits for debugger to be attached before starting the app in a clean state after installing.
2506 Equivalent to <code>--start=DEBUG</code>.
2507</p>
2508<h4 id='flag--start'><code class='flag'>--start=<i>start_type</i></code></h4>
2509<p>
2510 How the app should be started after installing it. Supported <i>start_type</i>s are:
2511 <ul>
2512 <li><code>NO</code> Does not start the app. This is the default.</li>
2513 <li><code>COLD</code> Starts the app from a clean state after install.</li>
2514 <li><code>WARM</code> Preserves and restores the application state on incremental installs.</li>
2515 <li><code>DEBUG</code> Waits for the debugger before starting the app in a clean state after install.</li>
2516 </ul>
2517 Note that if more than one of <code class='flag'>--start=<i>start_type</i></code>,
2518 <code class='flag'>--start_app</code> or
2519 <code class='flag'>--debug_app</code> is set, the last value will be used.
Alex Humesky105e6612017-01-06 19:03:10 +00002520</p>
2521<h4 id='flag--adb'><code class='flag'>--adb <var>path</var></code></h4>
2522<p>
2523 Indicates the <code>adb</code> binary to be used.
2524
2525 The default is to use the adb in the Android SDK specified by
2526 <a href='#flag--android_sdk'><code class='flag'>--android_sdk</code></a>.
2527
2528</p>
2529<h4 id='flag--adb_arg'><code class='flag'>--adb_arg <var>arg</var></code></h4>
David Chen8fe82a32016-08-24 10:55:41 +00002530<p>
2531 Extra arguments to <code>adb</code>. These come before the subcommand in the
2532 command line and are typically used to specify which device to install to.
Alex Humesky105e6612017-01-06 19:03:10 +00002533 For example, to select the Android device or emulator to use:
David Chen8fe82a32016-08-24 10:55:41 +00002534<pre>% bazel mobile-install --adb_arg=-s --adb_arg=deadbeef
2535</pre>
2536will invoke <code>adb</code> as
2537<pre>
2538adb -s deadbeef install ...
2539</pre>
Alex Humesky105e6612017-01-06 19:03:10 +00002540</p>
Alex Humesky105e6612017-01-06 19:03:10 +00002541<h4 id='flag--incremental_install_verbosity'><code class='flag'>--incremental_install_verbosity <var>number</var></code></h4>
2542<p>
2543 The verbosity for incremental install. Set to 1 for debug logging to be
2544 printed to the console.
David Chen8fe82a32016-08-24 10:55:41 +00002545</p>
2546
gregceca8ee232018-03-08 11:35:22 -08002547
brandjoncf0390b2020-02-20 10:37:40 -08002548<h3 id='dump'><code>dump</code></h3>
gregceca8ee232018-03-08 11:35:22 -08002549
2550<p>
2551 The <code>dump</code> command prints to stdout a dump of the
2552 internal state of the Bazel server. This command is intended
2553 primarily for use by Bazel developers, so the output of this command
2554 is not specified, and is subject to change.
2555</p>
2556
tomlu72642a22017-10-18 06:23:14 +02002557<p>
2558 By default, command will just print help message outlining possible
2559 options to dump specific areas of the Bazel state. In order to dump
2560 internal state, at least one of the options must be specified.
2561</p>
2562<p>
2563 Following options are supported:
2564</p>
2565<ul>
2566 <li><code class='flag'>--action_cache</code> dumps action cache content.</li>
2567 <li><code class='flag'>--packages</code> dumps package cache content.</li>
tomlu72642a22017-10-18 06:23:14 +02002568 <li><code class='flag'>--skyframe</code> dumps state of internal Bazel dependency graph.</li>
2569 <li><code class='flag'>--rules</code> dumps rule summary for each rule and aspect class,
gregceca48e9a2020-04-14 08:54:38 -07002570 including counts and action counts. This includes both native and Starlark rules.
tomlu72642a22017-10-18 06:23:14 +02002571 If memory tracking is enabled, then the rules' memory consumption is also printed.</li>
2572 <li><code class='flag'>--skylark_memory</code> dumps a
2573 <href a=https://github.com/google/pprof>pprof</href> compatible .gz file to the specified path.
2574 You must enable memory tracking for this to work.</li>
twerth700bc132018-03-05 01:32:50 -08002575 <li><code class='flag'>--action_graph=/path/to/file</code> dumps the state of
2576 the internal Bazel action graph in proto format to
2577 <code>/path/to/file</code>. You have to run (at least) the analysis phase
2578 for the targets you are interested in (for example, <code>bazel build --nobuild
2579 //foo:bar</code>). Note that this feature is still experimental, subject to
2580 change and will probably be integrated into <code>cquery</code> in the
2581 future.
2582 <li><code class='flag'>--action_graph:targets=target1,target2,...</code>
2583 filters the actions to the comma-separated list of targets when dumping the
2584 action graph.</li>
ahumeskya0f3a652018-09-17 09:23:44 -07002585 <li><code class='flag'>--action_graph:include_cmdline</code> Include the command lines of actions
2586 in the action graph dump.</li>
tomlu72642a22017-10-18 06:23:14 +02002587</ul>
2588
tomlu5af61382017-10-30 18:01:48 -04002589 <h4 id='memory-tracking'>Memory tracking</h4>
2590 <p>
2591 Some <code>dump</code> commands require memory tracking. To turn this on, you have to pass
2592 startup flags to Bazel:
2593 </p>
2594 <ul>
2595 <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 -04002596 <li><code>--host_jvm_args=-DRULE_MEMORY_TRACKER=1</code></li>
tomlu5af61382017-10-30 18:01:48 -04002597 </ul>
2598 <p>
2599 The java-agent is checked into bazel at
2600 third_party/allocation_instrumenter/java-allocation-instrumenter-3.0.1.jar, so make
2601 sure you adjust <code>$BAZEL</code> for where you keep your bazel repository.
tomlu72642a22017-10-18 06:23:14 +02002602
tomlu5af61382017-10-30 18:01:48 -04002603 Do not forget to keep passing these options to Bazel for every command or the server will
2604 restart.
2605 </p>
2606 <p>Example:</p>
2607 <pre>
2608 % bazel --host_jvm_args=-javaagent:$BAZEL/third_party/allocation_instrumenter/java-allocation-instrumenter-3.0.1.jar \
2609 --host_jvm_args=-DRULE_MEMORY_TRACKER=1 \
2610 build --nobuild &lt;targets&gt;
tomlu72642a22017-10-18 06:23:14 +02002611
tomlu5af61382017-10-30 18:01:48 -04002612 # Dump rules
2613 % bazel --host_jvm_args=-javaagent:$BAZEL/third_party/allocation_instrumenter/java-allocation-instrumenter-3.0.1.jar \
2614 --host_jvm_args=-DRULE_MEMORY_TRACKER=1 \
2615 dump --rules
tomlu72642a22017-10-18 06:23:14 +02002616
gregceca48e9a2020-04-14 08:54:38 -07002617 # Dump Starlark heap and analyze it with pprof
tomlu5af61382017-10-30 18:01:48 -04002618 % bazel --host_jvm_args=-javaagent:$BAZEL/third_party/allocation_instrumenter/java-allocation-instrumenter-3.0.1.jar \
2619 --host_jvm_args=-DRULE_MEMORY_TRACKER=1 \
2620 dump --skylark_memory=$HOME/prof.gz
2621 % pprof -flame $HOME/prof.gz
2622 </pre>
brandjoncf0390b2020-02-20 10:37:40 -08002623<h3 id='analyze-profile'><code>analyze-profile</code></h3>
tomlu72642a22017-10-18 06:23:14 +02002624
2625<p>
2626 The <code>analyze-profile</code> command analyzes data previously gathered
2627 during the build using <code class='flag'>--profile</code> option. It provides several
2628 options to either perform analysis of the build execution or export data in
2629 the specified format.
2630
2631</p>
2632<p>
2633 The following options are supported:
2634</p>
2635<ul>
2636 <li><code id='flag--dump'>--dump=text</code> displays all gathered data in a
Googler59830672019-01-03 10:33:49 -08002637 <a href='guide.html#dump-text-format'>human-readable format</a></li>
tomlu72642a22017-10-18 06:23:14 +02002638 <li><code>--dump=raw</code> displays all gathered data in a
Googler59830672019-01-03 10:33:49 -08002639 <a href='guide.html#dump-raw-format'>script-friendly format</a></li>
2640 <li><code id='flag--html'>--html</code> generates an <a href='guide.html#dump-html-format'>HTML file</a> visualizing the
tomlu72642a22017-10-18 06:23:14 +02002641 actions and rules executed in the build, as well as summary statistics for the build
2642 <ul>
2643 <li><code id='flag--html_details'>--html_details</code> adds more fine-grained
2644 information on actions and rules to the HTML visualization</li>
2645 <ul>
2646 <li><code id='flag--html_histograms'>--html_histograms</code> adds histograms for Skylark
2647 functions clicked in the statistics table. This will increase file size massively</li>
2648 <li><code id='flag--nochart'>--nochart</code> hides the task chart from generated HTML
2649 </li>
2650 </ul>
2651 </ul>
2652 </li>
2653 <li><code id='flag--combine'>--combine</code> combines multiple profile data files into a single
2654 report. Does not generate HTML task charts</li>
2655 <li><code id='flag--task_tree'>--task_tree</code> prints the tree of tasks matching the given
2656 regular expression
2657 <ul>
2658 <li><code id='flag--task_tree_threshold'>--task_tree_threshold</code> skip tasks with duration
jingwen74065202018-11-21 11:34:55 -08002659 less than threshold, in milliseconds. Default is 50ms</li>
tomlu72642a22017-10-18 06:23:14 +02002660 </ul>
2661 </li>
2662</ul>
2663
2664<p>
Googler59830672019-01-03 10:33:49 -08002665 See the section on <a href='guide.html#profiling'>Troubleshooting performance by profiling</a> for
tomlu72642a22017-10-18 06:23:14 +02002666 format details and usage help.
2667
David Chen8fe82a32016-08-24 10:55:41 +00002668</p>
2669
brandjoncf0390b2020-02-20 10:37:40 -08002670<h3 id='canonicalize'><code>canonicalize-flags</code></h3>
David Chen8fe82a32016-08-24 10:55:41 +00002671
2672<p>
2673 The <code>canonicalize-flags</code> command, which takes a list of options for
2674 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
2685 ensure that the effect is identical.
2686</p>
2687
brandjoncf0390b2020-02-20 10:37:40 -08002688<h3 id='startup_options'>Startup options</h3>
David Chen8fe82a32016-08-24 10:55:41 +00002689
2690<p>
2691 The options described in this section affect the startup of the Java
2692 virtual machine used by Bazel server process, and they apply to all
2693 subsequent commands handled by that server. If there is an already
2694 running Bazel server and the startup options do not match, it will
2695 be restarted.
2696</p>
2697<p>
2698 All of the options described in this section must be specified using the
2699 <code class='flag'>--key=value</code> or <code class='flag'>--key value</code>
2700 syntax. Also, these options must appear <i>before</i> the name of the Bazel
2701 command.
2702</p>
2703
2704<h4 id='flag--output_base'><code class='flag'>--output_base=<var>dir</var></code></h4>
2705<p>
2706 This option requires a path argument, which must specify a
2707 writable directory. Bazel will use this location to write all its
2708 output. The output base is also the key by which the client locates
2709 the Bazel server. By changing the output base, you change the server
2710 which will handle the command.
2711</p>
2712<p>
2713 By default, the output base is derived from the user's login name,
2714 and the name of the workspace directory (actually, its MD5 digest),
2715 so a typical value looks like:
2716
lberkif071a232017-12-07 04:21:34 -08002717 <code>/var/tmp/google/_bazel_johndoe/d41d8cd98f00b204e9800998ecf8427e</code>.
David Chen8fe82a32016-08-24 10:55:41 +00002718 Note that the client uses the output base to find the Bazel server
2719 instance, so if you specify a different output base in a Bazel
2720 command, a different server will be found (or started) to handle the
2721 request. It's possible to perform two concurrent builds in the same
2722 workspace directory by varying the output base.
2723</p>
2724
2725<p>For example:</p>
sxlijin90f244f2020-05-12 06:08:15 -07002726<pre><code>
2727 OUTPUT_BASE=/var/tmp/google/_bazel_johndoe/custom_output_base
laurentlbdad21ed2020-05-13 16:00:41 -07002728 % bazel --output_base $OUTPUT_BASE build //foo &amp; bazel --output_base $OUTPUT_BASE build //bar
2729</code></pre>
2730<p>
2731 In this command, the two Bazel commands run concurrently (because of
2732 the shell <code>&amp;</code> operator), each using a different Bazel
2733 server instance (because of the different output bases).
2734 In contrast, if the default output base was used in both commands,
2735 then both requests would be sent to the same server, which would
2736 handle them sequentially: building <code>//foo</code> first, followed
2737 by an incremental build of <code>//bar</code>.
2738</p>
2739<p>
2740 We recommend you do not use NFS locations for the output base, as
2741 the higher access latency of NFS will cause noticeably slower
2742 builds.
2743</p>
2744
David Chen8fe82a32016-08-24 10:55:41 +00002745<h4 id='flag--output_user_root'><code class='flag'>--output_user_root=<var>dir</var></code></h4>
2746<p>
2747 By default, the <code>output_base</code> value is chosen to as to
2748 avoid conflicts between multiple users building in the same workspace directory.
2749 In some situations, though, it is desirable to build from a directory
2750 shared between multiple users; release engineers often do this. In
2751 those cases it may be useful to deliberately override the default so
2752 as to ensure "conflicts" (i.e., sharing) between multiple users.
2753 Use the <code class='flag'>--output_user_root</code> option to achieve this: the
2754 output base is placed in a subdirectory of the output user root,
2755 with a unique name based on the workspace, so the result of using an
2756 output user root that is not a function of <code>$USER</code> is
2757 sharing. Of course, it is important to ensure (via umask and group
2758 membership) that all the cooperating users can read/write each
2759 others files.
2760</p>
2761<p>
2762 If the <code class='flag'>--output_base</code> option is specified, it overrides
2763 using <code class='flag'>--output_user_root</code> to calculate the output base.
2764</p>
2765<p>
2766 The install base location is also calculated based on
2767 <code class='flag'>--output_user_root</code>, plus the MD5 identity of the Bazel embedded
2768 binaries.
2769</p>
2770<p>
2771 You can also use the <code class='flag'>--output_user_root</code> option to choose an
2772 alternate base location for all of Bazel's output (install base and output
2773 base) if there is a better location in your filesystem layout.
2774</p>
2775
cushon2a8b6572018-07-25 10:33:40 -07002776<a name="startup_flag--host_javabase"></a>
2777<h4 id='startup_flag--server_javabase'><code class='flag'>--server_javabase=<var>dir</var></code></h4>
Googlerba66e722017-12-04 12:15:36 -08002778<p>
2779 Specifies the Java virtual machine in which <i>Bazel itself</i> runs. The value must be a path to
2780 the directory containing a JDK or JRE. It should not be a label.
Googlera37711b2018-09-11 10:25:01 -07002781 This option should appear before any Bazel command, for example:
Googlerba66e722017-12-04 12:15:36 -08002782</p>
2783<pre>
Googler1523e3b2020-04-17 09:31:34 -07002784 % bazel --server_javabase=/usr/local/buildtools/java/jdk11 build //foo
Googlerba66e722017-12-04 12:15:36 -08002785</pre>
2786<p>
2787 This flag does <i>not</i> affect the JVMs used by Bazel subprocesses such as applications, tests,
2788 tools, and so on. Use build options <a href='#flag--javabase'>--javabase</a> or
2789 <a href='#flag--host_javabase'>--host_javabase</a> instead.
2790</p>
cushon2a8b6572018-07-25 10:33:40 -07002791<p>
2792 This flag was previously named <code>--host_javabase</code> (sometimes referred to as the
2793 'left-hand side' <code>--host_javabase</code>), but was renamed to avoid confusion with the
2794 build flag <a href='#flag--host_javabase'>--host_javabase</a> (sometimes referred to as the
2795 'right-hand side' <code>--host_javabase</code>).
2796</p>
Googlerba66e722017-12-04 12:15:36 -08002797
David Chen8fe82a32016-08-24 10:55:41 +00002798<h4 id='flag--host_jvm_args'><code class='flag'>--host_jvm_args=<var>string</var></code></h4>
2799<p>
2800 Specifies a startup option to be passed to the Java virtual machine in which <i>Bazel itself</i>
2801 runs. This can be used to set the stack size, for example:
2802</p>
2803<pre>
2804 % bazel --host_jvm_args="-Xss256K" build //foo
2805</pre>
2806<p>
2807 This option can be used multiple times with individual arguments. Note that
2808 setting this flag should rarely be needed. You can also pass a space-separated list of strings,
2809 each of which will be interpreted as a separate JVM argument, but this feature will soon be
2810 deprecated.
2811
2812</p>
2813<p>
2814 That this does <i>not</i> affect any JVMs used by
ccalvarinaf8b7722018-06-06 11:54:00 -07002815 subprocesses of Bazel: applications, tests, tools, and so on. To pass
David Chen8fe82a32016-08-24 10:55:41 +00002816 JVM options to executable Java programs, whether run by <code>bazel
2817 run</code> or on the command-line, you should use
2818 the <code>--jvm_flags</code> argument which
2819 all <code>java_binary</code> and <code>java_test</code> programs
2820 support. Alternatively for tests, use <code>bazel
2821 test --test_arg=--jvm_flags=foo ...</code>.
2822</p>
2823
2824<h4 id='flag--host_jvm_debug'><code class='flag'>--host_jvm_debug</code></h4>
2825<p>
2826 This option causes the Java virtual machine to wait for a connection
2827 from a JDWP-compliant debugger before
2828 calling the main method of <i>Bazel itself</i>. This is primarily
2829 intended for use by Bazel developers.
2830</p>
2831<p>
2832 (Please note that this does <i>not</i> affect any JVMs used by
2833 subprocesses of Bazel: applications, tests, tools, etc.)
2834</p>
2835
2836<h4 id='flag--batch'><code class='flag'>--batch</code></h4>
ccalvarinaf8b7722018-06-06 11:54:00 -07002837
David Chen8fe82a32016-08-24 10:55:41 +00002838<p>
ccalvarinaf8b7722018-06-06 11:54:00 -07002839 Batch mode causes Bazel to not use the standard client/server mode described
Googler59830672019-01-03 10:33:49 -08002840 <a href='guide.html#client/server'>above</a>, instead running a bazel java process for a
ccalvarinaf8b7722018-06-06 11:54:00 -07002841 single command, which has been used for more predictable semantics with respect
2842 to signal handling, job control, and environment variable inheritance, and is
2843 necessary for running bazel in a chroot jail.
David Chen8fe82a32016-08-24 10:55:41 +00002844</p>
2845
2846<p>
2847 Batch mode retains proper queueing semantics within the same output_base.
2848 That is, simultaneous invocations will be processed in order, without overlap.
ccalvarinaf8b7722018-06-06 11:54:00 -07002849 If a batch mode Bazel is run on a client with a running server, it first
David Chen8fe82a32016-08-24 10:55:41 +00002850 kills the server before processing the command.
2851</p>
2852
2853<p>
ccalvarinaf8b7722018-06-06 11:54:00 -07002854 Bazel will run slower in batch mode, or with the alternatives described above.
2855 This is because, among other things, the build file cache is memory-resident, so it is not
David Chen8fe82a32016-08-24 10:55:41 +00002856 preserved between sequential batch invocations.
2857 Therefore, using batch mode often makes more sense in cases where performance
2858 is less critical, such as continuous builds.
2859</p>
2860
michajlod72eb8d2019-11-19 10:58:53 -08002861<p>
2862 <i>WARNING:</i> <code class='flag'>--batch</code> is sufficiently slower than standard
2863 client/server mode. Additionally it might not support all of the features and optimizations which
2864 are made possible by a persistent Bazel server. If you're using <code class='flag'>--batch</code>
2865 for the purpose of build isolation, we recommend using the command option
2866 <code class='flag'>--nokeep_state_after_build</code>, which guarantees that no incremental
2867 in-memory state is kept between builds. In order to restart the Bazel server and JVM after a
2868 build, please explicitly do so using the "shutdown" command.
2869</p>
2870
2871
David Chen8fe82a32016-08-24 10:55:41 +00002872<h4 id='flag--max_idle_secs'><code class='flag'>--max_idle_secs <var>n</var></code></h4>
2873<p>
2874 This option specifies how long, in seconds, the Bazel server process
2875 should wait after the last client request, before it exits. The
dchaicf988cd2019-08-23 06:35:03 -07002876 default value is 10800 (3 hours). <code class='flag'>--max_idle_secs=0</code> will cause the
2877 Bazel server process to persist indefinitely.
David Chen8fe82a32016-08-24 10:55:41 +00002878</p>
2879<p>
2880 This option may be used by scripts that invoke Bazel to ensure that
2881 they do not leave Bazel server processes on a user's machine when they
2882 would not be running otherwise.
2883 For example, a presubmit script might wish to
2884 invoke <code>bazel query</code> to ensure that a user's pending
2885 change does not introduce unwanted dependencies. However, if the
2886 user has not done a recent build in that workspace, it would be
2887 undesirable for the presubmit script to start a Bazel server just
2888 for it to remain idle for the rest of the day.
2889 By specifying a small value of <code class='flag'>--max_idle_secs</code> in the
2890 query request, the script can ensure that <i>if</i> it caused a new
2891 server to start, that server will exit promptly, but if instead
2892 there was already a server running, that server will continue to run
2893 until it has been idle for the usual time. Of course, the existing
2894 server's idle timer will be reset.
2895</p>
shreyax5f2d5642018-10-29 15:01:24 -07002896<h4 id='flag--shutdown_on_low_sys_mem'><code class='flag'>--[no]shutdown_on_low_sys_mem</code></h4>
2897<p>
2898 If enabled and <code class='flag'>--max_idle_secs</code> is set to a positive duration,
2899 after the build server has been idle for a while, shut down the server when the system is
2900 low on memory. Linux only.
2901</p>
2902<p>
2903 In addition to running an idle check corresponding to max_idle_secs, the build server will
2904 starts monitoring available system memory after the server has been idle for some time.
2905 If the available system memory becomes critically low, the server will exit.
2906</p>
David Chen8fe82a32016-08-24 10:55:41 +00002907
2908<h4 id='flag--block_for_lock'><code class='flag'>--[no]block_for_lock</code></h4>
2909<p>
2910 If enabled, Bazel will wait for other Bazel commands holding the
2911 server lock to complete before progressing. If disabled, Bazel will
2912 exit in error if it cannot immediately acquire the lock and
2913 proceed.
2914
2915 Developers might use this in presubmit checks to avoid long waits caused
2916 by another Bazel command in the same client.
2917</p>
2918
2919<h4 id='flag--io_nice_level'><code class='flag'>--io_nice_level <var>n</var></code></h4>
2920<p>
2921 Sets a level from 0-7 for best-effort IO scheduling. 0 is highest priority,
2922 7 is lowest. The anticipatory scheduler may only honor up to priority 4.
2923 Negative values are ignored.
2924</p>
2925
2926<h4 id='flag--batch_cpu_scheduling'><code class='flag'>--batch_cpu_scheduling</code></h4>
2927<p>
2928 Use <code>batch</code> CPU scheduling for Bazel. This policy is useful for
2929 workloads that are non-interactive, but do not want to lower their nice value.
2930 See 'man 2 sched_setscheduler'. This policy may provide for better system
2931 interactivity at the expense of Bazel throughput.
2932</p>
2933
2934<h3 id='misc_options'>Miscellaneous options</h3>
2935
2936<h4 id='flag--announce_rc'><code class='flag'>--[no]announce_rc</code></h4>
2937<p>
2938 Controls whether Bazel announces command options read from the bazelrc file when
2939 starting up. (Startup options are unconditionally announced.)
2940</p>
2941
2942<h4 id='flag--color'><code class='flag'>--color (yes|no|auto)</code></h4>
2943<p>
2944 This option determines whether Bazel will use colors to highlight
2945 its output on the screen.
2946</p>
2947<p>
2948 If this option is set to <code>yes</code>, color output is enabled.
2949 If this option is set to <code>auto</code>, Bazel will use color output only if
2950 the output is being sent to a terminal and the TERM environment variable
2951 is set to a value other than <code>dumb</code>, <code>emacs</code>, or <code>xterm-mono</code>.
2952 If this option is set to <code>no</code>, color output is disabled,
2953 regardless of whether the output is going to a terminal and regardless
2954 of the setting of the TERM environment variable.
2955</p>
2956
2957<h4 id='flag--config'><code class='flag'>--config <var>name</var></code></h4>
2958<p>
2959 Selects additional config section from the rc files; for the current
2960 <code>command</code>, it also pulls in the options from
Googlerc848bf32017-02-14 12:15:42 +00002961 <code>command:name</code> if such a section exists. Can be specified multiple
2962 times to add flags from several config sections. Expansions can refer to other
2963 definitions (i.e. expansions can be chained).
David Chen8fe82a32016-08-24 10:55:41 +00002964</p>
2965
2966<h4 id='flag--curses'><code class='flag'>--curses (yes|no|auto)</code></h4>
2967<p>
2968 This option determines whether Bazel will use cursor controls
2969 in its screen output. This results in less scrolling data, and a more
2970 compact, easy-to-read stream of output from Bazel. This works well with
2971 <code class='flag'>--color</code>.
2972</p>
2973<p>
2974 If this option is set to <code>yes</code>, use of cursor controls is enabled.
2975 If this option is set to <code>no</code>, use of cursor controls is disabled.
2976 If this option is set to <code>auto</code>, use of cursor controls will be
2977 enabled under the same conditions as for <code class='flag'>--color=auto</code>.
2978</p>
2979
2980<h4 id='flag--show_timestamps'><code class='flag'>--[no]show_timestamps</code></h4>
2981<p>
2982 If specified, a timestamp is added to each message generated by
2983 Bazel specifying the time at which the message was displayed.
2984</p>