bazel-lib/docs/directory_path.md

4.2 KiB

Rule and corresponding provider that joins a label pointing to a TreeArtifact with a path nested within that directory

directory_path

directory_path(name, directory, path)

Provide DirectoryPathInfo to reference some path within a directory.

Otherwise there is no way to give a Bazel label for it.

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
directory a TreeArtifact (ctx.actions.declare_directory) Label required
path path relative to the directory String required

DirectoryPathInfo

DirectoryPathInfo(directory, path)

Joins a label pointing to a TreeArtifact with a path nested within that directory.

FIELDS

Name Description
directory a TreeArtifact (ctx.actions.declare_directory)
path path relative to the directory

make_directory_path

make_directory_path(name, directory, path, kwargs)

Helper function to generate a directory_path target and return its label.

PARAMETERS

Name Description Default Value
name unique name for the generated directory_path target none
directory directory attribute passed to generated directory_path target none
path path attribute passed to generated directory_path target none
kwargs parameters to pass to generated output_files target none

RETURNS

The label name

make_directory_paths

make_directory_paths(name, dict, kwargs)

Helper function to convert a dict of directory to path mappings to directory_path targets and labels.

For example,

make_directory_paths("my_name", {
    "//directory/artifact:target_1": "file/path",
    "//directory/artifact:target_2": ["file/path1", "file/path2"],
})

generates the targets,

directory_path(
    name = "my_name_0",
    directory = "//directory/artifact:target_1",
    path = "file/path"
)

directory_path(
    name = "my_name_1",
    directory = "//directory/artifact:target_2",
    path = "file/path1"
)

directory_path(
    name = "my_name_2",
    directory = "//directory/artifact:target_2",
    path = "file/path2"
)

and the list of targets is returned,

[
    "my_name_0",
    "my_name_1",
    "my_name_2",
]

PARAMETERS

Name Description Default Value
name The target name to use for the generated targets & labels.

The names are generated as zero-indexed name + "_" + i
none
dict The dictionary of directory keys to path or path list values. none
kwargs additional parameters to pass to each generated target none

RETURNS

The label of the generated directory_path targets named name + "_" + i