Buck: zip_file()
Support Ukraine. Help Provide Humanitarian Aid to Ukraine.

zip_file()

This is liable to change in the future.

A zip_file() allows builds to create basic zip files in a platform-agnostic way.

Arguments

  • name (required) #

    The short name for this build target.

  • out (defaults to name.zip) #

    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 (required) #

    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.

  • 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 the on_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 from srcs.

  • 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.

  • 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.

  • visibility (defaults to []) #

    List of build target patterns that identify the build rules that can include this rule as a dependency, for example, by listing it in their deps or exported_deps attributes. For more information, see visibility.

  • licenses (defaults to []) #

    Set of license files for this library. To get the list of license files for a given build rule and all of its dependencies, you can use buck query.

  • labels (defaults to []) #

    Set of arbitrary strings which allow you to annotate a build rule with tags that can be searched for over an entire dependency tree using buck query attrfilter().

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