diff --git a/decls/core_rules.bzl b/decls/core_rules.bzl index e317d1c31..a586e5d94 100644 --- a/decls/core_rules.bzl +++ b/decls/core_rules.bzl @@ -1485,6 +1485,11 @@ zip_file = prelude_rule( The regexes must be defined using `java.util.regex.Pattern` syntax. """), + "deterministic_output": attrs.option(attrs.bool(), default = None, doc = """ + If set to true, Buck ensures that all files in the generated zip and their associated metadata are + consistent across all platforms, resulting in an identical zip file everywhere. Note that this might + come at the expense of losing some otherwise relevant metadata, like file permissions and timestamps. + """), "on_duplicate_entry": attrs.enum(OnDuplicateEntry, default = "overwrite", doc = """ Action performed when Buck detects that zip\\_file input contains multiple entries with the same name. diff --git a/zip_file/zip_file.bzl b/zip_file/zip_file.bzl index 3cf3c8017..ab3b43de0 100644 --- a/zip_file/zip_file.bzl +++ b/zip_file/zip_file.bzl @@ -26,6 +26,7 @@ def _zip_file_impl(ctx: AnalysisContext) -> list[Provider]: on_duplicate_entry = ctx.attrs.on_duplicate_entry entries_to_exclude = ctx.attrs.entries_to_exclude + deterministic_output = ctx.attrs.deterministic_output zip_srcs = ctx.attrs.zip_srcs srcs = ctx.attrs.srcs @@ -59,6 +60,9 @@ def _zip_file_impl(ctx: AnalysisContext) -> list[Provider]: create_zip_cmd.append("--entries_to_exclude") create_zip_cmd.append(entries_to_exclude) + if deterministic_output: + create_zip_cmd.append("--deterministic_output") + ctx.actions.run(cmd_args(create_zip_cmd), category = "zip") return [DefaultInfo(default_output = output)]