Add test for java generated sources
Bug: 67364649
Test: TestGeneratedSources
Change-Id: I5400e4b013dc47c04b9d32787e50c5281033484d
diff --git a/java/java_test.go b/java/java_test.go
index c2c7ee2..4034340 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -61,6 +61,7 @@
ctx.RegisterModuleType("java_import", android.ModuleFactoryAdaptor(ImportFactory))
ctx.RegisterModuleType("java_defaults", android.ModuleFactoryAdaptor(defaultsFactory))
ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(genrule.FileGroupFactory))
+ ctx.RegisterModuleType("genrule", android.ModuleFactoryAdaptor(genrule.GenRuleFactory))
ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators)
ctx.PreArchMutators(android.RegisterPrebuiltsPostDepsMutators)
ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
@@ -506,6 +507,39 @@
}
}
+func TestGeneratedSources(t *testing.T) {
+ ctx := testJava(t, `
+ java_library {
+ name: "foo",
+ srcs: [
+ "a*.java",
+ ":gen",
+ "b*.java",
+ ],
+ }
+
+ genrule {
+ name: "gen",
+ tool_files: ["res/a"],
+ out: ["gen.java"],
+ }
+ `)
+
+ javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
+ genrule := ctx.ModuleForTests("gen", "").Rule("generator")
+
+ if len(genrule.Outputs) != 1 || filepath.Base(genrule.Outputs[0].String()) != "gen.java" {
+ t.Fatalf(`gen output file %v is not [".../gen.java"]`, genrule.Outputs.Strings())
+ }
+
+ if len(javac.Inputs) != 3 ||
+ javac.Inputs[0].String() != "a.java" ||
+ javac.Inputs[1].String() != genrule.Outputs[0].String() ||
+ javac.Inputs[2].String() != "b.java" {
+ t.Errorf(`foo inputs %v != ["a.java", ".../gen.java", "b.java"]`, javac.Inputs)
+ }
+}
+
func fail(t *testing.T, errs []error) {
if len(errs) > 0 {
for _, err := range errs {