rust_unit_tests_group.gni (2899B)
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. 4 5 # Defines a Rust unit tests group. 6 # 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). 10 # 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 14 # executables). 15 # 16 # Parameters: 17 # 18 # deps - Will be recursively traversed to discover all the Rust unit test 19 # executables. 20 # 21 # Example usage: 22 # 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") { 30 # deps = [ 31 # "foo_crate1", 32 # "foo_mixed_source_set2", 33 # "foo_mixed_source_set3", 34 # ] 35 # } 36 37 template("rust_unit_tests_group") { 38 assert(defined(invoker.deps), "deps must be listed") 39 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). 43 bat = "" 44 if (is_win) { 45 bat = ".bat" 46 } 47 _script_filepath = "$root_out_dir/bin/run_${target_name}${bat}" 48 49 # Gathering metadata provided by the rust_unit_test gni template from all of 50 # our dependencies. 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" ], []) 55 56 testonly = true 57 outputs = [ _metadata_filepath ] 58 data_keys = [ "rust_unit_test_executables" ] 59 } 60 61 # Generating a script that can run all of the wrapped Rust unit test 62 # executables. 63 action(target_name) { 64 forward_variables_from(invoker, "*", []) 65 66 testonly = true 67 script = "//testing/scripts/rust/generate_script.py" 68 inputs = [ _metadata_filepath ] 69 outputs = [ _script_filepath ] 70 71 data = [ _script_filepath ] 72 73 if (!defined(data_deps)) { 74 data_deps = [] 75 } 76 data_deps += [ "//testing/scripts/rust" ] 77 data_deps += deps 78 79 deps += [ ":$_metadata_target_name" ] 80 81 args = [ 82 "--rust-test-executables", 83 rebase_path(_metadata_filepath, root_build_dir), 84 "--exe-dir", 85 rebase_path(root_out_dir, root_build_dir), 86 "--script-path", 87 rebase_path(_script_filepath, root_build_dir), 88 ] 89 if (is_win) { 90 args += [ "--make-bat" ] 91 } 92 } 93 }