blob: ca134aa3e4b3586edd840c5e8b267174752bc275 [file] [log] [blame]
# Copyright 2020 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.
import("//build/dist/generated_resource.gni")
# Generate a list of package metadata exported from all packages in the
# transitive closure of declared dependencies.
#
# Parameters
#
# data_keys (required)
# [list of strings] A list of package target metadata keys to collect into a
# list. See gn help for data_keys for more information.
#
# Well known package metadata:
#
# package_names
#
# snapshot_entries
# The snapshot entries are consumed for the production of the snapshots
# that feed into `fx delta` for version to version OTA size computations.
#
# blob_manifests
# The blob manifests are aggregated by the image build process to produce
# manifests to publish to repositories and to produce manifests to write
# into blobfs images.
#
# meta_far_merkle_index_entries
# The metafar merkle index entries are aggregated in image builds to
# produce package server indices for base serving.
#
# package_output_manifests
# The path of each output manifest for each package.
#
# package_barrier
# Metadata barrier.
#
# data_deps (optional)
# data_keys (optional)
# deps (optional)
# output_conversion (optional)
# outputs (optional)
# public_deps (optional)
# rebase (optional)
# testonly (optional)
# visibility (optional)
# Same as for any GN `generated_file()` target.
template("generate_package_metadata") {
generated_file(target_name) {
forward_variables_from(invoker,
[
"data_deps",
"data_keys",
"deps",
"output_conversion",
"outputs",
"public_deps",
"rebase",
"testonly",
"visibility",
])
if (!defined(outputs)) {
outputs = [ target_gen_dir + "/" + target_name ]
}
walk_keys = [ "package_barrier" ]
}
}
# Defines package metadata.
#
# This metadata is collected by `generate_package_metadata`.
# The caller should add a dep on the given target name for the metadata to take effect.
#
# Parameters (see `generate_package_metadata` for full definitions)
#
# package_name (required)
# snapshot_entry (required)
# blob_manifest (required)
# meta_far_merkle_index_entry (required)
# package_output_manifest (required)
# testonly (optional)
# visibility (optional)
template("define_package_metadata") {
assert(defined(invoker.package_name), "Missing package_name")
assert(defined(invoker.snapshot_entry), "Missing snapshot_entry")
assert(defined(invoker.blob_manifest), "Missing blob_manifest")
assert(defined(invoker.meta_far_merkle_index_entry),
"Missing meta_far_merkle_index_entry")
assert(defined(invoker.package_output_manifest),
"Missing package_output_manifest")
group(target_name) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
metadata = {
package_names = [ invoker.package_name ]
snapshot_entries = [ invoker.snapshot_entry ]
blob_manifests = [ rebase_path(invoker.blob_manifest, root_build_dir) ]
meta_far_merkle_index_entries = [ invoker.meta_far_merkle_index_entry ]
package_output_manifests = [ invoker.package_output_manifest ]
}
}
}
# Generate meta/package file.
#
# Parameters
#
# package_name (required)
# testonly
# visibility
template("generate_meta_package") {
generated_resource(target_name) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
contents = "{\"name\":\"${invoker.package_name}\",\"version\":\"0\"}"
outputs = [ "meta/package" ]
}
}
# Generate the `declared_subpackages` file, which will be passed to `pm build`
# with the optional flag `-subpackages <file>`. `pm build` will parse this file
# and generate a `meta/fuchsia.pkg/subpackages` file.
#
# Each subpackage entry includes either an explicit name or a path to a file
# containing the default package name for the subpackage, and a path to the
# subpackage's merkle.
#
# Parameters
#
# subpackages (required)
# testonly
# visibility
template("generate_meta_subpackages") {
rebased_subpackages = []
subpackage_targets = []
foreach(subpackage, invoker.subpackages) {
# name = "" # subpackage name, if explicitly provided
# meta_package_file = "" # to retrieve the package name, if no subpackage name
if (defined(subpackage.name)) {
name = subpackage.name
} else {
package_outputs = []
package_outputs = get_target_outputs(subpackage.package + "_meta_package")
meta_package_file = rebase_path(package_outputs[0], root_build_dir)
}
merkle_file = rebase_path(
get_label_info(subpackage.package, "target_out_dir") + "/" +
get_label_info(subpackage.package, "name") + "/meta.far.merkle",
root_build_dir)
rebased_subpackages += [
{
if (defined(name)) {
name = name
} else {
meta_package_file =
meta_package_file # to get the subpackage package name
}
merkle_file = merkle_file # to get the subpackage package hash
},
]
subpackage_targets += [ subpackage.package ]
}
generated_resource(target_name) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
contents = rebased_subpackages
outputs = [ "target_subpackages.json" ]
output_conversion = "json"
deps = subpackage_targets
}
}