1 # Copyright 2021 The Chromium Authors
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 # Defines a Rust unit tests group.
7 # This generates a script that wraps 1 or more Rust unit test executables.
8 # Such script would typically wrap all Rust unit tests from a set of related
9 # crates (e.g. all crates under //base).
11 # The script is primarily useful to enable running the tests on Chromium bots,
12 # but it is also a convenience for having a single entry point for running
13 # the tests locally (without having to manually fan out to all the individual
18 # deps - Will be recursively traversed to discover all the Rust unit test
23 # # This will generate a script at out/Default/bin/run_foo_tests (or
24 # # run_foo_tests.bat on Windows) that wraps the executables containing
25 # # native Rust unit tests:
26 # # * out/Default/foo_crate1_unittests
27 # # * out/Default/foo_mixed_source_set2_rs_unittests
28 # # * out/Default/foo_mixed_source_set3_rs_unittests
29 # rust_unit_tests_group("foo_tests") {
32 # "foo_mixed_source_set2",
33 # "foo_mixed_source_set3",
37 template("rust_unit_tests_group") {
38 assert(defined(invoker.deps), "deps must be listed")
40 # As noted in the top-level comment of //testing/buildbot/gn_isolate_map.pyl
41 # the script *must* be in output_dir/bin/run_$target (or
42 # output_dir\bin\run_$target.bat on Windows).
47 _script_filepath = "$root_out_dir/bin/run_${target_name}${bat}"
49 # Gathering metadata provided by the rust_unit_test gni template from all of
51 _metadata_target_name = "${target_name}_metadata"
52 _metadata_filepath = "$root_build_dir/${target_name}__rust_unittest_exes.txt"
53 generated_file(_metadata_target_name) {
54 forward_variables_from(invoker, [ "deps" ], [])
57 outputs = [ _metadata_filepath ]
58 data_keys = [ "rust_unit_test_executables" ]
61 # Generating a script that can run all of the wrapped Rust unit test
64 forward_variables_from(invoker, "*", [])
67 script = "//testing/scripts/rust/generate_script.py"
68 inputs = [ _metadata_filepath ]
69 outputs = [ _script_filepath ]
71 data = [ _script_filepath ]
73 if (!defined(data_deps)) {
76 data_deps += [ "//testing/scripts/rust" ]
79 deps += [ ":$_metadata_target_name" ]
82 "--rust-test-executables",
83 rebase_path(_metadata_filepath, root_build_dir),
85 rebase_path(root_out_dir, root_build_dir),
87 rebase_path(_script_filepath, root_build_dir),
90 args += [ "--make-bat" ]