blob: 9f220f7f72e7b131c9edc2f90227ae2f61496fe9 [file] [log] [blame]
# 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("config.gni") # icu_flavors, icu_fixup_deps
# An ICU-aware source_set.
#
# Args:
#
# - icu_deps: list(label): the target labels that need to be fixed up for
# ICU product assembly. Otherwise the same as deps.
# - icu_public_deps: list(label): Same as above, but for public_deps
#
# All other args are forwarded verbatim from the invoker.
template("icu_source_set") {
foreach(icu_flavor, icu_flavors) {
# While we could make do with shorter target labels, we're using a per-ICU
# commit ID so that we could possibly use targets from different builds.
source_set(
"${target_name}.icu_${icu_flavor.name}_${icu_flavor.commit_id}") {
# Do not forward variables which the template does not support. In addition,
# treat "visibility" and "testonly" as special.
forward_variables_from(invoker,
"*",
[
"visibility",
"testonly",
"icu_deps",
"icu_public_deps",
"target_name", # Workaround for
# https://fxbug.dev/42083609.
])
forward_variables_from(invoker,
[
"visibility",
"testonly",
])
# Ensure that we preserve the toolchain when adding dependencies.
_flavored_icu_deps = [
get_label_info("//third_party/icu/${icu_flavor.name}:icu",
"label_with_toolchain"),
get_label_info("//third_party/icu/${icu_flavor.name}:icudata",
"label_with_toolchain"),
]
not_needed([
"icu_flavor",
"_flavored_icu_deps",
])
if (defined(invoker.icu_deps)) {
if (!defined(deps)) {
deps = []
}
# Replace the ICU dependencies with a direct dependency on a flavored
# version of the same dependency.
deps += icu_fixup_deps + _flavored_icu_deps
deps -= icu_fixup_deps
foreach(icu_dep, invoker.icu_deps) {
# Fully resolve labels like "//foo/bar" to "//foo/bar:bar", so that
# ICU fixup doesn't change the leaf directory name.
_relabel = get_label_info(icu_dep, "label_no_toolchain")
deps +=
# TODO(fmil): Should this refer to the toolchain?
[ "${_relabel}.icu_${icu_flavor.name}_${icu_flavor.commit_id}(${current_toolchain})" ]
}
}
# Similar to above, but for public_deps.
if (defined(invoker.icu_public_deps)) {
if (!defined(public_deps)) {
public_deps = []
}
public_deps += icu_fixup_deps + _flavored_icu_deps
public_deps -= icu_fixup_deps
foreach(icu_public_dep, invoker.icu_public_deps) {
_relabel = get_label_info(icu_public_dep, "label_no_toolchain")
public_deps += [ "${_relabel}.icu_${icu_flavor.name}_${icu_flavor.commit_id}(${current_toolchain})" ]
}
}
}
}
# The original source set, with the original target name.
source_set(target_name) {
# Do not forward variables that this template does not support.
forward_variables_from(invoker,
"*",
[
"visibility",
"testonly",
"icu_deps",
"icu_public_deps",
])
forward_variables_from(invoker,
[
"visibility",
"testonly",
])
if (defined(invoker.icu_deps)) {
if (!defined(deps)) {
deps = []
}
deps += invoker.icu_deps
}
if (defined(invoker.icu_public_deps)) {
if (!defined(public_deps)) {
public_deps = []
}
public_deps += invoker.icu_public_deps
}
}
}