blob: bdf9097b60ed58e1217b110e6ea57eb9953110cb [file] [log] [blame]
# Copyright 2022 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("//build/dart/config.gni")
# This template provides a way to wrap a Dart test component in a Rust component
# parent, using Rust RealmBuilder APIs to route capabilities to the Dart test.
# Fuchsia's test manager supports Component Framework v2 ELF binaries (in C++
# and Rust) but does not yet support direct execution of Dart-based test
# components. When the upcoming Dart Test Runner is fully supported, this
# wrapper will no longer be needed.
#
# Arguments:
# * dart_test_component_name (required) - The target_name from
# `dart_test_component("target_name")`.
# * component_name (optional) - The target_name to be used by the generated
# fuchsia_component("target_name"). If not provided, the template
# target_name is used by default.
# * manifest (optional) - The path to the wrapper component manifest. If not
# provided, it is assumed to be the relative path:
# `meta/${wrapper_component_name}.cml`
# * wrapper_binary (optional) - The name of the wrapper binary. If not
# provided, it is assumed to be the same as the `wrapper_component_name`
#
# Example:
# import("//src/dart/testing/dart_test_wrapper_component.gni")
#
# dart_test_component("my-dart-test-component") {
# manifest = "meta/my-dart-tests.cml"
# null_safe = true
# # dart_test_component sources are implicitly found in the `test` subdirectory.
# sources = [ "my_dart_tests.dart" ]
# deps = [ ... ]
# }
#
# dart_test_wrapper_component("my_test_realm") {
# dart_test_component_name = "my-dart-test-component"
# }
#
# fuchsia_test_package("my_dart_test_package") {
# test_components = [ ":my_test_realm" ]
# deps = [ ":my-dart-test-component" ]
# }
template("dart_test_wrapper_component") {
assert(
defined(invoker.dart_test_component_name),
"The `dart_test_component_name` argument was missing when calling dart_test_wrapper_component($target_name)")
dart_test_component_name = invoker.dart_test_component_name
wrapper_component_name = target_name
if (defined(invoker.component_name)) {
wrapper_component_name = invoker.component_name
}
wrapper_component_manifest = "meta/${wrapper_component_name}.cml"
if (defined(invoker.manifest)) {
wrapper_component_manifest = invoker.manifest
}
wrapper_binary = wrapper_component_name
if (defined(invoker.wrapper_binary)) {
wrapper_binary = invoker.wrapper_binary
}
wrapper_dir = "//src/dart/testing"
config("dart_runner_rust_cfg") {
if (dart_default_build_cfg.is_aot) {
rustflags = [ "--cfg=use_dart_aot_runner" ]
}
}
config("${wrapper_component_name}_env") {
rustenv = [ "DART_TEST_COMPONENT_NAME=${dart_test_component_name}" ]
}
rustc_test("${wrapper_binary}_bin") {
output_name = wrapper_binary
source_root = "${wrapper_dir}/dart_test_wrapper_realm.rs"
deps = [
"//examples/fidl/fuchsia.examples:fuchsia.examples-rustc",
"//sdk/fidl/fuchsia.cobalt:fuchsia.cobalt-rustc",
"//sdk/fidl/fuchsia.component.decl:fuchsia.component.decl-rustc",
"//sdk/fidl/fuchsia.feedback:fuchsia.feedback-rustc",
"//sdk/fidl/fuchsia.hardware.power.statecontrol:fuchsia.hardware.power.statecontrol-rustc",
"//sdk/fidl/fuchsia.intl:fuchsia.intl-rustc",
"//sdk/fidl/fuchsia.io:fuchsia.io-rustc",
"//sdk/fidl/fuchsia.logger:fuchsia.logger-rustc",
"//sdk/fidl/fuchsia.modular:fuchsia.modular-rustc",
"//sdk/fidl/fuchsia.modular.internal:fuchsia.modular.internal-rustc",
"//sdk/fidl/fuchsia.posix.socket:fuchsia.posix.socket-rustc",
"//sdk/fidl/fuchsia.process.lifecycle:fuchsia.process.lifecycle-rustc",
"//sdk/fidl/fuchsia.sys:fuchsia.sys-rustc",
"//sdk/fidl/fuchsia.sys2:fuchsia.sys2-rustc",
"//sdk/fidl/fuchsia.tracing.provider:fuchsia.tracing.provider-rustc",
"//sdk/fidl/fuchsia.ui.policy:fuchsia.ui.policy-rustc",
"//src/lib/fidl/rust/fidl",
"//src/lib/fuchsia",
"//src/lib/fuchsia-async",
"//src/lib/fuchsia-component",
"//src/lib/fuchsia-component-test",
"//src/lib/storage/vfs/rust:vfs",
"//src/sys/lib/cm_rust",
"//src/sys/lib/component-events",
"//third_party/rust_crates:anyhow",
"//third_party/rust_crates:futures",
"//third_party/rust_crates:tracing",
]
sources = [ "${wrapper_dir}/dart_test_wrapper_realm.rs" ]
configs += [
":dart_runner_rust_cfg",
":${wrapper_component_name}_env",
]
disable_clippy = true # TODO(fxbug.dev/86506): clippy needs env vars
}
fuchsia_component(wrapper_component_name) {
testonly = true
manifest = wrapper_component_manifest
deps = [ ":${wrapper_binary}_bin" ]
}
}