blob: 26912bce754fbb9b8298ee65be2e90863370e386 [file] [log] [blame]
# Copyright 2021 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/sdk/sdk_atom.gni")
# Creates an SDK atom so that sources can be exported to the CTS SDK.
# This should not be called directly, but through the other CTS build rules.
#
# Parameters
# dest (optional)
# Location to copy this target to in the CTS archive.
# Dest should only be specified if the target is not in //sdk/cts. If the
# target is in //sdk/cts, it will be placed in the same path in the CTS
# archive.
# Type: string
template("cts_source_library") {
if (defined(invoker.dest)) {
file_base = invoker.dest
} else {
path = get_label_info(":${target_name}", "dir")
# No need to specify 'dest' if the sources are in //sdk/cts (CTS at TOT)
# or a previously released CTS archive (//prebuilt/cts/...)
if (string_replace(path, "//sdk/cts", "") == path &&
string_replace(path, "//prebuilt/cts", "") == path) {
assert(defined(invoker.dest),
"dest must be defined if the source file is not in //sdk/cts")
}
file_base = ""
if (path != "//sdk/cts") {
file_base = string_replace(path, "//sdk/cts/", "")
}
}
main_target_name = target_name
sdk_target_name = target_name + "_sdk"
sdk_deps = []
sdk_files = []
sdk_metadata_headers = []
sdk_metadata_sources = []
sdk_metas = []
all_sources = []
if (defined(invoker.sources)) {
all_sources += invoker.sources
}
if (defined(invoker.public)) {
all_sources += invoker.public
}
all_deps = []
if (defined(invoker.deps)) {
all_deps += invoker.deps
}
if (defined(invoker.public_deps)) {
all_deps += invoker.public_deps
}
foreach(dep, all_deps) {
full_label = get_label_info(dep, "label_no_toolchain")
sdk_dep = "${full_label}_sdk"
sdk_deps += [ sdk_dep ]
gen_dir = get_label_info(sdk_dep, "target_gen_dir")
name = get_label_info(sdk_dep, "name")
sdk_metas += [ rebase_path("$gen_dir/$name.meta.json", root_build_dir) ]
}
foreach(file, all_sources) {
extension = get_path_info(file, "extension")
destination = "${file_base}/${file}"
if (extension == "h") {
sdk_metadata_headers += [ destination ]
} else {
sdk_metadata_sources += [ destination ]
}
sdk_files += [
{
source = file
dest = destination
},
]
}
metadata_file = "${target_gen_dir}/${target_name}.sdk_meta.json"
metadata_target_name = "${target_name}_metadata"
action(metadata_target_name) {
forward_variables_from(invoker, [ "testonly" ])
script = "//sdk/cts/build/scripts/gen_cts_meta_file.py"
outputs = [ metadata_file ]
args = [
"--out",
rebase_path(metadata_file, root_build_dir),
"--name",
target_name,
"--root",
file_base,
"--include-dir",
"${file_base}/include",
]
args += [ "--deps" ] + sdk_metas
args += [ "--sources" ] + sdk_metadata_sources
args += [ "--headers" ] + sdk_metadata_headers
deps = sdk_deps
}
sdk_atom(sdk_target_name) {
forward_variables_from(invoker, [ "testonly" ])
category = "cts"
id = "sdk://tests/${main_target_name}"
meta = {
source = metadata_file
dest = "${file_base}/json/${main_target_name}/meta.json"
schema = "cts_source_library"
}
deps = sdk_deps
files = sdk_files
non_sdk_deps = [
":${main_target_name}",
":${metadata_target_name}",
]
if (defined(invoker.non_cts_deps)) {
non_sdk_deps += invoker.non_cts_deps
}
}
}