xref: /aosp_15_r20/external/bazel-skylib/docs/subpackages_doc.md (revision bcb5dc7965af6ee42bf2f21341a2ec00233a8c8a)
1*bcb5dc79SHONG Yifan<!-- Generated with Stardoc: http://skydoc.bazel.build -->
2*bcb5dc79SHONG Yifan
3*bcb5dc79SHONG YifanSkylib module containing common functions for working with native.subpackages()
4*bcb5dc79SHONG Yifan
5*bcb5dc79SHONG Yifan<a id="subpackages.all"></a>
6*bcb5dc79SHONG Yifan
7*bcb5dc79SHONG Yifan## subpackages.all
8*bcb5dc79SHONG Yifan
9*bcb5dc79SHONG Yifan<pre>
10*bcb5dc79SHONG Yifansubpackages.all(<a href="#subpackages.all-exclude">exclude</a>, <a href="#subpackages.all-allow_empty">allow_empty</a>, <a href="#subpackages.all-fully_qualified">fully_qualified</a>)
11*bcb5dc79SHONG Yifan</pre>
12*bcb5dc79SHONG Yifan
13*bcb5dc79SHONG YifanList all direct subpackages of the current package regardless of directory depth.
14*bcb5dc79SHONG Yifan
15*bcb5dc79SHONG YifanThe returned list contains all subpackages, but not subpackages of subpackages.
16*bcb5dc79SHONG Yifan
17*bcb5dc79SHONG YifanExample:
18*bcb5dc79SHONG YifanAssuming the following BUILD files exist:
19*bcb5dc79SHONG Yifan
20*bcb5dc79SHONG Yifan    BUILD
21*bcb5dc79SHONG Yifan    foo/BUILD
22*bcb5dc79SHONG Yifan    foo/sub/BUILD
23*bcb5dc79SHONG Yifan    bar/BUILD
24*bcb5dc79SHONG Yifan    baz/deep/dir/BUILD
25*bcb5dc79SHONG Yifan
26*bcb5dc79SHONG YifanIf the current package is '//' all() will return ['//foo', '//bar',
27*bcb5dc79SHONG Yifan'//baz/deep/dir'].  //foo/sub is not included because it is a direct
28*bcb5dc79SHONG Yifansubpackage of '//foo' not '//'
29*bcb5dc79SHONG Yifan
30*bcb5dc79SHONG YifanNOTE: fail()s if native.subpackages() is not supported.
31*bcb5dc79SHONG Yifan
32*bcb5dc79SHONG Yifan
33*bcb5dc79SHONG Yifan**PARAMETERS**
34*bcb5dc79SHONG Yifan
35*bcb5dc79SHONG Yifan
36*bcb5dc79SHONG Yifan| Name  | Description | Default Value |
37*bcb5dc79SHONG Yifan| :------------- | :------------- | :------------- |
38*bcb5dc79SHONG Yifan| <a id="subpackages.all-exclude"></a>exclude |  see native.subpackages(exclude)   |  `[]` |
39*bcb5dc79SHONG Yifan| <a id="subpackages.all-allow_empty"></a>allow_empty |  see native.subpackages(allow_empty)   |  `False` |
40*bcb5dc79SHONG Yifan| <a id="subpackages.all-fully_qualified"></a>fully_qualified |  It true return fully qualified Labels for subpackages, otherwise returns subpackage path relative to current package.   |  `True` |
41*bcb5dc79SHONG Yifan
42*bcb5dc79SHONG Yifan**RETURNS**
43*bcb5dc79SHONG Yifan
44*bcb5dc79SHONG YifanA mutable sorted list containing all sub-packages of the current Bazel
45*bcb5dc79SHONG Yifanpackage.
46*bcb5dc79SHONG Yifan
47*bcb5dc79SHONG Yifan
48*bcb5dc79SHONG Yifan<a id="subpackages.exists"></a>
49*bcb5dc79SHONG Yifan
50*bcb5dc79SHONG Yifan## subpackages.exists
51*bcb5dc79SHONG Yifan
52*bcb5dc79SHONG Yifan<pre>
53*bcb5dc79SHONG Yifansubpackages.exists(<a href="#subpackages.exists-relative_path">relative_path</a>)
54*bcb5dc79SHONG Yifan</pre>
55*bcb5dc79SHONG Yifan
56*bcb5dc79SHONG YifanChecks to see if relative_path is a direct subpackage of the current package.
57*bcb5dc79SHONG Yifan
58*bcb5dc79SHONG YifanExample:
59*bcb5dc79SHONG Yifan
60*bcb5dc79SHONG Yifan    BUILD
61*bcb5dc79SHONG Yifan    foo/BUILD
62*bcb5dc79SHONG Yifan    foo/sub/BUILD
63*bcb5dc79SHONG Yifan
64*bcb5dc79SHONG YifanIf the current package is '//' (the top-level BUILD file):
65*bcb5dc79SHONG Yifan    subpackages.exists("foo") == True
66*bcb5dc79SHONG Yifan    subpackages.exists("foo/sub") == False
67*bcb5dc79SHONG Yifan    subpackages.exists("bar") == False
68*bcb5dc79SHONG Yifan
69*bcb5dc79SHONG YifanNOTE: fail()s if native.subpackages() is not supported in the current Bazel version.
70*bcb5dc79SHONG Yifan
71*bcb5dc79SHONG Yifan
72*bcb5dc79SHONG Yifan**PARAMETERS**
73*bcb5dc79SHONG Yifan
74*bcb5dc79SHONG Yifan
75*bcb5dc79SHONG Yifan| Name  | Description | Default Value |
76*bcb5dc79SHONG Yifan| :------------- | :------------- | :------------- |
77*bcb5dc79SHONG Yifan| <a id="subpackages.exists-relative_path"></a>relative_path |  a path to a subpackage to test, must not be an absolute Label.   |  none |
78*bcb5dc79SHONG Yifan
79*bcb5dc79SHONG Yifan**RETURNS**
80*bcb5dc79SHONG Yifan
81*bcb5dc79SHONG YifanTrue if 'relative_path' is a subpackage of the current package.
82*bcb5dc79SHONG Yifan
83*bcb5dc79SHONG Yifan
84*bcb5dc79SHONG Yifan<a id="subpackages.supported"></a>
85*bcb5dc79SHONG Yifan
86*bcb5dc79SHONG Yifan## subpackages.supported
87*bcb5dc79SHONG Yifan
88*bcb5dc79SHONG Yifan<pre>
89*bcb5dc79SHONG Yifansubpackages.supported()
90*bcb5dc79SHONG Yifan</pre>
91*bcb5dc79SHONG Yifan
92*bcb5dc79SHONG Yifan
93*bcb5dc79SHONG Yifan
94*bcb5dc79SHONG Yifan
95*bcb5dc79SHONG Yifan
96