blob: b7f368e864eb6f704af068fa96b9e8a9d11fd920 [file] [log] [blame] [edit]
# Copyright 2023 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/config/compiler.gni")
import("//build/config/fuchsia/platform_version.gni")
import("//build/sdk/config.gni")
import("//build/sdk/idk.gni")
import("//build/sdk/idk_archive.gni")
import("//build/toolchain/goma.gni")
import("//build/toolchain/rbe.gni")
import("//sdk/config.gni")
# Generate a final Fuchsia IDK archive, which merges outputs from different
# arch-specific sub-builds into a single one. The generated archive will
# include prebuilts for x64 and arm64 libraries. On a host Linux machine, the
# generated archive will have host tools for both Linux/x64 and Linux/arm64.
#
# The generated archive will go into
# $root_build_dir/sdk/archive/{output_name}.tar.gz
#
# This template also creates two implicit targets which can be used
# internally, or during local development:
#
# - ${target_name}.exported target that will only create the final export
# directory, under $root_build_dir/sdk/exported/{output_name}, without
# validating its content or creating a compressed archive.
#
# - ${target_name}.validation that will validate the exported directory
# content, without creating the compressed archive.
#
# Arguments:
# target_cpus: (optional)
# List of target cpu names. This must include the default target_cpu
# value for the current build configuration. Defaults to `idk_target_cpus`.
#
# sdk_collection_label: (required)
# A single sdk_collection() GN target that will be built for several CPU
# architectures and API levels, and merged into the final archive.
#
# final_validation_target_labels: (optional)
# List of labels to a targets used to validate the content of the final
# exported directory before the archive is created. These targets should
# only depend on the ${target_name}.exported target, not the main one which
# builds the compressed archive.
#
# extra_api_levels: (optional)
# List of extra API levels, as integers, to build prebuilts for, in
# addition to the current (HEAD) one. The default value depends on the
# global sdk_with_all_supported_api_levels variable. If true, then
# the default will be platform_version.supported_fuchsia_api_levels,
# otherwise it will be empty.
#
# output_name: (optional)
# Name of the archive, without a .tar.gz suffix. Default is target_name
#
# testonly, visibility
# Usual GN meaning.
#
template("generate_final_idk") {
assert(defined(invoker.sdk_collection_label),
"sdk_collection_label must be defined for $target_name")
_archive_target = "${target_name}.archive"
_exported_dir_target = "${target_name}.exported"
_validation_target = "${target_name}.validation"
# Compute the list of target_cpu values that will require a sub-build
# directory.
if (defined(invoker.target_cpus)) {
_target_cpus = invoker.target_cpus
} else {
_target_cpus = idk_target_cpus
}
# Determine output archive location
_output_name = target_name
if (defined(invoker.output_name)) {
_output_name = invoker.output_name
}
if (defined(invoker.extra_api_levels)) {
_extra_api_levels = invoker.extra_api_levels
} else if (sdk_with_all_supported_api_levels) {
_extra_api_levels = platform_version.supported_fuchsia_api_levels
} else {
_extra_api_levels = []
}
# Run the script to generate the exported directory.
# This only contains symlinks to the real files, but can
# be used by other targets that need to use it without
# a full archive.
idk(_exported_dir_target) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
output_name = _output_name
sdk_collection_label = invoker.sdk_collection_label
target_cpus = _target_cpus
api_levels = _extra_api_levels
}
group(_validation_target) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
deps = [ ":" + _exported_dir_target ]
if (defined(invoker.final_validation_target_labels)) {
deps += invoker.final_validation_target_labels
}
}
idk_archive(_archive_target) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
idk = ":${_exported_dir_target}"
idk_output_name = _output_name
}
group(target_name) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
deps = [
":${_archive_target}",
":${_validation_target}",
]
}
}