| # 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/subbuild.gni") |
| import("//sdk/config.gni") |
| |
| # Calling this template generates a set of action() targets, each one building |
| # the atoms of a given sdk_collection() for a specific CPU architecture and API |
| # levels. This is used by the idk() template. |
| # |
| # The generated actions are named as follows: |
| # |
| # ${target_name}-${cpu} |
| # For the default API level, and each supported ${cpu} |
| # Uses ${root_build_dir}/${subbuild_prefix}-${cpu} as its build directory. |
| # |
| # ${target_name}-api${api_level}-${cpu} |
| # For individual API levels and cpu values. |
| # Uses ${root_build_dir}/${subbuild_prefix}-api${api_level}-${cpu} as |
| # its build directory. |
| # |
| # Each action will depend on sdk_collection_label as well as //sdk:idk_build_tools. |
| # |
| # Note that this does not define a top-level group() target that depends on all of |
| # them. Instead, users like the idk() template should pick the sub-build targets |
| # they need directly. |
| # |
| # Args: |
| # sdk_collection_label (required) |
| # [GN Label] Label of sdk_collection() target to generate sub-builds for. |
| # |
| # subbuild_prefix (optional) |
| # [string] A name prefix for all sub-build directories. Default is |
| # "idk_subbuild.<name>" where <name> is the name of the sdk_collection_label |
| # target. This is useful to differentiatte idk_subbuilds() instances that |
| # reference collections with the same name, but different directories |
| # (e.g. `//sdk:core` and `//vendor/acme/sdk:core`). |
| # |
| # sdk_collection_name (optional) |
| # The name of the collection specified by `sdk_collection_label`. |
| # Should match the name of the collection if it is overridden. |
| # Defaults to the name portion of the `sdk_collection_label`. |
| # |
| template("idk_subbuilds") { |
| main_target_name = target_name |
| |
| if (defined(invoker.subbuild_prefix)) { |
| subbuild_prefix = invoker.subbuild_prefix |
| } else { |
| subbuild_prefix = |
| "idk_subbuild." + get_label_info(invoker.sdk_collection_label, "name") |
| } |
| |
| _api_levels = platform_version.idk_buildable_api_levels |
| _target_cpus = idk_target_cpus_default |
| |
| if (defined(invoker.sdk_collection_name)) { |
| _sdk_collection_dir_name = invoker.sdk_collection_name |
| } else { |
| _sdk_collection_dir_name = |
| get_label_info(invoker.sdk_collection_label, "name") |
| } |
| |
| # First, define subbuild targets for the default API level. |
| foreach(target_cpu, _target_cpus) { |
| _subbuild_target = "${main_target_name}-${target_cpu}" |
| _subbuild_dir_prefix = "${subbuild_prefix}-${target_cpu}" |
| |
| subbuild(_subbuild_target) { |
| target = invoker.sdk_collection_label |
| use_idk_tools_only = true |
| |
| _collection_dir_manifest = |
| "/sdk/exported/${_sdk_collection_dir_name}/meta/manifest.json" |
| outputs = [ _collection_dir_manifest ] |
| |
| api_level_path = "/sdk/exported/${_sdk_collection_dir_name}/api_level" |
| |
| target_cpu = target_cpu |
| api_level = "PLATFORM" |
| build_dir_prefix = _subbuild_dir_prefix |
| |
| # Each subbuild depends on the `sdk_collection` in the main build, so |
| # that when a change happens that would cause the `sdk_collection` to be |
| # rebuilt, that also triggers the subbuilds to be rerun. |
| extra_deps = [ invoker.sdk_collection_label ] |
| |
| forward_variables_from(invoker, |
| [ |
| "testonly", |
| "visibility", |
| ]) |
| } |
| } |
| |
| # Now, define subbuild targets for all individual API levels and CPUs. |
| foreach(api_level, _api_levels) { |
| foreach(target_cpu, _target_cpus) { |
| _subbuild_target = "${main_target_name}-api${api_level}-${target_cpu}" |
| _subbuild_dir_prefix = "${subbuild_prefix}-api${api_level}-${target_cpu}" |
| |
| subbuild(_subbuild_target) { |
| target = invoker.sdk_collection_label |
| use_idk_tools_only = true |
| |
| _collection_dir_manifest = |
| "/sdk/exported/${_sdk_collection_dir_name}/meta/manifest.json" |
| outputs = [ _collection_dir_manifest ] |
| |
| api_level_path = "/sdk/exported/${_sdk_collection_dir_name}/api_level" |
| |
| target_cpu = target_cpu |
| api_level = "$api_level" |
| build_dir_prefix = _subbuild_dir_prefix |
| |
| # Each subbuild depends on the `sdk_collection` in the main build, so |
| # that when a change happens that would cause the `sdk_collection` to be |
| # rebuilt, that also triggers the subbuilds to be rerun. |
| extra_deps = [ invoker.sdk_collection_label ] |
| |
| forward_variables_from(invoker, |
| [ |
| "testonly", |
| "visibility", |
| ]) |
| } |
| } |
| } |
| } |