zip_file
zip_file
def zip_file(
*,
name: str,
default_target_platform: None | str = None,
target_compatible_with: list[str] = [],
compatible_with: list[str] = [],
exec_compatible_with: list[str] = [],
visibility: list[str] = [],
within_view: list[str] = ["PUBLIC"],
metadata: OpaqueMetadata = {},
tests: list[str] = [],
modifiers: OpaqueMetadata = [],
_apple_platforms: dict[str, str] = {},
_zip_file_toolchain: str = "gh_facebook_buck2_shims_meta//:zip_file",
contacts: list[str] = [],
default_host_platform: None | str = None,
entries_to_exclude: list[str] = [],
hardcode_permissions_for_deterministic_output: None | bool = None,
labels: list[str] = [],
licenses: list[str] = [],
on_duplicate_entry: str = "overwrite",
out: str = "",
srcs: list[str] = [],
zip_srcs: list[str] = [],
) -> None
A zip_file() allows builds to create basic zip files in a platform-agnostic way.
Parameters
-
name: name of the target -
default_target_platform: specifies the default target platform, used when no platforms are specified on the command line -
target_compatible_with: a list of constraints that are required to be satisfied for this target to be compatible with a configuration -
compatible_with: a list of constraints that are required to be satisfied for this target to be compatible with a configuration -
exec_compatible_with: a list of constraints that are required to be satisfied for this target to be compatible with an execution platform -
visibility: a list of visibility patterns restricting what targets can depend on this one -
within_view: a list of visibility patterns restricting what this target can depend on -
metadata: a key-value map of metadata associated with this target -
tests: a list of targets that provide tests for this one -
modifiers: an array of modifiers associated with this target -
entries_to_exclude: List of regex expressions that describe entries that should not be included in the output zip file.The regexes must be defined using
java.util.regex.Patternsyntax. -
hardcode_permissions_for_deterministic_output: If set to true, Buck hardcodes the permissions in order to ensures that all files have the same permissions regardless of the platform on which the zip was generated. -
on_duplicate_entry: Action performed when Buck detects that zip_file input contains multiple entries with the same name.The valid values are:
overwrite(default): the last entry overwrites all previous entries with the same name.append: all entries are added to the output file.fail: fail the build when duplicate entries are present.
-
out: The name of the zip file that should be generated. This allows builds to use a meaningful target name coupled with a meaningful zip file name. The default value takes the rule'snameand appends.zip. -
srcs: The set of files to include in the zip.Each
srcwill be added to the zip as follows:- If the
srcis the output of another rule, the output will be included using just the output's file name. - If the
srcis a file relative to the rule's declaration, it will be included in the zip with its relative file name.
- If the
-
zip_srcs: The set of zip files whose content to include in the output zip file.Note that the order of files in
zip_srcsmatters because the same zip entry can be included from multiple files. See theon_duplicate_entryargument to learn how to control the behavior when there are multiple entries with the same name.The entries from
zip_srcsare added before files fromsrcs.
Details
Examples:
This example will create a simple zip file.
zip_file(
# The output will be "example.zip"
name = 'example',
srcs =
# These files will be found in the zip under "dir/"
glob(['dir/**/*']) +
[
# Imagine this generates the output
# "buck-out/gen/foo/hello.txt". This output will
# be found in the zip at "hello.txt"
'//some/other:target',
],
zip_srcs = [
# The contents of this zip will be added to the generated zip.
'amazing-library-1.0-sources.zip',
],
entries_to_exclude = [
"com/example/amazinglibrary/Source1.java",
],
)
If you were to examine the generated zip, the contents would look
something like (assuming the output of
"//some/other:target" was a file who's path ended with
hello.txt, the "dir" glob found two files,
and "amazing-library-1.0-sources.zip" contained two Java
source files):
dir/file1.txt
dir/subdir/file2.txt
hello.txt
com/example/amazinglibrary/Source2.java