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