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

Macros and Functions

subpackages.all

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.

Example usage (generated)

load("@bazel_skylib//lib:subpackages.bzl", "subpackages")

subpackages.all(
)

exclude

see native.subpackages(exclude)

allow_empty

see native.subpackages(allow_empty)

fully_qualified

It true return fully qualified Labels for subpackages, otherwise returns subpackage path relative to current package.


subpackages.exists

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.

Example usage (generated)

load("@bazel_skylib//lib:subpackages.bzl", "subpackages")

subpackages.exists(
    # a path to a subpackage to test, must not be an absolute Label.
    relative_path = None,
)

relative_path

a path to a subpackage to test, must not be an absolute Label.


subpackages.supported

Example usage (generated)

load("@bazel_skylib//lib:subpackages.bzl", "subpackages")

subpackages.supported(
)