diff options
author | ThiƩbaud Weksteen <tweek@google.com> | 2020-12-03 20:58:32 +0100 |
---|---|---|
committer | ThiƩbaud Weksteen <tweek@google.com> | 2020-12-03 20:58:32 +0100 |
commit | 064f6e957ebe2bdac91d68d52af05f3402e49e33 (patch) | |
tree | 2968b66d42ed8ab7d7278c136fd7f8363b83937f /rust/project_json.go | |
parent | f202e4e7933b52b2df2150177bf668d07799878f (diff) |
Includes rust_binary in rust-project.json
Until now, only rust_library (and their derivatives such as
rust_library_host) were reported in rust-project.json. Adds support for
rust_binary and rust_tests.
Bug: 174743191
Test: Validate auto-completion in keystore2_main.rs
Change-Id: I17b3ec29e233f29b7abd16dc771070ada48d17fb
Diffstat (limited to 'rust/project_json.go')
-rw-r--r-- | rust/project_json.go | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/rust/project_json.go b/rust/project_json.go index 8d9e50ca9..c4d60ad53 100644 --- a/rust/project_json.go +++ b/rust/project_json.go @@ -75,12 +75,16 @@ func init() { android.RegisterSingletonType("rust_project_generator", rustProjectGeneratorSingleton) } -// librarySource finds the main source file (.rs) for a crate. -func librarySource(ctx android.SingletonContext, rModule *Module, rustLib *libraryDecorator) (string, bool) { - srcs := rustLib.baseCompiler.Properties.Srcs +// crateSource finds the main source file (.rs) for a crate. +func crateSource(ctx android.SingletonContext, rModule *Module, comp *baseCompiler) (string, bool) { + srcs := comp.Properties.Srcs if len(srcs) != 0 { return path.Join(ctx.ModuleDir(rModule), srcs[0]), true } + rustLib, ok := rModule.compiler.(*libraryDecorator) + if !ok { + return "", false + } if !rustLib.source() { return "", false } @@ -132,8 +136,15 @@ func (singleton *projectGeneratorSingleton) appendLibraryAndDeps(ctx android.Sin if rModule.compiler == nil { return 0, "", false } - rustLib, ok := rModule.compiler.(*libraryDecorator) - if !ok { + var comp *baseCompiler + switch c := rModule.compiler.(type) { + case *libraryDecorator: + comp = c.baseCompiler + case *binaryDecorator: + comp = c.baseCompiler + case *testDecorator: + comp = c.binaryDecorator.baseCompiler + default: return 0, "", false } moduleName := ctx.ModuleName(module) @@ -146,12 +157,12 @@ func (singleton *projectGeneratorSingleton) appendLibraryAndDeps(ctx android.Sin return cInfo.ID, crateName, true } crate := rustProjectCrate{Deps: make([]rustProjectDep, 0), Cfgs: make([]string, 0)} - rootModule, ok := librarySource(ctx, rModule, rustLib) + rootModule, ok := crateSource(ctx, rModule, comp) if !ok { return 0, "", false } crate.RootModule = rootModule - crate.Edition = rustLib.baseCompiler.edition() + crate.Edition = comp.edition() deps := make(map[string]int) singleton.mergeDependencies(ctx, module, &crate, deps) |