2
0
Fork 0
mirror of https://github.com/bazelbuild/bazel-skylib synced 2024-11-27 05:43:25 +00:00
bazel-skylib/docs/subpackages_doc.md
nickgooding 31ab4c8bd2
feat: bzlmod setup (#385)
Creates MODULE.bazel and WORKSPACE.bzlmod files to enable bazel-skylib
to work with the `--experimental_enable_bzlmod` flag.

rules_go has been updated as the previously used version is not
available in the BCR.

stardoc has been updated due to a strange issue with Bzlmod enabled that
caused the `diff_test` and `unittest` docs to be generated without any
contents that was magically fixed upon updating.

bazelbuild/bazel-central-registry#124

Co-authored-by: Alexandre Rostovtsev <arostovtsev@google.com>
2022-08-30 14:57:34 -04:00

2.5 KiB
Executable file

Skylib module containing common functions for working with native.subpackages()

subpackages.all

subpackages.all(exclude, allow_empty, fully_qualified)

List all direct subpackages of the current package regardless of directory depth.

The returned list contains all subpackages, but not subpackages of subpackages.

Example: Assuming the following BUILD files exist:

BUILD
foo/BUILD
foo/sub/BUILD
bar/BUILD
baz/deep/dir/BUILD

If the current package is '//' all() will return ['//foo', '//bar', '//baz/deep/dir']. //foo/sub is not included because it is a direct subpackage of '//foo' not '//'

NOTE: fail()s if native.subpackages() is not supported.

PARAMETERS

Name Description Default Value
exclude see native.subpackages(exclude) []
allow_empty see native.subpackages(allow_empty) False
fully_qualified It true return fully qualified Labels for subpackages, otherwise returns subpackage path relative to current package. True

RETURNS

A mutable sorted list containing all sub-packages of the current Bazel package.

subpackages.exists

subpackages.exists(relative_path)

Checks to see if relative_path is a direct subpackage of the current package.

Example:

BUILD
foo/BUILD
foo/sub/BUILD

If the current package is '//' (the top-level BUILD file): subpackages.exists("foo") == True subpackages.exists("foo/sub") == False subpackages.exists("bar") == False

NOTE: fail()s if native.subpackages() is not supported in the current Bazel version.

PARAMETERS

Name Description Default Value
relative_path a path to a subpackage to test, must not be an absolute Label. none

RETURNS

True if 'relative_path' is a subpackage of the current package.

subpackages.supported

subpackages.supported()