blob: 06bc7c2cb68c9320cfa42189cb691030c758bfc7 [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/fidl/fidl.gni")
import("//build/go/go_binary.gni")
import("//build/go/go_library.gni")
import("//build/rust/rustc_binary.gni")
is_go = current_toolchain == go_toolchain
# HLCPP Compatibility Test
template("_hlcpp_compat") {
executable(target_name) {
output_dir = target_out_dir
sources = [ invoker.source ]
deps = [
":${invoker.fidl}_hlcpp",
# Included for ZX_ASSERT, since assert may get compiled away leading to
# unused variable errors.
"//zircon/system/ulib/zx",
]
}
}
# LLCPP Compatibility Test
template("_llcpp_compat") {
executable(target_name) {
output_dir = target_out_dir
sources = [ invoker.source ]
deps = [ ":${invoker.fidl}_cpp" ]
}
}
# Rust Source Compatibility Test
template("_rust_compat") {
rustc_binary(target_name) {
output_dir = target_out_dir
edition = "2018"
deps = [
":${invoker.fidl}_rust",
"//src/lib/fidl/rust/fidl",
"//src/lib/fuchsia-async",
"//third_party/rust_crates:futures",
]
sources = [ invoker.source ]
source_root = invoker.source
# TODO(https://fxbug.dev/42055130): Avoid this suppression. At the time of
# writing it is needed because not all tests use all these dependencies.
configs += [ "//build/config/rust/lints:allow_unused_crate_dependencies" ]
}
}
if (is_go) {
# Go Source Compatibility Test
template("_go_compat") {
go_library("${target_name}_lib") {
source_dir = get_path_info(invoker.source, "dir")
sources = [ get_path_info(invoker.source, "file") ]
deps = [
":${invoker.fidl}_go($go_toolchain)",
"//src/lib/component",
]
}
go_binary(target_name) {
library = ":${target_name}_lib"
output_dir = target_out_dir
}
}
}
# Take the steps definition supplied and generate targets for each.
# This keeps track of the source and fidl for each step and invokes the
# supplied template_name.
template("_source_compat_steps") {
assert(defined(invoker.starting_fidl))
assert(defined(invoker.starting_src))
assert(defined(invoker.steps))
assert(defined(invoker.template_name))
assert(defined(invoker.fidl_targets))
fidl_targets = invoker.fidl_targets
step_labels = []
# initial state
step_source = invoker.starting_src
step_fidl = invoker.starting_fidl
init_step_label =
"${target_name}_${step_fidl}_" + get_path_info(step_source, "name")
step_labels += [ ":${init_step_label}" ]
target(invoker.template_name, init_step_label) {
source = step_source
fidl = fidl_targets[step_fidl]
}
# subsequent transition states
foreach(step, invoker.steps) {
# exactly one of source or fidl must be declared
assert((defined(step.source) || defined(step.fidl)) &&
!(defined(step.source) && defined(step.fidl)),
"Exactly one of 'source' or 'fidl' must be specified for each step")
if (defined(step.source)) {
step_source = step.source
} else {
step_fidl = step.fidl
}
step_label =
"${target_name}_${step_fidl}_" + get_path_info(step_source, "name")
step_labels += [ ":${step_label}" ]
target(invoker.template_name, step_label) {
source = step_source
fidl = fidl_targets[step_fidl]
}
}
group(target_name) {
deps = step_labels
}
}
template("source_compatibility_test") {
test_name = target_name
assert(defined(invoker.json),
"You must supply a json file describing the test.")
assert(defined(invoker.sidecar), "You must supply a json sidecar file.")
json_sidecar = invoker.sidecar
sidecar = read_file(json_sidecar, "json")
fidls = sidecar.fidl_names
fidl_targets = sidecar.fidl_targets
fidl_sources = sidecar.fidl_sources
fidl_library = "fidl.test.${test_name}"
# FIDL libraries
foreach(fidl, fidls) {
fidl(fidl_targets[fidl]) {
name = fidl_library
sources = [ fidl_sources[fidl] ]
enable_hlcpp = true
disable_rustdoc = true
}
}
test_targets = []
if (is_fuchsia) {
json_file = invoker.json
json = read_file(json_file, "json")
transitions = json.bindings
# HLCPP
if (defined(transitions.hlcpp)) {
_source_compat_steps("${target_name}_hlcpp") {
tmp = transitions.hlcpp
starting_fidl = tmp.starting_fidl
starting_src = tmp.starting_src
steps = tmp.steps
template_name = "_hlcpp_compat"
}
test_targets += [ ":${target_name}_hlcpp" ]
}
# LLCPP
if (defined(transitions.llcpp)) {
_source_compat_steps("${target_name}_cpp") {
tmp = transitions.llcpp
starting_fidl = tmp.starting_fidl
starting_src = tmp.starting_src
steps = tmp.steps
template_name = "_llcpp_compat"
}
test_targets += [ ":${target_name}_cpp" ]
}
if (is_go) {
# Go
if (defined(transitions.go)) {
_source_compat_steps("${target_name}_go") {
tmp = transitions.go
starting_fidl = tmp.starting_fidl
starting_src = tmp.starting_src
steps = tmp.steps
template_name = "_go_compat"
}
test_targets += [ ":${target_name}_go($go_toolchain)" ]
}
}
# Rust
if (defined(transitions.rust)) {
_source_compat_steps("${target_name}_rust") {
tmp = transitions.rust
starting_fidl = tmp.starting_fidl
starting_src = tmp.starting_src
steps = tmp.steps
template_name = "_rust_compat"
}
test_targets += [ ":${target_name}_rust" ]
}
} else {
not_needed(invoker, "*")
}
if (toolchain_variant.base == default_toolchain) {
group(target_name) {
deps = test_targets
}
} else {
not_needed([ "test_targets" ])
}
}