blob: 86516b84e9f2df1f92ac4f77e5588f80ec9daaf0 [file] [log] [blame]
Ulf Adams9e24ebd2016-06-23 09:24:57 +00001---
2layout: documentation
3title: Command-Line Reference
4---
Ulf Adams9e24ebd2016-06-23 09:24:57 +00005<h1>Command-Line Reference</h1>
6
7<pre>
Ulf Adams25f44042016-06-23 11:44:08 +00008bazel [&lt;startup options&gt;] &lt;command&gt; [&lt;args&gt;]
Ulf Adams9e24ebd2016-06-23 09:24:57 +00009</pre>
10
11or
12
13<pre>
Ulf Adams25f44042016-06-23 11:44:08 +000014bazel [&lt;startup options&gt;] &lt;command&gt; [&lt;args&gt;] -- [&lt;target patterns&gt;]
Ulf Adams9e24ebd2016-06-23 09:24:57 +000015</pre>
16
17<h2>Option Syntax</h2>
18
19<p>
Ulf Adams25f44042016-06-23 11:44:08 +000020Options can be passed to Bazel in different ways. Options that require a value
Ulf Adams9e24ebd2016-06-23 09:24:57 +000021can be passed with either an equals sign or a space:
22<pre>
23--&lt;option&gt;=&lt;value&gt;
24--&lt;option&gt; &lt;value&gt;
25</pre>
26Some options have a single character short form; in that case, the short form
27has to be passed with a single dash and a space.
28<pre>
29-&lt;short_form&gt; &lt;value&gt;
30</pre>
31</p>
32
33<p>
34Boolean options can be enabled as follows:
35<pre>
36--&lt;option&gt;
37--&lt;option&gt;=[true|yes|1]
38</pre>
39
40and disabled as follows:
41<pre>
42--no&lt;option&gt;
43--no_&lt;option&gt;
44--&lt;option&gt;=[false|no|0]
45</pre>
46</p>
47
48<p>
49Tristate options are usually set to automatic by default, and can be
50force-enabled as follows:
51<pre>
52--&lt;option&gt;=[true|yes|1]
53</pre>
54or force-disabled as follows:
55<pre>
56--no&lt;option&gt;
57--no_&lt;option&gt;
58--&lt;option&gt;=[false|no|0]
59</pre>
60</p>
61
62<h2>Target Pattern Syntax</h2>
63
64<p>
65A target pattern refers to a single or more targets, which are source files,
66output files, or rules specified in BUILD files. In addition to plain labels,
Ulf Adams25f44042016-06-23 11:44:08 +000067Bazel also supports working-directory-relative labels, recursive patterns, and
Ulf Adams9e24ebd2016-06-23 09:24:57 +000068target subtraction.
69</p>
70
71<p>
72All target patterns starting with '//' are resolved relative to the current
73workspace.
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>
107Targets with <code>tags=["manual"]</code> are not included in wildcard
108target patterns (<code>...</code>, <code>:*</code>, <code>:all</code>, etc).
109Specify such test targets with explicit labels on the command line if
Ulf Adams25f44042016-06-23 11:44:08 +0000110you want Bazel to build/test them.
Ulf Adams9e24ebd2016-06-23 09:24:57 +0000111</p>
112
113<p>
114Target patterns which do not begin with '//' are resolved relative to the
115current <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>
158By default, directory symlinks are followed for recursive target patterns,
159except those that point to under the output base, such as the convenience
160symlinks that are created in the root directory of the workspace.
161</p>
162
163<p>
Ulf Adams25f44042016-06-23 11:44:08 +0000164In addition, Bazel does not follow symlinks when evaluating recursive target
Ulf Adams9e24ebd2016-06-23 09:24:57 +0000165patterns in any directory that contains a file named as follows:
166<pre>
167DONT_FOLLOW_SYMLINKS_WHEN_TRAVERSING_THIS_DIRECTORY_VIA_A_RECURSIVE_TARGET_PATTERN
168</pre>
169</p>
170
171<p>
172Target patterns may be preceded by a single dash ('<code>-</code>'), in which
Ulf Adams25f44042016-06-23 11:44:08 +0000173case Bazel subtracts them from the set of targets accumulated by preceding
Ulf Adams9e24ebd2016-06-23 09:24:57 +0000174patterns. Note that this means <em>order matters</em>. In order to pass negative
Ulf Adams25f44042016-06-23 11:44:08 +0000175target patterns, you need to use '--' as an argument to prevent Bazel from
Ulf Adams9e24ebd2016-06-23 09:24:57 +0000176interpreting it as an option, e.g.:
177<pre>
Ulf Adams25f44042016-06-23 11:44:08 +0000178bazel build -- foo/... -foo/contrib/...
Ulf Adams9e24ebd2016-06-23 09:24:57 +0000179</pre>
Ulf Adams25f44042016-06-23 11:44:08 +0000180Note that Bazel may still build targets matched by a negative target pattern due
Ulf Adams9e24ebd2016-06-23 09:24:57 +0000181to dependencies, and may also load the corresponding BUILD files, even if the
182targets are never built.
183</p>
184
185
186