From 220a9a1245eca9200cf8117e9a3e414149bb135a Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Mon, 28 Mar 2022 17:08:01 -0700 Subject: Enable kotlin's jvm-abi-gen plugin to generate header jars Kotlin's jvm-abi-gen plugin can generate header jars similar to the turbine output for java sources, which can be used to avoid recompiling downstream modules when the ABI hasn't changed. Unlike turbine, the plugin runs as part of the main kotlinc invocation, so it doesn't allow the downstream modules to start compiling any sooner. A future possible optimization is to use turbine to compile the kapt stubs, at least for the kotlin+annotation processor modules that already generate them, which would allow compiling downstream modules before invoking kotlinc or javac, as well as invoking kotlinc and javac in parallel with each other. Bug: 222095735 Test: TestKotlin Test: m SystemUI Change-Id: Ib1bb2ecea47c851a108a26f9ed4f827f289d1321 --- java/kotlin.go | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'java/kotlin.go') diff --git a/java/kotlin.go b/java/kotlin.go index ce79bae16..eff5bb53f 100644 --- a/java/kotlin.go +++ b/java/kotlin.go @@ -28,17 +28,20 @@ import ( var kotlinc = pctx.AndroidRemoteStaticRule("kotlinc", android.RemoteRuleSupports{Goma: true}, blueprint.RuleParams{ - Command: `rm -rf "$classesDir" "$srcJarDir" "$kotlinBuildFile" "$emptyDir" && ` + - `mkdir -p "$classesDir" "$srcJarDir" "$emptyDir" && ` + + Command: `rm -rf "$classesDir" "$headerClassesDir" "$srcJarDir" "$kotlinBuildFile" "$emptyDir" && ` + + `mkdir -p "$classesDir" "$headerClassesDir" "$srcJarDir" "$emptyDir" && ` + `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` + `${config.GenKotlinBuildFileCmd} --classpath "$classpath" --name "$name"` + ` --out_dir "$classesDir" --srcs "$out.rsp" --srcs "$srcJarDir/list"` + ` $commonSrcFilesArg --out "$kotlinBuildFile" && ` + `${config.KotlincCmd} ${config.KotlincGlobalFlags} ` + - `${config.KotlincSuppressJDK9Warnings} ${config.JavacHeapFlags} ` + - `$kotlincFlags -jvm-target $kotlinJvmTarget -Xbuild-file=$kotlinBuildFile ` + - `-kotlin-home $emptyDir && ` + - `${config.SoongZipCmd} -jar -o $out -C $classesDir -D $classesDir && ` + + ` ${config.KotlincSuppressJDK9Warnings} ${config.JavacHeapFlags} ` + + ` $kotlincFlags -jvm-target $kotlinJvmTarget -Xbuild-file=$kotlinBuildFile ` + + ` -kotlin-home $emptyDir ` + + ` -Xplugin=${config.KotlinAbiGenPluginJar} ` + + ` -P plugin:org.jetbrains.kotlin.jvm.abi:outputDir=$headerClassesDir && ` + + `${config.SoongZipCmd} -jar -o $out -C $classesDir -D $classesDir -write_if_changed && ` + + `${config.SoongZipCmd} -jar -o $headerJar -C $headerClassesDir -D $headerClassesDir -write_if_changed && ` + `rm -rf "$srcJarDir"`, CommandDeps: []string{ "${config.KotlincCmd}", @@ -49,15 +52,17 @@ var kotlinc = pctx.AndroidRemoteStaticRule("kotlinc", android.RemoteRuleSupports "${config.KotlinStdlibJar}", "${config.KotlinTrove4jJar}", "${config.KotlinAnnotationJar}", + "${config.KotlinAbiGenPluginJar}", "${config.GenKotlinBuildFileCmd}", "${config.SoongZipCmd}", "${config.ZipSyncCmd}", }, Rspfile: "$out.rsp", RspfileContent: `$in`, + Restat: true, }, "kotlincFlags", "classpath", "srcJars", "commonSrcFilesArg", "srcJarDir", "classesDir", - "kotlinJvmTarget", "kotlinBuildFile", "emptyDir", "name") + "headerClassesDir", "headerJar", "kotlinJvmTarget", "kotlinBuildFile", "emptyDir", "name") func kotlinCommonSrcsList(ctx android.ModuleContext, commonSrcFiles android.Paths) android.OptionalPath { if len(commonSrcFiles) > 0 { @@ -76,7 +81,7 @@ func kotlinCommonSrcsList(ctx android.ModuleContext, commonSrcFiles android.Path } // kotlinCompile takes .java and .kt sources and srcJars, and compiles the .kt sources into a classes jar in outputFile. -func kotlinCompile(ctx android.ModuleContext, outputFile android.WritablePath, +func kotlinCompile(ctx android.ModuleContext, outputFile, headerOutputFile android.WritablePath, srcFiles, commonSrcFiles, srcJars android.Paths, flags javaBuilderFlags) { @@ -97,17 +102,20 @@ func kotlinCompile(ctx android.ModuleContext, outputFile android.WritablePath, } ctx.Build(pctx, android.BuildParams{ - Rule: kotlinc, - Description: "kotlinc", - Output: outputFile, - Inputs: srcFiles, - Implicits: deps, + Rule: kotlinc, + Description: "kotlinc", + Output: outputFile, + ImplicitOutput: headerOutputFile, + Inputs: srcFiles, + Implicits: deps, Args: map[string]string{ "classpath": flags.kotlincClasspath.FormJavaClassPath(""), "kotlincFlags": flags.kotlincFlags, "commonSrcFilesArg": commonSrcFilesArg, "srcJars": strings.Join(srcJars.Strings(), " "), "classesDir": android.PathForModuleOut(ctx, "kotlinc", "classes").String(), + "headerClassesDir": android.PathForModuleOut(ctx, "kotlinc", "header_classes").String(), + "headerJar": headerOutputFile.String(), "srcJarDir": android.PathForModuleOut(ctx, "kotlinc", "srcJars").String(), "kotlinBuildFile": android.PathForModuleOut(ctx, "kotlinc-build.xml").String(), "emptyDir": android.PathForModuleOut(ctx, "kotlinc", "empty").String(), -- cgit v1.2.3-59-g8ed1b