diff options
| author | 2021-10-13 15:32:18 -0700 | |
|---|---|---|
| committer | 2021-10-14 15:25:07 +0000 | |
| commit | 3afac0b36fc843e46bdbe43ab6fe57c794f12a5f (patch) | |
| tree | 04ab424f4d77ec1b0375c48b28e91f5005236192 | |
| parent | 2649c7913a541c0e0cc64f01a764139f76862241 (diff) | |
Flag an error on empty rust module srcs
It's an error if a rust module's srcs is empty. Prior to this change
the output was a panic that complains loudly about a slice error and
nothing else. This change doesn't stop the panic, but at least adds
a bit of context so devs who make a simple mistake can more easily
fix it.
Test: SOONG_GEN_RUST_PROJECT=1 m nothing
Change-Id: Id7d8465d533413c3000699661222a53a7c8678f3
| -rw-r--r-- | rust/compiler.go | 4 | ||||
| -rw-r--r-- | rust/compiler_test.go | 35 |
2 files changed, 39 insertions, 0 deletions
diff --git a/rust/compiler.go b/rust/compiler.go index 1ce71f60b..cada9854a 100644 --- a/rust/compiler.go +++ b/rust/compiler.go @@ -449,6 +449,10 @@ func (compiler *baseCompiler) relativeInstallPath() string { // Returns the Path for the main source file along with Paths for generated source files from modules listed in srcs. func srcPathFromModuleSrcs(ctx ModuleContext, srcs []string) (android.Path, android.Paths) { + if len(srcs) == 0 { + ctx.PropertyErrorf("srcs", "srcs must not be empty") + } + // The srcs can contain strings with prefix ":". // They are dependent modules of this module, with android.SourceDepTag. // They are not the main source file compiled by rustc. diff --git a/rust/compiler_test.go b/rust/compiler_test.go index f589b691d..ec6829a1b 100644 --- a/rust/compiler_test.go +++ b/rust/compiler_test.go @@ -98,6 +98,41 @@ func TestEnforceSingleSourceFile(t *testing.T) { }`) } +// Test that we reject _no_ source files. +func TestEnforceMissingSourceFiles(t *testing.T) { + + singleSrcError := "srcs must not be empty" + + // Test libraries + testRustError(t, singleSrcError, ` + rust_library_host { + name: "foo-bar-library", + crate_name: "foo", + }`) + + // Test binaries + testRustError(t, singleSrcError, ` + rust_binary_host { + name: "foo-bar-binary", + crate_name: "foo", + }`) + + // Test proc_macros + testRustError(t, singleSrcError, ` + rust_proc_macro { + name: "foo-bar-proc-macro", + crate_name: "foo", + }`) + + // Test prebuilts + testRustError(t, singleSrcError, ` + rust_prebuilt_dylib { + name: "foo-bar-prebuilt", + crate_name: "foo", + host_supported: true, + }`) +} + // Test environment vars for Cargo compat are set. func TestCargoCompat(t *testing.T) { ctx := testRust(t, ` |