blob: c2cdfe4d97a90e30e3845752d3dc907fe929a3e8 [file] [log] [blame]
# Copyright 2021 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Defines a Rust unit tests group.
#
# This generates a script that wraps 1 or more Rust unit test executables.
# Such script would typically wrap all Rust unit tests from a set of related
# crates (e.g. all crates under //base).
#
# The script is primarily useful to enable running the tests on Chromium bots,
# but it is also a convenience for having a single entry point for running
# the tests locally (without having to manually fan out to all the individual
# executables).
#
# Parameters:
#
# deps - Will be recursively traversed to discover all the Rust unit test
# executables.
#
# Example usage:
#
# # This will generate a script at out/Default/bin/run_foo_tests (or
# # run_foo_tests.bat on Windows) that wraps the executables containing
# # native Rust unit tests:
# # * out/Default/foo_crate1_unittests
# # * out/Default/foo_mixed_source_set2_rs_unittests
# # * out/Default/foo_mixed_source_set3_rs_unittests
# rust_unit_tests_group("foo_tests") {
# deps = [
# "foo_crate1",
# "foo_mixed_source_set2",
# "foo_mixed_source_set3",
# ]
# }
template("rust_unit_tests_group") {
assert(defined(invoker.deps), "deps must be listed")
# As noted in the top-level comment of //testing/buildbot/gn_isolate_map.pyl
# the script *must* be in output_dir/bin/run_$target (or
# output_dir\bin\run_$target.bat on Windows).
bat = ""
if (is_win) {
bat = ".bat"
}
_script_filepath = "$root_out_dir/bin/run_${target_name}${bat}"
# Gathering metadata provided by the rust_unit_test gni template from all of
# our dependencies.
_metadata_target_name = "${target_name}_metadata"
_metadata_filepath = "$root_build_dir/${target_name}__rust_unittest_exes.txt"
generated_file(_metadata_target_name) {
forward_variables_from(invoker, [ "deps" ], [])
testonly = true
outputs = [ _metadata_filepath ]
data_keys = [ "rust_unit_test_executables" ]
}
# Generating a script that can run all of the wrapped Rust unit test
# executables.
action(target_name) {
forward_variables_from(invoker, "*", [])
testonly = true
script = "//testing/scripts/rust/generate_script.py"
inputs = [ _metadata_filepath ]
outputs = [ _script_filepath ]
data = [ _script_filepath ]
if (!defined(data_deps)) {
data_deps = []
}
data_deps += [ "//testing/scripts/rust" ]
data_deps += deps
deps += [ ":$_metadata_target_name" ]
args = [
"--rust-test-executables",
rebase_path(_metadata_filepath, root_build_dir),
"--exe-dir",
rebase_path(root_out_dir, root_build_dir),
"--script-path",
rebase_path(_script_filepath, root_build_dir),
]
if (is_win) {
args += [ "--make-bat" ]
}
}
}