123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- # Copyright 2021 The Chromium Authors. All rights reserved.
- # 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 that wraps
- # # out/Default/foo_crate1_unittests,
- # # out/Default/foo_mixed_source_set2_rs_unittests,
- # # and out/Default/foo_mixed_source_set3_rs_unittests executables containing
- # # native Rust unit tests.
- # rust_unit_tests_group("foo_tests") {
- # deps = [
- # "foo_crate1",
- # "foo_mixed_source_set2",
- # "foo_mixed_source_set3",
- # ]
- # }
- # # TODO(https://crbug.com/1271215): Mention .bat generation once implemented.
- 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).
- _script_filepath = "$root_out_dir/bin/run_${target_name}"
- # 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.
- #
- # TODO(https://crbug.com/1271215): Also generate: bin/run_${target_name}.bat
- # when *targeting* Windows: if (is_win) { ... }. (The "targeting" part means
- # that we can't just detect whether the build is *hosted* on Windows.)
- action(target_name) {
- forward_variables_from(invoker, "*", [])
- testonly = true
- script = "//testing/scripts/rust/generate_bash_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),
- ]
- }
- }
|