blob: c652b35245d97fa284898bf64a99b68d32ecd4fc [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")
# 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.
#
# 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") {
if (current_toolchain == default_toolchain) {
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" ]
# TODO(fxbug.dev/76528) Support fuzzers in v2 testing.
v2 = false
}
group(meta_target_name) {
testonly = true
deps = invoker.deps + [ "//build/fuzzing:includes_cmx" ]
metadata = {
test_component_manifest_cmx = [
{
forward_variables_from(invoker, [ "include" ])
program = {
if (defined(invoker.options)) {
args = []
foreach(option, invoker.options) {
args += [ "-$option" ]
}
}
}
},
]
fuzz_spec = [
{
label = invoker.label
fuzzer = invoker.fuzzer
manifest = get_target_outputs(":${invoker.target_name}")
manifest = get_path_info(manifest[0], "file")
},
]
}
}
} else {
group(target_name) {
testonly = true
deps = [ ":$target_name($default_toolchain)" ]
}
not_needed(invoker, "*")
}
}