Generate Rust crate roots for test() targets.
Test targets don't have a public interface and are simply a collection
of independent test files. Instead of requiring devs to write a crate
root pointing to each of those files (and introducing a chance for
mistakenly forgetting a file which would then exclude its tests
silently), generate the crate root from the set of rust files in
`sources`.
The module name encodes the full path to each file in sources, so that
foo/bar.rs and baz/bar.rs do not collide as both being `mod bar;`.
Instead they would be `mod foo_bar;` and `mod baz_bar;`
Example generated file for base_unittests (which has a base_unittests_rs
Rust target):
% cat out_desktop/Release/gen/base/base_unittests_rs_crate_root.rs
// Generated crate root for base_unittests_rs.
#[path = "../../../../base/json/json_parser_unittest.rs"]
mod json_json_parser_unittest.rs;
#[path = "../../../../base/values_unittest.rs"]
mod values_unittest.rs;
[email protected], [email protected]
Bug: 1293979
Change-Id: I33c28a181340fbf75beb0a01dc851b268805a80e
Cq-Include-Trybots: luci.chromium.try:android-rust-arm-rel
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3513336
Reviewed-by: John Chen <[email protected]>
Reviewed-by: Ćukasz Anforowicz <[email protected]>
Commit-Queue: danakj <[email protected]>
Cr-Commit-Position: refs/heads/main@{#979869}
diff --git a/testing/test.gni b/testing/test.gni
index fc7644f94..a7682c6 100644
--- a/testing/test.gni
+++ b/testing/test.gni
@@ -59,6 +59,10 @@
}
rs_configs += [ "//build/rust:test" ]
+ # The crate_root is generated and should not be specified.
+ assert(!defined(rs_crate_root))
+ rs_generate_crate_root = true
+
# We could automatically add `rs_deps += [ "//testing/rust_gtest_interop" ]`
# if `rs_sources` is non-empty. But we don't automatically provide
# //testing/gtest either so it would be asymmetric and could break in that