Loading java/java.go +29 −16 Original line number Diff line number Diff line Loading @@ -248,6 +248,9 @@ type CompilerProperties struct { Errorprone struct { // List of javac flags that should only be used when running errorprone. Javacflags []string // List of java_plugin modules that provide extra errorprone checks. Extra_check_modules []string } Proto struct { Loading Loading @@ -569,6 +572,7 @@ var ( libTag = dependencyTag{name: "javalib"} java9LibTag = dependencyTag{name: "java9lib"} pluginTag = dependencyTag{name: "plugin"} errorpronePluginTag = dependencyTag{name: "errorprone-plugin"} exportedPluginTag = dependencyTag{name: "exported-plugin"} bootClasspathTag = dependencyTag{name: "bootclasspath"} systemModulesTag = dependencyTag{name: "system modules"} Loading Loading @@ -765,6 +769,7 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) { } ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), pluginTag, j.properties.Plugins...) ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), errorpronePluginTag, j.properties.Errorprone.Extra_check_modules...) ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), exportedPluginTag, j.properties.Exported_plugins...) android.ProtoDeps(ctx, &j.protoProperties) Loading Loading @@ -856,6 +861,7 @@ type deps struct { java9Classpath classpath bootClasspath classpath processorPath classpath errorProneProcessorPath classpath processorClasses []string staticJars android.Paths staticHeaderJars android.Paths Loading Loading @@ -1068,6 +1074,12 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { } else { ctx.PropertyErrorf("plugins", "%q is not a java_plugin module", otherName) } case errorpronePluginTag: if plugin, ok := dep.(*Plugin); ok { deps.errorProneProcessorPath = append(deps.errorProneProcessorPath, plugin.ImplementationAndResourcesJars()...) } else { ctx.PropertyErrorf("plugins", "%q is not a java_plugin module", otherName) } case exportedPluginTag: if plugin, ok := dep.(*Plugin); ok { if plugin.pluginProperties.Generates_api != nil && *plugin.pluginProperties.Generates_api { Loading Loading @@ -1191,7 +1203,7 @@ func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaB flags.javaVersion = getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j)) if ctx.Config().RunErrorProne() { if config.ErrorProneClasspath == nil { if config.ErrorProneClasspath == nil && ctx.Config().TestProductVariables == nil { ctx.ModuleErrorf("cannot build with Error Prone, missing external/error_prone?") } Loading @@ -1211,6 +1223,7 @@ func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaB flags.classpath = append(flags.classpath, deps.classpath...) flags.java9Classpath = append(flags.java9Classpath, deps.java9Classpath...) flags.processorPath = append(flags.processorPath, deps.processorPath...) flags.errorProneProcessorPath = append(flags.errorProneProcessorPath, deps.errorProneProcessorPath...) flags.processors = append(flags.processors, deps.processorClasses...) flags.processors = android.FirstUniqueStrings(flags.processors) Loading java/kotlin_test.go +108 −50 Original line number Diff line number Diff line Loading @@ -84,11 +84,14 @@ func TestKotlin(t *testing.T) { } func TestKapt(t *testing.T) { ctx, _ := testJava(t, ` bp := ` java_library { name: "foo", srcs: ["a.java", "b.kt"], plugins: ["bar", "baz"], errorprone: { extra_check_modules: ["my_check"], }, } java_plugin { Loading @@ -102,7 +105,14 @@ func TestKapt(t *testing.T) { processor_class: "com.baz", srcs: ["b.java"], } `) java_plugin { name: "my_check", srcs: ["b.java"], } ` t.Run("", func(t *testing.T) { ctx, _ := testJava(t, bp) buildOS := android.BuildOs.String() Loading Loading @@ -154,12 +164,60 @@ func TestKapt(t *testing.T) { } // Test that the processors are not passed to javac if javac.Args["processorPath"] != "" { t.Errorf("expected processorPath '', got %q", javac.Args["processorPath"]) if javac.Args["processorpath"] != "" { t.Errorf("expected processorPath '', got %q", javac.Args["processorpath"]) } if javac.Args["processor"] != "-proc:none" { t.Errorf("expected processor '-proc:none', got %q", javac.Args["processor"]) } }) t.Run("errorprone", func(t *testing.T) { env := map[string]string{ "RUN_ERROR_PRONE": "true", } config := testConfig(env, bp, nil) ctx, _ := testJavaWithConfig(t, config) buildOS := android.BuildOs.String() kapt := ctx.ModuleForTests("foo", "android_common").Rule("kapt") //kotlinc := ctx.ModuleForTests("foo", "android_common").Rule("kotlinc") javac := ctx.ModuleForTests("foo", "android_common").Description("javac") errorprone := ctx.ModuleForTests("foo", "android_common").Description("errorprone") bar := ctx.ModuleForTests("bar", buildOS+"_common").Description("javac").Output.String() baz := ctx.ModuleForTests("baz", buildOS+"_common").Description("javac").Output.String() myCheck := ctx.ModuleForTests("my_check", buildOS+"_common").Description("javac").Output.String() // Test that the errorprone plugins are not passed to kapt expectedProcessorPath := "-P plugin:org.jetbrains.kotlin.kapt3:apclasspath=" + bar + " -P plugin:org.jetbrains.kotlin.kapt3:apclasspath=" + baz if kapt.Args["kaptProcessorPath"] != expectedProcessorPath { t.Errorf("expected kaptProcessorPath %q, got %q", expectedProcessorPath, kapt.Args["kaptProcessorPath"]) } expectedProcessor := "-P plugin:org.jetbrains.kotlin.kapt3:processors=com.bar -P plugin:org.jetbrains.kotlin.kapt3:processors=com.baz" if kapt.Args["kaptProcessor"] != expectedProcessor { t.Errorf("expected kaptProcessor %q, got %q", expectedProcessor, kapt.Args["kaptProcessor"]) } // Test that the errorprone plugins are not passed to javac if javac.Args["processorpath"] != "" { t.Errorf("expected processorPath '', got %q", javac.Args["processorpath"]) } if javac.Args["processor"] != "-proc:none" { t.Errorf("expected processor '-proc:none', got %q", javac.Args["processor"]) } // Test that the errorprone plugins are passed to errorprone expectedProcessorPath = "-processorpath " + myCheck if errorprone.Args["processorpath"] != expectedProcessorPath { t.Errorf("expected processorpath %q, got %q", expectedProcessorPath, errorprone.Args["processorpath"]) } if errorprone.Args["processor"] != "-proc:none" { t.Errorf("expected processor '-proc:none', got %q", errorprone.Args["processor"]) } }) } func TestKaptEncodeFlags(t *testing.T) { Loading Loading
java/java.go +29 −16 Original line number Diff line number Diff line Loading @@ -248,6 +248,9 @@ type CompilerProperties struct { Errorprone struct { // List of javac flags that should only be used when running errorprone. Javacflags []string // List of java_plugin modules that provide extra errorprone checks. Extra_check_modules []string } Proto struct { Loading Loading @@ -569,6 +572,7 @@ var ( libTag = dependencyTag{name: "javalib"} java9LibTag = dependencyTag{name: "java9lib"} pluginTag = dependencyTag{name: "plugin"} errorpronePluginTag = dependencyTag{name: "errorprone-plugin"} exportedPluginTag = dependencyTag{name: "exported-plugin"} bootClasspathTag = dependencyTag{name: "bootclasspath"} systemModulesTag = dependencyTag{name: "system modules"} Loading Loading @@ -765,6 +769,7 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) { } ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), pluginTag, j.properties.Plugins...) ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), errorpronePluginTag, j.properties.Errorprone.Extra_check_modules...) ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), exportedPluginTag, j.properties.Exported_plugins...) android.ProtoDeps(ctx, &j.protoProperties) Loading Loading @@ -856,6 +861,7 @@ type deps struct { java9Classpath classpath bootClasspath classpath processorPath classpath errorProneProcessorPath classpath processorClasses []string staticJars android.Paths staticHeaderJars android.Paths Loading Loading @@ -1068,6 +1074,12 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { } else { ctx.PropertyErrorf("plugins", "%q is not a java_plugin module", otherName) } case errorpronePluginTag: if plugin, ok := dep.(*Plugin); ok { deps.errorProneProcessorPath = append(deps.errorProneProcessorPath, plugin.ImplementationAndResourcesJars()...) } else { ctx.PropertyErrorf("plugins", "%q is not a java_plugin module", otherName) } case exportedPluginTag: if plugin, ok := dep.(*Plugin); ok { if plugin.pluginProperties.Generates_api != nil && *plugin.pluginProperties.Generates_api { Loading Loading @@ -1191,7 +1203,7 @@ func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaB flags.javaVersion = getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j)) if ctx.Config().RunErrorProne() { if config.ErrorProneClasspath == nil { if config.ErrorProneClasspath == nil && ctx.Config().TestProductVariables == nil { ctx.ModuleErrorf("cannot build with Error Prone, missing external/error_prone?") } Loading @@ -1211,6 +1223,7 @@ func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaB flags.classpath = append(flags.classpath, deps.classpath...) flags.java9Classpath = append(flags.java9Classpath, deps.java9Classpath...) flags.processorPath = append(flags.processorPath, deps.processorPath...) flags.errorProneProcessorPath = append(flags.errorProneProcessorPath, deps.errorProneProcessorPath...) flags.processors = append(flags.processors, deps.processorClasses...) flags.processors = android.FirstUniqueStrings(flags.processors) Loading
java/kotlin_test.go +108 −50 Original line number Diff line number Diff line Loading @@ -84,11 +84,14 @@ func TestKotlin(t *testing.T) { } func TestKapt(t *testing.T) { ctx, _ := testJava(t, ` bp := ` java_library { name: "foo", srcs: ["a.java", "b.kt"], plugins: ["bar", "baz"], errorprone: { extra_check_modules: ["my_check"], }, } java_plugin { Loading @@ -102,7 +105,14 @@ func TestKapt(t *testing.T) { processor_class: "com.baz", srcs: ["b.java"], } `) java_plugin { name: "my_check", srcs: ["b.java"], } ` t.Run("", func(t *testing.T) { ctx, _ := testJava(t, bp) buildOS := android.BuildOs.String() Loading Loading @@ -154,12 +164,60 @@ func TestKapt(t *testing.T) { } // Test that the processors are not passed to javac if javac.Args["processorPath"] != "" { t.Errorf("expected processorPath '', got %q", javac.Args["processorPath"]) if javac.Args["processorpath"] != "" { t.Errorf("expected processorPath '', got %q", javac.Args["processorpath"]) } if javac.Args["processor"] != "-proc:none" { t.Errorf("expected processor '-proc:none', got %q", javac.Args["processor"]) } }) t.Run("errorprone", func(t *testing.T) { env := map[string]string{ "RUN_ERROR_PRONE": "true", } config := testConfig(env, bp, nil) ctx, _ := testJavaWithConfig(t, config) buildOS := android.BuildOs.String() kapt := ctx.ModuleForTests("foo", "android_common").Rule("kapt") //kotlinc := ctx.ModuleForTests("foo", "android_common").Rule("kotlinc") javac := ctx.ModuleForTests("foo", "android_common").Description("javac") errorprone := ctx.ModuleForTests("foo", "android_common").Description("errorprone") bar := ctx.ModuleForTests("bar", buildOS+"_common").Description("javac").Output.String() baz := ctx.ModuleForTests("baz", buildOS+"_common").Description("javac").Output.String() myCheck := ctx.ModuleForTests("my_check", buildOS+"_common").Description("javac").Output.String() // Test that the errorprone plugins are not passed to kapt expectedProcessorPath := "-P plugin:org.jetbrains.kotlin.kapt3:apclasspath=" + bar + " -P plugin:org.jetbrains.kotlin.kapt3:apclasspath=" + baz if kapt.Args["kaptProcessorPath"] != expectedProcessorPath { t.Errorf("expected kaptProcessorPath %q, got %q", expectedProcessorPath, kapt.Args["kaptProcessorPath"]) } expectedProcessor := "-P plugin:org.jetbrains.kotlin.kapt3:processors=com.bar -P plugin:org.jetbrains.kotlin.kapt3:processors=com.baz" if kapt.Args["kaptProcessor"] != expectedProcessor { t.Errorf("expected kaptProcessor %q, got %q", expectedProcessor, kapt.Args["kaptProcessor"]) } // Test that the errorprone plugins are not passed to javac if javac.Args["processorpath"] != "" { t.Errorf("expected processorPath '', got %q", javac.Args["processorpath"]) } if javac.Args["processor"] != "-proc:none" { t.Errorf("expected processor '-proc:none', got %q", javac.Args["processor"]) } // Test that the errorprone plugins are passed to errorprone expectedProcessorPath = "-processorpath " + myCheck if errorprone.Args["processorpath"] != expectedProcessorPath { t.Errorf("expected processorpath %q, got %q", expectedProcessorPath, errorprone.Args["processorpath"]) } if errorprone.Args["processor"] != "-proc:none" { t.Errorf("expected processor '-proc:none', got %q", errorprone.Args["processor"]) } }) } func TestKaptEncodeFlags(t *testing.T) { Loading