blob: 6b6d2b0f4bac7689bb56811f229b68df9da3cb95 [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.
import("//build/bazel/bazel_inputs.gni")
import("//build/python/python_action.gni")
import("//build/zircon/tools.gni")
# Creates a directory of platform artifacts that can be shipped to out-of-tree
# customers.
#
# Arguments
#
# check_production_eligibility (optional)
# [boolean] Whether to check that the inputs to these platform artifacts are suitable for
# production builds.
#
# deps (optional)
# [list] Deps to metadata walk to find the platform artifacts which will
# be copied into the output directory.
#
# version (required)
# [string] Release version for these platform artifacts.
#
template("platform_artifacts") {
assert(defined(invoker.version),
"platform_artifacts(\"target_name\") must define `version`")
artifacts_name = target_cpu
files = {
aib_list = "$target_out_dir/$target_name/aib_list.json"
platform_artifacts = "$target_out_dir/$target_name/platform_artifacts"
depfile = "$target_out_dir/$target_name.depfile"
}
labels = {
aib_list = "${target_name}.aib_list"
platform_artifacts = "${target_name}.platform_artifacts"
bazel_inputs = "${target_name}.bazel_inputs"
}
_check_production_eligibility =
defined(invoker.check_production_eligibility) &&
invoker.check_production_eligibility
generated_file(labels.aib_list) {
forward_variables_from(invoker,
[
"deps",
"testonly",
"visibility",
])
outputs = [ files.aib_list ]
data_keys = [ "assembly_input_bundles" ]
walk_keys = [ "assembly_input_bundles_barrier" ]
output_conversion = "json"
}
python_action(labels.platform_artifacts) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
hermetic_deps = false
hermetic_action_ignored_prefixes = [ "${files.platform_artifacts}" ]
binary_label = "//build/assembly/scripts:generate_platform_artifacts"
outputs = [ "${files.platform_artifacts}/platform_artifacts.json" ]
deps = [ ":${labels.aib_list}" ]
depfile = files.depfile
args = [
"--name",
artifacts_name,
"--aib-list",
rebase_path(files.aib_list, root_build_dir),
"--repo",
"fuchsia",
"--outdir",
rebase_path(files.platform_artifacts, root_build_dir),
"--depfile",
rebase_path(files.depfile, root_build_dir),
]
if (invoker.version != "") {
args += [
"--version",
invoker.version,
]
}
fvm_tool_target = "//src/storage/bin/fvm($host_toolchain)"
fvm_tool_path = get_label_info(fvm_tool_target, "root_out_dir") + "/fvm"
cmc_tool_target = "//tools/cmc($host_toolchain)"
cmc_tool_path = get_label_info(cmc_tool_target, "root_out_dir") + "/cmc"
assembly_tool_target = "//build/assembly/tools/assembly($host_toolchain)"
assembly_tool_path =
get_label_info(assembly_tool_target, "root_out_dir") + "/assembly"
# Add all the platform host tools.
deps += [
assembly_tool_target,
blobfs_tool_target,
cmc_tool_target,
fvm_tool_target,
zbi_tool_target,
]
inputs = [
assembly_tool_path,
blobfs_tool_path,
fvm_tool_path,
zbi_tool_path,
cmc_tool_path,
]
args += [
"--tools",
rebase_path(assembly_tool_path, root_build_dir),
rebase_path(blobfs_tool_path, root_build_dir),
rebase_path(fvm_tool_path, root_build_dir),
rebase_path(zbi_tool_path, root_build_dir),
rebase_path(cmc_tool_path, root_build_dir),
]
}
bazel_input_directory(labels.bazel_inputs) {
forward_variables_from(invoker, [ "testonly" ])
generator = ":${labels.platform_artifacts}"
output_directory = files.platform_artifacts
gn_targets_name = labels.bazel_inputs
}
group(target_name) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
deps = [ ":${labels.bazel_inputs}" ]
# Make the platform artifacts available to upstream dependencies.
public_deps = [ ":${labels.platform_artifacts}" ]
if (_check_production_eligibility) {
assert_no_deps = [ "//build/validate:non_production_tag" ]
}
metadata = {
package_barrier = []
platform_artifacts = [
{
name = artifacts_name
path = rebase_path(files.platform_artifacts, root_build_dir)
label = get_label_info(target_name, "label_no_toolchain")
},
]
}
}
}