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