blob: fd0629894b911f5571aaf2110618e12a361fdf60 [file] [log] [blame]
# Copyright 2021 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
import("//build_overrides/pigweed.gni")
import("$dir_pw_build/python_action.gni")
# GN target that creates update bundles.
#
# Args:
# out: Filename at which to output the serialized update bundle.
# targets: List of targets mapping filenames to target names.
# persist: Optional boolean; if true, the raw tuf repo will be persisted to
# disk in the target out dir in addition to being serialized as a bundle.
#
# Each target in targets should be a string formatted as follows:
# "/path/to/file > target_name"
template("pw_update_bundle") {
assert(defined(invoker.out), "An output path must be provided via 'out'")
assert(defined(invoker.targets),
"A list of targets must be provided via 'targets'")
pw_python_action(target_name) {
_delimiter = ">"
forward_variables_from(invoker,
[
"deps",
"public_deps",
])
_out_path = invoker.out
_persist_path = ""
if (defined(invoker.persist) && invoker.persist) {
_persist_path = "${target_out_dir}/${target_name}/tuf_repo"
}
module = "pw_software_update.update_bundle"
args = [
"--out",
rebase_path(_out_path),
"--targets",
]
outputs = [ _out_path ]
foreach(tuf_target, invoker.targets) {
# Remove possible spaces around the delimiter before splitting
tuf_target = string_replace(tuf_target, " $_delimiter", _delimiter)
tuf_target = string_replace(tuf_target, "$_delimiter ", _delimiter)
tuf_target_list = []
tuf_target_list = string_split(tuf_target, _delimiter)
tuf_target_path = rebase_path(tuf_target_list[0], root_build_dir)
tuf_target_name = tuf_target_list[1]
args += [ "${tuf_target_path} > ${tuf_target_name}" ]
if (_persist_path != "") {
outputs += [ "${_persist_path}/${tuf_target_name}" ]
}
}
if (_persist_path != "") {
args += [
"--persist-repo",
rebase_path(_persist_path),
]
}
}
}