blob: 91cecaea64c2dd2923b6f563fb2d6b413e9b0dff [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")
# Produces a (testonly) component with an isolated driver manager to launch drivers. The component
# name will always be `isolated-devmgr`.
#
# Example Usage:
#
# ```
# isolated_devmgr_v2_component("my-component") {
# package_name = "my-package"
# }
#
# fuchsia_package("my-package") {
# deps = [ ":my-component" ]
# }
# ```
# The above component will be accessible when building test realms (via CML or dynamically) as
# `fuchsia-pkg://fuchsia.com/my-package#meta/isolated-devmgr.cm`
#
# `isolated_devmgr_v2_component` may depend on any number of `driver_module()` targets to ensure
# that any `fuchsia_package()` that includes them will include the same drivers.
#
# ```
# driver_module("my_driver") {
# ...
# }
#
# isolated_devmgr_v2_component("my-component") {
# deps = [ ":my_driver" ]
# ...
# }
# ```
#
# The Isolated Device Manager defined above will be able to read my_driver under the path
# "my_driver.so".
#
# Parameters
#
# package_name (required)
# The name of the package in which this component will run.
# Type: string
#
# deps
# visibility
template("isolated_devmgr_v2_component") {
assert(defined(invoker.package_name),
"the package_name where the IsolateDevMgr will run must be defined")
package_name = invoker.package_name
manifest_path = "${target_gen_dir}/meta/isolated-devmgr.cml"
generated_file(manifest_path) {
contents = {
include = [
"sdk/lib/diagnostics/inspect/client.shard.cml",
"sdk/lib/diagnostics/syslog/client.shard.cml",
]
program = {
runner = "elf"
binary = "bin/support"
}
children = [
{
name = "driver-manager-test"
url = "fuchsia-pkg://fuchsia.com/${package_name}#meta/driver-manager-test.cm"
},
]
capabilities = [
{
protocol = [
"fuchsia.boot.Arguments",
"fuchsia.kernel.RootJob",
]
},
]
offer = [
{
protocol = [
"fuchsia.logger.LogSink",
"fuchsia.process.Launcher",
"fuchsia.sys.Launcher",
]
from = "parent"
to = [ "#driver-manager-test" ]
},
{
protocol = [
"fuchsia.boot.Arguments",
"fuchsia.kernel.RootJob",
]
from = "self"
to = [ "#driver-manager-test" ]
},
]
expose = [
{
directory = "dev"
from = "#driver-manager-test"
},
]
}
outputs = [ "$manifest_path" ]
output_conversion = "json"
testonly = true
visibility = [ ":*" ]
}
fuchsia_component(target_name) {
forward_variables_from(invoker, [ "visibility" ])
testonly = true
component_name = "isolated-devmgr"
manifest = manifest_path
deps = []
if (defined(invoker.deps)) {
deps += invoker.deps
}
deps += [
":$manifest_path",
"//src/lib/isolated_devmgr/v2_component:driver-manager-test",
"//src/lib/isolated_devmgr/v2_component:support",
]
}
}
template("isolated_devmgr_unittest_v2_component") {
if (!defined(invoker.manifest)) {
generated_target = "${target_name}_generated_manifest"
manifest = "$target_out_dir/${generated_target}.cml"
package_name = invoker.package_name
generated_file(generated_target) {
contents = {
include = [
"sdk/lib/diagnostics/inspect/client.shard.cml",
"sdk/lib/diagnostics/syslog/client.shard.cml",
]
program = {
if (defined(invoker.runner)) {
runner = invoker.runner
} else {
runner = "gtest_runner"
}
binary = invoker.executable_path
}
children = [
{
name = "isolated-devmgr"
url = "fuchsia-pkg://fuchsia.com/${package_name}#meta/isolated-devmgr.cm"
startup = "eager"
},
]
capabilities = [
{
protocol = "fuchsia.test.Suite"
},
]
use = [
{
protocol = "fuchsia.process.Launcher"
},
{
protocol = "fuchsia.sys2.Realm"
from = "framework"
},
]
offer = [
{
protocol = [
"fuchsia.logger.LogSink",
"fuchsia.process.Launcher",
"fuchsia.sys.Launcher",
]
from = "parent"
to = [ "#isolated-devmgr" ]
},
]
expose = [
{
protocol = "fuchsia.test.Suite"
from = "self"
},
]
}
outputs = [ "$manifest" ]
output_conversion = "json"
testonly = true
visibility = [ ":*" ]
}
}
fuchsia_component(target_name) {
testonly = true
forward_variables_from(invoker,
[
"deps",
"manifest",
"visibility",
"component_name",
])
if (defined(generated_target)) {
deps += [ ":$generated_target" ]
}
}
}