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> |
Ulf Adams | 9e24ebd | 2016-06-23 09:24:57 +0000 | [diff] [blame] | 43 | --<option>=[false|no|0] |
| 44 | </pre> |
| 45 | </p> |
| 46 | |
| 47 | <p> |
| 48 | Tristate options are usually set to automatic by default, and can be |
| 49 | force-enabled as follows: |
| 50 | <pre> |
| 51 | --<option>=[true|yes|1] |
| 52 | </pre> |
| 53 | or force-disabled as follows: |
| 54 | <pre> |
| 55 | --no<option> |
Ulf Adams | 9e24ebd | 2016-06-23 09:24:57 +0000 | [diff] [blame] | 56 | --<option>=[false|no|0] |
| 57 | </pre> |
| 58 | </p> |
| 59 | |
| 60 | <h2>Target Pattern Syntax</h2> |
| 61 | |
| 62 | <p> |
| 63 | A target pattern refers to a single or more targets, which are source files, |
| 64 | 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] | 65 | Bazel also supports working-directory-relative labels, recursive patterns, and |
Ulf Adams | 9e24ebd | 2016-06-23 09:24:57 +0000 | [diff] [blame] | 66 | target subtraction. |
| 67 | </p> |
| 68 | |
| 69 | <p> |
| 70 | All target patterns starting with '//' are resolved relative to the current |
| 71 | workspace. |
| 72 | <table> |
| 73 | <tr> |
| 74 | <td><code>//foo/bar:wiz</code></td> |
| 75 | <td>Just the single target '//foo/bar:wiz'.</td> |
| 76 | </tr> |
| 77 | <tr> |
| 78 | <td><code>//foo/bar</code></td> |
| 79 | <td>Equivalent to '//foo/bar:bar'.</td> |
| 80 | </tr> |
| 81 | <tr> |
| 82 | <td><code>//foo/bar:all</code></td> |
| 83 | <td>All rules in the package 'foo/bar'.</td> |
| 84 | </tr> |
| 85 | <tr> |
| 86 | <td><code>//foo/...</code></td> |
| 87 | <td>All rules in all packages beneath the directory 'foo'.</td> |
| 88 | </tr> |
| 89 | <tr> |
| 90 | <td><code>//foo/...:all</code></td> |
| 91 | <td>All rules in all packages beneath the directory 'foo'.</td> |
| 92 | </tr> |
| 93 | <tr> |
| 94 | <td><code>//foo/...:*</code></td> |
| 95 | <td>All targets (rules and files) in all packages beneath the directory 'foo'.</td> |
| 96 | </tr> |
| 97 | <tr> |
| 98 | <td><code>//foo/...:all-targets</code></td> |
| 99 | <td>All targets (rules and files) in all packages beneath the directory 'foo'.</td> |
| 100 | </tr> |
| 101 | </table> |
| 102 | </p> |
| 103 | |
| 104 | <p> |
| 105 | Targets with <code>tags=["manual"]</code> are not included in wildcard |
| 106 | target patterns (<code>...</code>, <code>:*</code>, <code>:all</code>, etc). |
| 107 | Specify such test targets with explicit labels on the command line if |
Ulf Adams | 25f4404 | 2016-06-23 11:44:08 +0000 | [diff] [blame] | 108 | you want Bazel to build/test them. |
Ulf Adams | 9e24ebd | 2016-06-23 09:24:57 +0000 | [diff] [blame] | 109 | </p> |
| 110 | |
| 111 | <p> |
| 112 | Target patterns which do not begin with '//' are resolved relative to the |
| 113 | current <em>working directory</em>. These examples assume a working directory of |
| 114 | 'foo': |
| 115 | <table> |
| 116 | <tr> |
| 117 | <td><code>:foo</code></td> |
| 118 | <td>Equivalent to '//foo:foo'.</td> |
| 119 | </tr> |
| 120 | <tr> |
| 121 | <td><code>bar:wiz</code></td> |
| 122 | <td>Equivalent to '//foo/bar:wiz'.</td> |
| 123 | </tr> |
| 124 | <tr> |
| 125 | <td><code>bar/wiz</code></td> |
| 126 | <td>Equivalent to: |
| 127 | '//foo/bar/wiz:wiz' if foo/bar/wiz is a package, |
| 128 | '//foo/bar:wiz' if foo/bar is a package, |
| 129 | '//foo:bar/wiz' otherwise. |
| 130 | </td> |
| 131 | </tr> |
| 132 | <tr> |
| 133 | <td><code>bar:all</code></td> |
| 134 | <td>Equivalent to '//foo/bar:all'.</td> |
| 135 | </tr> |
| 136 | <tr> |
| 137 | <td><code>:all</code></td> |
| 138 | <td>Equivalent to '//foo:all'.</td> |
| 139 | </tr> |
| 140 | <tr> |
| 141 | <td><code>...:all</code></td> |
| 142 | <td>Equivalent to '//foo/...:all'.</td> |
| 143 | </tr> |
| 144 | <tr> |
| 145 | <td><code>...</code></td> |
| 146 | <td>Equivalent to '//foo/...:all'.</td> |
| 147 | </tr> |
| 148 | <tr> |
| 149 | <td><code>bar/...:all</code></td> |
| 150 | <td>Equivalent to '//foo/bar/...:all'.</td> |
| 151 | </tr> |
| 152 | </table> |
| 153 | </p> |
| 154 | |
| 155 | <p> |
| 156 | By default, directory symlinks are followed for recursive target patterns, |
| 157 | except those that point to under the output base, such as the convenience |
| 158 | symlinks that are created in the root directory of the workspace. |
| 159 | </p> |
| 160 | |
| 161 | <p> |
Ulf Adams | 25f4404 | 2016-06-23 11:44:08 +0000 | [diff] [blame] | 162 | In addition, Bazel does not follow symlinks when evaluating recursive target |
Ulf Adams | 9e24ebd | 2016-06-23 09:24:57 +0000 | [diff] [blame] | 163 | patterns in any directory that contains a file named as follows: |
| 164 | <pre> |
| 165 | DONT_FOLLOW_SYMLINKS_WHEN_TRAVERSING_THIS_DIRECTORY_VIA_A_RECURSIVE_TARGET_PATTERN |
| 166 | </pre> |
| 167 | </p> |
| 168 | |
| 169 | <p> |
| 170 | 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] | 171 | case Bazel subtracts them from the set of targets accumulated by preceding |
Ulf Adams | 9e24ebd | 2016-06-23 09:24:57 +0000 | [diff] [blame] | 172 | 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] | 173 | 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] | 174 | interpreting it as an option, e.g.: |
| 175 | <pre> |
Ulf Adams | 25f4404 | 2016-06-23 11:44:08 +0000 | [diff] [blame] | 176 | bazel build -- foo/... -foo/contrib/... |
Ulf Adams | 9e24ebd | 2016-06-23 09:24:57 +0000 | [diff] [blame] | 177 | </pre> |
Ulf Adams | 25f4404 | 2016-06-23 11:44:08 +0000 | [diff] [blame] | 178 | 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] | 179 | to dependencies, and may also load the corresponding BUILD files, even if the |
| 180 | targets are never built. |
| 181 | </p> |