| # 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/dart/dart_library.gni") | |
| import("//build/fidl/fidl.gni") | |
| import("//build/go/go_binary.gni") | |
| import("//build/go/go_library.gni") | |
| import("//build/rust/rustc_binary.gni") | |
| # 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_wire" ] | |
| } | |
| } | |
| # 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 | |
| } | |
| } | |
| # 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/104019): 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" ] | |
| } | |
| } | |
| # Dart Source Compatibility Test | |
| template("_dart_compat") { | |
| copy_target_name = "${target_name}__copy" | |
| dest_dir = get_label_info(":${target_name}", "target_gen_dir") + | |
| "/${target_name}_dart_package" | |
| dest_file = "${dest_dir}/lib/" + invoker.source | |
| copy(copy_target_name) { | |
| sources = [ invoker.source ] | |
| outputs = [ dest_file ] | |
| } | |
| dart_library(target_name) { | |
| infer_package_name = true | |
| package_root = dest_dir | |
| sources = [ invoker.source ] | |
| deps = [ ":${invoker.fidl}_dart(${dart_toolchain})" ] | |
| non_dart_deps = [ ":${copy_target_name}" ] | |
| pubspec = "//src/tests/fidl/source_compatibility/pubspec.yaml" | |
| } | |
| } | |
| # 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] ] | |
| } | |
| } | |
| 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_wire") { | |
| 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_wire" ] | |
| } | |
| # 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" ] | |
| } | |
| # 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" ] | |
| } | |
| # Dart | |
| if (defined(transitions.dart)) { | |
| _source_compat_steps("${target_name}_dart") { | |
| tmp = transitions.dart | |
| starting_fidl = tmp.starting_fidl | |
| starting_src = tmp.starting_src | |
| steps = tmp.steps | |
| template_name = "_dart_compat" | |
| } | |
| test_targets += [ ":${target_name}_dart" ] | |
| } | |
| } else { | |
| not_needed(invoker, "*") | |
| } | |
| group(target_name) { | |
| deps = test_targets | |
| } | |
| } |