Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit afbb1734 authored by Colin Cross's avatar Colin Cross
Browse files

Pass annotation processors to kotlinc

Enable the kotlin-annotation-processing plugin and pass annotation
processors to it.

Bug: 122251693
Test: m checkbuild
Test: TestKapt in kotlin_test.go
Change-Id: I841df454beaaa7edd263eea714ca0d958a03c9de
parent 21fc9bbe
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -241,6 +241,7 @@ func TestArchConfig(buildDir string, env map[string]string) Config {
	}

	config.BuildOsVariant = config.Targets[BuildOs][0].String()
	config.BuildOsCommonVariant = getCommonTargets(config.Targets[BuildOs])[0].String()

	return testConfig
}
+3 −3
Original line number Diff line number Diff line
@@ -415,7 +415,7 @@ func (x *classpath) FormTurbineClasspath(optName string) []string {
	}
	flags := make([]string, len(*x))
	for i, v := range *x {
		flags[i] = optName + " " + v.String()
		flags[i] = optName + v.String()
	}

	return flags
+11 −0
Original line number Diff line number Diff line
@@ -14,6 +14,8 @@

package config

import "strings"

var (
	KotlinStdlibJar     = "external/kotlinc/lib/kotlin-stdlib.jar"
	KotlincIllegalFlags = []string{
@@ -25,5 +27,14 @@ var (
func init() {
	pctx.SourcePathVariable("KotlincCmd", "external/kotlinc/bin/kotlinc")
	pctx.SourcePathVariable("KotlinCompilerJar", "external/kotlinc/lib/kotlin-compiler.jar")
	pctx.SourcePathVariable("KotlinKaptJar", "external/kotlinc/lib/kotlin-annotation-processing.jar")
	pctx.SourcePathVariable("KotlinStdlibJar", KotlinStdlibJar)

	// These flags silence "Illegal reflective access" warnings when running kotlinc in OpenJDK9
	pctx.StaticVariable("KotlincSuppressJDK9Warnings", strings.Join([]string{
		"-J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
		"-J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
		"-J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
		"-J--add-opens=java.base/sun.net.www.protocol.jar=ALL-UNNAMED",
	}, " "))
}
+21 −4
Original line number Diff line number Diff line
@@ -379,6 +379,7 @@ var (
	frameworkResTag       = dependencyTag{name: "framework-res"}
	frameworkApkTag       = dependencyTag{name: "framework-apk"}
	kotlinStdlibTag       = dependencyTag{name: "kotlin-stdlib"}
	kotlinAnnotationsTag  = dependencyTag{name: "kotlin-annotations"}
	proguardRaiseTag      = dependencyTag{name: "proguard-raise"}
	certificateTag        = dependencyTag{name: "certificate"}
	instrumentationForTag = dependencyTag{name: "instrumentation_for"}
@@ -483,6 +484,9 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) {
		// TODO(ccross): move this to a mutator pass that can tell if generated sources contain
		// Kotlin files
		ctx.AddVariationDependencies(nil, kotlinStdlibTag, "kotlin-stdlib")
		if len(j.properties.Annotation_processors) > 0 {
			ctx.AddVariationDependencies(nil, kotlinAnnotationsTag, "kotlin-annotations")
		}
	}

	if j.shouldInstrumentStatic(ctx) {
@@ -564,6 +568,7 @@ type deps struct {
	systemModules      android.Path
	aidlPreprocess     android.OptionalPath
	kotlinStdlib       android.Paths
	kotlinAnnotations  android.Paths
}

func checkProducesJars(ctx android.ModuleContext, dep android.SourceFileProducer) {
@@ -723,6 +728,8 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
				}
			case kotlinStdlibTag:
				deps.kotlinStdlib = dep.HeaderJars()
			case kotlinAnnotationsTag:
				deps.kotlinAnnotations = dep.HeaderJars()
			}

			deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
@@ -969,9 +976,20 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
		kotlinSrcFiles = append(kotlinSrcFiles, uniqueSrcFiles...)
		kotlinSrcFiles = append(kotlinSrcFiles, srcFiles.FilterByExt(".kt")...)

		flags.kotlincClasspath = append(flags.kotlincClasspath, deps.bootClasspath...)
		flags.kotlincClasspath = append(flags.kotlincClasspath, deps.kotlinStdlib...)
		flags.kotlincClasspath = append(flags.kotlincClasspath, deps.classpath...)
		flags.classpath = append(flags.classpath, deps.kotlinStdlib...)
		flags.classpath = append(flags.classpath, deps.kotlinAnnotations...)

		flags.kotlincClasspath = append(flags.kotlincClasspath, flags.bootClasspath...)
		flags.kotlincClasspath = append(flags.kotlincClasspath, flags.classpath...)

		if len(flags.processorPath) > 0 {
			// Use kapt for annotation processing
			kaptSrcJar := android.PathForModuleOut(ctx, "kapt", "kapt-sources.jar")
			kotlinKapt(ctx, kaptSrcJar, kotlinSrcFiles, srcJars, flags)
			srcJars = append(srcJars, kaptSrcJar)
			// Disable annotation processing in javac, it's already been handled by kapt
			flags.processorPath = nil
		}

		kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName)
		kotlinCompile(ctx, kotlinJar, kotlinSrcFiles, srcJars, flags)
@@ -980,7 +998,6 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
		}

		// Make javac rule depend on the kotlinc rule
		flags.classpath = append(flags.classpath, deps.kotlinStdlib...)
		flags.classpath = append(flags.classpath, kotlinJar)

		// Jar kotlin classes into the final jar after javac
+1 −0
Original line number Diff line number Diff line
@@ -121,6 +121,7 @@ func testContext(config android.Config, bp string,
		"core.current.stubs",
		"core.platform.api.stubs",
		"kotlin-stdlib",
		"kotlin-annotations",
	}

	for _, extra := range extraModules {
Loading