1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
build / rust / rust_unit_tests_group.gni [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" ]
}
}
}