Ulf Adams | 9e24ebd | 2016-06-23 09:24:57 +0000 | [diff] [blame] | 1 | --- |
| 2 | layout: documentation |
| 3 | title: Command-Line Reference |
| 4 | --- |
Ulf Adams | 9e24ebd | 2016-06-23 09:24:57 +0000 | [diff] [blame] | 5 | <h1>Command-Line Reference</h1> |
| 6 | |
| 7 | <pre> |
Ulf Adams | 25f4404 | 2016-06-23 11:44:08 +0000 | [diff] [blame] | 8 | bazel [<startup options>] <command> [<args>] |
Ulf Adams | 9e24ebd | 2016-06-23 09:24:57 +0000 | [diff] [blame] | 9 | </pre> |
| 10 | |
| 11 | or |
| 12 | |
| 13 | <pre> |
Ulf Adams | 25f4404 | 2016-06-23 11:44:08 +0000 | [diff] [blame] | 14 | bazel [<startup options>] <command> [<args>] -- [<target patterns>] |
Ulf Adams | 9e24ebd | 2016-06-23 09:24:57 +0000 | [diff] [blame] | 15 | </pre> |
| 16 | |
| 17 | <h2>Option Syntax</h2> |
| 18 | |
| 19 | <p> |
Ulf Adams | 25f4404 | 2016-06-23 11:44:08 +0000 | [diff] [blame] | 20 | Options can be passed to Bazel in different ways. Options that require a value |
Ulf Adams | 9e24ebd | 2016-06-23 09:24:57 +0000 | [diff] [blame] | 21 | can be passed with either an equals sign or a space: |
| 22 | <pre> |
| 23 | --<option>=<value> |
| 24 | --<option> <value> |
| 25 | </pre> |
| 26 | Some options have a single character short form; in that case, the short form |
| 27 | has to be passed with a single dash and a space. |
| 28 | <pre> |
| 29 | -<short_form> <value> |
| 30 | </pre> |
| 31 | </p> |
| 32 | |
| 33 | <p> |
| 34 | Boolean options can be enabled as follows: |
| 35 | <pre> |
| 36 | --<option> |
| 37 | --<option>=[true|yes|1] |
| 38 | </pre> |
| 39 | |
| 40 | and disabled as follows: |
| 41 | <pre> |
| 42 | --no<option> |
| 43 | --no_<option> |
| 44 | --<option>=[false|no|0] |
| 45 | </pre> |
| 46 | </p> |
| 47 | |
| 48 | <p> |
| 49 | Tristate options are usually set to automatic by default, and can be |
| 50 | force-enabled as follows: |
| 51 | <pre> |
| 52 | --<option>=[true|yes|1] |
| 53 | </pre> |
| 54 | or force-disabled as follows: |
| 55 | <pre> |
| 56 | --no<option> |
| 57 | --no_<option> |
| 58 | --<option>=[false|no|0] |
| 59 | </pre> |
| 60 | </p> |
| 61 | |
| 62 | <h2>Target Pattern Syntax</h2> |
| 63 | |
| 64 | <p> |
| 65 | A target pattern refers to a single or more targets, which are source files, |
| 66 | output files, or rules specified in BUILD files. In addition to plain labels, |
Ulf Adams | 25f4404 | 2016-06-23 11:44:08 +0000 | [diff] [blame] | 67 | Bazel also supports working-directory-relative labels, recursive patterns, and |
Ulf Adams | 9e24ebd | 2016-06-23 09:24:57 +0000 | [diff] [blame] | 68 | target subtraction. |
| 69 | </p> |
| 70 | |
| 71 | <p> |
| 72 | All target patterns starting with '//' are resolved relative to the current |
| 73 | workspace. |
| 74 | <table> |
| 75 | <tr> |
| 76 | <td><code>//foo/bar:wiz</code></td> |
| 77 | <td>Just the single target '//foo/bar:wiz'.</td> |
| 78 | </tr> |
| 79 | <tr> |
| 80 | <td><code>//foo/bar</code></td> |
| 81 | <td>Equivalent to '//foo/bar:bar'.</td> |
| 82 | </tr> |
| 83 | <tr> |
| 84 | <td><code>//foo/bar:all</code></td> |
| 85 | <td>All rules in the package 'foo/bar'.</td> |
| 86 | </tr> |
| 87 | <tr> |
| 88 | <td><code>//foo/...</code></td> |
| 89 | <td>All rules in all packages beneath the directory 'foo'.</td> |
| 90 | </tr> |
| 91 | <tr> |
| 92 | <td><code>//foo/...:all</code></td> |
| 93 | <td>All rules in all packages beneath the directory 'foo'.</td> |
| 94 | </tr> |
| 95 | <tr> |
| 96 | <td><code>//foo/...:*</code></td> |
| 97 | <td>All targets (rules and files) in all packages beneath the directory 'foo'.</td> |
| 98 | </tr> |
| 99 | <tr> |
| 100 | <td><code>//foo/...:all-targets</code></td> |
| 101 | <td>All targets (rules and files) in all packages beneath the directory 'foo'.</td> |
| 102 | </tr> |
| 103 | </table> |
| 104 | </p> |
| 105 | |
| 106 | <p> |
| 107 | Targets with <code>tags=["manual"]</code> are not included in wildcard |
| 108 | target patterns (<code>...</code>, <code>:*</code>, <code>:all</code>, etc). |
| 109 | Specify such test targets with explicit labels on the command line if |
Ulf Adams | 25f4404 | 2016-06-23 11:44:08 +0000 | [diff] [blame] | 110 | you want Bazel to build/test them. |
Ulf Adams | 9e24ebd | 2016-06-23 09:24:57 +0000 | [diff] [blame] | 111 | </p> |
| 112 | |
| 113 | <p> |
| 114 | Target patterns which do not begin with '//' are resolved relative to the |
| 115 | current <em>working directory</em>. These examples assume a working directory of |
| 116 | 'foo': |
| 117 | <table> |
| 118 | <tr> |
| 119 | <td><code>:foo</code></td> |
| 120 | <td>Equivalent to '//foo:foo'.</td> |
| 121 | </tr> |
| 122 | <tr> |
| 123 | <td><code>bar:wiz</code></td> |
| 124 | <td>Equivalent to '//foo/bar:wiz'.</td> |
| 125 | </tr> |
| 126 | <tr> |
| 127 | <td><code>bar/wiz</code></td> |
| 128 | <td>Equivalent to: |
| 129 | '//foo/bar/wiz:wiz' if foo/bar/wiz is a package, |
| 130 | '//foo/bar:wiz' if foo/bar is a package, |
| 131 | '//foo:bar/wiz' otherwise. |
| 132 | </td> |
| 133 | </tr> |
| 134 | <tr> |
| 135 | <td><code>bar:all</code></td> |
| 136 | <td>Equivalent to '//foo/bar:all'.</td> |
| 137 | </tr> |
| 138 | <tr> |
| 139 | <td><code>:all</code></td> |
| 140 | <td>Equivalent to '//foo:all'.</td> |
| 141 | </tr> |
| 142 | <tr> |
| 143 | <td><code>...:all</code></td> |
| 144 | <td>Equivalent to '//foo/...:all'.</td> |
| 145 | </tr> |
| 146 | <tr> |
| 147 | <td><code>...</code></td> |
| 148 | <td>Equivalent to '//foo/...:all'.</td> |
| 149 | </tr> |
| 150 | <tr> |
| 151 | <td><code>bar/...:all</code></td> |
| 152 | <td>Equivalent to '//foo/bar/...:all'.</td> |
| 153 | </tr> |
| 154 | </table> |
| 155 | </p> |
| 156 | |
| 157 | <p> |
| 158 | By default, directory symlinks are followed for recursive target patterns, |
| 159 | except those that point to under the output base, such as the convenience |
| 160 | symlinks that are created in the root directory of the workspace. |
| 161 | </p> |
| 162 | |
| 163 | <p> |
Ulf Adams | 25f4404 | 2016-06-23 11:44:08 +0000 | [diff] [blame] | 164 | In addition, Bazel does not follow symlinks when evaluating recursive target |
Ulf Adams | 9e24ebd | 2016-06-23 09:24:57 +0000 | [diff] [blame] | 165 | patterns in any directory that contains a file named as follows: |
| 166 | <pre> |
| 167 | DONT_FOLLOW_SYMLINKS_WHEN_TRAVERSING_THIS_DIRECTORY_VIA_A_RECURSIVE_TARGET_PATTERN |
| 168 | </pre> |
| 169 | </p> |
| 170 | |
| 171 | <p> |
| 172 | Target patterns may be preceded by a single dash ('<code>-</code>'), in which |
Ulf Adams | 25f4404 | 2016-06-23 11:44:08 +0000 | [diff] [blame] | 173 | case Bazel subtracts them from the set of targets accumulated by preceding |
Ulf Adams | 9e24ebd | 2016-06-23 09:24:57 +0000 | [diff] [blame] | 174 | patterns. Note that this means <em>order matters</em>. In order to pass negative |
Ulf Adams | 25f4404 | 2016-06-23 11:44:08 +0000 | [diff] [blame] | 175 | target patterns, you need to use '--' as an argument to prevent Bazel from |
Ulf Adams | 9e24ebd | 2016-06-23 09:24:57 +0000 | [diff] [blame] | 176 | interpreting it as an option, e.g.: |
| 177 | <pre> |
Ulf Adams | 25f4404 | 2016-06-23 11:44:08 +0000 | [diff] [blame] | 178 | bazel build -- foo/... -foo/contrib/... |
Ulf Adams | 9e24ebd | 2016-06-23 09:24:57 +0000 | [diff] [blame] | 179 | </pre> |
Ulf Adams | 25f4404 | 2016-06-23 11:44:08 +0000 | [diff] [blame] | 180 | Note that Bazel may still build targets matched by a negative target pattern due |
Ulf Adams | 9e24ebd | 2016-06-23 09:24:57 +0000 | [diff] [blame] | 181 | to dependencies, and may also load the corresponding BUILD files, even if the |
| 182 | targets are never built. |
| 183 | </p> |
| 184 | |
| 185 | |
| 186 | |