| # 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}", |
| |
| # 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}_llcpp" ] |
| } |
| } |
| |
| # Go Source Compatibility Test |
| template("_go_compat") { |
| gopackage = target_name |
| |
| go_library("${target_name}_lib") { |
| name = gopackage |
| source_dir = get_path_info(invoker.source, "dir") |
| sources = [ get_path_info(invoker.source, "file") ] |
| deps = [ |
| ":${invoker.fidl}($go_toolchain)", |
| "//src/lib/component", |
| ] |
| } |
| |
| go_binary(target_name) { |
| output_dir = target_out_dir |
| gopackage = gopackage |
| deps = [ ":${target_name}_lib" ] |
| } |
| } |
| |
| # Rust Source Compatibility Test |
| template("_rust_compat") { |
| rustc_binary(target_name) { |
| output_dir = target_out_dir |
| edition = "2018" |
| deps = [ |
| ":${invoker.fidl}-rustc", |
| "//src/lib/fidl/rust/fidl", |
| "//src/lib/fuchsia-async", |
| "//third_party/rust_crates:futures", |
| ] |
| sources = [ invoker.source ] |
| source_root = invoker.source |
| } |
| } |
| |
| # 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_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] ] |
| excluded_checks = [ "too-many-nested-libraries" ] |
| } |
| } |
| |
| 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}_llcpp") { |
| tmp = transitions.llcpp |
| starting_fidl = tmp.starting_fidl |
| starting_src = tmp.starting_src |
| steps = tmp.steps |
| template_name = "_llcpp_compat" |
| } |
| test_targets += [ ":${target_name}_llcpp" ] |
| } |
| |
| # 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 |
| } |
| } |