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/rust_test.go | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'rust/rust_test.go') diff --git a/rust/rust_test.go b/rust/rust_test.go index 08bc8ca48..e80392589 100644 --- a/rust/rust_test.go +++ b/rust/rust_test.go @@ -61,6 +61,7 @@ func testConfig(bp string) android.Config { "foo.rs": nil, "foo.c": nil, "src/bar.rs": nil, + "src/any.h": nil, "liby.so": nil, "libz.so": nil, } @@ -181,7 +182,7 @@ func TestDepsTracking(t *testing.T) { } rust_library_host_rlib { name: "librlib", - srcs: ["foo.rs"], + srcs: ["foo.rs", ":my_generator"], crate_name: "rlib", } rust_proc_macro { @@ -189,17 +190,38 @@ func TestDepsTracking(t *testing.T) { srcs: ["foo.rs"], crate_name: "pm", } + genrule { + name: "my_generator", + tools: ["any_rust_binary"], + cmd: "$(location) -o $(out) $(in)", + srcs: ["src/any.h"], + out: ["src/any.rs"], + } rust_binary_host { - name: "fizz-buzz", + name: "fizz-buzz-dep", dylibs: ["libdylib"], rlibs: ["librlib"], proc_macros: ["libpm"], static_libs: ["libstatic"], shared_libs: ["libshared"], - srcs: ["foo.rs"], + srcs: [ + "foo.rs", + ":my_generator", + ], } `) - module := ctx.ModuleForTests("fizz-buzz", "linux_glibc_x86_64").Module().(*Module) + module := ctx.ModuleForTests("fizz-buzz-dep", "linux_glibc_x86_64").Module().(*Module) + rlibmodule := ctx.ModuleForTests("librlib", "linux_glibc_x86_64_rlib").Module().(*Module) + + srcs := module.compiler.(*binaryDecorator).baseCompiler.Properties.Srcs + if len(srcs) != 2 || !android.InList(":my_generator", srcs) { + t.Errorf("missing module dependency in fizz-buzz)") + } + + srcs = rlibmodule.compiler.(*libraryDecorator).baseCompiler.Properties.Srcs + if len(srcs) != 2 || !android.InList(":my_generator", srcs) { + t.Errorf("missing module dependency in rlib") + } // Since dependencies are added to AndroidMk* properties, we can check these to see if they've been picked up. if !android.InList("libdylib", module.Properties.AndroidMkDylibs) { -- cgit v1.2.3-59-g8ed1b