From bbd25aeb428edaa7fb332cc0a6771aeede38e286 Mon Sep 17 00:00:00 2001 From: Chih-Hung Hsieh Date: Fri, 15 May 2020 17:36:30 -0700 Subject: Specify module dependency in the srcs list * "srcs" list contains one main Rust source file, followed by optional dependent modules. * A dependent module included in the "srcs" list is the module name prefixed with ":". * Add a simple test. Bug: 160331255 Test: make and manual test build dependencies on genrule modules Change-Id: I4f079138c2599158810b6412fce81b612a3f64a4 --- rust/compiler.go | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'rust/compiler.go') diff --git a/rust/compiler.go b/rust/compiler.go index 92a3b07f2..c20179bd0 100644 --- a/rust/compiler.go +++ b/rust/compiler.go @@ -253,10 +253,24 @@ func (compiler *baseCompiler) relativeInstallPath() string { return String(compiler.Properties.Relative_install_path) } -func srcPathFromModuleSrcs(ctx ModuleContext, srcs []string) android.Path { - srcPaths := android.PathsForModuleSrc(ctx, srcs) - if len(srcPaths) != 1 { - ctx.PropertyErrorf("srcs", "srcs can only contain one path for rust modules") +func srcPathFromModuleSrcs(ctx ModuleContext, srcs []string) (android.Path, android.Paths) { + // 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. + numSrcs := 0 + srcIndex := 0 + for i, s := range srcs { + if android.SrcIsModule(s) == "" { + numSrcs++ + srcIndex = i + } + } + if numSrcs != 1 { + ctx.PropertyErrorf("srcs", "srcs can only contain one path for a rust file") + } + if srcIndex != 0 { + ctx.PropertyErrorf("srcs", "main source file must be the first in srcs") } - return srcPaths[0] + paths := android.PathsForModuleSrc(ctx, srcs) + return paths[srcIndex], paths } -- cgit v1.2.3-59-g8ed1b