blob: 003b76901e83c7e84b38750d40f91c45ec739bed [file] [log] [blame]
# Copyright 2024 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Generate a file containing a unique content hash corresponding to the content
# of a given list of source paths.
#
# Arguments:
# source_paths: [required]
# A list of GN path string to the input files and directories.
#
# output: [optional]
# An optional output path, default is
# $target_out_dir/$target_name
#
# cipd_name: [optiona]
# A CIPD archive name for the content of source directories.
# If .versions/$cipd_name.cipd_version exists, its content will be used
# directly to avoid recursively hashing all files in the directory.
#
# exclude_suffixes: [optional]
# A list of file name suffixes to exclude from the content scan.
#
template("generate_content_hash_file") {
if (defined(invoker.output)) {
_output = invoker.output
} else {
_output = "$target_out_dir/${target_name}"
}
assert(defined(invoker.source_paths),
"The source_paths argument must be defined")
action(target_name) {
script = "//build/bazel/scripts/compute_content_hash.py"
inputs = [ "//build/bazel/scripts/get_git_head_commit.py" ]
outputs = [ _output ]
depfile = "${_output}.d"
args = [
"--output",
rebase_path(outputs[0], root_build_dir),
"--depfile",
rebase_path(depfile, root_build_dir),
] + rebase_path(invoker.source_paths, root_build_dir)
if (defined(invoker.cipd_name)) {
args += [ "--cipd-name=${invoker.cipd_name}" ]
}
if (defined(invoker.exclude_suffixes)) {
foreach(suffix, invoker.exclude_suffixes) {
args += [ "--exclude-suffix=${suffix}" ]
}
}
forward_variables_from(invoker, [ "deps" ])
}
}