blob: a870193feaf8cb3705bac1081e8e64e39dd468b6 [file] [log] [blame]
# Copyright 2022 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/dist/resource.gni")
import("//src/lib/icu/tzdata/icu_tzres_source.gni")
# Provide ICU time zone resource files to the given package.
#
# The following files will be available in the component's namespace:
#
# * /pkg/tzdata/revision.txt
# * /pkg/tzdata/icu/revision.txt
# * /pkg/tzdata/icu/${data_version}/${format}/revision.txt
# * /pkg/tzdata/icu/${data_version}/${format}/metaZones.res
# * /pkg/tzdata/icu/${data_version}/${format}/timezoneTypes.res
# * /pkg/tzdata/icu/${data_version}/${format}/zoneinfo64.res
#
# We provide several instances of `revision.txt` as the tzdata_provider
# component offers several different flavors of ICU-related capabilities.
#
# For `testonly = true` targets, the rule will add a marker file:
#
# * /pkg/FUCHSIA_IN_TREE_TEST
#
# Please see `README.md` for detailed documentation.
#
# Parameters
#
# data_version (optional)
# Timezone data version.
# Type: string
# Default: 44
#
# format (optional)
# Timezone data format.
# Type: string
# Default: le
template("icu_tzdata_resource") {
data_version = "44"
if (defined(invoker.data_version)) {
data_version = invoker.data_version
}
format = "le"
if (defined(invoker.format)) {
format = invoker.format
}
assert(data_version == "44" && format == "le",
"Unsupported data version or format")
_resources_label = "_${target_name}_resources"
resource(_resources_label) {
forward_variables_from(invoker, [ "testonly" ])
outputs =
[ "data/tzdata/icu/${data_version}/${format}/{{source_file_part}}" ]
sources = [
"${icu_tzres_path}/metaZones.res",
"${icu_tzres_path}/timezoneTypes.res",
"${icu_tzres_path}/zoneinfo64.res",
]
}
_revision_label = "_${target_name}_revision"
resource(_revision_label) {
forward_variables_from(invoker, [ "testonly" ])
deps = [ "//src/lib/icu/tzdata:revision" ]
outputs = [ "data/tzdata/{{source_file_part}}" ]
# get_target_outputs("//src/lib/icu/tzdata:revision") can only be used in
# //src/lib/icu/tzdata/BUILD.gn, so we have to hard-code the file path.
sources = [
# This is usually `out/default/gen/src/lib/icu/tzdata/revision.txt`
"${root_gen_dir}/src/lib/icu/tzdata/revision.txt",
]
}
_revision_versioned_label = "_${target_name}_revision_versioned"
resource(_revision_versioned_label) {
forward_variables_from(invoker, [ "testonly" ])
deps = [ "//src/lib/icu/tzdata:revision" ]
outputs =
[ "data/tzdata/icu/${data_version}/${format}/{{source_file_part}}" ]
# See above.
sources = [
# This is usually `out/default/gen/src/lib/icu/tzdata/revision.txt`
"${root_gen_dir}/src/lib/icu/tzdata/revision.txt",
]
}
_revision_tzdata_icu_versioned_label =
"_${target_name}_tzdata_icu_revision_versioned"
resource(_revision_tzdata_icu_versioned_label) {
forward_variables_from(invoker, [ "testonly" ])
deps = [ "//src/lib/icu/tzdata:revision" ]
outputs = [ "data/tzdata/icu/{{source_file_part}}" ]
# See above.
sources = [ "${root_gen_dir}/src/lib/icu/tzdata/revision.txt" ]
}
# Includes a placeholder file only for test targets.
_test_marker_label = "_${target_name}_test_marker"
resource(_test_marker_label) {
forward_variables_from(invoker, [ "testonly" ])
sources = [ "//src/lib/icu/tzdata/testing/FUCHSIA_IN_TREE_TEST" ]
outputs = [ "data/FUCHSIA_IN_TREE_TEST" ]
}
# tzdata-provider is not `testonly` so it can't depend on the main target.
group("${target_name}_for_tzdata_provider") {
forward_variables_from(invoker, [ "testonly" ])
visibility = [ "//src/intl/tzdata_provider/*" ]
deps = [
":${_resources_label}",
# Used via the `config-data` capability.
":${_revision_label}",
":${_revision_versioned_label}",
# Used via the `tzdata-icu` capability.
":${_revision_tzdata_icu_versioned_label}",
# Used via the `tzdata-icu-44-le` capability.
":${_revision_versioned_label}",
]
}
group(target_name) {
forward_variables_from(invoker, [ "visibility" ])
# Production components should use ICU data from a directory
# exposed by tzdata_provider for storage efficiency and for
# configuration consistency.
# Tests can include whatever data they need in the test package.
testonly = true
deps = [
":${_resources_label}",
# Used via the `config-data` capability.
":${_revision_label}",
# Used via the `tzdata-icu` capability.
":${_revision_tzdata_icu_versioned_label}",
# Used via the `tzdata-icu-44-le` capability.
":${_revision_versioned_label}",
]
if (defined(testonly) && testonly) {
deps += [ ":${_test_marker_label}" ]
}
}
}