David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 1 | --- |
| 2 | layout: documentation |
| 3 | title: User Manual |
| 4 | --- |
laurentlb | 27453bf | 2018-10-08 11:23:18 -0700 | [diff] [blame] | 5 | <h1>Commands and Options</h1> |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 6 | |
laurentlb | adf3607 | 2018-11-05 16:20:20 -0800 | [diff] [blame] | 7 | <h2 id='target-patterns'>Target Syntax</h2> |
| 8 | |
| 9 | Some commands, like <code>build</code> or <code>test</code>, can operate |
| 10 | on a list of targets. They use a syntax more flexible than labels, which is |
| 11 | documented in the "<a href="guide.html#target-patterns">Specifying |
| 12 | targets to build</a>" section of the User's Guide. |
| 13 | |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 14 | <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 | |
| 29 | <h3>Options that affect how packages are located</h3> |
| 30 | |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 31 | <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 Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 35 | </p> |
| 36 | |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 37 | <p> |
laurentlb | 1591818 | 2018-10-17 11:44:25 -0700 | [diff] [blame] | 38 | 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 Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 41 | </p> |
| 42 | |
laurentlb | 1591818 | 2018-10-17 11:44:25 -0700 | [diff] [blame] | 43 | <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> |
| 51 | Package 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 Chebotarev | 66885ff | 2018-12-04 14:08:16 -0800 | [diff] [blame^] | 77 | it in your <a href='guide.html#bazelrc'>Bazel configuration file</a> for |
laurentlb | 1591818 | 2018-10-17 11:44:25 -0700 | [diff] [blame] | 78 | 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> |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 95 | <h3 id='checking-options'>Error checking options</h3> |
| 96 | <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 Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 129 | <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 |
ulfjack | 171314b | 2017-06-02 09:09:43 +0200 | [diff] [blame] | 134 | output and standard error are thrown away. |
| 135 | </p> |
| 136 | <p> |
| 137 | Here are some typical values for this option: |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 138 | </p> |
| 139 | <table> |
| 140 | <tr> |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 141 | <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> |
ulfjack | 171314b | 2017-06-02 09:09:43 +0200 | [diff] [blame] | 149 | <td><code class='flag'>--output_filter=</code></td> |
Googler | 4da2f16 | 2017-07-17 21:36:56 +0200 | [diff] [blame] | 150 | <td>Show everything. |
ulfjack | 171314b | 2017-06-02 09:09:43 +0200 | [diff] [blame] | 151 | </td> |
| 152 | </tr> |
| 153 | <tr> |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 154 | <td><code class='flag'>--output_filter=DONT_MATCH_ANYTHING</code></td> |
ulfjack | 171314b | 2017-06-02 09:09:43 +0200 | [diff] [blame] | 155 | <td>Show nothing. |
| 156 | </td> |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 157 | </tr> |
| 158 | </table> |
| 159 | |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 160 | <h3 id='flags-options'>Flags options</h3> |
| 161 | <p> |
| 162 | These options control which options Bazel will pass to other tools. |
| 163 | </p> |
| 164 | |
Googler | 9cfa4cb | 2018-06-04 22:19:11 -0700 | [diff] [blame] | 165 | <h4 id='flag--copt'><code class='flag'>--copt <var>cc-option</var></code></h4> |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 166 | <p> |
Googler | 9cfa4cb | 2018-06-04 22:19:11 -0700 | [diff] [blame] | 167 | 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 Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 169 | 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 |
Googler | 9cfa4cb | 2018-06-04 22:19:11 -0700 | [diff] [blame] | 186 | cc_library or cc_binary build rules will be placed on the compiler command line |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 187 | <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>. |
Googler | 9cfa4cb | 2018-06-04 22:19:11 -0700 | [diff] [blame] | 194 | Similarly, compiler options that only have an |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 195 | 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 | |
Googler | 9cfa4cb | 2018-06-04 22:19:11 -0700 | [diff] [blame] | 199 | <h4 id='flag--host_copt'><code class='flag'>--host_copt <var>cc-option</var></code></h4> |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 200 | <p> |
Googler | 9cfa4cb | 2018-06-04 22:19:11 -0700 | [diff] [blame] | 201 | This option takes an argument which is to be passed to the compiler for source files |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 202 | 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 | |
Googler | 9cfa4cb | 2018-06-04 22:19:11 -0700 | [diff] [blame] | 207 | <h4 id='flag--host_cxxopt'><code class='flag'>--host_cxxopt <var>cc-option</var></code></h4> |
Marcel Hlopko | 4c1b1fd | 2017-02-24 12:54:17 +0000 | [diff] [blame] | 208 | <p> |
Googler | 9cfa4cb | 2018-06-04 22:19:11 -0700 | [diff] [blame] | 209 | This option takes an argument which is to be passed to the compiler for C++ source files |
Marcel Hlopko | 4c1b1fd | 2017-02-24 12:54:17 +0000 | [diff] [blame] | 210 | 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 | |
Googler | 9cfa4cb | 2018-06-04 22:19:11 -0700 | [diff] [blame] | 215 | <h4 id='flag--conlyopt'><code class='flag'>--conlyopt <var>cc-option</var></code></h4> |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 216 | <p> |
Googler | 9cfa4cb | 2018-06-04 22:19:11 -0700 | [diff] [blame] | 217 | This option takes an argument which is to be passed to the compiler when compiling C source files. |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 218 | </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 |
Googler | 9cfa4cb | 2018-06-04 22:19:11 -0700 | [diff] [blame] | 226 | will be placed on the compiler command line <em>after</em> these options. |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 227 | </p> |
| 228 | |
Googler | 9cfa4cb | 2018-06-04 22:19:11 -0700 | [diff] [blame] | 229 | <h4 id='flag--cxxopt'><code class='flag'>--cxxopt <var>cc-option</var></code></h4> |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 230 | <p> |
Googler | 9cfa4cb | 2018-06-04 22:19:11 -0700 | [diff] [blame] | 231 | This option takes an argument which is to be passed to the compiler when compiling C++ source |
| 232 | files. |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 233 | </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 |
Googler | 9cfa4cb | 2018-06-04 22:19:11 -0700 | [diff] [blame] | 245 | will be placed on the compiler command line <em>after</em> these options. |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 246 | </p> |
| 247 | |
| 248 | <h4 id='flag--linkopt'><code class='flag'>--linkopt <var>linker-option</var></code></h4> |
| 249 | <p> |
Googler | 9cfa4cb | 2018-06-04 22:19:11 -0700 | [diff] [blame] | 250 | This option takes an argument which is to be passed to the compiler when linking. |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 251 | </p> |
| 252 | <p> |
| 253 | This is similar to <code class='flag'>--copt</code>, but only applies to linking, |
Googler | 9cfa4cb | 2018-06-04 22:19:11 -0700 | [diff] [blame] | 254 | not to compilation. So you can pass compiler options that only make sense |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 255 | 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. |
| 273 | The default value of <code class='flag'>--strip=sometimes</code> means strip iff the <code class='flag'>--compilation_mode</code> |
| 274 | is <code>fastbuild</code>. |
| 275 | </p> |
| 276 | <pre> |
| 277 | % bazel build --strip=always //foo:bar |
| 278 | </pre> |
| 279 | <p> |
| 280 | will compile the target while stripping debugging information from all generated |
| 281 | binaries. |
| 282 | </p> |
| 283 | <p> |
| 284 | Note that if you want debugging information, it's not enough to disable stripping; you also need to make |
| 285 | sure that the debugging information was generated by the compiler, which you can do by using either |
| 286 | <code>-c dbg</code> or <code class='flag'>--copt -g</code>. |
| 287 | </p> |
| 288 | <p> |
| 289 | Note also that Bazel's <code class='flag'>--strip</code> option corresponds with ld's <code>--strip-debug</code> option: |
| 290 | it only strips debugging information. If for some reason you want to strip <em>all</em> symbols, |
| 291 | not just <em>debug</em> symbols, you would need to use ld's <code>--strip-all</code> option, |
| 292 | which you can do by passing <code class='flag'>--linkopt=-Wl,--strip-all</code> to Bazel. |
| 293 | </p> |
| 294 | |
| 295 | <h4 id='flag--stripopt'><code class='flag'>--stripopt <var>strip-option</var></code></h4> |
| 296 | <p> |
| 297 | An additional option to pass to the <code>strip</code> command when generating |
| 298 | a <a href="be/c-cpp.html#cc_binary_implicit_outputs"><code>*.stripped</code> |
| 299 | binary</a>. The default is <code>-S -p</code>. This option can be used |
| 300 | multiple times. |
| 301 | </p> |
| 302 | <p> |
| 303 | Note that <code class='flag'>--stripopt</code> does not apply to the stripping of the main |
| 304 | binary with <code><a href='#flag--strip'>--strip</a>=(always|sometimes)</code>. |
| 305 | </p> |
| 306 | |
| 307 | <h4 id='flag--fdo_instrument'><code class='flag'>--fdo_instrument <var>profile-output-dir</var></code></h4> |
| 308 | <p> |
| 309 | The <code class='flag'>--fdo_instrument</code> option enables the generation of |
| 310 | FDO (feedback directed optimization) profile output when the |
| 311 | built C/C++ binary is executed. For GCC, the argument provided is used as a |
| 312 | directory prefix for a per-object file directory tree of .gcda files |
| 313 | containing profile information for each .o file. |
| 314 | </p> |
| 315 | <p> |
| 316 | Once the profile data tree has been generated, the profile tree |
| 317 | should be zipped up, and provided to the |
| 318 | <code class='flag'>--fdo_optimize=<var>profile-zip</var></code> |
| 319 | Bazel option to enable the FDO optimized compilation. |
| 320 | |
| 321 | </p> |
| 322 | <p> |
| 323 | For the LLVM compiler the argument is also the directory under which the raw LLVM profile |
| 324 | data file(s) is dumped, e.g. |
| 325 | <code class='flag'>--fdo_instrument=<var>/path/to/rawprof/dir/</var></code>. |
| 326 | </p> |
| 327 | <p> |
| 328 | The options <code class='flag'>--fdo_instrument</code> and <code class='flag'>--fdo_optimize</code> |
| 329 | cannot be used at the same time. |
| 330 | </p> |
| 331 | |
| 332 | <h4 id='flag--fdo_optimize'><code class='flag'>--fdo_optimize <var>profile-zip</var></code></h4> |
| 333 | <p> |
| 334 | The <code class='flag'>--fdo_optimize</code> option enables the use of the |
| 335 | per-object file profile information to perform FDO (feedback |
| 336 | directed optimization) optimizations when compiling. For GCC, the argument |
| 337 | provided is the zip file containing the previously-generated file tree |
| 338 | of .gcda files containing profile information for each .o file. |
| 339 | </p> |
| 340 | <p> |
| 341 | Alternatively, the argument provided can point to an auto profile |
| 342 | identified by the extension .afdo. |
| 343 | |
| 344 | </p> |
| 345 | <p> |
| 346 | Note that this option also accepts labels that resolve to source files. You |
| 347 | may need to add an <code>exports_files</code> directive to the corresponding package to |
| 348 | make the file visible to Bazel. |
| 349 | </p> |
| 350 | <p> |
| 351 | For the LLVM compiler the argument provided should point to the indexed LLVM |
| 352 | profile output file prepared by the llvm-profdata tool, and should have a .profdata |
| 353 | extension. |
| 354 | </p> |
| 355 | <p> |
| 356 | The options <code class='flag'>--fdo_instrument</code> and <code class='flag'> |
| 357 | --fdo_optimize</code> cannot be used at the same time. |
| 358 | </p> |
| 359 | |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 360 | |
| 361 | <h4 id='flag--output_symbol_counts'><code class='flag'>--[no]output_symbol_counts</code></h4> |
| 362 | <p> |
Googler | d727327 | 2017-05-02 18:56:29 +0200 | [diff] [blame] | 363 | If enabled, each gold-invoked link of a C++ executable binary will output |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 364 | a <i>symbol counts</i> file (via the <code>--print-symbol-counts</code> gold |
Googler | d727327 | 2017-05-02 18:56:29 +0200 | [diff] [blame] | 365 | option). For each linker input, the file logs the number of symbols that were |
| 366 | defined and the number of symbols that were used in the binary. |
| 367 | This information can be used to track unnecessary link dependencies. |
| 368 | The symbol counts file is written to the binary's output path with the name |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 369 | <code>[targetname].sc</code>. |
| 370 | </p> |
| 371 | <p> |
| 372 | This option is disabled by default. |
| 373 | </p> |
| 374 | |
| 375 | <h4 id='flag--jvmopt'><code class='flag'>--jvmopt <var>jvm-option</var></code></h4> |
| 376 | <p> |
| 377 | This option allows option arguments to be passed to the Java VM. It can be used |
| 378 | with one big argument, or multiple times with individual arguments. For example: |
| 379 | </p> |
| 380 | <pre> |
| 381 | % bazel build --jvmopt="-server -Xms256m" java/com/example/common/foo:all |
| 382 | </pre> |
| 383 | <p> |
| 384 | will use the server VM for launching all Java binaries and set the |
| 385 | startup heap size for the VM to 256 MB. |
| 386 | </p> |
| 387 | |
| 388 | <h4 id='flag--javacopt'><code class='flag'>--javacopt <var>javac-option</var></code></h4> |
| 389 | <p> |
| 390 | This option allows option arguments to be passed to javac. It can be used |
| 391 | with one big argument, or multiple times with individual arguments. For example: |
| 392 | </p> |
| 393 | <pre> |
| 394 | % bazel build --javacopt="-g:source,lines" //myprojects:prog |
| 395 | </pre> |
| 396 | <p> |
| 397 | will rebuild a java_binary with the javac default debug info |
| 398 | (instead of the bazel default). |
| 399 | </p> |
| 400 | <p> |
| 401 | The option is passed to javac after the Bazel built-in default options for |
| 402 | javac and before the per-rule options. The last specification of |
| 403 | any option to javac wins. The default options for javac are: |
| 404 | </p> |
| 405 | |
| 406 | <pre> |
| 407 | -source 8 -target 8 -encoding UTF-8 |
| 408 | </pre> |
| 409 | <p> |
| 410 | Note that changing <code class='flag'>--javacopt</code> settings will force a recompilation |
| 411 | of all affected classes. Also note that javacopts parameters listed in |
| 412 | specific java_library or java_binary build rules will be placed on the javac |
| 413 | command line <em>after</em> these options. |
| 414 | </p> |
| 415 | |
| 416 | <h5 id='-extra_checks'><code>-extra_checks[:(off|on)]</code></h5> |
| 417 | |
| 418 | <p> |
| 419 | This javac option enables extra correctness checks. Any problems found will |
| 420 | be presented as errors. |
| 421 | Either <code>-extra_checks</code> or <code>-extra_checks:on</code> may be used |
| 422 | to force the checks to be turned on. <code>-extra_checks:off</code> completely |
| 423 | disables the analysis. |
| 424 | When this option is not specified, the default behavior is used. |
| 425 | </p> |
| 426 | |
| 427 | <h4 id='flag--strict_java_deps'><code class='flag'>--strict_java_deps |
| 428 | (default|strict|off|warn|error)</code></h4> |
| 429 | <p> |
| 430 | This option controls whether javac checks for missing direct dependencies. |
| 431 | Java targets must explicitly declare all directly used targets as |
| 432 | dependencies. This flag instructs javac to determine the jars actually used |
| 433 | for type checking each java file, and warn/error if they are not the output |
| 434 | of a direct dependency of the current target. |
| 435 | </p> |
| 436 | |
| 437 | <ul> |
| 438 | <li> <code>off</code> means checking is disabled. |
| 439 | </li> |
| 440 | <li> <code>warn</code> means javac will generate standard java warnings of |
| 441 | type <code>[strict]</code> for each missing direct dependency. |
| 442 | </li> |
| 443 | <li> <code>default</code>, <code>strict</code> and <code>error</code> all |
| 444 | mean javac will generate errors instead of warnings, causing the current |
| 445 | target to fail to build if any missing direct dependencies are found. |
| 446 | This is also the default behavior when the flag is unspecified. |
| 447 | </li> |
| 448 | </ul> |
| 449 | |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 450 | <h3 id='semantics-options'>Semantics options</h3> |
| 451 | <p> |
| 452 | These options affect the build commands and/or the output file contents. |
| 453 | </p> |
| 454 | |
| 455 | <h4 id='flag--compilation_mode'><code class='flag'>--compilation_mode (fastbuild|opt|dbg)</code> (-c)</h4> |
| 456 | <p> |
| 457 | This option takes an argument of <code>fastbuild</code>, <code>dbg</code> |
| 458 | or <code>opt</code>, and affects various C/C++ code-generation |
| 459 | options, such as the level of optimization and the completeness of |
| 460 | debug tables. Bazel uses a different output directory for each |
| 461 | different compilation mode, so you can switch between modes without |
| 462 | needing to do a full rebuild <i>every</i> time. |
| 463 | </p> |
| 464 | <ul> |
| 465 | <li> <code>fastbuild</code> means build as fast as possible: |
| 466 | generate minimal debugging information (<code>-gmlt |
| 467 | -Wl,-S</code>), and don't optimize. This is the |
| 468 | default. Note: <code>-DNDEBUG</code> will <b>not</b> be set. |
| 469 | </li> |
| 470 | <li> <code>dbg</code> means build with debugging enabled (<code>-g</code>), |
| 471 | so that you can use gdb (or another debugger). |
| 472 | </li> |
| 473 | <li> <code>opt</code> means build with optimization enabled and |
| 474 | with <code>assert()</code> calls disabled (<code>-O2 -DNDEBUG</code>). |
| 475 | Debugging information will not be generated in <code>opt</code> mode |
| 476 | unless you also pass <code class='flag'>--copt -g</code>. |
| 477 | </li> |
| 478 | </ul> |
| 479 | |
| 480 | <h4 id='flag--cpu'><code class='flag'>--cpu <var>cpu</var></code></h4> |
| 481 | <p> |
| 482 | This option specifies the target CPU architecture to be used for |
| 483 | the compilation of binaries during the build. |
| 484 | </p> |
| 485 | <p> |
| 486 | |
| 487 | </p> |
Googler | f12e802 | 2018-09-11 07:51:31 -0700 | [diff] [blame] | 488 | <p> |
| 489 | Note that a particular combination of crosstool version, compiler version, |
| 490 | and target CPU is allowed only if it has been specified in the currently |
| 491 | used CROSSTOOL file. |
| 492 | </p> |
| 493 | |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 494 | |
Benjamin Peterson | 0b31854 | 2017-12-04 10:46:48 -0800 | [diff] [blame] | 495 | <h4 id='flag--experimental_action_listener'> |
| 496 | <code class='flag'>--experimental_action_listener=<var>label</var></code> |
| 497 | </h4> |
| 498 | <p> |
| 499 | The <code>experimental_action_listener</code> option instructs Bazel to use |
| 500 | details from the <a href="be/extra-actions.html#action_listener" |
| 501 | ><code>action_listener</code></a> rule specified by <var>label</var> to |
| 502 | insert <a href="be/extra-actions.html#extra_action" |
| 503 | ><code>extra_actions</code></a> into the build graph. |
| 504 | </p> |
| 505 | |
| 506 | <h4 id='flag--experimental_extra_action_top_level_only'> |
| 507 | <code class='flag'>--[no]experimental_extra_action_top_level_only</code> |
| 508 | </h4> |
| 509 | <p> |
| 510 | If this option is set to true, extra actions specified by the |
| 511 | <a href='#flag--experimental_action_listener'> <code> |
| 512 | --experimental_action_listener</code></a> command line option will only be |
| 513 | scheduled for top level targets. |
| 514 | </p> |
| 515 | |
| 516 | <h4 id='flag--experimental_extra_action_filter'> |
| 517 | <code class='flag'>--experimental_extra_action_filter=<var>regex</var></code> |
| 518 | </h4> |
| 519 | <p> |
| 520 | The <code>experimental_extra_action_filter</code> option instructs Bazel to |
| 521 | filter the set of targets to schedule <code>extra_actions</code> for. |
| 522 | </p> |
| 523 | <p> |
| 524 | This flag is only applicable in combination with the |
| 525 | <a href='#flag--experimental_action_listener' |
| 526 | ><code>--experimental_action_listener</code></a> flag. |
| 527 | </p> |
| 528 | <p> |
| 529 | By default all <code>extra_actions</code> in the transitive closure of the |
| 530 | requested targets-to-build get scheduled for execution. |
| 531 | <code>--experimental_extra_action_filter</code> will restrict scheduling to |
| 532 | <code>extra_actions</code> of which the owner's label matches the specified |
| 533 | regular expression. |
| 534 | </p> |
| 535 | <p> |
| 536 | The following example will limit scheduling of <code>extra_actions</code> |
| 537 | to only apply to actions of which the owner's label contains '/bar/': |
| 538 | </p> |
| 539 | <pre>% bazel build --experimental_action_listener=//test:al //foo/... \ |
| 540 | --experimental_extra_action_filter=.*/bar/.* |
| 541 | </pre> |
| 542 | |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 543 | <h4 id='flag--host_cpu'><code class='flag'>--host_cpu <var>cpu</var></code></h4> |
| 544 | <p> |
| 545 | This option specifies the name of the CPU architecture that should be |
| 546 | used to build host tools. |
| 547 | </p> |
| 548 | |
Alex Humesky | 105e661 | 2017-01-06 19:03:10 +0000 | [diff] [blame] | 549 | <h4 id='flag--fat_apk_cpu'><code class='flag'>--fat_apk_cpu <var>cpu[,cpu]*</var></code></h4> |
| 550 | <p> |
| 551 | The CPUs to build C/C++ libraries for in the transitive <code>deps</code> of |
| 552 | <code>android_binary</code> |
| 553 | |
| 554 | rules. Other C/C++ rules are not affected. For example, if a <code>cc_library</code> |
| 555 | appears in the transitive <code>deps</code> of an <code>android_binary</code> rule and a |
| 556 | <code>cc_binary</code> rule, the <code>cc_library</code> will be built at least twice: |
| 557 | once for each CPU specified with <code class='flag'>--fat_apk_cpu</code> for the |
| 558 | <code>android_binary</code> rule, and once for the CPU specified with |
| 559 | <code class='flag'>--cpu</code> for the <code>cc_binary</code> rule. |
| 560 | |
| 561 | <p> |
| 562 | The default is <code>armeabi-v7a</code>. |
| 563 | </p> |
| 564 | <p> |
| 565 | One <code>.so</code> file will be created and packaged in the APK for |
| 566 | each CPU specified with <code class='flag'>--fat_apk_cpu</code>. The name of the <code>.so</code> |
| 567 | file will be the name of the <code>android_binary</code> rule prefixed with "lib", e.g., if the name |
| 568 | of the <code>android_binary</code> is "foo", then the file will be <code>libfoo.so</code>. |
| 569 | </p> |
| 570 | |
| 571 | <p> |
| 572 | Note that an Android-compatible crosstool must be selected. |
| 573 | If an <code>android_ndk_repository</code> rule is defined in the |
| 574 | WORKSPACE file, an Android-compatible crosstool is automatically selected. |
| 575 | Otherwise, the crostool can be selected using the |
| 576 | <a href='#flag--android_crosstool_top'><code class='flag'>--android_crosstool_top</code></a> |
| 577 | or <a href='#flag--crosstool_top'><code class='flag'>--crosstool_top</code></a> flags. |
| 578 | </p> |
| 579 | </p> |
| 580 | |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 581 | <h4 id='flag--per_file_copt'><code class='flag'>--per_file_copt |
| 582 | <var>[+-]regex[,[+-]regex]...@option[,option]...</var></code></h4> |
| 583 | <p> |
| 584 | When present, any C++ file with a label or an execution path matching one of the inclusion regex |
| 585 | expressions and not matching any of the exclusion expressions will be built |
| 586 | with the given options. The label matching uses the canonical form of the label |
| 587 | (i.e //<code>package</code>:<code>label_name</code>). |
| 588 | |
| 589 | The execution path is the relative path to your workspace directory including the base name |
| 590 | (including extension) of the C++ file. It also includes any platform dependent prefixes. |
| 591 | Note, that if only one of the label or the execution path matches the options will be used. |
| 592 | </p> |
| 593 | <p> |
| 594 | <b>Notes</b>: |
| 595 | To match the generated files (e.g. genrule outputs) |
| 596 | Bazel can only use the execution path. In this case the regexp shouldn't start with '//' |
| 597 | since that doesn't match any execution paths. Package names can be used like this: |
| 598 | <code class='flag'>--per_file_copt=base/.*\.pb\.cc@-g0</code>. This will match every |
| 599 | <code>.pb.cc</code> file under a directory called <code>base</code>. |
| 600 | </p> |
| 601 | <p> |
| 602 | This option can be used multiple times. |
| 603 | </p> |
| 604 | <p> |
| 605 | The option is applied regardless of the compilation mode used. I.e. it is possible |
| 606 | to compile with <code class='flag'>--compilation_mode=opt</code> and selectively compile some |
| 607 | files with stronger optimization turned on, or with optimization disabled. |
| 608 | </p> |
| 609 | <p> |
| 610 | <b>Caveat</b>: If some files are selectively compiled with debug symbols the symbols |
| 611 | might be stripped during linking. This can be prevented by setting |
| 612 | <code class='flag'>--strip=never</code>. |
| 613 | </p> |
| 614 | <p> |
| 615 | <b>Syntax</b>: <code>[+-]regex[,[+-]regex]...@option[,option]...</code> Where |
| 616 | <code>regex</code> stands for a regular expression that can be prefixed with |
| 617 | a <code>+</code> to identify include patterns and with <code>-</code> to identify |
| 618 | exclude patterns. <code>option</code> stands for an arbitrary option that is passed |
| 619 | to the C++ compiler. If an option contains a <code>,</code> it has to be quoted like so |
| 620 | <code>\,</code>. Options can also contain <code>@</code>, since only the first |
| 621 | <code>@</code> is used to separate regular expressions from options. |
| 622 | </p> |
| 623 | <p> |
| 624 | <b>Example</b>: |
| 625 | <code class='flag'>--per_file_copt=//foo:.*\.cc,-//foo:file\.cc@-O0,-fprofile-arcs</code> |
| 626 | adds the <code>-O0</code> and the <code>-fprofile-arcs</code> options to the command |
| 627 | line of the C++ compiler for all <code>.cc</code> files in <code>//foo/</code> except |
| 628 | <code>file.cc</code>. |
| 629 | </p> |
| 630 | <h4 id='flag--dynamic_mode'><code class='flag'>--dynamic_mode <var>mode</var></code></h4> |
| 631 | <p> |
| 632 | Determines whether C++ binaries will be linked dynamically, interacting with |
| 633 | the <a href='be/c-cpp.html#cc_binary.linkstatic'>linkstatic |
| 634 | attribute</a> on build rules. |
| 635 | </p> |
| 636 | |
| 637 | <p> |
| 638 | Modes: |
| 639 | </p> |
| 640 | <ul> |
| 641 | <li><code>auto</code>: Translates to a platform-dependent mode; |
| 642 | <code>default</code> for linux and <code>off</code> for cygwin.</li> |
| 643 | <li><code>default</code>: Allows bazel to choose whether to link dynamically. |
| 644 | See <a href='be/c-cpp.html#cc_binary.linkstatic'>linkstatic</a> for more |
| 645 | information.</li> |
| 646 | <li><code>fully</code>: Links all targets dynamically. This will speed up |
| 647 | linking time, and reduce the size of the resulting binaries. |
| 648 | |
| 649 | </li> |
| 650 | <li><code>off</code>: Links all targets in |
| 651 | <a href='be/c-cpp.html#cc_binary.linkstatic'>mostly static</a> mode. |
| 652 | If <code>-static</code> is set in linkopts, targets will change to fully |
| 653 | static.</li> |
| 654 | </ul> |
| 655 | |
| 656 | <h4 id='flag--fission'><code class='flag'>--fission (yes|no|[dbg][,opt][,fastbuild])</code></h4> |
| 657 | <p> |
| 658 | Enables |
| 659 | |
| 660 | <a href='https://gcc.gnu.org/wiki/DebugFission'>Fission</a>, |
| 661 | which writes C++ debug information to dedicated .dwo files instead of .o files, where it would |
| 662 | otherwise go. This substantially reduces the input size to links and can reduce link times. |
| 663 | |
| 664 | </p> |
| 665 | <p> |
| 666 | When set to <code class='flag'>[dbg][,opt][,fastbuild]</code> (example: |
| 667 | <code class='flag'>--fission=dbg,fastbuild</code>), Fission is enabled |
| 668 | only for the specified set of compilation modes. This is useful for bazelrc |
| 669 | settings. When set to <code class='flag'>yes</code>, Fission is enabled |
| 670 | universally. When set to <code class='flag'>no</code>, Fission is disabled |
| 671 | universally. Default is <code class='flag'>dbg</code>. |
| 672 | </p> |
| 673 | |
| 674 | <h4 id='flag--force_ignore_dash_static'><code class='flag'>--force_ignore_dash_static</code></h4> |
| 675 | <p> |
| 676 | If this flag is set, any <code>-static</code> options in linkopts of |
| 677 | <code>cc_*</code> rules BUILD files are ignored. This is only intended as a |
| 678 | workaround for C++ hardening builds. |
| 679 | </p> |
| 680 | |
| 681 | <h4 id='flag--force_pic'><code class='flag'>--[no]force_pic</code></h4> |
| 682 | <p> |
| 683 | If enabled, all C++ compilations produce position-independent code ("-fPIC"), |
| 684 | links prefer PIC pre-built libraries over non-PIC libraries, and links produce |
| 685 | position-independent executables ("-pie"). Default is disabled. |
| 686 | </p> |
| 687 | <p> |
| 688 | Note that dynamically linked binaries (i.e. <code>--dynamic_mode fully</code>) |
| 689 | generate PIC code regardless of this flag's setting. So this flag is for cases |
| 690 | where users want PIC code explicitly generated for static links. |
| 691 | </p> |
| 692 | |
Andrew Pellegrini | 8d2c166 | 2017-01-26 16:04:12 +0000 | [diff] [blame] | 693 | <h4 id='flag--android_resource_shrinking'><code class='flag'>--android_resource_shrinking</code></h4> |
| 694 | <p> |
| 695 | Selects whether to perform resource shrinking for android_binary rules. Sets the default for the |
| 696 | <a href='be/android.html#android_binary.shrink_resources'>shrink_resources attribute</a> on |
| 697 | android_binary rules; see the documentation for that rule for further details. Defaults to off. |
| 698 | </p> |
| 699 | |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 700 | <h4 id='flag--custom_malloc'><code class='flag'>--custom_malloc <var>malloc-library-target</var></code></h4> |
| 701 | <p> |
| 702 | When specified, always use the given malloc implementation, overriding all |
| 703 | <code>malloc="target"</code> attributes, including in those targets that use the |
| 704 | default (by not specifying any <code>malloc</code>). |
| 705 | </p> |
| 706 | |
| 707 | <h4 id='flag--crosstool_top'><code class='flag'>--crosstool_top <var>label</var></code></h4> |
| 708 | <p> |
| 709 | This option specifies the location of the crosstool compiler suite |
| 710 | to be used for all C++ compilation during a build. Bazel will look in that |
| 711 | location for a CROSSTOOL file and uses that to automatically determine |
| 712 | settings for |
| 713 | |
| 714 | <code class='flag'>--compiler</code>. |
| 715 | </p> |
| 716 | |
| 717 | <h4 id='flag--host_crosstool_top'><code class='flag'>--host_crosstool_top <var>label</var></code></h4> |
| 718 | <p> |
| 719 | If not specified, bazel uses the value of <code class='flag'>--crosstool_top</code> to compile |
| 720 | code in the host configuration, i.e., tools run during the build. The main purpose of this flag |
| 721 | is to enable cross-compilation. |
| 722 | </p> |
| 723 | |
Cal Peyser | f1a15c0 | 2017-01-17 20:26:00 +0000 | [diff] [blame] | 724 | <h4 id='flag--apple_crosstool_top'><code class='flag'>--apple_crosstool_top <var>label</var></code></h4> |
| 725 | <p> |
| 726 | The crosstool to use for compiling C/C++ rules in the transitive <code>deps</code> of |
| 727 | objc_*, ios__*, and apple_* rules. For those targets, this flag overwrites |
| 728 | <code class='flag'>--crosstool_top</code>. |
| 729 | </p> |
| 730 | |
Alex Humesky | 105e661 | 2017-01-06 19:03:10 +0000 | [diff] [blame] | 731 | <h4 id='flag--android_crosstool_top'><code class='flag'>--android_crosstool_top <var>label</var></code></h4> |
| 732 | <p> |
| 733 | The crosstool to use for compiling C/C++ rules in the transitive <code>deps</code> of |
| 734 | <code>android_binary</code> rules. This is useful if other targets in the |
| 735 | build require a different crosstool. The default is to use the crosstool |
| 736 | generated by the <code>android_ndk_repository</code> rule in the WORKSPACE file. |
| 737 | See also <a href='#flag--fat_apk_cpu'><code class='flag'>--fat_apk_cpu</code></a>. |
| 738 | </p> |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 739 | <h4 id='flag--compiler'><code class='flag'>--compiler <var>version</var></code></h4> |
| 740 | <p> |
| 741 | This option specifies the C/C++ compiler version (e.g. <code>gcc-4.1.0</code>) |
| 742 | to be used for the compilation of binaries during the build. If you want to |
| 743 | build with a custom crosstool, you should use a CROSSTOOL file instead of |
| 744 | specifying this flag. |
| 745 | </p> |
| 746 | <p> |
| 747 | Note that only certain combinations of crosstool version, compiler version, |
rosica | 25ae199 | 2018-06-04 10:41:53 -0700 | [diff] [blame] | 748 | and target CPU are allowed. |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 749 | </p> |
| 750 | |
Alex Humesky | 105e661 | 2017-01-06 19:03:10 +0000 | [diff] [blame] | 751 | <h4 id='flag--android_sdk'><code class='flag'>--android_sdk <var>label</var></code></h4> |
| 752 | <p> |
| 753 | This option specifies the Android SDK/platform toolchain |
| 754 | and Android runtime library that will be used to build any Android-related |
| 755 | rule. |
| 756 | |
| 757 | The Android SDK will be automatically selected if an <code>android_sdk_repository</code> |
| 758 | rule is defined in the WORKSPACE file. |
| 759 | </p> |
| 760 | |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 761 | <h4 id='flag--java_toolchain'><code class='flag'>--java_toolchain <var>label</var></code></h4> |
| 762 | <p> |
| 763 | This option specifies the label of the java_toolchain used to compile Java |
| 764 | source files. |
| 765 | </p> |
| 766 | |
cushon | 41375ac4 | 2017-10-30 17:03:18 -0400 | [diff] [blame] | 767 | <h4 id='flag--host_java_toolchain'><code class='flag'>--host_java_toolchain <var>label</var></code></h4> |
| 768 | <p> |
| 769 | If not specified, bazel uses the value of <code class='flag'>--java_toolchain</code> to compile |
| 770 | code in the host configuration, i.e., tools run during the build. The main purpose of this flag |
| 771 | is to enable cross-compilation. |
| 772 | </p> |
| 773 | |
Gregg Donovan | fb915e8 | 2018-02-20 09:10:21 -0800 | [diff] [blame] | 774 | <h4 id='flag--javabase'><code class='flag'>--javabase (<var>label</var>)</code></h4> |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 775 | <p> |
cushon | 7d9596c | 2018-07-23 13:55:14 -0700 | [diff] [blame] | 776 | This option sets the <i>label</i> of the base Java installation to use for <i>bazel run</i>, |
| 777 | <i>bazel test</i>, and for Java binaries built by <code>java_binary</code> and |
| 778 | <code>java_test</code> rules. The <code>JAVABASE</code> and <code>JAVA</code> |
| 779 | <a href='be/make-variables.html'>"Make" variables</a> are derived from this option. |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 780 | </p> |
| 781 | |
cushon | 41375ac4 | 2017-10-30 17:03:18 -0400 | [diff] [blame] | 782 | <h4 id='flag--host_javabase'><code class='flag'>--host_javabase <var>label</var></code></h4> |
| 783 | <p> |
cushon | 2a8b657 | 2018-07-25 10:33:40 -0700 | [diff] [blame] | 784 | This option sets the <i>label</i> of the base Java installation to use in the host configuration, |
cushon | 7d9596c | 2018-07-23 13:55:14 -0700 | [diff] [blame] | 785 | for example for host build tools including JavaBuilder and Singlejar. |
cushon | 41375ac4 | 2017-10-30 17:03:18 -0400 | [diff] [blame] | 786 | </p> |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 787 | <p> |
| 788 | This does not select the Java compiler that is used to compile Java |
| 789 | source files. The compiler can be selected by settings the |
| 790 | <a href="#flag--java_toolchain"><code class='flag'>--java_toolchain</code></a> |
| 791 | option. |
| 792 | </p> |
| 793 | |
| 794 | <h3 id='strategy-options'>Build strategy options</h3> |
| 795 | <p> |
| 796 | These options affect how Bazel will execute the build. |
| 797 | They should not have any significant effect on the output files |
| 798 | generated by the build. Typically their main effect is on the |
| 799 | speed on the build. |
| 800 | </p> |
| 801 | |
| 802 | <h4 id='flag--spawn_strategy'><code class='flag'>--spawn_strategy <var>strategy</var></code></h4> |
| 803 | <p> |
| 804 | This option controls where and how commands are executed. |
| 805 | </p> |
| 806 | <ul> |
| 807 | |
| 808 | <li> |
| 809 | <code>standalone</code> causes commands to be executed as local subprocesses. |
| 810 | </li> |
| 811 | <li> |
| 812 | <code>sandboxed</code> causes commands to be executed inside a sandbox on the local machine. |
| 813 | This requires that all input files, data dependencies and tools are listed as direct |
| 814 | dependencies in the <code>srcs</code>, <code>data</code> and <code>tools</code> attributes. |
| 815 | This is the default on systems that support sandboxed execution. |
| 816 | </li> |
| 817 | |
| 818 | </ul> |
| 819 | |
| 820 | <h4 id='flag--genrule_strategy'><code class='flag'>--genrule_strategy <var>strategy</var></code></h4> |
| 821 | <p> |
| 822 | This option controls where and how genrules are executed. |
| 823 | </p> |
| 824 | <ul> |
| 825 | |
| 826 | <li> |
| 827 | <code>standalone</code> causes genrules to run as local subprocesses. |
| 828 | </li> |
| 829 | <li> |
| 830 | <code>sandboxed</code> causes genrules to run inside a sandbox on the local machine. |
| 831 | This requires that all input files are listed as direct dependencies in |
| 832 | the <code>srcs</code> attribute, and the program(s) executed are listed |
| 833 | in the <code>tools</code> attribute. |
| 834 | This is the default for Bazel on systems that support sandboxed execution. |
| 835 | </li> |
| 836 | |
| 837 | </ul> |
| 838 | |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 839 | <h4 id='flag--jobs'><code class='flag'>--jobs <var>n</var></code> (-j)</h4> |
| 840 | <p> |
| 841 | This option, which takes an integer argument, specifies a limit on |
| 842 | the number of jobs that should be executed concurrently during the |
Googler | b6857d5 | 2017-09-22 14:03:21 -0400 | [diff] [blame] | 843 | execution phase of the build. |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 844 | </p> |
| 845 | <p> |
| 846 | Note that the number of concurrent jobs that Bazel will run |
| 847 | is determined not only by the <code class='flag'>--jobs</code> setting, but also |
| 848 | by Bazel's scheduler, which tries to avoid running concurrent jobs |
| 849 | that will use up more resources (RAM or CPU) than are available, |
| 850 | based on some (very crude) estimates of the resource consumption |
| 851 | of each job. The behavior of the scheduler can be controlled by |
| 852 | the <code class='flag'>--ram_utilization_factor</code> option. |
| 853 | </p> |
| 854 | |
| 855 | <h4 id='flag--progress_report_interval'><code class='flag'>--progress_report_interval <var>n</var></code></h4> |
| 856 | <p> |
| 857 | |
| 858 | Bazel periodically prints a progress report on jobs that are not |
| 859 | finished yet (e.g. long running tests). This option sets the |
| 860 | reporting frequency, progress will be printed every <code>n</code> |
| 861 | seconds. |
| 862 | </p> |
| 863 | <p> |
| 864 | The default is 0, that means an incremental algorithm: the first |
| 865 | report will be printed after 10 seconds, then 30 seconds and after |
| 866 | that progress is reported once every minute. |
| 867 | </p> |
| 868 | |
| 869 | <h4 id='flag--ram_utilization_factor'><code class='flag'>--ram_utilization_factor</code> <var>percentage</var></h4> |
| 870 | <p> |
| 871 | This option, which takes an integer argument, specifies what percentage |
| 872 | of the system's RAM Bazel should try to use for its subprocesses. |
| 873 | This option affects how many processes Bazel will try to run |
| 874 | in parallel. The default value is 67. |
| 875 | If you run several Bazel builds in parallel, using a lower |
| 876 | value for this option may avoid thrashing and thus improve overall |
| 877 | throughput. Using a value higher than the default is NOT recommended. Note |
| 878 | that Bazel's estimates are very coarse, so the actual RAM usage may be much |
| 879 | higher or much lower than specified. Note also that this option does not |
| 880 | affect the amount of memory that the Bazel server itself will use. |
| 881 | </p> |
| 882 | |
| 883 | <h4 id='flag--local_resources'><code class='flag'>--local_resources</code> <var>availableRAM,availableCPU,availableIO</var></h4> |
| 884 | <p> |
| 885 | This option, which takes three comma-separated floating point arguments, |
| 886 | specifies the amount of local resources that Bazel can take into |
| 887 | consideration when scheduling build and test activities. Option expects amount of |
| 888 | available RAM (in MB), number of CPU cores (with 1.0 representing single full |
| 889 | core) and workstation I/O capability (with 1.0 representing average |
| 890 | workstation). By default Bazel will estimate amount of RAM and number of CPU |
| 891 | cores directly from system configuration and will assume 1.0 I/O resource. |
| 892 | </p> |
| 893 | <p> |
| 894 | If this option is used, Bazel will ignore --ram_utilization_factor. |
| 895 | </p> |
| 896 | |
| 897 | <h4 id='flag--build_runfile_links'><code class='flag'>--[no]build_runfile_links</code></h4> |
| 898 | <p> |
Googler | 5a49584 | 2017-08-22 01:30:36 +0200 | [diff] [blame] | 899 | This option, which is enabled by default, specifies whether the runfiles |
| 900 | symlinks for tests and binaries should be built in the output directory. |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 901 | Using <code class='flag'>--nobuild_runfile_links</code> can be useful |
| 902 | to validate if all targets compile without incurring the overhead |
| 903 | for building the runfiles trees. |
| 904 | |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 905 | </p> |
| 906 | |
| 907 | <p> |
Googler | 5a49584 | 2017-08-22 01:30:36 +0200 | [diff] [blame] | 908 | When tests (or applications) are executed, their run-time data |
| 909 | dependencies are gathered together in one place. Within Bazel's |
| 910 | output tree, this "runfiles" tree is typically rooted as a sibling of |
| 911 | the corresponding binary or test. |
| 912 | During test execution, runfiles may be accessed using paths of the form |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 913 | <code>$TEST_SRCDIR/workspace/<var>packagename</var>/<var>filename</var></code>. |
Googler | 5a49584 | 2017-08-22 01:30:36 +0200 | [diff] [blame] | 914 | The runfiles tree ensures that tests have access to all the files |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 915 | upon which they have a declared dependence, and nothing more. By |
| 916 | default, the runfiles tree is implemented by constructing a set of |
| 917 | symbolic links to the required files. As the set of links grows, so |
| 918 | does the cost of this operation, and for some large builds it can |
| 919 | contribute significantly to overall build time, particularly because |
| 920 | each individual test (or application) requires its own runfiles tree. |
| 921 | </p> |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 922 | |
Googler | 01f659d | 2017-08-22 02:53:02 +0200 | [diff] [blame] | 923 | <h4 id='flag--build_runfile_manifests'><code class='flag'>--[no]build_runfile_manifests</code></h4> |
| 924 | <p> |
| 925 | This option, which is enabled by default, specifies whether runfiles manifests |
| 926 | should be written to the output tree. |
| 927 | Disabling it implies <code class='flag'>--nobuild_runfile_links</code>. |
| 928 | |
| 929 | It can be disabled when executing tests on Forge, as runfiles trees will |
| 930 | be created remotely from in-memory manifests. |
| 931 | |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 932 | <h4 id='flag--discard_analysis_cache'> |
| 933 | <code class='flag'>--[no]discard_analysis_cache</code></h4> |
| 934 | <p> |
| 935 | When this option is enabled, Bazel will discard the analysis cache |
| 936 | right before execution starts, thus freeing up additional memory |
| 937 | (around 10%) for the <a href="#execution-phase">execution phase</a>. |
| 938 | The drawback is that further incremental builds will be slower. |
| 939 | </p> |
| 940 | |
| 941 | <h4 id='flag--keep_going'><code class='flag'>--[no]keep_going</code> (-k)</h4> |
| 942 | <p> |
| 943 | As in GNU Make, the execution phase of a build stops when the first |
| 944 | error is encountered. Sometimes it is useful to try to build as |
| 945 | much as possible even in the face of errors. This option enables |
| 946 | that behavior, and when it is specified, the build will attempt to |
| 947 | build every target whose prerequisites were successfully built, but |
| 948 | will ignore errors. |
| 949 | </p> |
| 950 | <p> |
| 951 | While this option is usually associated with the execution phase of |
| 952 | a build, it also effects the analysis phase: if several targets are |
| 953 | specified in a build command, but only some of them can be |
| 954 | successfully analyzed, the build will stop with an error |
| 955 | unless <code class='flag'>--keep_going</code> is specified, in which case the |
| 956 | build will proceed to the execution phase, but only for the targets |
| 957 | that were successfully analyzed. |
| 958 | </p> |
| 959 | |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 960 | <h4 id='flag--use_ijars'><code class='flag'>--[no]use_ijars</code></h4> |
| 961 | <p> |
| 962 | This option changes the way <code>java_library</code> targets are |
| 963 | compiled by Bazel. Instead of using the output of a |
| 964 | <code>java_library</code> for compiling dependent |
| 965 | <code>java_library</code> targets, Bazel will create interface jars |
| 966 | that contain only the signatures of non-private members (public, |
| 967 | protected, and default (package) access methods and fields) and use |
| 968 | the interface jars to compile the dependent targets. This makes it |
| 969 | possible to avoid recompilation when changes are only made to |
| 970 | method bodies or private members of a class. |
| 971 | </p> |
| 972 | <p> |
| 973 | Note that using <code class='flag'>--use_ijars</code> might give you a different |
| 974 | error message when you are accidentally referring to a non visible |
| 975 | member of another class: Instead of getting an error that the member |
| 976 | is not visible you will get an error that the member does not exist. |
| 977 | </p> |
| 978 | <p> |
| 979 | Note that changing the <code class='flag'>--use_ijars</code> setting will force |
| 980 | a recompilation of all affected classes. |
| 981 | </p> |
| 982 | |
| 983 | <h4 id='flag--interface_shared_objects'> |
| 984 | <code class='flag'>--[no]interface_shared_objects</code> |
| 985 | </h4> |
| 986 | <p> |
| 987 | This option enables <i>interface shared objects</i>, which makes binaries and |
| 988 | other shared libraries depend on the <i>interface</i> of a shared object, |
| 989 | rather than its implementation. When only the implementation changes, Bazel |
| 990 | can avoid rebuilding targets that depend on the changed shared library |
| 991 | unnecessarily. |
| 992 | </p> |
| 993 | |
| 994 | <h3 id='output-selection-options'>Output selection options</h3> |
| 995 | <p> |
| 996 | These options determine what to build or test. |
| 997 | </p> |
| 998 | |
| 999 | <h4 id="nobuild"><code class='flag'>--[no]build</code></h4> |
| 1000 | <p> |
| 1001 | This option causes the execution phase of the build to occur; it is |
| 1002 | on by default. When it is switched off, the execution phase is |
| 1003 | skipped, and only the first two phases, loading and analysis, occur. |
| 1004 | </p> |
| 1005 | <p> |
| 1006 | This option can be useful for validating BUILD files and detecting |
| 1007 | errors in the inputs, without actually building anything. |
| 1008 | </p> |
| 1009 | |
| 1010 | <h4 id='flag--build_tests_only'><code class='flag'>--[no]build_tests_only</code></h4> |
| 1011 | <p> |
| 1012 | If specified, Bazel will build only what is necessary to run the *_test |
| 1013 | and test_suite rules that were not filtered due to their |
| 1014 | <a href='#flag--test_size_filters'>size</a>, |
| 1015 | <a href='#flag--test_timeout_filters'>timeout</a>, |
| 1016 | <a href='#flag--test_tag_filters'>tag</a>, or |
| 1017 | <a href='#flag--test_lang_filters'>language</a>. |
| 1018 | If specified, Bazel will ignore other targets specified on the command line. |
| 1019 | By default, this option is disabled and Bazel will build everything |
| 1020 | requested, including *_test and test_suite rules that are filtered out from |
| 1021 | testing. This is useful because running |
| 1022 | <code>bazel test --build_tests_only foo/...</code> may not detect all build |
| 1023 | breakages in the <code>foo</code> tree. |
| 1024 | </p> |
| 1025 | |
| 1026 | <h4 id='flag--check_up_to_date'><code class='flag'>--[no]check_up_to_date</code></h4> |
| 1027 | <p> |
| 1028 | This option causes Bazel not to perform a build, but merely check |
| 1029 | whether all specified targets are up-to-date. If so, the build |
| 1030 | completes successfully, as usual. However, if any files are out of |
| 1031 | date, instead of being built, an error is reported and the build |
| 1032 | fails. This option may be useful to determine whether a build has |
| 1033 | been performed more recently than a source edit (e.g. for pre-submit |
| 1034 | checks) without incurring the cost of a build. |
| 1035 | </p> |
| 1036 | <p> |
| 1037 | See also <a href="#flag--check_tests_up_to_date"><code class='flag'>--check_tests_up_to_date</code></a>. |
| 1038 | </p> |
| 1039 | |
| 1040 | <h4 id='flag--compile_one_dependency'><code class='flag'>--[no]compile_one_dependency</code></h4> |
| 1041 | <p> |
| 1042 | Compile a single dependency of the argument files. This is useful for |
| 1043 | syntax checking source files in IDEs, for example, by rebuilding a single |
| 1044 | target that depends on the source file to detect errors as early as |
| 1045 | possible in the edit/build/test cycle. This argument affects the way all |
| 1046 | non-flag arguments are interpreted: for each source filename, one |
| 1047 | rule that depends on it will be built. For |
| 1048 | |
| 1049 | C++ and Java |
| 1050 | sources, rules in the same language space are preferentially chosen. For |
| 1051 | multiple rules with the same preference, the one that appears first in the |
| 1052 | BUILD file is chosen. An explicitly named target pattern which does not |
| 1053 | reference a source file results in an error. |
| 1054 | </p> |
| 1055 | |
| 1056 | <h4 id='flag--save_temps'><code class='flag'>--save_temps</code></h4> |
| 1057 | <p> |
Googler | 9cfa4cb | 2018-06-04 22:19:11 -0700 | [diff] [blame] | 1058 | The <code class='flag'>--save_temps</code> option causes temporary outputs from the compiler to be |
| 1059 | saved. These include .s files (assembler code), .i (preprocessed C) and .ii |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 1060 | (preprocessed C++) files. These outputs are often useful for debugging. Temps will only be |
| 1061 | generated for the set of targets specified on the command line. |
| 1062 | </p> |
| 1063 | <p> |
Googler | 9cfa4cb | 2018-06-04 22:19:11 -0700 | [diff] [blame] | 1064 | Note that our implementation of <code class='flag'>--save_temps</code> does not use the compiler's |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 1065 | <code>-save-temps</code> flag. Instead, we do two passes, one with <code>-S</code> |
| 1066 | and one with <code>-E</code>. A consequence of this is that if your build fails, |
| 1067 | Bazel may not yet have produced the ".i" or ".ii" and ".s" files. |
| 1068 | If you're trying to use <code class='flag'>--save_temps</code> to debug a failed compilation, |
| 1069 | you may need to also use <code class='flag'>--keep_going</code> so that Bazel will still try to |
| 1070 | produce the preprocessed files after the compilation fails. |
| 1071 | </p> |
| 1072 | <p> |
| 1073 | The <code class='flag'>--save_temps</code> flag currently works only for cc_* rules. |
| 1074 | </p> |
| 1075 | <p> |
| 1076 | To ensure that Bazel prints the location of the additional output files, check that |
| 1077 | your <a href='#flag--show_result'><code class='flag'>--show_result <var>n</var></code></a> |
| 1078 | setting is high enough. |
| 1079 | </p> |
| 1080 | |
Googler | d9db169 | 2017-01-05 19:34:30 +0000 | [diff] [blame] | 1081 | <h4 id='flag--build_tag_filters'><code class='flag'>--build_tag_filters <var>tag[,tag]*</var></code></h4> |
| 1082 | <p> |
| 1083 | If specified, Bazel will build only targets that have at least one required tag |
| 1084 | (if any of them are specified) and does not have any excluded tags. Build tag |
| 1085 | filter is specified as comma delimited list of tag keywords, optionally |
| 1086 | preceded with '-' sign used to denote excluded tags. Required tags may also |
| 1087 | have a preceding '+' sign. |
| 1088 | </p> |
| 1089 | |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 1090 | <h4 id='flag--test_size_filters'><code class='flag'>--test_size_filters <var>size[,size]*</var></code></h4> |
| 1091 | <p> |
| 1092 | If specified, Bazel will test (or build if <code class='flag'>--build_tests_only</code> |
| 1093 | is also specified) only test targets with the given size. Test size filter |
| 1094 | is specified as comma delimited list of allowed test size values (small, |
| 1095 | medium, large or enormous), optionally preceded with '-' sign used to denote |
| 1096 | excluded test sizes. For example, |
| 1097 | </p> |
| 1098 | <pre> |
| 1099 | % bazel test --test_size_filters=small,medium //foo:all |
| 1100 | </pre> |
| 1101 | and |
| 1102 | <pre> |
| 1103 | % bazel test --test_size_filters=-large,-enormous //foo:all |
| 1104 | </pre> |
| 1105 | <p> |
| 1106 | will test only small and medium tests inside //foo. |
| 1107 | </p> |
| 1108 | <p> |
| 1109 | By default, test size filtering is not applied. |
| 1110 | </p> |
| 1111 | |
| 1112 | <h4 id='flag--test_timeout_filters'><code class='flag'>--test_timeout_filters <var>timeout[,timeout]*</var></code></h4> |
| 1113 | <p> |
| 1114 | If specified, Bazel will test (or build if <code class='flag'>--build_tests_only</code> |
| 1115 | is also specified) only test targets with the given timeout. Test timeout filter |
| 1116 | is specified as comma delimited list of allowed test timeout values (short, |
| 1117 | moderate, long or eternal), optionally preceded with '-' sign used to denote |
| 1118 | excluded test timeouts. See <a href='#flag--test_size_filters'>--test_size_filters</a> |
| 1119 | for example syntax. |
| 1120 | </p> |
| 1121 | <p> |
| 1122 | By default, test timeout filtering is not applied. |
| 1123 | </p> |
| 1124 | |
| 1125 | |
| 1126 | <h4 id='flag--test_tag_filters'><code class='flag'>--test_tag_filters <var>tag[,tag]*</var></code></h4> |
| 1127 | <p> |
| 1128 | If specified, Bazel will test (or build if <code class='flag'>--build_tests_only</code> |
| 1129 | is also specified) only test targets that have at least one required tag |
| 1130 | (if any of them are specified) and does not have any excluded tags. Test tag |
| 1131 | filter is specified as comma delimited list of tag keywords, optionally |
| 1132 | preceded with '-' sign used to denote excluded tags. Required tags may also |
| 1133 | have a preceding '+' sign. |
| 1134 | </p> |
| 1135 | <p> |
| 1136 | For example, |
| 1137 | <pre> |
| 1138 | % bazel test --test_tag_filters=performance,stress,-flaky //myproject:all |
| 1139 | </pre> |
| 1140 | <p> |
| 1141 | will test targets that are tagged with either <code>performance</code> or |
| 1142 | <code>stress</code> tag but are <b>not</b> tagged with the <code>flaky</code> |
| 1143 | tag. |
| 1144 | </p> |
| 1145 | <p> |
| 1146 | By default, test tag filtering is not applied. Note that you can also filter |
| 1147 | on test's <code>size</code> and <code>local</code> tags in |
| 1148 | this manner. |
| 1149 | </p> |
| 1150 | |
| 1151 | <h4 id='flag--test_lang_filters'><code class='flag'>--test_lang_filters <var>lang[,lang]*</var></code></h4> |
| 1152 | <p> |
| 1153 | Specifies a comma-separated list of test languages for languages with an official <code>*_test</code> rule the |
| 1154 | (see <a href="be/overview.html">build encyclopedia</a> for a full list of these). Each |
| 1155 | language can be optionally preceded with '-' to specify excluded |
| 1156 | languages. The name used for each language should be the same as |
| 1157 | the language prefix in the <code>*_test</code> rule, for example, |
| 1158 | <code>cc</code>, <code>java</code> or <code>sh</code>. |
| 1159 | </p> |
| 1160 | <p> |
| 1161 | If specified, Bazel will test (or build if <code class='flag'>--build_tests_only</code> |
| 1162 | is also specified) only test targets of the specified language(s). |
| 1163 | </p> |
| 1164 | <p> |
| 1165 | For example, |
| 1166 | </p> |
| 1167 | <pre> |
| 1168 | % bazel test --test_lang_filters=cc,java foo/... |
| 1169 | </pre> |
| 1170 | <p> |
| 1171 | will test only the C/C++ and Java tests (defined using |
| 1172 | <code>cc_test</code> and <code>java_test</code> rules, respectively) |
| 1173 | in <code>foo/...</code>, while |
| 1174 | </p> |
| 1175 | <pre> |
| 1176 | % bazel test --test_lang_filters=-sh,-java foo/... |
| 1177 | </pre> |
| 1178 | <p> |
| 1179 | will run all of the tests in <code>foo/...</code> except for the |
| 1180 | <code>sh_test</code> and <code>java_test</code> tests. |
| 1181 | </p> |
| 1182 | <p> |
| 1183 | By default, test language filtering is not applied. |
| 1184 | </p> |
| 1185 | |
| 1186 | <h4 id="flag--test_filter"><code class='flag'>--test_filter=<var>filter-expression</var></code></h4> |
| 1187 | <p> |
| 1188 | Specifies a filter that the test runner may use to pick a subset of tests for |
| 1189 | running. All targets specified in the invocation are built, but depending on |
| 1190 | the expression only some of them may be executed; in some cases, only certain |
| 1191 | test methods are run. |
| 1192 | </p> |
| 1193 | <p> |
| 1194 | The particular interpretation of <var>filter-expression</var> is up to |
| 1195 | the test framework responsible for running the test. It may be a glob, |
| 1196 | substring, or regexp. <code class='flag'>--test_filter</code> is a convenience |
| 1197 | over passing different <code class='flag'>--test_arg</code> filter arguments, |
| 1198 | but not all frameworks support it. |
| 1199 | </p> |
| 1200 | |
| 1201 | <h3>Verbosity options: options that control what Bazel prints</h3> |
| 1202 | |
| 1203 | These options control the verbosity of Bazel's output, |
| 1204 | either to the terminal, or to additional log files. |
| 1205 | |
| 1206 | <h4 id='flag--explain'><code class='flag'>--explain <var>logfile</var></code></h4> |
| 1207 | <p> |
| 1208 | This option, which requires a filename argument, causes the |
| 1209 | dependency checker in <code>bazel build</code>'s execution phase to |
| 1210 | explain, for each build step, either why it is being executed, or |
| 1211 | that it is up-to-date. The explanation is written |
| 1212 | to <i>logfile</i>. |
| 1213 | </p> |
| 1214 | <p> |
| 1215 | If you are encountering unexpected rebuilds, this option can help to |
| 1216 | understand the reason. Add it to your <code>.bazelrc</code> so that |
| 1217 | logging occurs for all subsequent builds, and then inspect the log |
| 1218 | when you see an execution step executed unexpectedly. This option |
| 1219 | may carry a small performance penalty, so you might want to remove |
| 1220 | it when it is no longer needed. |
| 1221 | </p> |
| 1222 | |
| 1223 | <h4 id='flag--verbose_explanations'><code class='flag'>--verbose_explanations</code></h4> |
| 1224 | <p> |
| 1225 | This option increases the verbosity of the explanations generated |
| 1226 | when the <a href='#flag--explain'>--explain</a> option is enabled. |
| 1227 | </p> |
| 1228 | <p> |
| 1229 | In particular, if verbose explanations are enabled, |
| 1230 | and an output file is rebuilt because the command used to |
| 1231 | build it has changed, then the output in the explanation file will |
| 1232 | include the full details of the new command (at least for most |
| 1233 | commands). |
| 1234 | </p> |
| 1235 | <p> |
| 1236 | Using this option may significantly increase the length of the |
| 1237 | generated explanation file and the performance penalty of using |
| 1238 | <code class='flag'>--explain</code>. |
| 1239 | </p> |
| 1240 | <p> |
| 1241 | If <code class='flag'>--explain</code> is not enabled, then |
| 1242 | <code class='flag'>--verbose_explanations</code> has no effect. |
| 1243 | </p> |
| 1244 | |
| 1245 | <h4 id='flag--profile'><code class='flag'>--profile <var>file</var></code></h4> |
| 1246 | <p> |
| 1247 | This option, which takes a filename argument, causes Bazel to write |
| 1248 | profiling data into a file. The data then can be analyzed or parsed using the |
| 1249 | <code>bazel analyze-profile</code> command. The Build profile can be useful in |
| 1250 | understanding where Bazel's <code>build</code> command is spending its time. |
| 1251 | </p> |
| 1252 | |
| 1253 | <h4 id='flag--show_loading_progress'><code class='flag'>--[no]show_loading_progress</code></h4> |
| 1254 | <p> |
| 1255 | This option causes Bazel to output package-loading progress |
| 1256 | messages. If it is disabled, the messages won't be shown. |
| 1257 | </p> |
| 1258 | |
| 1259 | <h4 id='flag--show_progress'><code class='flag'>--[no]show_progress</code></h4> |
| 1260 | <p> |
| 1261 | This option causes progress messages to be displayed; it is on by |
| 1262 | default. When disabled, progress messages are suppressed. |
| 1263 | </p> |
| 1264 | |
| 1265 | <h4 id='flag--show_progress_rate_limit'><code class='flag'>--show_progress_rate_limit |
| 1266 | <var>n</var></code></h4> |
| 1267 | <p> |
| 1268 | This option causes bazel to display only |
| 1269 | one progress message per <code>n</code> seconds, where <var>n</var> is a real number. |
| 1270 | If <code>n</code> is -1, all progress messages will be displayed. The default value for |
| 1271 | this option is 0.03, meaning bazel will limit the progress messages to one per every |
| 1272 | 0.03 seconds. |
| 1273 | </p> |
| 1274 | |
| 1275 | <h4 id='flag--show_result'><code class='flag'>--show_result <var>n</var></code></h4> |
| 1276 | <p> |
| 1277 | This option controls the printing of result information at the end |
| 1278 | of a <code>bazel build</code> command. By default, if a single |
| 1279 | build target was specified, Bazel prints a message stating whether |
| 1280 | or not the target was successfully brought up-to-date, and if so, |
| 1281 | the list of output files that the target created. If multiple |
| 1282 | targets were specified, result information is not displayed. |
| 1283 | </p> |
| 1284 | <p> |
| 1285 | While the result information may be useful for builds of a single |
| 1286 | target or a few targets, for large builds (e.g. an entire top-level |
| 1287 | project tree), this information can be overwhelming and distracting; |
| 1288 | this option allows it to be controlled. <code class='flag'>--show_result</code> |
| 1289 | takes an integer argument, which is the maximum number of targets |
| 1290 | for which full result information should be printed. By default, |
| 1291 | the value is 1. Above this threshold, no result information is |
| 1292 | shown for individual targets. Thus zero causes the result |
| 1293 | information to be suppressed always, and a very large value causes |
| 1294 | the result to be printed always. |
| 1295 | </p> |
| 1296 | <p> |
| 1297 | Users may wish to choose a value in-between if they regularly |
| 1298 | alternate between building a small group of targets (for example, |
| 1299 | during the compile-edit-test cycle) and a large group of targets |
| 1300 | (for example, when establishing a new workspace or running |
| 1301 | regression tests). In the former case, the result information is |
| 1302 | very useful whereas in the latter case it is less so. As with all |
| 1303 | options, this can be specified implicitly via |
Vladimir Chebotarev | 66885ff | 2018-12-04 14:08:16 -0800 | [diff] [blame^] | 1304 | the <a href='guide.html#bazelrc'><code>.bazelrc</code></a> file. |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 1305 | </p> |
| 1306 | <p> |
| 1307 | The files are printed so as to make it easy to copy and paste the |
| 1308 | filename to the shell, to run built executables. The "up-to-date" |
| 1309 | or "failed" messages for each target can be easily parsed by scripts |
| 1310 | which drive a build. |
| 1311 | </p> |
| 1312 | |
| 1313 | <h4 id='flag--subcommands'><code class='flag'>--subcommands</code> (<code>-s</code>)</h4> |
| 1314 | <p> |
| 1315 | This option causes Bazel's execution phase to print the full command line |
| 1316 | for each command prior to executing it. |
| 1317 | </p> |
| 1318 | |
| 1319 | <pre> |
| 1320 | >>>>> # //examples/cpp:hello-world [action 'Linking examples/cpp/hello-world'] |
lberki | f071a23 | 2017-12-07 04:21:34 -0800 | [diff] [blame] | 1321 | (cd /home/johndoe/.cache/bazel/_bazel_johndoe/4c084335afceb392cfbe7c31afee3a9f/bazel && \ |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 1322 | exec env - \ |
lberki | cbac328 | 2017-12-07 05:47:43 -0800 | [diff] [blame] | 1323 | /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 Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 1324 | </pre> |
| 1325 | <p> |
| 1326 | Where possible, commands are printed in a Bourne shell compatible syntax, |
| 1327 | so that they can be easily copied and pasted to a shell command prompt. |
| 1328 | (The surrounding parentheses are provided to protect your shell from the |
| 1329 | <code>cd</code> and <code>exec</code> calls; be sure to copy them!) |
| 1330 | However some commands are implemented internally within Bazel, such as |
| 1331 | creating symlink trees. For these there's no command line to display. |
| 1332 | |
| 1333 | </p> |
| 1334 | |
| 1335 | <p> |
ahumesky | be31bb8 | 2018-07-26 13:37:45 -0700 | [diff] [blame] | 1336 | <code class='flag'>--subcommands=pretty_print</code> may be passed to print |
| 1337 | the arguments of the command as a list rather than as a single line. This may |
| 1338 | help make long command lines more readable. |
| 1339 | </p> |
| 1340 | |
| 1341 | <p> |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 1342 | See also <a href="#flag--verbose_failures">--verbose_failures</a>, below. |
| 1343 | </p> |
| 1344 | |
| 1345 | <h4 id='flag--verbose_failures'><code class='flag'>--verbose_failures</code></h4> |
| 1346 | <p> |
| 1347 | This option causes Bazel's execution phase to print the full command line |
| 1348 | for commands that failed. This can be invaluable for debugging a |
| 1349 | failing build. |
| 1350 | </p> |
| 1351 | <p> |
| 1352 | Failing commands are printed in a Bourne shell compatible syntax, suitable |
| 1353 | for copying and pasting to a shell prompt. |
| 1354 | </p> |
| 1355 | |
laszlocsomor | 45a0ffe | 2018-02-05 00:48:35 -0800 | [diff] [blame] | 1356 | <h3 id='workspace_status'>Options that control how Bazel embeds workspace status information |
| 1357 | into binaries ("stamping")</h3> |
| 1358 | |
| 1359 | <p> |
| 1360 | Use these options to "stamp" Bazel-built binaries: to embed additional information into the |
| 1361 | binaries, such as the source control revision or other workspace-related information. You can use |
| 1362 | this mechanism with rules that support the <code>stamp</code> attribute, such as |
| 1363 | <code>genrule</code>, <code>cc_binary</code>, and more. |
| 1364 | </p> |
| 1365 | |
| 1366 | <h4 id='flag--workspace_status_command'><code class='flag'>--workspace_status_command <var>program</var></code></h4> |
| 1367 | <p> |
| 1368 | This flag lets you specify a binary that Bazel runs before each build. The program can report |
| 1369 | information about the status of the workspace, such as the current source control revision. |
| 1370 | </p> |
| 1371 | <p> |
| 1372 | The flag's value must be a path to a native program. On Linux/macOS this may be any executable. |
| 1373 | On Windows this must be a native binary, typically an ".exe", ".bat", or a ".cmd" file. |
| 1374 | </p> |
| 1375 | |
| 1376 | <p> |
| 1377 | The program should print zero or more key/value pairs to standard output, one entry on each line, |
| 1378 | then exit with zero (otherwise the build fails). The key names can be anything but they may only |
| 1379 | use upper case letters and underscores. The first space after the key name separates it from the |
| 1380 | value. The value is the rest of the line (including additional whitespaces). |
| 1381 | </p> |
| 1382 | <p> |
| 1383 | Bazel partitions the keys into two buckets: "stable" and "volatile". (The names "stable" and |
| 1384 | "volatile" are a bit counter-intuitive, so don't think much about them.) |
| 1385 | </p> |
| 1386 | |
| 1387 | <p>Bazel then writes the key-value pairs into two files:</p> |
| 1388 | <ul> |
| 1389 | <li> |
ahumesky | 5a6d8b6 | 2018-11-15 14:05:34 -0800 | [diff] [blame] | 1390 | <code>bazel-out/stable-status.txt</code> |
| 1391 | contains all keys and values where the key's name starts with <code>STABLE_</code> |
laszlocsomor | 45a0ffe | 2018-02-05 00:48:35 -0800 | [diff] [blame] | 1392 | </li> |
ahumesky | 5a6d8b6 | 2018-11-15 14:05:34 -0800 | [diff] [blame] | 1393 | <li> |
| 1394 | <code>bazel-out/volatile-status.txt</code> |
| 1395 | contains the rest of the keys and their values |
| 1396 | </li> |
laszlocsomor | 45a0ffe | 2018-02-05 00:48:35 -0800 | [diff] [blame] | 1397 | </ul> |
| 1398 | |
| 1399 | <p>The contract is:</p> |
| 1400 | <ul> |
| 1401 | <li> |
| 1402 | <p> |
| 1403 | "stable" keys' values should change rarely, if possible. If the contents of |
ahumesky | 5a6d8b6 | 2018-11-15 14:05:34 -0800 | [diff] [blame] | 1404 | <code>bazel-out/stable-status.txt</code> |
| 1405 | change, Bazel invalidates the actions that depend on them. In |
| 1406 | other words, if a stable key's value changes, Bazel will rerun stamped actions. |
laszlocsomor | 45a0ffe | 2018-02-05 00:48:35 -0800 | [diff] [blame] | 1407 | Therefore the stable status should not contain things like timestamps, because they change all |
ahumesky | 5a6d8b6 | 2018-11-15 14:05:34 -0800 | [diff] [blame] | 1408 | the time, and would make Bazel rerun stamped actions with each build. |
laszlocsomor | 45a0ffe | 2018-02-05 00:48:35 -0800 | [diff] [blame] | 1409 | </p> |
| 1410 | <p>Bazel always outputs the following stable keys:</p> |
| 1411 | <ul> |
| 1412 | <li><code>BUILD_EMBED_LABEL</code>: value of <code class='flag'>--embed_label</code></li> |
| 1413 | <li><code>BUILD_HOST</code>: the name of the host machine that Bazel is running on</li> |
| 1414 | <li><code>BUILD_USER</code>: the name of the user that Bazel is running as</li> |
| 1415 | </ul> |
| 1416 | </li> |
| 1417 | <li> |
| 1418 | <p> |
| 1419 | "volatile" keys' values may change often. Bazel expects them to change all the time, like |
ahumesky | 5a6d8b6 | 2018-11-15 14:05:34 -0800 | [diff] [blame] | 1420 | timestamps do, and duly updates the |
| 1421 | <code>bazel-out/stable-status.txt</code> |
| 1422 | file. In order to avoid |
| 1423 | rerunning stamped actions all the time though, <b>Bazel pretends that the volatile file never |
| 1424 | changes</b>. In other words, if the volatile status file is the only file whose contents has |
| 1425 | changed, Bazel will not invalidate actions that depend on it. If other inputs of the actions |
| 1426 | have changed, then Bazel reruns that action, and the action will see the updated volatile |
laszlocsomor | 45a0ffe | 2018-02-05 00:48:35 -0800 | [diff] [blame] | 1427 | status, but just the volatile status changing alone will not invalidate the action. |
| 1428 | </p> |
| 1429 | <p>Bazel always outputs the following volatile keys:</p> |
| 1430 | <ul> |
| 1431 | <li> |
lberki | 911c7c5 | 2018-04-25 07:56:27 -0700 | [diff] [blame] | 1432 | <code>BUILD_TIMESTAMP</code>: time of the build in seconds since the Unix Epoch (the value |
| 1433 | of <code>System.currentTimeMillis()</code> divided by a thousand) |
laszlocsomor | 45a0ffe | 2018-02-05 00:48:35 -0800 | [diff] [blame] | 1434 | </li> |
| 1435 | </ul> |
| 1436 | </li> |
| 1437 | </ul> |
| 1438 | |
| 1439 | <p> |
| 1440 | On Linux/macOS you can pass <code class='flag'>--workspace_status_command=/bin/true</code> to |
Googler | 956ecf6 | 2018-11-26 10:15:05 -0800 | [diff] [blame] | 1441 | disable retrieving workspace status, because <code>true</code> does nothing, successfully (exits |
laszlocsomor | 45a0ffe | 2018-02-05 00:48:35 -0800 | [diff] [blame] | 1442 | with zero) and prints no output. On Windows you can pass the path of MSYS's <code>true.exe</code> |
| 1443 | for the same effect. |
| 1444 | </p> |
| 1445 | |
| 1446 | <p>If the workspace status command fails (exits non-zero) for any reason, the build will fail.</p> |
| 1447 | |
| 1448 | <p>Example program on Linux using Git:</p> |
| 1449 | |
| 1450 | <pre> |
| 1451 | #!/bin/bash |
| 1452 | echo "CURRENT_TIME $(date +%s)" |
| 1453 | echo "RANDOM_HASH $(cat /dev/urandom | head -c16 | md5sum 2>/dev/null | cut -f1 -d' ')" |
| 1454 | echo "STABLE_GIT_COMMIT $(git rev-parse HEAD)" |
| 1455 | echo "STABLE_USER_NAME $USER" |
| 1456 | </pre> |
| 1457 | |
| 1458 | <p> |
| 1459 | Pass this program's path with <code>--workspace_status_command</code>, and the stable status file |
| 1460 | will include the STABLE lines and the volatile status file will include the rest of the lines. |
| 1461 | </p> |
| 1462 | |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 1463 | <h4 id='flag--stamp'><code class='flag'>--[no]stamp</code></h4> |
| 1464 | <p> |
| 1465 | This option controls whether stamping is enabled for |
| 1466 | rule types that support it. For most of the supported rule types stamping is |
| 1467 | enabled by default (e.g. <code>cc_binary</code>). |
| 1468 | |
| 1469 | By default, stamping is disabled for all tests. Specifying |
| 1470 | <code class='flag'>--stamp</code> does not force affected targets to be rebuilt, |
| 1471 | if their dependencies have not changed. |
| 1472 | </p> |
| 1473 | |
| 1474 | <p> |
| 1475 | Stamping can be enabled or disabled explicitly in BUILD using |
| 1476 | the <code>stamp</code> attribute of certain rule types, please refer to |
| 1477 | the <a href="be/overview.html">build encyclopedia</a> for details. For |
| 1478 | rules that are neither explicitly or implicitly configured as <code>stamp = |
| 1479 | 0</code> or <code>stamp = 1</code>, the <code class='flag'>--[no]stamp</code> option |
| 1480 | selects whether stamping is enabled. Bazel never stamps binaries that are |
| 1481 | built for the host configuration, regardless of the stamp attribute. |
| 1482 | </p> |
| 1483 | |
jcater | bf57a0a | 2018-06-13 10:16:31 -0700 | [diff] [blame] | 1484 | <h3 id='platform_build_options'>Platform options</h3> |
| 1485 | |
| 1486 | <p> |
| 1487 | Use these options to control the host and target platforms that configure how builds work, and to |
| 1488 | control what execution platforms and toolchains are available to Bazel rules. |
| 1489 | </p> |
| 1490 | |
| 1491 | <p> |
| 1492 | Please see background information on |
| 1493 | <a href="platforms.html">Platforms</a> and <a href="toolchains.html">Toolchains</a>. |
| 1494 | </p> |
| 1495 | |
| 1496 | <h4 id="flag--platforms"><code class='flag'>--platforms <var>labels</var></code></h4> |
| 1497 | <p> |
| 1498 | The labels of the platform rules describing the target platforms for the |
| 1499 | current command. |
| 1500 | </p> |
| 1501 | |
| 1502 | <h4 id="flag--host_platform"><code class='flag'>--host_platform <var>label</var></code></h4> |
| 1503 | <p> |
| 1504 | The label of a platform rule that describes the host system. |
| 1505 | </p> |
| 1506 | |
| 1507 | <h4 id="flag--extra_execution_platforms"><code class='flag'>--extra_execution_platforms <var>labels</var></code></h4> |
| 1508 | <p> |
| 1509 | The platforms that are available as execution platforms to run actions. |
| 1510 | Platforms can be specified by exact target, or as a target pattern. These |
| 1511 | platforms will be considered before those declared in the WORKSPACE file by |
| 1512 | <a href="https://docs.bazel.build/versions/master/skylark/lib/globals.html#register_execution_platforms"> |
| 1513 | register_execution_platforms()</a>. |
| 1514 | </p> |
| 1515 | |
| 1516 | <h4 id="flag--extra_toolchains"><code class='flag'>--extra_toolchains <var>labels</var></code></h4> |
| 1517 | <p> |
| 1518 | The toolchain rules to be considered during toolchain resolution. Toolchains |
| 1519 | can be specified by exact target, or as a target pattern. These toolchains will |
| 1520 | be considered before those declared in the WORKSPACE file by |
| 1521 | <a href="https://docs.bazel.build/versions/master/skylark/lib/globals.html#register_toolchains"> |
| 1522 | register_toolchains()</a>. |
| 1523 | </p> |
| 1524 | |
| 1525 | <h4 id="flag--toolchain_resolution_debug"><code class='flag'>--toolchain_resolution_debug=false</code></h4> |
| 1526 | <p> |
| 1527 | Print debug information while finding toolchains for a rule. This might help |
| 1528 | developers of Bazel or Skylark rules with debugging failures due to missing |
| 1529 | toolchains. |
| 1530 | </p> |
| 1531 | |
| 1532 | <h4 id="flag--enabled_toolchain_types"><code class='flag'>--enabled_toolchain_types <var>labels</var></code></h4> |
| 1533 | <p> |
| 1534 | Enable toolchain resolution for the given toolchain type, if the rules used support that. |
| 1535 | This does not directly change the core Bazel machinery, but is a signal to participating rule |
| 1536 | implementations that toolchain resolution should be used. |
| 1537 | </p> |
| 1538 | |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 1539 | <h3 id='misc_build_options'>Miscellaneous options</h3> |
| 1540 | |
| 1541 | <h4 id='flag--symlink_prefix'><code class='flag'>--symlink_prefix <var>string</var></code></h4> |
| 1542 | <p> |
| 1543 | Changes the prefix of the generated convenience symlinks. The |
| 1544 | default value for the symlink prefix is <code>bazel-</code> which |
| 1545 | will create the symlinks <code>bazel-bin</code>, <code>bazel-testlogs</code>, and |
| 1546 | <code>bazel-genfiles</code>. |
| 1547 | </p> |
| 1548 | <p> |
| 1549 | If the symbolic links cannot be created for any reason, a warning is |
| 1550 | issued but the build is still considered a success. In particular, |
| 1551 | this allows you to build in a read-only directory or one that you have no |
| 1552 | permission to write into. Any paths printed in informational |
| 1553 | messages at the conclusion of a build will only use the |
| 1554 | symlink-relative short form if the symlinks point to the expected |
| 1555 | location; in other words, you can rely on the correctness of those |
| 1556 | paths, even if you cannot rely on the symlinks being created. |
| 1557 | </p> |
| 1558 | <p> |
| 1559 | Some common values of this option: |
| 1560 | </p> |
| 1561 | <ul> |
| 1562 | |
| 1563 | <li> |
| 1564 | <p><b>Suppress symlink creation:</b> |
| 1565 | <code class='flag'>--symlink_prefix=/</code> will cause Bazel to not |
| 1566 | create or update any symlinks, including the <code>bazel-out</code> and |
| 1567 | |
| 1568 | <code>bazel-<workspace></code> |
| 1569 | symlinks. Use this option to suppress symlink creation entirely. |
| 1570 | </p> |
| 1571 | </li> |
| 1572 | <li> |
| 1573 | <p><b>Reduce clutter:</b> |
| 1574 | <code class='flag'>--symlink_prefix=.bazel/</code> will cause Bazel to create |
| 1575 | symlinks called <code>bin</code> (etc) inside a hidden directory <code>.bazel</code>. |
| 1576 | </p> |
| 1577 | </li> |
| 1578 | </ul> |
| 1579 | |
| 1580 | <h4 id='flag--platform_suffix'><code class='flag'>--platform_suffix <var>string</var></code></h4> |
| 1581 | <p> |
| 1582 | Adds a suffix to the configuration short name, which is used to determine the |
| 1583 | output directory. Setting this option to different values puts the files into |
| 1584 | different directories, for example to improve cache hit rates for builds that |
| 1585 | otherwise clobber each others output files, or to keep the output files around |
| 1586 | for comparisons. |
| 1587 | </p> |
| 1588 | |
| 1589 | <h4 id='flag--default_visibility'><code class='flag'>--default_visibility=<var>(private|public)</var></code></h4> |
| 1590 | <p> |
| 1591 | Temporary flag for testing bazel default visibility changes. Not intended for general use |
| 1592 | but documented for completeness' sake. |
| 1593 | </p> |
| 1594 | |
Googler | 2347169 | 2017-06-02 11:26:16 -0400 | [diff] [blame] | 1595 | <h4 id='flag--use_action_cache'><code class='flag'>--[no]use_action_cache</code></h4> |
| 1596 | <p> |
| 1597 | This option is enabled by default. If disabled, Bazel will not use its local action cache. |
| 1598 | Disabling the local action cache saves memory and disk space for clean builds, but will make |
| 1599 | incremental builds slower. |
| 1600 | </p> |
| 1601 | |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 1602 | <h2 id='bazel-releng'>Using Bazel for releases</h2> |
| 1603 | <p> |
| 1604 | Bazel is used both by software engineers during the development |
| 1605 | cycle, and by release engineers when preparing binaries for deployment |
| 1606 | to production. This section provides a list of tips for release |
| 1607 | engineers using Bazel. |
| 1608 | |
| 1609 | </p> |
| 1610 | |
| 1611 | <h3>Significant options</h3> |
| 1612 | |
| 1613 | <p> |
| 1614 | When using Bazel for release builds, the same issues arise as for |
| 1615 | other scripts that perform a build, so you should read |
| 1616 | the <a href='#scripting'>scripting</a> section of this manual. |
| 1617 | In particular, the following options are strongly recommended: |
| 1618 | </p> |
| 1619 | <ul> |
Vladimir Chebotarev | 66885ff | 2018-12-04 14:08:16 -0800 | [diff] [blame^] | 1620 | <li><a href='guide.html#bazelrc'><code class='flag'>--bazelrc=/dev/null</code></a></li> |
ccalvarin | af8b772 | 2018-06-06 11:54:00 -0700 | [diff] [blame] | 1621 | <li><a href='#flag--keep_state_after_build'><code class='flag'>--nokeep_state_after_build</code></a></li> |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 1622 | </ul> |
| 1623 | |
| 1624 | <p> |
| 1625 | These options (q.v.) are also important: |
| 1626 | </p> |
| 1627 | |
| 1628 | <ul> |
| 1629 | |
| 1630 | <li><a href='#flag--package_path'><code class='flag'>--package_path</code></a></li> |
| 1631 | <li><a href='#flag--symlink_prefix'><code class='flag'>--symlink_prefix</code></a>: |
| 1632 | for managing builds for multiple configurations, |
| 1633 | it may be convenient to distinguish each build |
| 1634 | with a distinct identifier, e.g. "64bit" vs. "32bit". This option |
| 1635 | differentiates the <code>bazel-bin</code> (etc.) symlinks. |
| 1636 | </li> |
| 1637 | </ul> |
| 1638 | |
| 1639 | <h2 id='test'>Running tests with Bazel</h2> |
| 1640 | <p> |
| 1641 | To build and run tests with bazel, type <code>bazel test</code> followed by |
| 1642 | the name of the test targets. |
| 1643 | </p> |
| 1644 | <p> |
| 1645 | By default, this command performs simultaneous build and test |
| 1646 | activity, building all specified targets (including any non-test |
| 1647 | targets specified on the command line) and testing |
| 1648 | <code>*_test</code> and <code>test_suite</code> targets as soon as |
| 1649 | their prerequisites are built, meaning that test execution is |
| 1650 | interleaved with building. Doing so usually results in significant |
| 1651 | speed gains. |
| 1652 | |
| 1653 | </p> |
| 1654 | |
| 1655 | <h3>Options for <code>bazel test</code></h3> |
| 1656 | |
| 1657 | <h4 id="flag--cache_test_results"><code class='flag'>--cache_test_results=(yes|no|auto)</code> (<code>-t</code>)</h4> |
| 1658 | <p> |
| 1659 | If this option is set to 'auto' (the default) then Bazel will only rerun a test if any of the |
| 1660 | following conditions applies: |
| 1661 | </p> |
| 1662 | <ul> |
| 1663 | <li>Bazel detects changes in the test or its dependencies</li> |
| 1664 | <li>the test is marked as <code>external</code></li> |
| 1665 | <li>multiple test runs were requested with <code class='flag'>--runs_per_test</code></li> |
| 1666 | <li>the test failed.</li> |
| 1667 | </ul> |
| 1668 | <p> |
| 1669 | If 'no', all tests will be executed unconditionally. |
| 1670 | </p> |
| 1671 | <p> |
| 1672 | If 'yes', the caching behavior will be the same as auto |
| 1673 | except that it may cache test failures and test runs with |
| 1674 | <code class='flag'>--runs_per_test</code>. |
| 1675 | </p> |
| 1676 | <p> |
| 1677 | Note that test results are <em>always</em> saved in Bazel's output tree, |
| 1678 | regardless of whether this option is enabled, so |
| 1679 | you needn't have used <code class='flag'>--cache_test_results</code> on the |
| 1680 | prior run(s) of <code>bazel test</code> in order to get cache hits. |
| 1681 | The option only affects whether Bazel will <em>use</em> previously |
| 1682 | saved results, not whether it will save results of the current run. |
| 1683 | </p> |
| 1684 | <p> |
| 1685 | Users who have enabled this option by default in |
| 1686 | their <code>.bazelrc</code> file may find the |
| 1687 | abbreviations <code>-t</code> (on) or <code>-t-</code> (off) |
| 1688 | convenient for overriding the default on a particular run. |
| 1689 | </p> |
| 1690 | |
| 1691 | <h4 id="flag--check_tests_up_to_date"><code class='flag'>--check_tests_up_to_date</code></h4> |
| 1692 | <p> |
| 1693 | This option tells Bazel not to run the tests, but to merely check and report |
| 1694 | the cached test results. If there are any tests which have not been |
| 1695 | previously built and run, or whose tests results are out-of-date (e.g. because |
| 1696 | the source code or the build options have changed), then Bazel will report |
| 1697 | an error message ("test result is not up-to-date"), will record the test's |
| 1698 | status as "NO STATUS" (in red, if color output is enabled), and will return |
| 1699 | a non-zero exit code. |
| 1700 | </p> |
| 1701 | <p> |
| 1702 | This option also implies |
| 1703 | <code><a href="#flag--check_up_to_date">--check_up_to_date</a></code> behavior. |
| 1704 | </p> |
| 1705 | <p> |
| 1706 | This option may be useful for pre-submit checks. |
| 1707 | </p> |
| 1708 | |
| 1709 | <h4 id="flag--test_verbose_timeout_warnings"><code class='flag'>--test_verbose_timeout_warnings</code></h4> |
| 1710 | <p> |
| 1711 | This option tells Bazel to explicitly warn the user if a test's timeout is |
Googler | 6d2bfa4 | 2018-09-21 10:25:21 -0700 | [diff] [blame] | 1712 | significantly longer than the test's actual execution time. While a test's |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 1713 | timeout should be set such that it is not flaky, a test that has a highly |
| 1714 | over-generous timeout can hide real problems that crop up unexpectedly. |
| 1715 | </p> |
| 1716 | <p> |
| 1717 | For instance, a test that normally executes in a minute or two should not have |
| 1718 | a timeout of ETERNAL or LONG as these are much, much too generous. |
| 1719 | |
| 1720 | This option is useful to help users decide on a good timeout value or |
| 1721 | sanity check existing timeout values. |
| 1722 | </p> |
| 1723 | <p> |
| 1724 | Note that each test shard is allotted the timeout of the entire |
| 1725 | <code>XX_test</code> target. Using this option does not affect a test's timeout |
| 1726 | value, merely warns if Bazel thinks the timeout could be restricted further. |
| 1727 | </p> |
| 1728 | |
| 1729 | <h4 id='flag--test_keep_going'><code class='flag'>--[no]test_keep_going</code></h4> |
| 1730 | <p> |
| 1731 | By default, all tests are run to completion. If this flag is disabled, |
| 1732 | however, the build is aborted on any non-passing test. Subsequent build steps |
| 1733 | and test invocations are not run, and in-flight invocations are canceled. |
| 1734 | Do not specify both <code class='flag'>--notest_keep_going</code> and |
| 1735 | <code class='flag'>--keep_going</code>. |
| 1736 | </p> |
| 1737 | |
| 1738 | <h4 id='flag--flaky_test_attempts'><code class='flag'>--flaky_test_attempts <var>attempts</var></code></h4> |
| 1739 | <p> |
| 1740 | This option specifies the maximum number of times a test should be attempted |
| 1741 | if it fails for any reason. A test that initially fails but eventually |
| 1742 | succeeds is reported as <code>FLAKY</code> on the test summary. It is, |
| 1743 | however, considered to be passed when it comes to identifying Bazel exit code |
| 1744 | or total number of passed tests. Tests that fail all allowed attempts are |
| 1745 | considered to be failed. |
| 1746 | </p> |
| 1747 | <p> |
| 1748 | By default (when this option is not specified, or when it is set to |
| 1749 | "default"), only a single attempt is allowed for regular tests, and |
| 1750 | 3 for test rules with the <code>flaky</code> attribute set. You can specify |
| 1751 | an integer value to override the maximum limit of test attempts. Bazel allows |
| 1752 | a maximum of 10 test attempts in order to prevent abuse of the system. |
| 1753 | </p> |
| 1754 | |
| 1755 | <h4 id='flag--runs_per_test'><code class='flag'>--runs_per_test <var>[regex@]number</var></code></h4> |
| 1756 | <p> |
| 1757 | This option specifies the number of times each test should be executed. All |
| 1758 | test executions are treated as separate tests (e.g. fallback functionality |
| 1759 | will apply to each of them independently). |
| 1760 | </p> |
| 1761 | <p> |
| 1762 | The status of a target with failing runs depends on the value of the |
| 1763 | <code>--runs_per_test_detects_flakes</code> flag: |
| 1764 | </p> |
| 1765 | <ul> |
| 1766 | <li>If absent, any failing run causes the entire test to fail.</li> |
| 1767 | <li>If present and two runs from the same shard return PASS and FAIL, the test |
| 1768 | will receive a status of flaky (unless other failing runs cause it to |
| 1769 | fail).</li> |
| 1770 | </ul> |
| 1771 | |
| 1772 | <p> |
| 1773 | If a single number is specified, all tests will run that many times. |
| 1774 | Alternatively, a regular expression may be specified using the syntax |
| 1775 | regex@number. This constrains the effect of --runs_per_test to targets |
| 1776 | which match the regex (e.g. "--runs_per_test=^//pizza:.*@4" runs all tests |
| 1777 | under //pizza/ 4 times). |
| 1778 | This form of --runs_per_test may be specified more than once. |
| 1779 | </p> |
| 1780 | |
| 1781 | <h4 id='flag--runs_per_test_detects_flakes'><code |
| 1782 | class='flag'>--[no]runs_per_test_detects_flakes</code></h4> |
| 1783 | <p> |
| 1784 | If this option is specified (by default it is not), Bazel will detect flaky |
| 1785 | test shards through --runs_per_test. If one or more runs for a single shard |
| 1786 | fail and one or more runs for the same shard pass, the target will be |
| 1787 | considered flaky with the flag. If unspecified, the target will report a |
| 1788 | failing status. |
| 1789 | </p> |
| 1790 | |
| 1791 | <h4 id='flag--test_summary'><code class='flag'>--test_summary <var>output_style</var></code></h4> |
| 1792 | <p> |
| 1793 | Specifies how the test result summary should be displayed. |
| 1794 | </p> |
| 1795 | <ul> |
| 1796 | <li><code>short</code> prints the results of each test along with the name of |
| 1797 | the file containing the test output if the test failed. This is the default |
| 1798 | value. |
| 1799 | </li> |
| 1800 | <li><code>terse</code> like <code>short</code>, but even shorter: only print |
| 1801 | information about tests which did not pass. |
| 1802 | </li> |
| 1803 | <li><code>detailed</code> prints each individual test case that failed, not |
| 1804 | only each test. The names of test output files are omitted. |
| 1805 | </li> |
| 1806 | <li><code>none</code> does not print test summary. |
| 1807 | </li> |
| 1808 | </ul> |
| 1809 | |
| 1810 | <h4 id='flag--test_output'><code class='flag'>--test_output <var>output_style</var></code></h4> |
| 1811 | <p> |
| 1812 | Specifies how test output should be displayed: |
| 1813 | </p> |
| 1814 | <ul> |
| 1815 | <li><code>summary</code> shows a summary of whether each test passed or |
| 1816 | failed. Also shows the output log file name for failed tests. The summary |
| 1817 | will be printed at the end of the build (during the build, one would see |
| 1818 | just simple progress messages when tests start, pass or fail). |
| 1819 | This is the default behavior. |
| 1820 | </li> |
| 1821 | <li><code>errors</code> sends combined stdout/stderr output from failed tests |
| 1822 | only into the stdout immediately after test is completed, ensuring that |
| 1823 | test output from simultaneous tests is not interleaved with each other. |
| 1824 | Prints a summary at the build as per summary output above. |
| 1825 | </li> |
| 1826 | <li><code>all</code> is similar to <code>errors</code> but prints output for |
| 1827 | all tests, including those which passed. |
| 1828 | </li> |
| 1829 | <li><code>streamed</code> streams stdout/stderr output from each test in |
| 1830 | real-time. |
| 1831 | |
| 1832 | </li> |
| 1833 | </ul> |
| 1834 | |
| 1835 | <h4 id='flag--java_debug'><code class='flag'>--java_debug</code></h4> |
| 1836 | <p> |
| 1837 | This option causes the Java virtual machine of a java test to wait for a connection from a |
| 1838 | JDWP-compliant debugger before starting the test. This option implies --test_output=streamed. |
| 1839 | </p> |
| 1840 | |
| 1841 | <h4 id='flag--verbose_test_summary'><code class='flag'>--[no]verbose_test_summary</code></h4> |
| 1842 | <p> |
| 1843 | By default this option is enabled, causing test times and other additional |
| 1844 | information (such as test attempts) to be printed to the test summary. If |
| 1845 | <code class='flag'>--noverbose_test_summary</code> is specified, test summary will |
| 1846 | include only test name, test status and cached test indicator and will |
| 1847 | be formatted to stay within 80 characters when possible. |
| 1848 | </p> |
| 1849 | |
| 1850 | <h4 id='flag--test_tmpdir'><code class='flag'>--test_tmpdir <var>path</var></code></h4> |
| 1851 | <p> |
| 1852 | Specifies temporary directory for tests executed locally. Each test will be |
| 1853 | executed in a separate subdirectory inside this directory. The directory will |
| 1854 | be cleaned at the beginning of the each <code>bazel test</code> command. |
| 1855 | By default, bazel will place this directory under Bazel output base directory. |
| 1856 | Note that this is a directory for running tests, not storing test results |
| 1857 | (those are always stored under the <code>bazel-out</code> directory). |
| 1858 | </p> |
| 1859 | |
| 1860 | <h4 id='flag--test_timeout'> |
| 1861 | <code class='flag'>--test_timeout |
| 1862 | <var>seconds</var></code> |
| 1863 | OR |
| 1864 | <code class='flag'>--test_timeout |
| 1865 | <var>seconds</var>,<var>seconds</var>,<var>seconds</var>,<var>seconds</var> |
| 1866 | </code> |
| 1867 | </h4> |
| 1868 | <p> |
| 1869 | Overrides the timeout value for all tests by using specified number of |
| 1870 | seconds as a new timeout value. If only one value is provided, then it will |
| 1871 | be used for all test timeout categories. |
| 1872 | </p> |
| 1873 | <p> |
| 1874 | Alternatively, four comma-separated values may be provided, specifying |
| 1875 | individual timeouts for short, moderate, long and eternal tests (in that |
| 1876 | order). |
| 1877 | In either form, zero or a negative value for any of the test sizes will |
| 1878 | be substituted by the default timeout for the given timeout categories as |
| 1879 | defined by the page |
| 1880 | <a href="test-encyclopedia.html">Writing Tests</a>. |
| 1881 | By default, Bazel will use these timeouts for all tests by |
| 1882 | inferring the timeout limit from the test's size whether the size is |
| 1883 | implicitly or explicitly set. |
| 1884 | </p> |
| 1885 | <p> |
| 1886 | Tests which explicitly state their timeout category as distinct from their |
| 1887 | size will receive the same value as if that timeout had been implicitly set by |
| 1888 | the size tag. So a test of size 'small' which declares a 'long' timeout will |
| 1889 | have the same effective timeout that a 'large' tests has with no explicit |
| 1890 | timeout. |
| 1891 | </p> |
| 1892 | |
| 1893 | <h4 id='flag--test_arg'><code class='flag'>--test_arg <var>arg</var></code></h4> |
| 1894 | <p> |
Michael Staib | 3df106e | 2017-02-23 23:08:40 +0000 | [diff] [blame] | 1895 | Passes command-line options/flags/arguments to each test process. This |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 1896 | option can be used multiple times to pass several arguments, e.g. |
| 1897 | <code class='flag'>--test_arg=--logtostderr --test_arg=--v=3</code>. |
| 1898 | </p> |
| 1899 | |
| 1900 | <h4 id='flag--test_env'><code class='flag'>--test_env <var>variable</var>=<i>value</i></code> |
| 1901 | OR |
| 1902 | <code class='flag'>--test_env <var>variable</var></code></h4> |
| 1903 | <p> |
| 1904 | Specifies additional variables that must be injected into the test |
| 1905 | environment for each test. If <var>value</var> is not specified it will be |
| 1906 | inherited from the shell environment used to start the <code>bazel test</code> |
| 1907 | command. |
| 1908 | </p> |
| 1909 | <p> |
| 1910 | The environment can be accessed from within a test by using |
| 1911 | <code>System.getenv("var")</code> (Java), |
| 1912 | <code>getenv("var")</code> (C or C++), |
| 1913 | |
| 1914 | </p> |
| 1915 | |
| 1916 | <h4 id="flag--run_under"><code class='flag'>--run_under=<var>command-prefix</var></code></h4> |
| 1917 | <p> |
| 1918 | This specifies a prefix that the test runner will insert in front |
| 1919 | of the test command before running it. The |
| 1920 | <var>command-prefix</var> is split into words using Bourne shell |
| 1921 | tokenization rules, and then the list of words is prepended to the |
| 1922 | command that will be executed. |
| 1923 | </p> |
| 1924 | <p> |
Googler | a0f79b1 | 2018-11-29 06:31:16 -0800 | [diff] [blame] | 1925 | If the first word is a fully-qualified label (i.e. starts with |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 1926 | <code>//</code>) it is built. Then the label is substituted by the |
| 1927 | corresponding executable location that is prepended to the command |
| 1928 | that will be executed along with the other words. |
| 1929 | </p> |
| 1930 | |
| 1931 | <p> |
| 1932 | Some caveats apply: |
| 1933 | </p> |
| 1934 | <ul> |
| 1935 | <li> |
| 1936 | The PATH used for running tests may be different than the PATH in your environment, |
| 1937 | so you may need to use an <b>absolute path</b> for the <code class='flag'>--run_under</code> |
| 1938 | command (the first word in <var>command-prefix</var>). |
| 1939 | </li> |
| 1940 | <li> |
| 1941 | <b><code>stdin</code> is not connected</b>, so <code class='flag'>--run_under</code> |
| 1942 | can't be used for interactive commands. |
| 1943 | </li> |
| 1944 | |
| 1945 | </ul> |
| 1946 | <p> |
| 1947 | Examples: |
| 1948 | </p> |
| 1949 | <pre> |
| 1950 | --run_under=/usr/bin/valgrind |
| 1951 | --run_under=/usr/bin/strace |
| 1952 | --run_under='/usr/bin/strace -c' |
| 1953 | --run_under='/usr/bin/valgrind --quiet --num-callers=20' |
| 1954 | |
| 1955 | </pre> |
| 1956 | |
| 1957 | <h4>Test selection</h4> |
| 1958 | <p> |
| 1959 | As documented under <a href='#output-selection-options'>Output selection options</a>, |
| 1960 | you can filter tests by <a href='#flag--test_size_filters'>size</a>, |
| 1961 | <a href='#flag--test_timeout_filters'>timeout</a>, |
| 1962 | <a href='#flag--test_tag_filters'>tag</a>, or |
| 1963 | <a href='#flag--test_lang_filters'>language</a>. A convenience |
| 1964 | <a href='#flag--test_filter'>general name filter</a> can forward particular |
| 1965 | filter args to the test runner. |
| 1966 | </p> |
| 1967 | |
kchodorow | fae5c74 | 2017-03-28 16:53:24 +0000 | [diff] [blame] | 1968 | <h4 id="other_options_for_bazel_test">Other options for <code>bazel test</code></h4> |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 1969 | <p> |
| 1970 | The syntax and the remaining options are exactly like |
| 1971 | <a href='#build'>bazel build</a>. |
| 1972 | </p> |
| 1973 | |
| 1974 | |
laurentlb | c85de9c | 2018-11-05 08:30:36 -0800 | [diff] [blame] | 1975 | <h3 id='clean'>Deleting the outputs of a build</h3> |
| 1976 | |
| 1977 | <h4>The <code>clean</code> command</h4> |
| 1978 | |
| 1979 | <p> |
| 1980 | Bazel has a <code>clean</code> command, analogous to that of Make. |
| 1981 | It deletes the output directories for all build configurations performed |
| 1982 | by this Bazel instance, or the entire working tree created by this |
| 1983 | Bazel instance, and resets internal caches. If executed without any |
| 1984 | command-line options, then the output directory for all configurations |
| 1985 | will be cleaned. |
| 1986 | </p> |
| 1987 | |
| 1988 | <p>Recall that each Bazel instance is associated with a single workspace, thus the |
| 1989 | <code>clean</code> command will delete all outputs from all builds you've done |
| 1990 | with that Bazel instance in that workspace. |
| 1991 | </p> |
| 1992 | <p> |
| 1993 | To completely remove the entire working tree created by a Bazel |
| 1994 | instance, you can specify the <code class='flag'>--expunge</code> option. When |
| 1995 | executed with <code class='flag'>--expunge</code>, the clean command simply |
| 1996 | removes the entire output base tree which, in addition to the build |
| 1997 | output, contains all temp files created by Bazel. It also |
| 1998 | stops the Bazel server after the clean, equivalent to the <a |
| 1999 | href='#shutdown'><code>shutdown</code></a> command. For example, to |
| 2000 | clean up all disk and memory traces of a Bazel instance, you could |
| 2001 | specify: |
| 2002 | </p> |
| 2003 | <pre> |
| 2004 | % bazel clean --expunge |
| 2005 | </pre> |
| 2006 | <p> |
| 2007 | Alternatively, you can expunge in the background by using |
| 2008 | <code class='flag'>--expunge_async</code>. It is safe to invoke a Bazel command |
| 2009 | in the same client while the asynchronous expunge continues to run. |
| 2010 | Note, however, that this may introduce IO contention. |
| 2011 | </p> |
| 2012 | |
| 2013 | <p> |
| 2014 | The <code>clean</code> command is provided primarily as a means of |
| 2015 | reclaiming disk space for workspaces that are no longer needed. |
| 2016 | However, we recognize that Bazel's incremental rebuilds might not be |
| 2017 | perfect; <code>clean</code> may be used to recover a consistent |
| 2018 | state when problems arise. |
| 2019 | </p> |
| 2020 | <p> |
| 2021 | Bazel's design is such that these problems are fixable; we consider |
| 2022 | such bugs a high priority, and will do our best fix them. If you |
| 2023 | ever find an incorrect incremental build, please file a bug report. |
| 2024 | We encourage developers to get out of the habit of |
| 2025 | using <code>clean</code> and into that of reporting bugs in the |
| 2026 | tools. |
| 2027 | </p> |
| 2028 | |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 2029 | |
| 2030 | <h2 id='run'>Running executables with Bazel</h2> |
| 2031 | <p> |
| 2032 | The <code>bazel run</code> command is similar to <code>bazel build</code>, except |
| 2033 | it is used to build and run a single target. Here is a typical session: |
| 2034 | </p> |
| 2035 | <pre> |
| 2036 | % bazel run -- java/myapp:myapp --arg1 --arg2 |
| 2037 | Welcome to Bazel |
| 2038 | INFO: Loading package: java/myapp |
| 2039 | INFO: Loading package: foo/bar |
| 2040 | INFO: Loading complete. Analyzing... |
| 2041 | INFO: Found 1 target... |
| 2042 | ... |
| 2043 | Target //java/myapp:myapp up-to-date: |
| 2044 | bazel-bin/java/myapp:myapp |
| 2045 | INFO: Elapsed time: 0.638s, Critical Path: 0.34s |
| 2046 | |
| 2047 | INFO: Running command line: bazel-bin/java/myapp:myapp --arg1 --arg2 |
| 2048 | Hello there |
| 2049 | $EXEC_ROOT/java/myapp/myapp |
| 2050 | --arg1 |
| 2051 | --arg2 |
| 2052 | </pre> |
| 2053 | |
| 2054 | <p> |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 2055 | Note the use of the <code>--</code>. This is needed so that Bazel |
| 2056 | does not interpret <code>--arg1</code> and <code>--arg2</code> as |
| 2057 | Bazel options, but rather as part of the command line for running the binary. |
| 2058 | (The program being run simply says hello and prints out its args.) |
| 2059 | </p> |
| 2060 | |
| 2061 | <h3>Options for <code>bazel run</code></h3> |
| 2062 | |
| 2063 | <h4 id='flag--run_under_run'><code class='flag'>--run_under=<var>command-prefix</var></code></h4> |
| 2064 | <p> |
| 2065 | This has the same effect as the <code class='flag'>--run_under</code> option for |
| 2066 | <code>bazel test</code> (<a href='#flag--run_under'>see above</a>), |
| 2067 | except that it applies to the command being run by <code>bazel |
| 2068 | run</code> rather than to the tests being run by <code>bazel test</code> |
| 2069 | and cannot run under label. |
| 2070 | </p> |
| 2071 | |
| 2072 | <h3>Executing tests</h3> |
| 2073 | |
| 2074 | <p> |
| 2075 | <code>bazel run</code> can also execute test binaries, which has the effect of |
lberki | 5a2238d | 2018-05-18 03:15:32 -0700 | [diff] [blame] | 2076 | running the test in a close approximation of the environment described at |
| 2077 | <a href='test-encyclopedia.html'>Writing Tests</a>. Note that none of the |
| 2078 | <code>--test_*</code>code> arguments have an effect when running a test in this manner except |
| 2079 | <code>--test_arg</code> . |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 2080 | </p> |
| 2081 | |
| 2082 | <h2 id='query'>Querying the dependency graph with Bazel</h2> |
| 2083 | |
| 2084 | <p> |
| 2085 | Bazel includes a query language for asking questions about the |
juliexxia | a8082fc | 2018-03-15 09:58:51 -0700 | [diff] [blame] | 2086 | dependency graph used during the build. The query language is used |
| 2087 | by two commands: query and cquery. The major difference between the |
| 2088 | two commands is that query runs after the <a href='#loading-phase'>loading phase</a> |
juliexxia | 928320e | 2018-03-23 12:17:58 -0700 | [diff] [blame] | 2089 | and cquery runs after the <a href='#analysis-phase'>analysis phase</a>. These tools are an |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 2090 | invaluable aid to many software engineering tasks. |
| 2091 | </p> |
| 2092 | <p> |
| 2093 | The query language is based on the idea of |
| 2094 | algebraic operations over graphs; it is documented in detail in |
| 2095 | |
| 2096 | <a href="query.html">Bazel Query Reference</a>. |
| 2097 | Please refer to that document for reference, for |
| 2098 | examples, and for query-specific command-line options. |
| 2099 | </p> |
| 2100 | |
| 2101 | <p> |
| 2102 | The query tool accepts several command-line |
| 2103 | option. <code class='flag'>--output</code> selects the output format. |
| 2104 | <code class='flag'>--[no]keep_going</code> (disabled by default) causes the query |
| 2105 | tool to continue to make progress upon errors; this behavior may be |
| 2106 | disabled if an incomplete result is not acceptable in case of errors. |
| 2107 | </p> |
| 2108 | <p> |
| 2109 | The <code class='flag'>--[no]host_deps</code> option, |
| 2110 | enabled by default, causes dependencies on "host |
| 2111 | configuration" targets to be included in the dependency graph over |
| 2112 | which the query operates. |
| 2113 | |
| 2114 | </p> |
| 2115 | <p> |
| 2116 | The <code class='flag'>--[no]implicit_deps</code> option, enabled by default, causes |
| 2117 | implicit dependencies to be included in the dependency graph over which the query operates. An |
| 2118 | implicit dependency is one that is not explicitly specified in the BUILD file |
| 2119 | but added by bazel. |
| 2120 | </p> |
| 2121 | <p> |
| 2122 | Example: "Show the locations of the definitions (in BUILD files) of |
| 2123 | all genrules required to build all the tests in the PEBL tree." |
| 2124 | </p> |
| 2125 | <pre> |
| 2126 | bazel query --output location 'kind(genrule, deps(kind(".*_test rule", foo/bar/pebl/...)))' |
| 2127 | </pre> |
| 2128 | |
twerth | e7fcab3 | 2018-08-09 08:03:41 -0700 | [diff] [blame] | 2129 | <h2 id='aquery'>Querying the action graph with Bazel</h2> |
| 2130 | |
| 2131 | <b>Caution</b>: The aquery command is still experimental and its API will change. |
| 2132 | |
| 2133 | <p> |
| 2134 | The <code>aquery</code> command allows you to query for actions in your build graph. |
| 2135 | It operates on the post-analysis configured target graph and exposes |
| 2136 | information about actions, artifacts and their relationships. |
| 2137 | </p> |
| 2138 | |
| 2139 | <p> |
| 2140 | The tool accepts several command-line options. |
| 2141 | <code class='flag'>--output</code> selects the output format |
| 2142 | (<code>proto</code> is the default, use <code>text</code> for human readable |
| 2143 | output). |
| 2144 | Notably, the aquery command runs on top of a regular Bazel build and inherits |
| 2145 | the set of options available during a build. |
| 2146 | </p> |
| 2147 | |
| 2148 | <p> |
| 2149 | It supports the same set of functions that is also available to traditional |
| 2150 | <code>query</code> but <code>siblings</code>, <code>buildfiles</code> and |
| 2151 | <code>tests</code>. |
| 2152 | </p> |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 2153 | |
| 2154 | <h2 id='misc'>Miscellaneous Bazel commands and options</h2> |
| 2155 | |
| 2156 | <h3 id='help'>The <code>help</code> command</h3> |
| 2157 | |
| 2158 | <p> |
| 2159 | The <code>help</code> command provides on-line help. By default, it |
| 2160 | shows a summary of available commands and help topics, as shown in |
| 2161 | the <a href='#overview'><i>Bazel overview</i></a> section above. |
| 2162 | Specifying an argument displays detailed help for a particular |
| 2163 | topic. Most topics are Bazel commands, e.g. <code>build</code> |
| 2164 | or <code>query</code>, but there are some additional help topics |
| 2165 | that do not correspond to commands. |
| 2166 | </p> |
| 2167 | |
| 2168 | <h4 id='flag--long'><code class='flag'>--[no]long</code> (<code>-l</code>)</h4> |
| 2169 | <p> |
| 2170 | By default, <code>bazel help [<var>topic</var>]</code> prints only a |
| 2171 | summary of the relevant options for a topic. If |
| 2172 | the <code class='flag'>--long</code> option is specified, the type, default value |
| 2173 | and full description of each option is also printed. |
| 2174 | </p> |
| 2175 | |
| 2176 | <h3 id='shutdown'>The <code>shutdown</code> command</h3> |
| 2177 | |
| 2178 | <p> |
| 2179 | Bazel server processes (see <a href='#client/server'>Client/server |
| 2180 | implementation</a>) may be stopped by using the <code>shutdown</code> |
| 2181 | command. This command causes the Bazel server to exit as soon as it |
| 2182 | becomes idle (i.e. after the completion of any builds or other |
| 2183 | commands that are currently in progress). |
| 2184 | |
| 2185 | Bazel servers stop themselves after an idle timeout, so this command |
| 2186 | is rarely necessary; however, it can be useful in scripts when it is |
| 2187 | known that no further builds will occur in a given workspace. |
| 2188 | </p> |
| 2189 | <p> |
| 2190 | <code>shutdown</code> accepts one |
| 2191 | option, <code class='flag'>--iff_heap_size_greater_than <i>n</i></code>, which |
| 2192 | requires an integer argument (in MB). If specified, this makes the shutdown |
| 2193 | conditional on the amount of memory already consumed. This is |
| 2194 | useful for scripts that initiate a lot of builds, as any memory |
| 2195 | leaks in the Bazel server could cause it to crash spuriously on |
| 2196 | occasion; performing a conditional restart preempts this condition. |
| 2197 | </p> |
| 2198 | |
| 2199 | <h3 id='info'>The <code>info</code> command</h3> |
| 2200 | |
| 2201 | <p> |
| 2202 | The <code>info</code> command prints various values associated with |
| 2203 | the Bazel server instance, or with a specific build configuration. |
| 2204 | (These may be used by scripts that drive a build.) |
| 2205 | </p> |
| 2206 | |
| 2207 | <p> |
| 2208 | The <code>info</code> command also permits a single (optional) |
| 2209 | argument, which is the name of one of the keys in the list below. |
| 2210 | In this case, <code>bazel info <var>key</var></code> will print only |
| 2211 | the value for that one key. (This is especially convenient when |
| 2212 | scripting Bazel, as it avoids the need to pipe the result |
| 2213 | through <code>sed -ne /key:/s/key://p</code>: |
| 2214 | </p> |
| 2215 | |
| 2216 | <h4>Configuration-independent data</h4> |
| 2217 | <ul> |
| 2218 | <li><code>release</code>: the release label for this Bazel |
| 2219 | instance, or "development version" if this is not a released |
| 2220 | binary. |
| 2221 | </li> |
| 2222 | <li><code>workspace</code> the absolute path to the base workspace |
| 2223 | directory. |
| 2224 | </li> |
| 2225 | <li><code>install_base</code>: the absolute path to the installation |
| 2226 | directory used by this Bazel instance for the current user. Bazel |
| 2227 | installs its internally required executables below this directory. |
| 2228 | |
| 2229 | </li> |
| 2230 | <li><code>output_base</code>: the absolute path to the base output |
| 2231 | directory used by this Bazel instance for the current user and |
| 2232 | workspace combination. Bazel puts all of its scratch and build |
| 2233 | output below this directory. |
| 2234 | </li> |
| 2235 | <li><code>execution_root</code>: the absolute path to the execution |
| 2236 | root directory under output_base. This directory is the root for all files |
| 2237 | accessible to commands executed during the build, and is the working |
| 2238 | directory for those commands. If the workspace directory is writable, a |
| 2239 | symlink named |
| 2240 | |
| 2241 | <code>bazel-<workspace></code> |
| 2242 | is placed there pointing to this directory. |
| 2243 | </li> |
| 2244 | <li><code>output_path</code>: the absolute path to the output |
| 2245 | directory beneath the execution root used for all files actually |
| 2246 | generated as a result of build commands. If the workspace directory is |
| 2247 | writable, a symlink named <code>bazel-out</code> is placed there pointing |
| 2248 | to this directory. |
| 2249 | </li> |
| 2250 | <li><code>server_pid</code>: the process ID of the Bazel server |
| 2251 | process. </li> |
| 2252 | <li><code>command_log</code>: the absolute path to the command log file; |
| 2253 | this contains the interleaved stdout and stderr streams of the most recent |
| 2254 | Bazel command. Note that running <code>bazel info</code> will overwrite the |
| 2255 | contents of this file, since it then becomes the most recent Bazel command. |
| 2256 | However, the location of the command log file will not change unless you |
| 2257 | change the setting of the <code class='flag'>--output_base</code> or |
| 2258 | <code class='flag'>--output_user_root</code> options. |
| 2259 | </li> |
| 2260 | |
| 2261 | <li><code>used-heap-size</code>, |
Googler | 82085c4 | 2018-08-16 08:01:39 -0700 | [diff] [blame] | 2262 | <code>committed-heap-size</code>, |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 2263 | <code>max-heap-size</code>: reports various JVM heap size |
| 2264 | parameters. Respectively: memory currently used, memory currently |
| 2265 | guaranteed to be available to the JVM from the system, maximum |
| 2266 | possible allocation. |
| 2267 | </li> |
| 2268 | <li><code>gc-count</code>, <code>gc-time</code>: The cumulative count of |
| 2269 | garbage collections since the start of this Bazel server and the time spent |
| 2270 | to perform them. Note that these values are not reset at the start of every |
| 2271 | build. |
| 2272 | </li> |
| 2273 | <li><code>package_path</code>: A colon-separated list of paths which would be |
| 2274 | searched for packages by bazel. Has the same format as the |
| 2275 | <code class='flag'>--package_path</code> build command line argument. |
| 2276 | </li> |
| 2277 | </ul> |
| 2278 | <p> |
| 2279 | Example: the process ID of the Bazel server. |
| 2280 | </p> |
| 2281 | <pre>% bazel info server_pid |
| 2282 | 1285 |
| 2283 | </pre> |
| 2284 | |
| 2285 | <h4>Configuration-specific data</h4> |
| 2286 | <p> |
| 2287 | These data may be affected by the configuration options passed |
| 2288 | to <code>bazel info</code>, for |
| 2289 | example <code class='flag'>--cpu</code>, <code class='flag'>--compilation_mode</code>, |
| 2290 | etc. The <code>info</code> command accepts all |
| 2291 | the <a href='#analysis-options'>options that control dependency |
| 2292 | analysis</a>, since some of these determine the location of the |
| 2293 | output directory of a build, the choice of compiler, etc. |
| 2294 | </p> |
| 2295 | <ul> |
| 2296 | <li> |
| 2297 | <code>bazel-bin</code>, <code>bazel-testlogs</code>, |
| 2298 | <code>bazel-genfiles</code>: reports the absolute path to |
| 2299 | the <code>bazel-*</code> directories in which programs generated by the |
| 2300 | build are located. This is usually, though not always, the same as |
| 2301 | the <code>bazel-*</code> symlinks created in the base workspace directory after a |
| 2302 | successful build. However, if the workspace directory is read-only, |
| 2303 | no <code>bazel-*</code> symlinks can be created. Scripts that use |
| 2304 | the value reported by <code>bazel info</code>, instead of assuming the |
| 2305 | existence of the symlink, will be more robust. |
| 2306 | </li> |
| 2307 | <li> |
| 2308 | The complete |
| 2309 | <a href='be/make-variables.html' |
| 2310 | >"Make" environment</a>. If the <code class='flag'>--show_make_env</code> flag is |
| 2311 | specified, all variables in the current configuration's "Make" environment |
| 2312 | are also displayed (e.g. <code>CC</code>, <code>GLIBC_VERSION</code>, etc). |
| 2313 | These are the variables accessed using the <code>$(CC)</code> |
| 2314 | or <code>varref("CC")</code> syntax inside BUILD files. |
| 2315 | </li> |
| 2316 | </ul> |
| 2317 | |
| 2318 | <p> |
| 2319 | Example: the C++ compiler for the current configuration. |
| 2320 | This is the <code>$(CC)</code> variable in the "Make" environment, |
| 2321 | so the <code class='flag'>--show_make_env</code> flag is needed. |
| 2322 | </p> |
| 2323 | |
| 2324 | <pre> |
Ulf Adams | e0437b1 | 2016-08-29 14:48:47 +0000 | [diff] [blame] | 2325 | % bazel info --show_make_env -c opt COMPILATION_MODE |
| 2326 | opt |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 2327 | </pre> |
| 2328 | |
| 2329 | <p> |
| 2330 | Example: the <code>bazel-bin</code> output directory for the current |
| 2331 | configuration. This is guaranteed to be correct even in cases where |
| 2332 | the <code>bazel-bin</code> symlink cannot be created for some reason |
| 2333 | (e.g. you are building from a read-only directory). |
| 2334 | </p> |
| 2335 | |
| 2336 | <h3 id='version'>The <code>version</code> command</h3> |
| 2337 | |
| 2338 | <p> |
| 2339 | The version command prints version details about the built Bazel |
| 2340 | binary, including the changelist at which it was built and the date. |
| 2341 | These are particularly useful in determining if you have the latest |
| 2342 | Bazel, or if you are reporting bugs. Some of the interesting values |
| 2343 | are: |
| 2344 | </p> |
| 2345 | <ul> |
| 2346 | <li><code>changelist</code>: the changelist at which this version of |
| 2347 | Bazel was released. |
| 2348 | </li> |
| 2349 | <li><code>label</code>: the release label for this Bazel |
| 2350 | instance, or "development version" if this is not a released |
| 2351 | binary. Very useful when reporting bugs. |
| 2352 | </li> |
| 2353 | </ul> |
| 2354 | |
| 2355 | <h3 id='mobile-install'>The <code>mobile-install</code> command</h3> |
| 2356 | <p> |
| 2357 | The <code>mobile-install</code> command installs apps to mobile devices. |
| 2358 | Currently only Android devices running ART are supported. |
Alex Humesky | 105e661 | 2017-01-06 19:03:10 +0000 | [diff] [blame] | 2359 | |
| 2360 | See <a href="mobile-install.html">bazel mobile-install</a> |
| 2361 | for more information. |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 2362 | </p> |
| 2363 | <p> |
| 2364 | Note that this command does not install the same thing that |
| 2365 | <code>bazel build</code> produces: Bazel tweaks the app so that it can be |
| 2366 | built, installed and re-installed quickly. This should, however, be mostly |
| 2367 | transparent to the app. |
| 2368 | </p> |
| 2369 | <p> |
| 2370 | The following options are supported: |
| 2371 | </p> |
| 2372 | <h4 id='flag--incremental'><code class='flag'>--incremental</code></h4> |
| 2373 | <p> |
| 2374 | If set, Bazel tries to install the app incrementally, that is, only those |
| 2375 | parts that have changed since the last build. This cannot update resources |
| 2376 | referenced from <code>AndroidManifest.xml</code>, native code or Java |
| 2377 | resources (i.e. ones referenced by <code>Class.getResource()</code>). If these |
| 2378 | things change, this option must be omitted. Contrary to the spirit of Bazel |
| 2379 | and due to limitations of the Android platform, it is the |
| 2380 | <b>responsibility of the user</b> to know when this command is good enough and |
Alex Humesky | 105e661 | 2017-01-06 19:03:10 +0000 | [diff] [blame] | 2381 | when a full install is needed. |
| 2382 | |
| 2383 | If you are using a device with Marshmallow or later, consider the |
| 2384 | <a href='#flag--split_apks'><code class='flag'>--split_apks</code></a> flag. |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 2385 | </p> |
Alex Humesky | 105e661 | 2017-01-06 19:03:10 +0000 | [diff] [blame] | 2386 | <h4 id='flag--split_apks'><code class='flag'>--split_apks</code></h4> |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 2387 | <p> |
Alex Humesky | 105e661 | 2017-01-06 19:03:10 +0000 | [diff] [blame] | 2388 | Whether to use split apks to install and update the application on the device. |
| 2389 | Works only with devices with Marshmallow or later. Note that the |
| 2390 | <a href='#flag--incremental'><code class='flag'>--incremental</code></a> flag |
| 2391 | is not necessary when using <code class='flag'>--split_apks</code>. |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 2392 | </p> |
Alex Humesky | 105e661 | 2017-01-06 19:03:10 +0000 | [diff] [blame] | 2393 | <h4 id='flag--start_app'><code class='flag'>--start_app</code></h4> |
| 2394 | <p> |
| 2395 | Starts the app in a clean state after installing. Equivalent to |
| 2396 | <code>--start=COLD</code>. |
| 2397 | </p> |
Googler | 2b88f62 | 2017-03-16 21:52:14 +0000 | [diff] [blame] | 2398 | <h4 id='flag--debug_app'><code class='flag'>--debug_app</code></h4> |
Alex Humesky | 105e661 | 2017-01-06 19:03:10 +0000 | [diff] [blame] | 2399 | <p> |
Googler | 2b88f62 | 2017-03-16 21:52:14 +0000 | [diff] [blame] | 2400 | Waits for debugger to be attached before starting the app in a clean state after installing. |
| 2401 | Equivalent to <code>--start=DEBUG</code>. |
| 2402 | </p> |
| 2403 | <h4 id='flag--start'><code class='flag'>--start=<i>start_type</i></code></h4> |
| 2404 | <p> |
| 2405 | How the app should be started after installing it. Supported <i>start_type</i>s are: |
| 2406 | <ul> |
| 2407 | <li><code>NO</code> Does not start the app. This is the default.</li> |
| 2408 | <li><code>COLD</code> Starts the app from a clean state after install.</li> |
| 2409 | <li><code>WARM</code> Preserves and restores the application state on incremental installs.</li> |
| 2410 | <li><code>DEBUG</code> Waits for the debugger before starting the app in a clean state after install.</li> |
| 2411 | </ul> |
| 2412 | Note that if more than one of <code class='flag'>--start=<i>start_type</i></code>, |
| 2413 | <code class='flag'>--start_app</code> or |
| 2414 | <code class='flag'>--debug_app</code> is set, the last value will be used. |
Alex Humesky | 105e661 | 2017-01-06 19:03:10 +0000 | [diff] [blame] | 2415 | </p> |
| 2416 | <h4 id='flag--adb'><code class='flag'>--adb <var>path</var></code></h4> |
| 2417 | <p> |
| 2418 | Indicates the <code>adb</code> binary to be used. |
| 2419 | |
| 2420 | The default is to use the adb in the Android SDK specified by |
| 2421 | <a href='#flag--android_sdk'><code class='flag'>--android_sdk</code></a>. |
| 2422 | |
| 2423 | </p> |
| 2424 | <h4 id='flag--adb_arg'><code class='flag'>--adb_arg <var>arg</var></code></h4> |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 2425 | <p> |
| 2426 | Extra arguments to <code>adb</code>. These come before the subcommand in the |
| 2427 | command line and are typically used to specify which device to install to. |
Alex Humesky | 105e661 | 2017-01-06 19:03:10 +0000 | [diff] [blame] | 2428 | For example, to select the Android device or emulator to use: |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 2429 | <pre>% bazel mobile-install --adb_arg=-s --adb_arg=deadbeef |
| 2430 | </pre> |
| 2431 | will invoke <code>adb</code> as |
| 2432 | <pre> |
| 2433 | adb -s deadbeef install ... |
| 2434 | </pre> |
Alex Humesky | 105e661 | 2017-01-06 19:03:10 +0000 | [diff] [blame] | 2435 | </p> |
Alex Humesky | 105e661 | 2017-01-06 19:03:10 +0000 | [diff] [blame] | 2436 | <h4 id='flag--incremental_install_verbosity'><code class='flag'>--incremental_install_verbosity <var>number</var></code></h4> |
| 2437 | <p> |
| 2438 | The verbosity for incremental install. Set to 1 for debug logging to be |
| 2439 | printed to the console. |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 2440 | </p> |
| 2441 | |
gregce | ca8ee23 | 2018-03-08 11:35:22 -0800 | [diff] [blame] | 2442 | |
| 2443 | <h3 id='dump'>The <code>dump</code> command</h3> |
| 2444 | |
| 2445 | <p> |
| 2446 | The <code>dump</code> command prints to stdout a dump of the |
| 2447 | internal state of the Bazel server. This command is intended |
| 2448 | primarily for use by Bazel developers, so the output of this command |
| 2449 | is not specified, and is subject to change. |
| 2450 | </p> |
| 2451 | |
tomlu | 72642a2 | 2017-10-18 06:23:14 +0200 | [diff] [blame] | 2452 | <p> |
| 2453 | By default, command will just print help message outlining possible |
| 2454 | options to dump specific areas of the Bazel state. In order to dump |
| 2455 | internal state, at least one of the options must be specified. |
| 2456 | </p> |
| 2457 | <p> |
| 2458 | Following options are supported: |
| 2459 | </p> |
| 2460 | <ul> |
| 2461 | <li><code class='flag'>--action_cache</code> dumps action cache content.</li> |
| 2462 | <li><code class='flag'>--packages</code> dumps package cache content.</li> |
tomlu | 72642a2 | 2017-10-18 06:23:14 +0200 | [diff] [blame] | 2463 | <li><code class='flag'>--skyframe</code> dumps state of internal Bazel dependency graph.</li> |
| 2464 | <li><code class='flag'>--rules</code> dumps rule summary for each rule and aspect class, |
| 2465 | including counts and action counts. This includes both native and Skylark rules. |
| 2466 | If memory tracking is enabled, then the rules' memory consumption is also printed.</li> |
| 2467 | <li><code class='flag'>--skylark_memory</code> dumps a |
| 2468 | <href a=https://github.com/google/pprof>pprof</href> compatible .gz file to the specified path. |
| 2469 | You must enable memory tracking for this to work.</li> |
twerth | 700bc13 | 2018-03-05 01:32:50 -0800 | [diff] [blame] | 2470 | <li><code class='flag'>--action_graph=/path/to/file</code> dumps the state of |
| 2471 | the internal Bazel action graph in proto format to |
| 2472 | <code>/path/to/file</code>. You have to run (at least) the analysis phase |
| 2473 | for the targets you are interested in (for example, <code>bazel build --nobuild |
| 2474 | //foo:bar</code>). Note that this feature is still experimental, subject to |
| 2475 | change and will probably be integrated into <code>cquery</code> in the |
| 2476 | future. |
| 2477 | <li><code class='flag'>--action_graph:targets=target1,target2,...</code> |
| 2478 | filters the actions to the comma-separated list of targets when dumping the |
| 2479 | action graph.</li> |
ahumesky | a0f3a65 | 2018-09-17 09:23:44 -0700 | [diff] [blame] | 2480 | <li><code class='flag'>--action_graph:include_cmdline</code> Include the command lines of actions |
| 2481 | in the action graph dump.</li> |
tomlu | 72642a2 | 2017-10-18 06:23:14 +0200 | [diff] [blame] | 2482 | </ul> |
| 2483 | |
tomlu | 5af6138 | 2017-10-30 18:01:48 -0400 | [diff] [blame] | 2484 | <h4 id='memory-tracking'>Memory tracking</h4> |
| 2485 | <p> |
| 2486 | Some <code>dump</code> commands require memory tracking. To turn this on, you have to pass |
| 2487 | startup flags to Bazel: |
| 2488 | </p> |
| 2489 | <ul> |
| 2490 | <li><code>--host_jvm_args=-javaagent:$BAZEL/third_party/allocation_instrumenter/java-allocation-instrumenter-3.0.1.jar</code></li> |
tomlu | 4cad14a | 2017-10-31 09:08:32 -0400 | [diff] [blame] | 2491 | <li><code>--host_jvm_args=-DRULE_MEMORY_TRACKER=1</code></li> |
tomlu | 5af6138 | 2017-10-30 18:01:48 -0400 | [diff] [blame] | 2492 | </ul> |
| 2493 | <p> |
| 2494 | The java-agent is checked into bazel at |
| 2495 | third_party/allocation_instrumenter/java-allocation-instrumenter-3.0.1.jar, so make |
| 2496 | sure you adjust <code>$BAZEL</code> for where you keep your bazel repository. |
tomlu | 72642a2 | 2017-10-18 06:23:14 +0200 | [diff] [blame] | 2497 | |
tomlu | 5af6138 | 2017-10-30 18:01:48 -0400 | [diff] [blame] | 2498 | Do not forget to keep passing these options to Bazel for every command or the server will |
| 2499 | restart. |
| 2500 | </p> |
| 2501 | <p>Example:</p> |
| 2502 | <pre> |
| 2503 | % bazel --host_jvm_args=-javaagent:$BAZEL/third_party/allocation_instrumenter/java-allocation-instrumenter-3.0.1.jar \ |
| 2504 | --host_jvm_args=-DRULE_MEMORY_TRACKER=1 \ |
| 2505 | build --nobuild <targets> |
tomlu | 72642a2 | 2017-10-18 06:23:14 +0200 | [diff] [blame] | 2506 | |
tomlu | 5af6138 | 2017-10-30 18:01:48 -0400 | [diff] [blame] | 2507 | # Dump rules |
| 2508 | % bazel --host_jvm_args=-javaagent:$BAZEL/third_party/allocation_instrumenter/java-allocation-instrumenter-3.0.1.jar \ |
| 2509 | --host_jvm_args=-DRULE_MEMORY_TRACKER=1 \ |
| 2510 | dump --rules |
tomlu | 72642a2 | 2017-10-18 06:23:14 +0200 | [diff] [blame] | 2511 | |
tomlu | 5af6138 | 2017-10-30 18:01:48 -0400 | [diff] [blame] | 2512 | # Dump Skylark heap and analyze it with pprof |
| 2513 | % bazel --host_jvm_args=-javaagent:$BAZEL/third_party/allocation_instrumenter/java-allocation-instrumenter-3.0.1.jar \ |
| 2514 | --host_jvm_args=-DRULE_MEMORY_TRACKER=1 \ |
| 2515 | dump --skylark_memory=$HOME/prof.gz |
| 2516 | % pprof -flame $HOME/prof.gz |
| 2517 | </pre> |
tomlu | 72642a2 | 2017-10-18 06:23:14 +0200 | [diff] [blame] | 2518 | <h3 id='analyze-profile'>The <code>analyze-profile</code> command</h3> |
| 2519 | |
| 2520 | <p> |
| 2521 | The <code>analyze-profile</code> command analyzes data previously gathered |
| 2522 | during the build using <code class='flag'>--profile</code> option. It provides several |
| 2523 | options to either perform analysis of the build execution or export data in |
| 2524 | the specified format. |
| 2525 | |
| 2526 | </p> |
| 2527 | <p> |
| 2528 | The following options are supported: |
| 2529 | </p> |
| 2530 | <ul> |
| 2531 | <li><code id='flag--dump'>--dump=text</code> displays all gathered data in a |
| 2532 | <a href='#dump-text-format'>human-readable format</a></li> |
| 2533 | <li><code>--dump=raw</code> displays all gathered data in a |
| 2534 | <a href='#dump-raw-format'>script-friendly format</a></li> |
| 2535 | <li><code id='flag--html'>--html</code> generates an <a href='#dump-html-format'>HTML file</a> visualizing the |
| 2536 | actions and rules executed in the build, as well as summary statistics for the build |
| 2537 | <ul> |
| 2538 | <li><code id='flag--html_details'>--html_details</code> adds more fine-grained |
| 2539 | information on actions and rules to the HTML visualization</li> |
| 2540 | <ul> |
| 2541 | <li><code id='flag--html_histograms'>--html_histograms</code> adds histograms for Skylark |
| 2542 | functions clicked in the statistics table. This will increase file size massively</li> |
| 2543 | <li><code id='flag--nochart'>--nochart</code> hides the task chart from generated HTML |
| 2544 | </li> |
| 2545 | </ul> |
| 2546 | </ul> |
| 2547 | </li> |
| 2548 | <li><code id='flag--combine'>--combine</code> combines multiple profile data files into a single |
| 2549 | report. Does not generate HTML task charts</li> |
| 2550 | <li><code id='flag--task_tree'>--task_tree</code> prints the tree of tasks matching the given |
| 2551 | regular expression |
| 2552 | <ul> |
| 2553 | <li><code id='flag--task_tree_threshold'>--task_tree_threshold</code> skip tasks with duration |
jingwen | 7406520 | 2018-11-21 11:34:55 -0800 | [diff] [blame] | 2554 | less than threshold, in milliseconds. Default is 50ms</li> |
tomlu | 72642a2 | 2017-10-18 06:23:14 +0200 | [diff] [blame] | 2555 | </ul> |
| 2556 | </li> |
| 2557 | </ul> |
| 2558 | |
| 2559 | <p> |
| 2560 | See the section on <a href='#profiling'>Troubleshooting performance by profiling</a> for |
| 2561 | format details and usage help. |
| 2562 | |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 2563 | </p> |
| 2564 | |
| 2565 | <h3 id='canonicalize'>The <code>canonicalize-flags</code> command</h3> |
| 2566 | |
| 2567 | <p> |
| 2568 | The <code>canonicalize-flags</code> command, which takes a list of options for |
| 2569 | a Bazel command and returns a list of options that has the same effect. The |
| 2570 | new list of options is canonical, i.e., two lists of options with the same |
| 2571 | effect are canonicalized to the same new list. |
| 2572 | </p> |
| 2573 | <p> |
| 2574 | The <code class='flag'>--for_command</code> option can be used to select between different |
| 2575 | commands. At this time, only <code>build</code> and <code>test</code> are |
| 2576 | supported. Options that the given command does not support cause an error. |
| 2577 | </p> |
| 2578 | <p> |
| 2579 | Note that a small number of options cannot be reordered, because Bazel cannot |
| 2580 | ensure that the effect is identical. |
| 2581 | </p> |
| 2582 | |
| 2583 | <h3 id='startup_options'>Bazel startup options</h3> |
| 2584 | |
| 2585 | <p> |
| 2586 | The options described in this section affect the startup of the Java |
| 2587 | virtual machine used by Bazel server process, and they apply to all |
| 2588 | subsequent commands handled by that server. If there is an already |
| 2589 | running Bazel server and the startup options do not match, it will |
| 2590 | be restarted. |
| 2591 | </p> |
| 2592 | <p> |
| 2593 | All of the options described in this section must be specified using the |
| 2594 | <code class='flag'>--key=value</code> or <code class='flag'>--key value</code> |
| 2595 | syntax. Also, these options must appear <i>before</i> the name of the Bazel |
| 2596 | command. |
| 2597 | </p> |
| 2598 | |
| 2599 | <h4 id='flag--output_base'><code class='flag'>--output_base=<var>dir</var></code></h4> |
| 2600 | <p> |
| 2601 | This option requires a path argument, which must specify a |
| 2602 | writable directory. Bazel will use this location to write all its |
| 2603 | output. The output base is also the key by which the client locates |
| 2604 | the Bazel server. By changing the output base, you change the server |
| 2605 | which will handle the command. |
| 2606 | </p> |
| 2607 | <p> |
| 2608 | By default, the output base is derived from the user's login name, |
| 2609 | and the name of the workspace directory (actually, its MD5 digest), |
| 2610 | so a typical value looks like: |
| 2611 | |
lberki | f071a23 | 2017-12-07 04:21:34 -0800 | [diff] [blame] | 2612 | <code>/var/tmp/google/_bazel_johndoe/d41d8cd98f00b204e9800998ecf8427e</code>. |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 2613 | Note that the client uses the output base to find the Bazel server |
| 2614 | instance, so if you specify a different output base in a Bazel |
| 2615 | command, a different server will be found (or started) to handle the |
| 2616 | request. It's possible to perform two concurrent builds in the same |
| 2617 | workspace directory by varying the output base. |
| 2618 | </p> |
| 2619 | |
| 2620 | <p>For example:</p> |
| 2621 | <pre> |
| 2622 | % bazel --output_base /tmp/1 build //foo & bazel --output_base /tmp/2 build //bar |
| 2623 | </pre> |
| 2624 | <p> |
| 2625 | In this command, the two Bazel commands run concurrently (because of |
| 2626 | the shell <code>&</code> operator), each using a different Bazel |
| 2627 | server instance (because of the different output bases). |
| 2628 | In contrast, if the default output base was used in both commands, |
| 2629 | then both requests would be sent to the same server, which would |
| 2630 | handle them sequentially: building <code>//foo</code> first, followed |
| 2631 | by an incremental build of <code>//bar</code>. |
| 2632 | </p> |
| 2633 | <p> |
| 2634 | We recommend you do not use NFS locations for the output base, as |
| 2635 | the higher access latency of NFS will cause noticeably slower |
| 2636 | builds. |
| 2637 | </p> |
| 2638 | |
| 2639 | <h4 id='flag--output_user_root'><code class='flag'>--output_user_root=<var>dir</var></code></h4> |
| 2640 | <p> |
| 2641 | By default, the <code>output_base</code> value is chosen to as to |
| 2642 | avoid conflicts between multiple users building in the same workspace directory. |
| 2643 | In some situations, though, it is desirable to build from a directory |
| 2644 | shared between multiple users; release engineers often do this. In |
| 2645 | those cases it may be useful to deliberately override the default so |
| 2646 | as to ensure "conflicts" (i.e., sharing) between multiple users. |
| 2647 | Use the <code class='flag'>--output_user_root</code> option to achieve this: the |
| 2648 | output base is placed in a subdirectory of the output user root, |
| 2649 | with a unique name based on the workspace, so the result of using an |
| 2650 | output user root that is not a function of <code>$USER</code> is |
| 2651 | sharing. Of course, it is important to ensure (via umask and group |
| 2652 | membership) that all the cooperating users can read/write each |
| 2653 | others files. |
| 2654 | </p> |
| 2655 | <p> |
| 2656 | If the <code class='flag'>--output_base</code> option is specified, it overrides |
| 2657 | using <code class='flag'>--output_user_root</code> to calculate the output base. |
| 2658 | </p> |
| 2659 | <p> |
| 2660 | The install base location is also calculated based on |
| 2661 | <code class='flag'>--output_user_root</code>, plus the MD5 identity of the Bazel embedded |
| 2662 | binaries. |
| 2663 | </p> |
| 2664 | <p> |
| 2665 | You can also use the <code class='flag'>--output_user_root</code> option to choose an |
| 2666 | alternate base location for all of Bazel's output (install base and output |
| 2667 | base) if there is a better location in your filesystem layout. |
| 2668 | </p> |
| 2669 | |
cushon | 2a8b657 | 2018-07-25 10:33:40 -0700 | [diff] [blame] | 2670 | <a name="startup_flag--host_javabase"></a> |
| 2671 | <h4 id='startup_flag--server_javabase'><code class='flag'>--server_javabase=<var>dir</var></code></h4> |
Googler | ba66e72 | 2017-12-04 12:15:36 -0800 | [diff] [blame] | 2672 | <p> |
| 2673 | Specifies the Java virtual machine in which <i>Bazel itself</i> runs. The value must be a path to |
| 2674 | the directory containing a JDK or JRE. It should not be a label. |
Googler | a37711b | 2018-09-11 10:25:01 -0700 | [diff] [blame] | 2675 | This option should appear before any Bazel command, for example: |
Googler | ba66e72 | 2017-12-04 12:15:36 -0800 | [diff] [blame] | 2676 | </p> |
| 2677 | <pre> |
cushon | 2a8b657 | 2018-07-25 10:33:40 -0700 | [diff] [blame] | 2678 | % bazel --server_javabase=/usr/local/buildtools/java/jdk9 build //foo |
Googler | ba66e72 | 2017-12-04 12:15:36 -0800 | [diff] [blame] | 2679 | </pre> |
| 2680 | <p> |
| 2681 | This flag does <i>not</i> affect the JVMs used by Bazel subprocesses such as applications, tests, |
| 2682 | tools, and so on. Use build options <a href='#flag--javabase'>--javabase</a> or |
| 2683 | <a href='#flag--host_javabase'>--host_javabase</a> instead. |
| 2684 | </p> |
cushon | 2a8b657 | 2018-07-25 10:33:40 -0700 | [diff] [blame] | 2685 | <p> |
| 2686 | This flag was previously named <code>--host_javabase</code> (sometimes referred to as the |
| 2687 | 'left-hand side' <code>--host_javabase</code>), but was renamed to avoid confusion with the |
| 2688 | build flag <a href='#flag--host_javabase'>--host_javabase</a> (sometimes referred to as the |
| 2689 | 'right-hand side' <code>--host_javabase</code>). |
| 2690 | </p> |
Googler | ba66e72 | 2017-12-04 12:15:36 -0800 | [diff] [blame] | 2691 | |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 2692 | <h4 id='flag--host_jvm_args'><code class='flag'>--host_jvm_args=<var>string</var></code></h4> |
| 2693 | <p> |
| 2694 | Specifies a startup option to be passed to the Java virtual machine in which <i>Bazel itself</i> |
| 2695 | runs. This can be used to set the stack size, for example: |
| 2696 | </p> |
| 2697 | <pre> |
| 2698 | % bazel --host_jvm_args="-Xss256K" build //foo |
| 2699 | </pre> |
| 2700 | <p> |
| 2701 | This option can be used multiple times with individual arguments. Note that |
| 2702 | setting this flag should rarely be needed. You can also pass a space-separated list of strings, |
| 2703 | each of which will be interpreted as a separate JVM argument, but this feature will soon be |
| 2704 | deprecated. |
| 2705 | |
| 2706 | </p> |
| 2707 | <p> |
| 2708 | That this does <i>not</i> affect any JVMs used by |
ccalvarin | af8b772 | 2018-06-06 11:54:00 -0700 | [diff] [blame] | 2709 | subprocesses of Bazel: applications, tests, tools, and so on. To pass |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 2710 | JVM options to executable Java programs, whether run by <code>bazel |
| 2711 | run</code> or on the command-line, you should use |
| 2712 | the <code>--jvm_flags</code> argument which |
| 2713 | all <code>java_binary</code> and <code>java_test</code> programs |
| 2714 | support. Alternatively for tests, use <code>bazel |
| 2715 | test --test_arg=--jvm_flags=foo ...</code>. |
| 2716 | </p> |
| 2717 | |
| 2718 | <h4 id='flag--host_jvm_debug'><code class='flag'>--host_jvm_debug</code></h4> |
| 2719 | <p> |
| 2720 | This option causes the Java virtual machine to wait for a connection |
| 2721 | from a JDWP-compliant debugger before |
| 2722 | calling the main method of <i>Bazel itself</i>. This is primarily |
| 2723 | intended for use by Bazel developers. |
| 2724 | </p> |
| 2725 | <p> |
| 2726 | (Please note that this does <i>not</i> affect any JVMs used by |
| 2727 | subprocesses of Bazel: applications, tests, tools, etc.) |
| 2728 | </p> |
| 2729 | |
| 2730 | <h4 id='flag--batch'><code class='flag'>--batch</code></h4> |
ccalvarin | af8b772 | 2018-06-06 11:54:00 -0700 | [diff] [blame] | 2731 | |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 2732 | <p> |
ccalvarin | af8b772 | 2018-06-06 11:54:00 -0700 | [diff] [blame] | 2733 | WARNING: <code class='flag'>--batch</code> is deprecated. For build isolation, we recommend |
| 2734 | using the command option <code class='flag'>--nokeep_state_after_build</code>, which guarantees |
| 2735 | that no incremental in-memory state is kept between builds. In order to restart the |
| 2736 | Bazel server and JVM after a build, please explicitly do so using the “shutdown” command. |
| 2737 | </p> |
| 2738 | |
| 2739 | <p> |
| 2740 | Batch mode causes Bazel to not use the standard client/server mode described |
| 2741 | <a href='#client/server'>above</a>, instead running a bazel java process for a |
| 2742 | single command, which has been used for more predictable semantics with respect |
| 2743 | to signal handling, job control, and environment variable inheritance, and is |
| 2744 | necessary for running bazel in a chroot jail. |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 2745 | </p> |
| 2746 | |
| 2747 | <p> |
| 2748 | Batch mode retains proper queueing semantics within the same output_base. |
| 2749 | That is, simultaneous invocations will be processed in order, without overlap. |
ccalvarin | af8b772 | 2018-06-06 11:54:00 -0700 | [diff] [blame] | 2750 | If a batch mode Bazel is run on a client with a running server, it first |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 2751 | kills the server before processing the command. |
| 2752 | </p> |
| 2753 | |
| 2754 | <p> |
ccalvarin | af8b772 | 2018-06-06 11:54:00 -0700 | [diff] [blame] | 2755 | Bazel will run slower in batch mode, or with the alternatives described above. |
| 2756 | This is because, among other things, the build file cache is memory-resident, so it is not |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 2757 | preserved between sequential batch invocations. |
| 2758 | Therefore, using batch mode often makes more sense in cases where performance |
| 2759 | is less critical, such as continuous builds. |
| 2760 | </p> |
| 2761 | |
| 2762 | <h4 id='flag--max_idle_secs'><code class='flag'>--max_idle_secs <var>n</var></code></h4> |
| 2763 | <p> |
| 2764 | This option specifies how long, in seconds, the Bazel server process |
| 2765 | should wait after the last client request, before it exits. The |
shreyax | 5f2d564 | 2018-10-29 15:01:24 -0700 | [diff] [blame] | 2766 | default value is 10800 (3 hours). To disable the feature, set `--max_idle_secs=0`. |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 2767 | </p> |
| 2768 | <p> |
| 2769 | This option may be used by scripts that invoke Bazel to ensure that |
| 2770 | they do not leave Bazel server processes on a user's machine when they |
| 2771 | would not be running otherwise. |
| 2772 | For example, a presubmit script might wish to |
| 2773 | invoke <code>bazel query</code> to ensure that a user's pending |
| 2774 | change does not introduce unwanted dependencies. However, if the |
| 2775 | user has not done a recent build in that workspace, it would be |
| 2776 | undesirable for the presubmit script to start a Bazel server just |
| 2777 | for it to remain idle for the rest of the day. |
| 2778 | By specifying a small value of <code class='flag'>--max_idle_secs</code> in the |
| 2779 | query request, the script can ensure that <i>if</i> it caused a new |
| 2780 | server to start, that server will exit promptly, but if instead |
| 2781 | there was already a server running, that server will continue to run |
| 2782 | until it has been idle for the usual time. Of course, the existing |
| 2783 | server's idle timer will be reset. |
| 2784 | </p> |
shreyax | 5f2d564 | 2018-10-29 15:01:24 -0700 | [diff] [blame] | 2785 | <h4 id='flag--shutdown_on_low_sys_mem'><code class='flag'>--[no]shutdown_on_low_sys_mem</code></h4> |
| 2786 | <p> |
| 2787 | If enabled and <code class='flag'>--max_idle_secs</code> is set to a positive duration, |
| 2788 | after the build server has been idle for a while, shut down the server when the system is |
| 2789 | low on memory. Linux only. |
| 2790 | </p> |
| 2791 | <p> |
| 2792 | In addition to running an idle check corresponding to max_idle_secs, the build server will |
| 2793 | starts monitoring available system memory after the server has been idle for some time. |
| 2794 | If the available system memory becomes critically low, the server will exit. |
| 2795 | </p> |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 2796 | |
| 2797 | <h4 id='flag--block_for_lock'><code class='flag'>--[no]block_for_lock</code></h4> |
| 2798 | <p> |
| 2799 | If enabled, Bazel will wait for other Bazel commands holding the |
| 2800 | server lock to complete before progressing. If disabled, Bazel will |
| 2801 | exit in error if it cannot immediately acquire the lock and |
| 2802 | proceed. |
| 2803 | |
| 2804 | Developers might use this in presubmit checks to avoid long waits caused |
| 2805 | by another Bazel command in the same client. |
| 2806 | </p> |
| 2807 | |
| 2808 | <h4 id='flag--io_nice_level'><code class='flag'>--io_nice_level <var>n</var></code></h4> |
| 2809 | <p> |
| 2810 | Sets a level from 0-7 for best-effort IO scheduling. 0 is highest priority, |
| 2811 | 7 is lowest. The anticipatory scheduler may only honor up to priority 4. |
| 2812 | Negative values are ignored. |
| 2813 | </p> |
| 2814 | |
| 2815 | <h4 id='flag--batch_cpu_scheduling'><code class='flag'>--batch_cpu_scheduling</code></h4> |
| 2816 | <p> |
| 2817 | Use <code>batch</code> CPU scheduling for Bazel. This policy is useful for |
| 2818 | workloads that are non-interactive, but do not want to lower their nice value. |
| 2819 | See 'man 2 sched_setscheduler'. This policy may provide for better system |
| 2820 | interactivity at the expense of Bazel throughput. |
| 2821 | </p> |
| 2822 | |
| 2823 | <h3 id='misc_options'>Miscellaneous options</h3> |
| 2824 | |
| 2825 | <h4 id='flag--announce_rc'><code class='flag'>--[no]announce_rc</code></h4> |
| 2826 | <p> |
| 2827 | Controls whether Bazel announces command options read from the bazelrc file when |
| 2828 | starting up. (Startup options are unconditionally announced.) |
| 2829 | </p> |
| 2830 | |
| 2831 | <h4 id='flag--color'><code class='flag'>--color (yes|no|auto)</code></h4> |
| 2832 | <p> |
| 2833 | This option determines whether Bazel will use colors to highlight |
| 2834 | its output on the screen. |
| 2835 | </p> |
| 2836 | <p> |
| 2837 | If this option is set to <code>yes</code>, color output is enabled. |
| 2838 | If this option is set to <code>auto</code>, Bazel will use color output only if |
| 2839 | the output is being sent to a terminal and the TERM environment variable |
| 2840 | is set to a value other than <code>dumb</code>, <code>emacs</code>, or <code>xterm-mono</code>. |
| 2841 | If this option is set to <code>no</code>, color output is disabled, |
| 2842 | regardless of whether the output is going to a terminal and regardless |
| 2843 | of the setting of the TERM environment variable. |
| 2844 | </p> |
| 2845 | |
| 2846 | <h4 id='flag--config'><code class='flag'>--config <var>name</var></code></h4> |
| 2847 | <p> |
| 2848 | Selects additional config section from the rc files; for the current |
| 2849 | <code>command</code>, it also pulls in the options from |
Googler | c848bf3 | 2017-02-14 12:15:42 +0000 | [diff] [blame] | 2850 | <code>command:name</code> if such a section exists. Can be specified multiple |
| 2851 | times to add flags from several config sections. Expansions can refer to other |
| 2852 | definitions (i.e. expansions can be chained). |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 2853 | </p> |
| 2854 | |
| 2855 | <h4 id='flag--curses'><code class='flag'>--curses (yes|no|auto)</code></h4> |
| 2856 | <p> |
| 2857 | This option determines whether Bazel will use cursor controls |
| 2858 | in its screen output. This results in less scrolling data, and a more |
| 2859 | compact, easy-to-read stream of output from Bazel. This works well with |
| 2860 | <code class='flag'>--color</code>. |
| 2861 | </p> |
| 2862 | <p> |
| 2863 | If this option is set to <code>yes</code>, use of cursor controls is enabled. |
| 2864 | If this option is set to <code>no</code>, use of cursor controls is disabled. |
| 2865 | If this option is set to <code>auto</code>, use of cursor controls will be |
| 2866 | enabled under the same conditions as for <code class='flag'>--color=auto</code>. |
| 2867 | </p> |
| 2868 | |
| 2869 | <h4 id='flag--show_timestamps'><code class='flag'>--[no]show_timestamps</code></h4> |
| 2870 | <p> |
| 2871 | If specified, a timestamp is added to each message generated by |
| 2872 | Bazel specifying the time at which the message was displayed. |
| 2873 | </p> |