forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.html
1753 lines (1598 loc) · 68.6 KB
/
query.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Bazel Query Reference</title>
<style type="text/css">
body {
background-color: #ffffff;
color: black;
margin-right: 10%;
margin-left: 10%;
}
h1, h2, h3, h4, h5, h6 {
color: #dd7755;
font-family: sans-serif;
}
@media print {
/* Darker version for printing */
h1, h2, h3, h4, h5, h6 {
color: #008000;
font-family: helvetica, sans-serif;
}
}
h1 {
text-align: center;
}
h2 {
margin-left: -0.5in;
}
h3 {
margin-left: -0.25in;
}
h4 {
margin-left: -0.125in;
}
hr {
margin-left: -1in;
}
address {
text-align: right;
}
/* A compact unordered list */
ul.tight > li {
margin-bottom: 0;
}
/* Use the <code> tag for bits of code and <var> for variable and object names. */
code,pre,samp,var {
color: #006000;
}
/* Use the <file> tag for file and directory paths and names. */
file {
color: #905050;
font-family: monospace;
}
/* Use the <kbd> tag for stuff the user should type. */
kbd {
color: #600000;
}
div.note p {
float: right;
width: 3in;
margin-right: 0%;
padding: 1px;
border: 2px solid #60a060;
background-color: #fffff0;
}
table.grid {
background-color: #ffffee;
border: 1px solid black;
border-collapse: collapse;
margin-left: 2mm;
margin-right: 2mm;
}
table.grid th,
table.grid td {
border: 1px solid black;
padding: 0 2mm 0 2mm;
}
/* Use pre.code for code listings.
Use pre.interaction for "Here's what you see when you run a.out.".
(Within pre.interaction, use <kbd> things the user types)
*/
pre.code {
background-color: #FFFFEE;
border: 1px solid black;
color: #004000;
font-size: 10pt;
margin-left: 2mm;
margin-right: 2mm;
padding: 2mm;
-moz-border-radius: 12px 0px 0px 0px;
}
pre.interaction {
background-color: #EEFFEE;
color: #004000;
padding: 2mm;
}
pre.interaction kbd {
font-weight: bold;
color: #000000;
}
/* legacy style */
pre.interaction b.astyped {
color: #000000;
}
pre {
margin-left: 5em;
color: #008000;
}
.tt td {
font-family: courier;
}
.deprecated { text-decoration: line-through; }
.discouraged { text-decoration: line-through; }
table.layout { width: 980px; }
table.layout td { vertical-align: top; }
#maintainer { text-align: right; }
</style>
</head>
<body>
<h1>The Bazel Query Reference</h1>
<p>
When you use <code>bazel query</code> to analyze build
dependencies, you use a little language, the <em>Bazel Query
Language</em>. This document is the reference manual for that
language. This document also describes the output
formats <code>bazel query</code> supports.
</p>
<h2>Examples</h2>
<p>
How do people use <code>bazel query</code>? Here are typical examples:
</p>
<p>
Why does the <code>//foo</code> tree depend on <code>//bar/baz</code>?
Show a path:</p>
<pre>somepath(foo/..., //bar/baz:all)</pre>
<p>
What C++ libraries do all the <code>foo</code> tests depend on that
the <code>foo_bin</code> target does not?</p>
<pre>kind("cc_library", deps(kind(".*test rule", foo/...)) except deps(//foo:foo_bin))</pre>
<h2>Tokens: the lexical syntax</h2>
<p>
Expressions in the query language are composed of the following
tokens:</p>
<ul>
<li>
<p>
<b>Keywords</b>, such as <code>somepath</code> or
<code>let</code>. Keywords are the reserved words of the
language, and each of them is described below. The complete set
of keywords is:
</p>
<code><!-- keep this alphabetically sorted -->
<a href="#path-operators">allpaths</a><br/>
<a href="#attr">attr</a><br/>
<a href="#buildfiles">buildfiles</a><br/>
<a href="#deps">deps</a><br/>
<a href="#set-operations">except</a><br/>
<a href="#filter">filter</a><br/>
<a href="#variables">in</a><br/>
<a href="#set-operations">intersect</a><br/>
<a href="#kind">kind</a><br/>
<a href="#labels">labels</a><br/>
<a href="#variables">let</a><br/>
<a href="#rdeps">rdeps</a><br/>
<a href="#set">set</a><br/>
<a href="#some">some</a><br/>
<a href="#path-operators">somepath</a><br/>
<a href="#tests">tests</a><br/>
<a href="#set-operations">union</a><br/>
</code>
</li>
<li>
<p>
<b>Words</b>, such as <code>foo/...</code> or
<code>".*test rule"</code> or
<code>//bar/baz:all</code>.
If a character sequence is "quoted" (begins and ends with a
single-quote <code>'</code>, or begins and ends with a
double-quote <code>"</code>), it is a word.
If a character sequence is not quoted, it may still be parsed as a word.
Unquoted words are sequences of characters drawn from
the set of alphabet characters, numerals, slash <code>/</code>,
hyphen <code>-</code>, underscore <code>_</code>, star <code>*</code>, and
period <code>.</code>. Unquoted words may not start with a
hyphen or period.
</p>
<p>We chose this syntax so that quote marks aren't needed in most cases.
The (unusual) <code>".*test rule"</code> example needs quotes: it
starts with a period and contains a space.
Quoting <code>"cc_library"</code> is unnecessary but harmless.
</p>
<p>
Quoting <em>is</em> necessary when writing scripts that
construct Bazel query expressions from user-supplied values.
</p>
<pre>
//foo:bar+wiz # WRONG: scanned as //foo:bar + wiz.
//foo:bar=wiz # WRONG: scanned as //foo:bar = wiz.
"//foo:bar+wiz" # ok.
"//foo:bar=wiz" # ok.
</pre>
<p>
Note that this quoting is in addition to any quoting that may
be required by your shell. e.g.
</p>
<pre>% bazel query ' "//foo:bar=wiz" ' # single-quotes for shell, double-quotes for Bazel.</pre>
<p>
Keywords, when quoted, are treated as ordinary words, thus
<code>some</code> is a keyword but <code>"some"</code> is a word.
Both <code>foo</code> and <code>"foo"</code> are words.
</p>
<li><b>Punctuation</b>, such as parens <code>()</code>, period
<code>.</code> and comma <code>,</code>, etc. Words containing
punctuation (other than the exceptions listed above) must be quoted.
</ul>
<p>
Whitespace characters outside of a quoted word are ignored.
</p>
<h2 id='concepts'>Bazel Query Language Concepts</h2>
<p>
The Bazel query language is a language of expressions. Every
expression evaluates to a <b>partially-ordered set</b> of targets,
or equivalently, a <b>graph</b> (DAG) of targets. This is the only
datatype.
</p>
<p>
In some expressions, the partial order of the graph is
not interesting; In this case, we call the values
"sets". In cases where the partial order of elements
is significant, we call values "graphs". Note
that both terms refer to the same datatype, but merely emphasize
different aspects of it.
</p>
<h3>Cycles in the dependency graph</h3>
<p>
Build dependency graphs should be acyclic, but in fact cycles do occur.
The algorithms used by the query language are intended for use in
acyclic graphs, but are robust against cycles. The details of how
cycles are treated are not specified and should not be relied upon.
</p>
<h3 id='implicit_deps'>Implicit dependencies</h3>
<p>
In addition to build dependencies that are defined explicitly in BUILD files,
Bazel adds additional <em>implicit</em> dependencies to rules. For example
every Java rule implicitly depends on the JavaBuilder. Implicit dependencies
are established using attributes that start with <code>$</code> and they
cannot overridden in BUILD files.
</p>
<p>
Per default <code>bazel query</code> takes implicit dependencies into account
when computing the query result. This behavior can be changed with
the <code>--[no]implicit_deps</code> option.
</p>
<h3 id='soundness'>Soundness</h3>
<p>
Bazel query language expressions operate over the build
dependency graph, which is the graph implicitly defined by all
rule declarations in all BUILD files. It is important to understand
that this graph is somewhat abstract, and does not constitute a
complete description of how to perform all the steps of a build. In
order to perform a build, a <em>configuration</em> is required too;
see the <a href='bazel-user-manual.html#configurations'>configurations</a>
section of the User's Guide for more detail.
</p>
<p>
The result of evaluating an expression in the Bazel query language
is true <em>for all configurations</em>, which means that it may be
a conservative over-approximation, and not exactly precise. If you
use the query tool to compute the set of all source files needed
during a build, it may report more than are actually necessary
because, for example, the query tool will include all the files
needed to support message translation, even though you don't intend
to use that feature in your build.
</p>
<h4 id='unsoundness'>Unsoundness</h4>
<p>
Beware, there are a few limited cases where the query tool
returns an under-approximation or is <em>unsound</em>. (You can find
them by comparing the results of a <code>bazel query</code> with the
set of files mentioned in the Makefile obtained
from <a href='bazel-user-manual.html#--dump_makefile'><code>bazel
build --dump_makefile</code></a>.
</p>
<h3 id='graph-order'>On the preservation of graph order</h3>
<p>
Operations preserve any ordering
constraints inherited from their subexpressions. You can think of
this as "the law of conservation of partial order". Consider an
example: if you issue a query to determine the transitive closure of
dependencies of a particular target, the resulting set is ordered
according to the dependency graph. If you filter that set to
include only the targets of <code>file</code> kind, the same
<em>transitive</em> partial ordering relation holds between every
pair of targets in the resulting subset—even though none of
these pairs is actually directly connected in the original graph.
(There are no file–file edges in the build dependency graph).
</p>
<p>
However, while all operators <em>preserve</em> order, some
operations, such as the <a href='#set-operations'>set operations</a>
don't <em>introduce</em> any ordering constraints of their own.
Consider this expression:
</p>
<pre>deps(x) union y</pre>
<p>
The order of the final result set is guaranteed to preserve all the
ordering constraints of its subexpressions, namely, that all the
transitive dependencies of <code>x</code> are correctly ordered with
respect to each other. However, the query guarantees nothing about
the ordering of the targets in <code>y</code>, nor about the
ordering of the targets in <code>deps(x)</code> relative to those in
<code>y</code> (except for those targets in
<code>y</code> that also happen to be in <code>deps(x)</code>).
</p>
<p>
Operators that introduce ordering constraints include:
<code>allpaths</code>,
<code>deps</code>,
<code>rdeps</code>,
<code>somepath</code>,
and the target pattern wildcards
<code>package:*</code>,
<code>dir/...</code>, etc.
</p>
<h2>Expressions: syntax and semantics of the grammar</h2>
<p>
This is the grammar of the Bazel query language, expressed in EBNF
notation:
</p>
<pre>expr ::= <var>word</var>
| let <var>name</var> = <var>expr</var> in <var>expr</var>
| (<var>expr</var>)
| <var>expr</var> intersect <var>expr</var>
| <var>expr</var> ^ <var>expr</var>
| <var>expr</var> union <var>expr</var>
| <var>expr</var> + <var>expr</var>
| <var>expr</var> except <var>expr</var>
| <var>expr</var> - <var>expr</var>
| deps(<var>expr</var>)
| deps(<var>expr</var>, <var>depth</var>)
| rdeps(<var>expr</var>, <var>expr</var>)
| rdeps(<var>expr</var>, <var>expr</var>, <var>depth</var>)
| some(<var>expr</var>)
| somepath(<var>expr</var>, <var>expr</var>)
| allpaths(<var>expr</var>, <var>expr</var>)
| kind(<var>word</var>, <var>expr</var>)
| labels(<var>word</var>, <var>expr</var>)
| filter(<var>word</var>, <var>expr</var>)
| set(<var>word</var> *)
| attr(<var>word</var>, <var>word</var>, <var>expr</var>)
</pre>
<p>
We will examine each of the productions of this grammar in order.
</p>
<h3 id="target-patterns">Target patterns</h3>
<pre>expr ::= <var>word</var></pre>
<p>
Syntactically, a <em>target pattern</em> is just a word. It
is interpreted as an (unordered) set of targets. The simplest
target pattern is a label,
which identifies a single target (file or rule). For example, the
target pattern <code>//foo:bar</code> evaluates to a set
containing one element, the target, the <code>bar</code>
rule.
</p>
<p>
Target patterns generalize labels to include wildcards over packages
and targets. For example, <code>foo/...:all</code> (or
just <code>foo/...</code>) is a target pattern that evaluates to a
set containing all <em>rules</em> in every package recursively
beneath the <code>foo</code> directory;
<code>bar/baz:all</code> is a target pattern that
evaluates to a set containing all the rules in the
<code>bar/baz</code> package, but not its subpackages.
</p>
<p>
Similarly, <code>foo/...:*</code> is a target pattern that evaluates
to a set containing all <em>targets</em> (rules <em>and</em> files) in
every package recursively beneath the <code>foo</code> directory;
<code>bar/baz:*</code> evaluates to a set containing
all the targets in the
<code>bar/baz</code> package, but not its subpackages.
</p>
<p>
Because the <code>:*</code> wildcard matches files as well as rules,
it is often more useful than <code>:all</code> for queries.
Conversely, the <code>:all</code> wildcard (implicit in target
patterns like <code>foo/...</code>) is typically more useful for
builds.
</p>
<p>
<code>bazel query</code> target patterns work the same as
<code>bazel build</code> build targets do;
refer to <a href='bazel-user-manual.html#target-patterns'>Target Patterns</a>
in the Bazel User Manual for further details, or type <code>bazel
help target-syntax</code>.
</p>
<p>
Target patterns may evaluate to a singleton set (in the case of a
label), to a set containing many elements (as in the case of
<code>foo/...</code>, which has thousands of elements) or to the
empty set, if the target pattern matches no targets.
</p>
<p>
All nodes in the result of a target pattern expression are correctly
ordered relative to each other according to the dependency relation.
So, the result of <code>foo:*</code> is not just the set of targets
in package <code>foo</code>, it is also the <em>graph</em> over
those targets. (No guarantees are made about the relative ordering
of the result nodes against other nodes.) See the section
on <a href='#graph-order'>graph order</a> for more details.
</p>
<h3 id="variables">Variables</h3>
<pre>expr ::= let <var>name</var> = <var>expr</var><sub>1</sub> in <var>expr</var><sub>2</sub>
| <var>$name</var></pre>
<p>
The Bazel query language allows definitions of and references to
variables. The
result of evaluation of a <code>let</code> expression is the same as
that of <var>expr</var><sub>2</sub>, with all free occurrences of
variable <var>name</var> replaced by the value of
<var>expr</var><sub>1</sub>.
</p>
<p>
For example, <code>let v = foo/... in allpaths($v, //common)
intersect $v</code> is equivalent to the <code>allpaths(foo/...,
//common) intersect foo/...</code>.
</p>
<p>
An occurrence of a variable reference <code>name</code> other than in
an enclosing <code>let <var>name</var> = ...</code> expression is an
error. In other words, toplevel query expressions cannot have free
variables.
</p>
<p>
In the above grammar productions, <code>name</code> is like
<em>word</em>, but with the additional constraint that it be a legal
identifier in the C programming language. References to the variable
must be prepended with the "$" character.
</p>
<p>
Each <code>let</code> expression defines only a single variable,
but you can nest them.
</p>
<p>
(Both <a
href='#target-patterns'>target patterns</a> and variable references
consist of just a single token, a word, creating a syntactic
ambiguity. However, there is no semantic ambiguity, because the
subset of words that are legal variable names is disjoint from the
subset of words that are legal target patterns.)
</p>
<p>
(Technically speaking, <code>let</code> expressions do not increase
the expressiveness of the query language: any query expressible in
the language can also be expressed without them. However, they
improve the conciseness of many queries, and may also lead to more
efficient query evaluation.)
</p>
<h3 id="parentheses">Parenthesized expressions</h3>
<pre>expr ::= (<var>expr</var>)</pre>
<p>
Parentheses associate subexpressions to force an
order of evaluation.
A parenthesized expression evaluates
to the value of its argument.
</p>
<h3 id="set-operations">Algebraic set operations:
intersection, union, set difference</h3>
<pre>expr ::= <var>expr</var> intersect <var>expr</var>
| <var>expr</var> ^ <var>expr</var>
| <var>expr</var> union <var>expr</var>
| <var>expr</var> + <var>expr</var>
| <var>expr</var> except <var>expr</var>
| <var>expr</var> - <var>expr</var>
</pre>
<p>
These three operators compute the usual set operations over their
arguments. Each operator has two forms, a nominal form such
as <code>intersect</code> and a symbolic form such
as <code>^</code>. Both forms are equivalent;
the symbolic forms are quicker to type. (For clarity, the rest of
this manual uses the nominal forms.) For example,
</p>
<pre>foo/... except foo/bar/...</pre>
evaluates to the set of targets that match
<code>foo/...</code> but not
<code>foo/bar/...</code> . Equivalently:
<pre>foo/... - foo/bar/...</pre>
The <code>intersect</code> (<code>^</code>)
and <code>union</code> (<code>+</code>) operations are commutative
(symmetric); <code>except</code> (<code>-</code>) is
asymmetric. The parser treats all three operators as
left-associative and of equal precedence, so you might want parentheses.
For example, the first two of these expressions are
equivalent, but the third is not:
<pre>x intersect y union z
(x intersect y) union z
x intersect (y union z)</pre>
<p>
(We strongly recommend that you use parentheses where there is
any danger of ambiguity in reading a query expression.)
</p>
<h3 id="set">Read targets from an external source: set</h3>
<pre>expr ::= set(<var>word</var> *) </pre>
<p>
The <code>set(<var>a</var> <var>b</var> <var>c</var> ...)</code>
operator computes the union of a set of zero or
more <a href='#target-patterns'>target patterns</a>, separated by
whitespace (no commas).
</p>
<p>
In conjunction with the Bourne shell's <code>$(...)</code>
feature, <code>set()</code> provides a means of saving the results
of one query in a regular text file, manipulating that text file
using other programs (e.g. standard UNIX shell tools), and then
introducing the result back into the query tool as a value for
further processing. For example:
</p>
<pre>
% bazel query deps(//my:target) --output=label | grep ... | sed ... | awk ... > foo
% bazel query "kind(cc_binary, set($(<foo)))"
</pre>
<p>
In the next example, <code>kind(cc_library,
deps(//some_dir/foo:main, 5))</code> is effectively computed
by filtering on the <code>maxrank</code> values using
an <code>awk</code> program.
</p>
<pre>
% bazel query 'deps(//some_dir/foo:main)' --output maxrank |
awk '($1 < 5) { print $2;} ' > foo
% bazel query "kind(cc_library, set($(<foo)))"
</pre>
<p>
In these examples, <code>$(<foo)</code> is a shorthand
for <code>$(cat foo)</code>, but shell commands other
than <code>cat</code> may be used too—such as
the previous <code>awk</code> command.
</p>
<p>
Note, <code>set()</code> introduces no graph ordering constraints,
so path information may be lost when saving and reloading sets of
nodes using it. See the <a href='#graph-order'>graph order</a>
section below for more detail.
</p>
<h3 id="deps">Transitive closure of dependencies: deps</h3>
<pre>expr ::= deps(<var>expr</var>)
| deps(<var>expr</var>, <var>depth</var>)</pre>
<p>
The <code>deps(<var>x</var>)</code> operator evaluates to the graph
formed by the transitive closure of dependencies of its argument set
<var>x</var>. For example, the value of <code>deps(//foo)</code> is
the dependency graph rooted at the single node <code>foo</code>,
including all its dependencies. The value of
<code>deps(foo/...)</code> is the dependency graphs whose roots are
all rules in every package beneath the <code>foo</code> directory.
Please note that 'dependencies' means only rule and file targets
in this context, therefore the BUILD, Skylark and EBL files needed to
create these targets are not included here. For that you should use the
<a href="#buildfiles"><code>buildfiles</code></a> operator.
</p>
<p>
The resulting graph is ordered according to the dependency relation.
See the section on <a href='#graph-order'>graph order</a> for more
details.
</p>
<p>
The <code>deps</code> operator accepts an optional second argument,
which is an integer literal specifying an upper bound on the depth
of the search. So <code>deps(foo:*, 1)</code> evaluates to all the
direct prerequisites of any target in the <code>foo</code> package,
and <code>deps(foo:*, 2)</code> further includes the nodes directly
reachable from the nodes in <code>deps(foo:*, 1)</code>, and so on.
(These numbers correspond to the ranks shown in
the <a href='#output-ranked'><code>minrank</code></a> output
format.) If the <var>depth</var> parameter is omitted, the search
is unbounded, i.e. it computes the reflexive transitive closure of
prerequsites.
</p>
<h3 id="rdeps">Transitive closure of reverse dependencies: rdeps</h3>
<pre>expr ::= rdeps(<var>expr</var>, <var>expr</var>)
| rdeps(<var>expr</var>, <var>expr</var>, <var>depth</var>)</pre>
<p>
The <code>rdeps(<var>u</var>, <var>x</var>)</code> operator evaluates
to the reverse dependencies of the argument set <var>x</var> within the
transitive closure of the universe set <var>u</var>.
</p>
<p>
The resulting graph is ordered according to the dependency relation. See the
section on <a href='#graph-order'>graph order</a> for more details.
</p>
<p>
The <code>rdeps</code> operator accepts an optional third argument,
which is an integer literal specifying an upper bound on the depth of the
search. The resulting graph will only include nodes within a distance of the
specified depth from any node in the argument set. So
<code>rdeps(//foo, //common, 1)</code> evaluates to all nodes in the
transitive closure of <code>//foo</code> that directly depend on
<code>//common</code>. (These numbers correspond to the ranks shown in the
<a href='#output-ranked'><code>minrank</code></a> output format.) If the
<var>depth</var> parameter is omitted, the search is unbounded.
</p>
<h3 id="some">Arbitrary choice: some</h3>
<pre>expr ::= some(<var>expr</var>)</pre>
<p>
The <code>some(<var>x</var>)</code> operator selects one target
arbitrarily from its argument set <var>x</var>, and evaluates to a
singleton set containing only that target. For example, the
expression <code>some(//foo:main union //bar:baz)</code>
evaluates to a set containing either <code>//foo:main</code> or
<code>//bar:baz</code>—though which one is not defined.
</p>
<p>
If the argument is a singleton, then <code>some</code>
computes the identity function: <code>some(//foo:main)</code> is
equivalent to <code>//foo:main</code>.
It is an error if the specified argument set is empty, as in the
expression <code>some(//foo:main intersect //bar:baz)</code>.
</p>
<h3 id="path-operators">Path operators: somepath, allpaths</h3>
<pre>expr ::= somepath(<var>expr</var>, <var>expr</var>)
| allpaths(<var>expr</var>, <var>expr</var>)</pre>
<p>
The <code>somepath(<var>S</var>, <var>E</var>)</code> and
<code>allpaths(<var>S</var>, <var>E</var>)</code> operators compute
paths between two sets of targets. Both queries accept two
arguments, a set <var>S</var> of starting points and a set
<var>E</var> of ending points. <code>somepath</code> returns the
graph of nodes on <em>some</em> arbitrary path from a target in
<var>S</var> to a target in <var>E</var>; <code>allpaths</code>
returns the graph of nodes on <em>all</em> paths from any target in
<var>S</var> to any target in <var>E</var>.
</p>
<p>
The resulting graphs are ordered according to the dependency relation.
See the section on <a href='#graph-order'>graph order</a> for more
details.
</p>
<table style='margin: auto'><tr>
<td style='text-align: center'>
<svg width="153pt" height="288pt"
viewBox="0.00 0.00 153.40 288.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(0.839179 0.839179) rotate(0) translate(4 339.193)">
<title>somepath1</title>
<polygon fill="white" stroke="none" points="-4,4 -4,-339.193 178.798,-339.193 178.798,4 -4,4"/>
<!-- n1 -->
<g id="node1" class="node"><title>n1</title>
<ellipse fill="none" stroke="black" cx="40" cy="-314.394" rx="18" ry="18"/>
</g>
<!-- n2 -->
<g id="node2" class="node"><title>n2</title>
<ellipse fill="pink" stroke="black" cx="41" cy="-236.798" rx="18" ry="18"/>
</g>
<!-- n1->n2 -->
<g id="edge1" class="edge"><title>n1->n2</title>
<path fill="none" stroke="black" d="M40.2269,-296.24C40.3484,-287.058 40.5009,-275.531 40.6382,-265.147"/>
<polygon fill="black" stroke="black" points="44.1413,-264.93 40.774,-254.884 37.1419,-264.837 44.1413,-264.93"/>
</g>
<!-- n3 -->
<g id="node3" class="node"><title>n3</title>
<ellipse fill="pink" stroke="black" cx="18" cy="-162" rx="18" ry="18"/>
</g>
<!-- n2->n3 -->
<g id="edge2" class="edge"><title>n2->n3</title>
<path fill="none" stroke="black" d="M35.7809,-219.279C32.9579,-210.344 29.4064,-199.103 26.2211,-189.021"/>
<polygon fill="black" stroke="black" points="29.5485,-187.935 23.1984,-179.454 22.8737,-190.044 29.5485,-187.935"/>
</g>
<!-- n10 -->
<g id="node10" class="node"><title>n10</title>
<ellipse fill="pink" stroke="black" cx="37" cy="-90" rx="18" ry="18"/>
</g>
<!-- n2->n10 -->
<g id="edge9" class="edge"><title>n2->n10</title>
<path fill="none" stroke="black" d="M42.9371,-218.86C44.7656,-200.425 46.9578,-170.088 45,-144 44.3634,-135.518 43.1616,-126.336 41.8792,-118.036"/>
<polygon fill="black" stroke="black" points="45.3237,-117.412 40.2483,-108.112 38.4164,-118.547 45.3237,-117.412"/>
</g>
<!-- n3->n10 -->
<g id="edge10" class="edge"><title>n3->n10</title>
<path fill="none" stroke="black" d="M22.5027,-144.411C24.7033,-136.304 27.404,-126.354 29.8755,-117.248"/>
<polygon fill="black" stroke="black" points="33.2878,-118.038 32.5296,-107.47 26.5322,-116.204 33.2878,-118.038"/>
</g>
<!-- n4 -->
<g id="node4" class="node"><title>n4</title>
<ellipse fill="pink" stroke="black" cx="87" cy="-18" rx="18" ry="18"/>
<text text-anchor="middle" x="87" y="-14.3" font-family="arial" font-size="14.00">E</text>
</g>
<!-- n5 -->
<g id="node5" class="node"><title>n5</title>
<ellipse fill="none" stroke="black" cx="97" cy="-236.798" rx="18" ry="18"/>
</g>
<!-- n6 -->
<g id="node6" class="node"><title>n6</title>
<ellipse fill="none" stroke="black" cx="121" cy="-162" rx="18" ry="18"/>
</g>
<!-- n5->n6 -->
<g id="edge5" class="edge"><title>n5->n6</title>
<path fill="none" stroke="black" d="M102.446,-219.279C105.413,-210.281 109.15,-198.944 112.492,-188.808"/>
<polygon fill="black" stroke="black" points="115.851,-189.796 115.658,-179.203 109.203,-187.604 115.851,-189.796"/>
</g>
<!-- n6->n4 -->
<g id="edge6" class="edge"><title>n6->n4</title>
<path fill="none" stroke="black" d="M115.99,-144.365C112.931,-133.96 109.038,-120.252 106,-108 100.867,-87.3 95.8646,-63.6851 92.2822,-45.9844"/>
<polygon fill="black" stroke="black" points="95.6398,-44.9258 90.2466,-35.8064 88.7758,-46.2987 95.6398,-44.9258"/>
</g>
<!-- n9 -->
<g id="node9" class="node"><title>n9</title>
<ellipse fill="none" stroke="black" cx="133" cy="-90" rx="18" ry="18"/>
</g>
<!-- n6->n9 -->
<g id="edge8" class="edge"><title>n6->n9</title>
<path fill="none" stroke="black" d="M123.905,-144.055C125.261,-136.145 126.907,-126.54 128.425,-117.688"/>
<polygon fill="black" stroke="black" points="131.882,-118.237 130.122,-107.789 124.982,-117.054 131.882,-118.237"/>
</g>
<!-- n7 -->
<g id="node7" class="node"><title>n7</title>
<ellipse fill="pink" stroke="black" cx="97" cy="-314.394" rx="20.5982" ry="20.5982"/>
<text text-anchor="middle" x="97" y="-310.694" font-family="arial" font-size="14.00">S1</text>
</g>
<!-- n7->n2 -->
<g id="edge4" class="edge"><title>n7->n2</title>
<path fill="none" stroke="black" d="M84.8488,-296.991C76.7726,-286.089 66.0734,-271.646 57.2656,-259.756"/>
<polygon fill="black" stroke="black" points="60.0158,-257.588 51.2509,-251.636 54.391,-261.755 60.0158,-257.588"/>
</g>
<!-- n7->n5 -->
<g id="edge3" class="edge"><title>n7->n5</title>
<path fill="none" stroke="black" d="M97,-293.532C97,-284.887 97,-274.612 97,-265.254"/>
<polygon fill="black" stroke="black" points="100.5,-265.213 97,-255.213 93.5001,-265.213 100.5,-265.213"/>
</g>
<!-- n8 -->
<g id="node8" class="node"><title>n8</title>
<ellipse fill="none" stroke="black" cx="154" cy="-236.798" rx="20.5982" ry="20.5982"/>
<text text-anchor="middle" x="154" y="-233.098" font-family="arial" font-size="14.00">S2</text>
</g>
<!-- n8->n6 -->
<g id="edge7" class="edge"><title>n8->n6</title>
<path fill="none" stroke="black" d="M145.673,-217.428C141.606,-208.456 136.653,-197.53 132.254,-187.827"/>
<polygon fill="black" stroke="black" points="135.411,-186.313 128.095,-178.651 129.036,-189.204 135.411,-186.313"/>
</g>
<!-- n10->n4 -->
<g id="edge11" class="edge"><title>n10->n4</title>
<path fill="none" stroke="black" d="M47.1182,-74.8345C53.9632,-65.2515 63.1483,-52.3924 70.9784,-41.4303"/>
<polygon fill="black" stroke="black" points="73.9325,-43.3162 76.8968,-33.1445 68.2363,-39.2475 73.9325,-43.3162"/>
</g>
<!-- n11 -->
<g id="node11" class="node"><title>n11</title>
<ellipse fill="none" stroke="black" cx="33" cy="-18" rx="18" ry="18"/>
</g>
<!-- n10->n11 -->
<g id="edge12" class="edge"><title>n10->n11</title>
<path fill="none" stroke="black" d="M36.0112,-71.6966C35.5704,-63.9827 35.0407,-54.7125 34.5493,-46.1124"/>
<polygon fill="black" stroke="black" points="38.0423,-45.8883 33.9774,-36.1043 31.0537,-46.2878 38.0423,-45.8883"/>
</g>
</g>
</svg>
<p><code>somepath(S1 + S2, E)</code>,<br/>one possible result.</p>
</td>
<td style='padding: 40px; text-align: center'>
<svg width="153pt" height="288pt"
viewBox="0.00 0.00 153.40 288.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(0.839179 0.839179) rotate(0) translate(4 339.193)">
<title>somepath2</title>
<polygon fill="white" stroke="none" points="-4,4 -4,-339.193 178.798,-339.193 178.798,4 -4,4"/>
<!-- n1 -->
<g id="node1" class="node"><title>n1</title>
<ellipse fill="none" stroke="black" cx="40" cy="-314.394" rx="18" ry="18"/>
</g>
<!-- n2 -->
<g id="node2" class="node"><title>n2</title>
<ellipse fill="none" stroke="black" cx="41" cy="-236.798" rx="18" ry="18"/>
</g>
<!-- n1->n2 -->
<g id="edge1" class="edge"><title>n1->n2</title>
<path fill="none" stroke="black" d="M40.2269,-296.24C40.3484,-287.058 40.5009,-275.531 40.6382,-265.147"/>
<polygon fill="black" stroke="black" points="44.1413,-264.93 40.774,-254.884 37.1419,-264.837 44.1413,-264.93"/>
</g>
<!-- n3 -->
<g id="node3" class="node"><title>n3</title>
<ellipse fill="none" stroke="black" cx="18" cy="-162" rx="18" ry="18"/>
</g>
<!-- n2->n3 -->
<g id="edge2" class="edge"><title>n2->n3</title>
<path fill="none" stroke="black" d="M35.7809,-219.279C32.9579,-210.344 29.4064,-199.103 26.2211,-189.021"/>
<polygon fill="black" stroke="black" points="29.5485,-187.935 23.1984,-179.454 22.8737,-190.044 29.5485,-187.935"/>
</g>
<!-- n10 -->
<g id="node10" class="node"><title>n10</title>
<ellipse fill="none" stroke="black" cx="37" cy="-90" rx="18" ry="18"/>
</g>
<!-- n2->n10 -->
<g id="edge9" class="edge"><title>n2->n10</title>
<path fill="none" stroke="black" d="M42.9371,-218.86C44.7656,-200.425 46.9578,-170.088 45,-144 44.3634,-135.518 43.1616,-126.336 41.8792,-118.036"/>
<polygon fill="black" stroke="black" points="45.3237,-117.412 40.2483,-108.112 38.4164,-118.547 45.3237,-117.412"/>
</g>
<!-- n3->n10 -->
<g id="edge10" class="edge"><title>n3->n10</title>
<path fill="none" stroke="black" d="M22.5027,-144.411C24.7033,-136.304 27.404,-126.354 29.8755,-117.248"/>
<polygon fill="black" stroke="black" points="33.2878,-118.038 32.5296,-107.47 26.5322,-116.204 33.2878,-118.038"/>
</g>
<!-- n4 -->
<g id="node4" class="node"><title>n4</title>
<ellipse fill="pink" stroke="black" cx="87" cy="-18" rx="18" ry="18"/>
<text text-anchor="middle" x="87" y="-14.3" font-family="arial" font-size="14.00">E</text>
</g>
<!-- n5 -->
<g id="node5" class="node"><title>n5</title>
<ellipse fill="none" stroke="black" cx="97" cy="-236.798" rx="18" ry="18"/>
</g>
<!-- n6 -->
<g id="node6" class="node"><title>n6</title>
<ellipse fill="pink" stroke="black" cx="121" cy="-162" rx="18" ry="18"/>
</g>
<!-- n5->n6 -->
<g id="edge5" class="edge"><title>n5->n6</title>
<path fill="none" stroke="black" d="M102.446,-219.279C105.413,-210.281 109.15,-198.944 112.492,-188.808"/>
<polygon fill="black" stroke="black" points="115.851,-189.796 115.658,-179.203 109.203,-187.604 115.851,-189.796"/>
</g>
<!-- n6->n4 -->
<g id="edge6" class="edge"><title>n6->n4</title>
<path fill="none" stroke="black" d="M115.99,-144.365C112.931,-133.96 109.038,-120.252 106,-108 100.867,-87.3 95.8646,-63.6851 92.2822,-45.9844"/>
<polygon fill="black" stroke="black" points="95.6398,-44.9258 90.2466,-35.8064 88.7758,-46.2987 95.6398,-44.9258"/>
</g>
<!-- n9 -->
<g id="node9" class="node"><title>n9</title>
<ellipse fill="none" stroke="black" cx="133" cy="-90" rx="18" ry="18"/>
</g>
<!-- n6->n9 -->
<g id="edge8" class="edge"><title>n6->n9</title>
<path fill="none" stroke="black" d="M123.905,-144.055C125.261,-136.145 126.907,-126.54 128.425,-117.688"/>
<polygon fill="black" stroke="black" points="131.882,-118.237 130.122,-107.789 124.982,-117.054 131.882,-118.237"/>
</g>
<!-- n7 -->
<g id="node7" class="node"><title>n7</title>
<ellipse fill="none" stroke="black" cx="97" cy="-314.394" rx="20.5982" ry="20.5982"/>
<text text-anchor="middle" x="97" y="-310.694" font-family="arial" font-size="14.00">S1</text>
</g>
<!-- n7->n2 -->
<g id="edge4" class="edge"><title>n7->n2</title>
<path fill="none" stroke="black" d="M84.8488,-296.991C76.7726,-286.089 66.0734,-271.646 57.2656,-259.756"/>
<polygon fill="black" stroke="black" points="60.0158,-257.588 51.2509,-251.636 54.391,-261.755 60.0158,-257.588"/>
</g>
<!-- n7->n5 -->
<g id="edge3" class="edge"><title>n7->n5</title>
<path fill="none" stroke="black" d="M97,-293.532C97,-284.887 97,-274.612 97,-265.254"/>
<polygon fill="black" stroke="black" points="100.5,-265.213 97,-255.213 93.5001,-265.213 100.5,-265.213"/>
</g>
<!-- n8 -->
<g id="node8" class="node"><title>n8</title>
<ellipse fill="pink" stroke="black" cx="154" cy="-236.798" rx="20.5982" ry="20.5982"/>
<text text-anchor="middle" x="154" y="-233.098" font-family="arial" font-size="14.00">S2</text>
</g>
<!-- n8->n6 -->
<g id="edge7" class="edge"><title>n8->n6</title>
<path fill="none" stroke="black" d="M145.673,-217.428C141.606,-208.456 136.653,-197.53 132.254,-187.827"/>
<polygon fill="black" stroke="black" points="135.411,-186.313 128.095,-178.651 129.036,-189.204 135.411,-186.313"/>
</g>
<!-- n10->n4 -->
<g id="edge11" class="edge"><title>n10->n4</title>
<path fill="none" stroke="black" d="M47.1182,-74.8345C53.9632,-65.2515 63.1483,-52.3924 70.9784,-41.4303"/>
<polygon fill="black" stroke="black" points="73.9325,-43.3162 76.8968,-33.1445 68.2363,-39.2475 73.9325,-43.3162"/>
</g>
<!-- n11 -->
<g id="node11" class="node"><title>n11</title>
<ellipse fill="none" stroke="black" cx="33" cy="-18" rx="18" ry="18"/>
</g>
<!-- n10->n11 -->
<g id="edge12" class="edge"><title>n10->n11</title>
<path fill="none" stroke="black" d="M36.0112,-71.6966C35.5704,-63.9827 35.0407,-54.7125 34.5493,-46.1124"/>
<polygon fill="black" stroke="black" points="38.0423,-45.8883 33.9774,-36.1043 31.0537,-46.2878 38.0423,-45.8883"/>
</g>
</g>
</svg>
<p><code>somepath(S1 + S2, E)</code>,<br/>another possible result.</p>
</td>
<td style='text-align: center'>
<svg width="153pt" height="288pt"
viewBox="0.00 0.00 153.40 288.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(0.839179 0.839179) rotate(0) translate(4 339.193)">
<title>allpaths</title>
<polygon fill="white" stroke="none" points="-4,4 -4,-339.193 178.798,-339.193 178.798,4 -4,4"/>
<!-- n1 -->
<g id="node1" class="node"><title>n1</title>
<ellipse fill="none" stroke="black" cx="40" cy="-314.394" rx="18" ry="18"/>
</g>
<!-- n2 -->
<g id="node2" class="node"><title>n2</title>
<ellipse fill="pink" stroke="black" cx="41" cy="-236.798" rx="18" ry="18"/>
</g>
<!-- n1->n2 -->
<g id="edge1" class="edge"><title>n1->n2</title>
<path fill="none" stroke="black" d="M40.2269,-296.24C40.3484,-287.058 40.5009,-275.531 40.6382,-265.147"/>
<polygon fill="black" stroke="black" points="44.1413,-264.93 40.774,-254.884 37.1419,-264.837 44.1413,-264.93"/>
</g>
<!-- n3 -->
<g id="node3" class="node"><title>n3</title>
<ellipse fill="pink" stroke="black" cx="18" cy="-162" rx="18" ry="18"/>
</g>
<!-- n2->n3 -->
<g id="edge2" class="edge"><title>n2->n3</title>