blob: d4bebd839e1904655fc4355acbbe35f6c768a1bf [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("//src/sys/build/fuchsia_unittest_component.gni")
# Defines a Fuchsia component for a fuzzer.
# See: https://fuchsia.dev/fuchsia-src/development/components/build
#
# This template extends `fuchsia_component` by automatically generating a fuzzer manifest to act as
# the component manifest. A fuzzer is a binary that generates and tests inputs in a (possibly open-
# ended) loop, looking for evidence of defects (e.g. crashes, memory corruptions, hangs, etc.).
#
# This template is NOT typically used directly. Instead, use templates like `fuzzer` from
# //build/fuzzing/fuzzer.gni
#
# Parameters:
#
# fuzzer (required)
# [string] The name of the fuzzer.
#
# label (required)
# [label] The GN label of the associated fuzzer.
#
# deps (required)
# [list of labels] Same meaning as for `fuchsia_component`, but required. This typically
# includes the fuzzer binary. It may also include the fuzzer corpus and dictionary, when
# present.
#
# features, services (optional)
# [list of strings] Extra (v1) sandbox features/services for the fuzzer and test components.
#
# options (optional)
# [list of strings] Key-value pairs representing libFuzzer options, e.g. "foo=bar". See
# See https://llvm.org/docs/LibFuzzer.html#options.
#
template("fuzzer_component") {
assert(defined(invoker.fuzzer),
"missing 'fuzzer' for fuzzer_component($target_name)")
assert(defined(invoker.label),
"missing 'label' for fuzzer_component($target_name)")
assert(defined(invoker.deps),
"missing 'deps' for fuzzer_component($target_name)")
meta_target_name = "${target_name}_metadata"
fuchsia_unittest_component(target_name) {
forward_variables_from(invoker, [ "visibility" ])
component_name = invoker.fuzzer
deps = invoker.deps + [ ":$meta_target_name" ]
}
group(meta_target_name) {
testonly = true
deps = invoker.deps + [ "//build/fuzzing:fuzzer_includes" ]
metadata = {
test_component_manifest_cmx = [
{
forward_variables_from(invoker, [ "include" ])
program = {
if (defined(invoker.options)) {
args = []
foreach(option, invoker.options) {
args += [ "-$option" ]
}
}
}
sandbox = {
forward_variables_from(invoker,
[
"features",
"services",
])
}
},
]
fuzz_spec = [
{
label = invoker.label
fuzzer = invoker.fuzzer
manifest = get_target_outputs(":${invoker.target_name}")
manifest = get_path_info(manifest[0], "file")
},
]
}
}
}