blob: d6b30132c1c88cfd602369a3a5e1199135b35169 [file] [log] [blame]
# Copyright 2018 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/packages/package_metadata.gni")
# Generates package metadata from a prebuilt FAR archive.
#
# Parameters
#
# archive (required)
# Path to archive containing a package.
#
# package_name (optional)
# Name of the package.
# Defaults to the target's name.
#
# repository (optional)
# The repository host name part of the package URL. Defaults to "fuchsia.com".
# See https://fuchsia.dev/fuchsia-src/concepts/packages/package_url#repository
# for more details.
# Type: string
# Default: fuchsia.com
#
# deps (optional)
# testonly (optional)
# visibility (optional)
# Usual GN meanings.
#
template("prebuilt_package") {
if (!defined(invoker.package_name)) {
invoker.package_name = target_name
}
repository = "fuchsia.com"
if (defined(invoker.repository)) {
repository = invoker.repository
}
pkg_out_dir = "$target_out_dir/$target_name"
_out_blobs_json = "$pkg_out_dir/blobs.json"
_out_blobs_manifest = "$pkg_out_dir/blobs.manifest"
_out_package_manifest_json = "$pkg_out_dir/package_manifest.json"
_out_meta_merkle = "$pkg_out_dir/meta.far.merkle"
define_package_metadata_target = "${target_name}_metadata"
define_package_metadata(define_package_metadata_target) {
_pkg_version_key = "${invoker.package_name}/0"
_blobs_json = rebase_path(_out_blobs_json, root_build_dir)
_meta_merkle = rebase_path(_out_meta_merkle, root_build_dir)
blob_manifest = _out_blobs_manifest
meta_far_merkle_index_entry = "$_pkg_version_key=$_meta_merkle"
package_name = invoker.package_name
package_output_manifest = _out_package_manifest_json
snapshot_entry = "$_pkg_version_key=$_blobs_json"
}
main_target_name = target_name
manifest_target_name = "${target_name}.manifest"
group(manifest_target_name) {
forward_variables_from(invoker, [ "testonly" ])
public_deps = [ ":$main_target_name" ]
}
action(target_name) {
forward_variables_from(invoker,
[
"metadata",
"testonly",
"visibility",
])
archive = invoker.archive
if (defined(visibility)) {
visibility += [ ":$manifest_target_name" ]
}
script = "//build/packages/prebuilt_package.py"
pm = "$host_out_dir/pm"
args = [
"--pm-tool",
rebase_path(pm, root_build_dir),
"--name",
invoker.package_name,
"--archive",
rebase_path(archive, root_build_dir),
"--workdir",
rebase_path(pkg_out_dir, root_build_dir),
"--repository",
repository,
]
inputs = [
archive,
pm,
]
outputs = [
_out_blobs_manifest,
_out_blobs_json,
_out_package_manifest_json,
_out_meta_merkle,
]
deps = [
":$define_package_metadata_target",
"//src/sys/pkg/bin/pm:pm_bin($host_toolchain)",
]
if (defined(invoker.deps)) {
deps += invoker.deps
}
# Outputs seem nondeterministic, or contain timestamps.
# Specifically (inside PACKAGE.meta):
# blobs.manifest
# blobs.json
# package_manifest.json
repeatable = false
}
}