| def _source_hasher_impl(ctx): | |
| out_file = ctx.outputs.out_file | |
| args = ctx.actions.args() | |
| args.use_param_file("@%s", use_always = True) | |
| args.set_param_file_format("multiline") | |
| args.add("--out-file", out_file.path) | |
| args.add_all(ctx.files.srcs) | |
| ctx.actions.run( | |
| inputs = ctx.files.srcs, | |
| outputs = [out_file], | |
| arguments = [args], | |
| executable = ctx.executable._runner, | |
| mnemonic = "SourceHash", | |
| progress_message = "Hashing {} source files".format(len(ctx.files.srcs)), | |
| ) | |
| # We use a dedicated rule instead of genrule, so that we can use a parameter file, which is scalable | |
| # to thousands of files and won't exceed the argument length limit. | |
| source_hasher = rule( | |
| implementation = _source_hasher_impl, | |
| attrs = { | |
| "srcs": attr.label_list( | |
| allow_files = True, | |
| doc = "The list of source files to hash.", | |
| ), | |
| "out_file": attr.output( | |
| mandatory = True, | |
| doc = "The output file where the 16-digit hex string will be written.", | |
| ), | |
| "_runner": attr.label( | |
| default = Label("//third_party/vkd3d_v3.0/programs/stardust-source-hasher:source_hasher"), | |
| executable = True, | |
| cfg = "exec", | |
| doc = "The Python executable that computes the hash.", | |
| ), | |
| }, | |
| ) |