zip_file
A zip_file()
allows builds to create basic zip files in a platform-agnostic way.
Function Signature
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
Parameters
-
name
: (required)name of the target
-
default_target_platform
: (defaults to:None
)specifies the default target platform, used when no platforms are specified on the command line
-
target_compatible_with
: (defaults to:[]
)a list of constraints that are required to be satisfied for this target to be compatible with a configuration
-
compatible_with
: (defaults to:[]
)a list of constraints that are required to be satisfied for this target to be compatible with a configuration
-
exec_compatible_with
: (defaults to:[]
)a list of constraints that are required to be satisfied for this target to be compatible with an execution platform
-
visibility
: (defaults to:[]
)a list of visibility patterns restricting what targets can depend on this one
-
within_view
: (defaults to:["PUBLIC"]
)a list of visibility patterns restricting what this target can depend on
-
metadata
: (defaults to:{}
)a key-value map of metadata associated with this target
-
tests
: (defaults to:[]
)a list of targets that provide tests for this one
-
modifiers
: (defaults to:[]
)an array of modifiers associated with this target
-
entries_to_exclude
: (defaults to:[]
)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.Pattern
syntax. -
hardcode_permissions_for_deterministic_output
: (defaults to:None
)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
: (defaults to:"overwrite"
)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
: (defaults to:""
)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's
name
and appends.zip
. -
srcs
: (defaults to:[]
)The set of files to include in the zip.
Each
src
will be added to the zip as follows:- If the
src
is the output of another rule, the output will be included using just the output's file name. - If the
src
is a file relative to the rule's declaration, it will be included in the zip with its relative file name.
- If the
-
zip_srcs
: (defaults to:[]
)The set of zip files whose content to include in the output zip file.
Note that the order of files in
zip_srcs
matters because the same zip entry can be included from multiple files. See theon_duplicate_entry
argument to learn how to control the behavior when there are multiple entries with the same name.The entries from
zip_srcs
are added before files fromsrcs
.
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