From ad8b18b87260a83aeadb28d637f77474158fcdb1 Mon Sep 17 00:00:00 2001 From: Ivan Lozano Date: Thu, 31 Oct 2019 19:38:29 -0700 Subject: 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 --- rust/library_test.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'rust/library_test.go') diff --git a/rust/library_test.go b/rust/library_test.go index 66bcd20fb..9f9f374b9 100644 --- a/rust/library_test.go +++ b/rust/library_test.go @@ -77,3 +77,40 @@ func TestDylibPreferDynamic(t *testing.T) { t.Errorf("missing prefer-dynamic flag for libfoo dylib, rustcFlags: %#v", libfooDylib.Args["rustcFlags"]) } } + +func TestValidateLibraryStem(t *testing.T) { + testRustError(t, "crate_name must be defined.", ` + rust_library_host { + name: "libfoo", + srcs: ["foo.rs"], + }`) + + testRustError(t, "library crate_names must be alphanumeric with underscores allowed", ` + rust_library_host { + name: "libfoo-bar", + srcs: ["foo.rs"], + crate_name: "foo-bar" + }`) + + testRustError(t, "Invalid name or stem property; library filenames must start with lib", ` + rust_library_host { + name: "foobar", + srcs: ["foo.rs"], + crate_name: "foo_bar" + }`) + testRustError(t, "Invalid name or stem property; library filenames must start with lib", ` + rust_library_host { + name: "foobar", + stem: "libfoo", + srcs: ["foo.rs"], + crate_name: "foo_bar" + }`) + testRustError(t, "Invalid name or stem property; library filenames must start with lib", ` + rust_library_host { + name: "foobar", + stem: "foo_bar", + srcs: ["foo.rs"], + crate_name: "foo_bar" + }`) + +} -- cgit v1.2.3-59-g8ed1b