diff options
| author | 2020-07-20 21:18:33 +0000 | |
|---|---|---|
| committer | 2020-07-20 21:18:33 +0000 | |
| commit | c3b1a6125328b81344401a47239a2e7fd5642a93 (patch) | |
| tree | 05e7d13684d1761f91792d5685c37fad8457443b /rust/rust_test.go | |
| parent | dd35943b62ca6e6f84eba40ac33e208adc8de0fb (diff) | |
| parent | 43845688bccfdeabb7f78baca4ba6f8a243c9ad3 (diff) | |
Merge changes from topic "rust_bindgen"
* changes:
Allow rust module dependency on SourceProviders.
Add SourceProviders and a rust_bindgen module type
Diffstat (limited to 'rust/rust_test.go')
| -rw-r--r-- | rust/rust_test.go | 96 |
1 files changed, 71 insertions, 25 deletions
diff --git a/rust/rust_test.go b/rust/rust_test.go index e80392589..89dfb67e1 100644 --- a/rust/rust_test.go +++ b/rust/rust_test.go @@ -182,7 +182,7 @@ func TestDepsTracking(t *testing.T) { } rust_library_host_rlib { name: "librlib", - srcs: ["foo.rs", ":my_generator"], + srcs: ["foo.rs"], crate_name: "rlib", } rust_proc_macro { @@ -190,38 +190,17 @@ 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-dep", + name: "fizz-buzz", dylibs: ["libdylib"], rlibs: ["librlib"], proc_macros: ["libpm"], static_libs: ["libstatic"], shared_libs: ["libshared"], - srcs: [ - "foo.rs", - ":my_generator", - ], + srcs: ["foo.rs"], } `) - 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") - } + module := ctx.ModuleForTests("fizz-buzz", "linux_glibc_x86_64").Module().(*Module) // 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) { @@ -245,6 +224,73 @@ func TestDepsTracking(t *testing.T) { } } +func TestSourceProviderDeps(t *testing.T) { + ctx := testRust(t, ` + rust_binary { + name: "fizz-buzz-dep", + srcs: [ + "foo.rs", + ":my_generator", + ":libbindings", + ], + } + rust_proc_macro { + name: "libprocmacro", + srcs: [ + "foo.rs", + ":my_generator", + ":libbindings", + ], + crate_name: "procmacro", + } + rust_library { + name: "libfoo", + srcs: [ + "foo.rs", + ":my_generator", + ":libbindings"], + crate_name: "foo", + } + genrule { + name: "my_generator", + tools: ["any_rust_binary"], + cmd: "$(location) -o $(out) $(in)", + srcs: ["src/any.h"], + out: ["src/any.rs"], + } + rust_bindgen { + name: "libbindings", + stem: "bindings", + host_supported: true, + wrapper_src: "src/any.h", + } + `) + + libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_rlib").Rule("rustc") + if !android.SuffixInList(libfoo.Implicits.Strings(), "/out/bindings.rs") { + t.Errorf("rust_bindgen generated source not included as implicit input for libfoo; Implicits %#v", libfoo.Implicits.Strings()) + } + if !android.SuffixInList(libfoo.Implicits.Strings(), "/out/any.rs") { + t.Errorf("genrule generated source not included as implicit input for libfoo; Implicits %#v", libfoo.Implicits.Strings()) + } + + fizzBuzz := ctx.ModuleForTests("fizz-buzz-dep", "android_arm64_armv8-a").Rule("rustc") + if !android.SuffixInList(fizzBuzz.Implicits.Strings(), "/out/bindings.rs") { + t.Errorf("rust_bindgen generated source not included as implicit input for fizz-buzz-dep; Implicits %#v", libfoo.Implicits.Strings()) + } + if !android.SuffixInList(fizzBuzz.Implicits.Strings(), "/out/any.rs") { + t.Errorf("genrule generated source not included as implicit input for fizz-buzz-dep; Implicits %#v", libfoo.Implicits.Strings()) + } + + libprocmacro := ctx.ModuleForTests("libprocmacro", "linux_glibc_x86_64").Rule("rustc") + if !android.SuffixInList(libprocmacro.Implicits.Strings(), "/out/bindings.rs") { + t.Errorf("rust_bindgen generated source not included as implicit input for libprocmacro; Implicits %#v", libfoo.Implicits.Strings()) + } + if !android.SuffixInList(libprocmacro.Implicits.Strings(), "/out/any.rs") { + t.Errorf("genrule generated source not included as implicit input for libprocmacro; Implicits %#v", libfoo.Implicits.Strings()) + } +} + // Test to make sure proc_macros use host variants when building device modules. func TestProcMacroDeviceDeps(t *testing.T) { ctx := testRust(t, ` |