blob: a907e28655dc7cbbf8b0c09a69473a64351c96ad [file] [log] [blame]
# Copyright 2020 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/components.gni")
import("//sdk/cts/build/cts_copy_to_sdk.gni")
import("//sdk/cts/build/cts_element.gni")
import("//sdk/cts/build/cts_version.gni")
import("//sdk/cts/build/write_cts_file.gni")
# A Fuchsia component that can be used in CTS.
#
# An equivalent to fuchsia_component, but ensures dependencies are allowed in CTS.
# Creates an SDK atom so that this target can be released in the CTS SDK.
#
# Example:
# ```
# cts_fuchsia_component("my-test-component") {
# deps = [ ":my-test" ]
# manifest = "meta/my-test.cml"
# testonly = true
# }
# ```
#
# 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
#
# prebuilt_only (optional)
# Indicates whether a test is an ABI only test. When true, the template does
# not create an _sdk target.
# Type: bool
template("cts_fuchsia_component") {
assert(
defined(invoker.manifest),
"`manifest` must be specified when calling cts_fuchsia_component($target_name)")
assert(get_path_info(invoker.manifest, "extension") == "cml",
"CTS component manifests must be CFv2.")
if (!defined(invoker.deps)) {
invoker.deps = []
}
if (invoker.deps != [] && cts_version == "") {
verify_target = target_name + "_verify_deps"
}
write_file_target = target_name + "_cts_file"
if (defined(verify_target)) {
cts_element(verify_target) {
deps = invoker.deps
invoker_label = get_label_info(invoker.target_name, "label_no_toolchain")
}
}
write_cts_file(write_file_target) {
}
fuchsia_component(target_name) {
forward_variables_from(invoker,
"*",
[
"dest",
"prebuilt_only",
])
if (defined(verify_target)) {
deps += [ ":$verify_target" ]
}
deps += [ ":$write_file_target" ]
}
current_dir = get_label_info(":${target_name}", "dir")
is_prebuilt_cts =
string_replace(current_dir, "//prebuilt/cts", "") != current_dir ||
(defined(invoker.prebuilt_only) && invoker.prebuilt_only)
if (!is_prebuilt_cts) {
cts_copy_to_sdk(target_name) {
forward_variables_from(invoker,
[
"dest",
"manifest",
"testonly",
])
sources = [ manifest ]
}
}
}