2
0
Fork 0
mirror of https://github.com/bazel-contrib/bazel-lib synced 2024-12-01 07:15:24 +00:00
bazel-lib/docs/copy_to_directory.md

4.8 KiB

Copy files and directories to an output directory

copy_to_directory

copy_to_directory(name, exclude_prefixes, include_external_repositories, is_windows,
                  replace_prefixes, root_paths, srcs)

Copies files and directories to an output directory.

Files and directories can be arranged as needed in the output directory using the root_paths, exclude_prefixes and replace_prefixes attributes.

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
exclude_prefixes List of path prefixes to exclude from output directory.

If the output directory path for a file or directory starts with or is equal to a path in the list then that file is not copied to the output directory.

Exclude prefixes are matched before replace_prefixes are applied.
List of strings optional []
include_external_repositories List of external repository names to include in the output directory.

Files from external repositories are not copied into the output directory unless the external repository they come from is listed here.

When copied from an external repository, the file path in the output directory defaults to the file's path within the external repository. The external repository name is not included in that path.

For example, the following copies @external_repo//path/to:file to path/to/file within the output directory.

 copy_to_directory(     name = "dir",     include_external_repositories = ["external_repo"],     srcs = ["@external_repo//path/to:file"], ) 


Files from external repositories are subject to root_paths, exclude_prefixes and replace_prefixes in the same way as files form the main repository.
List of strings optional []
is_windows - Boolean required
replace_prefixes Map of paths prefixes to replace in the output directory path when copying files.

If the output directory path for a file or directory starts with or is equal to a key in the dict then the matching portion of the output directory path is replaced with the dict value for that key.

Forward slashes (/) should be used as path separators. The final path segment of the key can be a partial match in the corresponding segment of the output directory path.

If there are multiple keys that match, the longest match wins.
Dictionary: String -> String optional {}
root_paths List of paths that are roots in the output directory. If a file or directory being copied is in one of the listed paths or one of its subpaths, the output directory path is the path relative to the root path instead of the path relative to the file's workspace.

Forward slashes (/) should be used as path separators. Partial matches on the final path segment of a root path against the corresponding segment in the full workspace relative path of a file are not matched.

If there are multiple root paths that match, the longest match wins.

Defaults to [package_name()] so that the output directory path of files in the target's package and and sub-packages are relative to the target's package and files outside of that retain their full workspace relative paths.
List of strings optional []
srcs Files and/or directories to copy into the output directory List of labels optional []

copy_to_directory_lib.impl

copy_to_directory_lib.impl(ctx)

PARAMETERS

Name Description Default Value
ctx

-

none