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