Enforce correct rust library file names.
rustc expects libraries and proc_macro filenames to conform to
a particular format, alphanumeric with underscores and lib${crate_name}.*.
Enforce this with a check when getStem() is called.
This makes the crate_name property required for proc_macros and
libraries. This also removes the notion of a default crate name derived
from the module name. It's not needed for binaries, so this won't impact
them.
Bug: 143579265
Test: m -j crosvm.experimental
Change-Id: I2770cf7d02dd4291c3d240d58d242b940098dcee
diff --git a/rust/rust_test.go b/rust/rust_test.go
index eb04e72..599af09 100644
--- a/rust/rust_test.go
+++ b/rust/rust_test.go
@@ -129,44 +129,33 @@
}
}
-// Test default crate names from module names are generated correctly.
-func TestDefaultCrateName(t *testing.T) {
- ctx := testRust(t, `
- rust_library_host_dylib {
- name: "fizz-buzz",
- srcs: ["foo.rs"],
- }`)
- module := ctx.ModuleForTests("fizz-buzz", "linux_glibc_x86_64_dylib").Module().(*Module)
- crateName := module.CrateName()
- expectedResult := "fizz_buzz"
-
- if crateName != expectedResult {
- t.Errorf("CrateName() returned the wrong default crate name; expected '%#v', got '%#v'", expectedResult, crateName)
- }
-}
-
// Test to make sure dependencies are being picked up correctly.
func TestDepsTracking(t *testing.T) {
ctx := testRust(t, `
rust_library_host_static {
name: "libstatic",
srcs: ["foo.rs"],
+ crate_name: "static",
}
rust_library_host_shared {
name: "libshared",
srcs: ["foo.rs"],
+ crate_name: "shared",
}
rust_library_host_dylib {
name: "libdylib",
srcs: ["foo.rs"],
+ crate_name: "dylib",
}
rust_library_host_rlib {
name: "librlib",
srcs: ["foo.rs"],
+ crate_name: "rlib",
}
rust_proc_macro {
name: "libpm",
srcs: ["foo.rs"],
+ crate_name: "pm",
}
rust_binary_host {
name: "fizz-buzz",
@@ -208,11 +197,13 @@
rust_library_host_rlib {
name: "libbar",
srcs: ["foo.rs"],
+ crate_name: "bar",
}
rust_proc_macro {
name: "libpm",
rlibs: ["libbar"],
srcs: ["foo.rs"],
+ crate_name: "pm",
}
rust_binary {
name: "fizz-buzz",