Support kotlin multiplatform sources
Add a common_srcs property and propagate it to the module.xml file passed to kotlinc. Test: m checkbuild Change-Id: Ief768bafb943513c9ffbc01e829abc078f0a72bc
This commit is contained in:
@@ -33,7 +33,7 @@ var kotlinc = pctx.AndroidRemoteStaticRule("kotlinc", android.RemoteRuleSupports
|
||||
`${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"` +
|
||||
` --out "$kotlinBuildFile" && ` +
|
||||
` $commonSrcFilesArg --out "$kotlinBuildFile" && ` +
|
||||
`${config.KotlincCmd} ${config.JavacHeapFlags} $kotlincFlags ` +
|
||||
`-jvm-target $kotlinJvmTarget -Xbuild-file=$kotlinBuildFile -kotlin-home $emptyDir && ` +
|
||||
`${config.SoongZipCmd} -jar -o $out -C $classesDir -D $classesDir && ` +
|
||||
@@ -54,21 +54,43 @@ var kotlinc = pctx.AndroidRemoteStaticRule("kotlinc", android.RemoteRuleSupports
|
||||
Rspfile: "$out.rsp",
|
||||
RspfileContent: `$in`,
|
||||
},
|
||||
"kotlincFlags", "classpath", "srcJars", "srcJarDir", "classesDir", "kotlinJvmTarget", "kotlinBuildFile",
|
||||
"emptyDir", "name")
|
||||
"kotlincFlags", "classpath", "srcJars", "commonSrcFilesArg", "srcJarDir", "classesDir",
|
||||
"kotlinJvmTarget", "kotlinBuildFile", "emptyDir", "name")
|
||||
|
||||
func kotlinCommonSrcsList(ctx android.ModuleContext, commonSrcFiles android.Paths) android.OptionalPath {
|
||||
if len(commonSrcFiles) > 0 {
|
||||
// The list of common_srcs may be too long to put on the command line, but
|
||||
// we can't use the rsp file because it is already being used for srcs.
|
||||
// Insert a second rule to write out the list of resources to a file.
|
||||
commonSrcsList := android.PathForModuleOut(ctx, "kotlinc_common_srcs.list")
|
||||
rule := android.NewRuleBuilder()
|
||||
rule.Command().Text("cp").FlagWithRspFileInputList("", commonSrcFiles).Output(commonSrcsList)
|
||||
rule.Build(pctx, ctx, "kotlin_common_srcs_list", "kotlin common_srcs list")
|
||||
return android.OptionalPathForPath(commonSrcsList)
|
||||
}
|
||||
return android.OptionalPath{}
|
||||
}
|
||||
|
||||
// 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,
|
||||
srcFiles, srcJars android.Paths,
|
||||
srcFiles, commonSrcFiles, srcJars android.Paths,
|
||||
flags javaBuilderFlags) {
|
||||
|
||||
var deps android.Paths
|
||||
deps = append(deps, flags.kotlincClasspath...)
|
||||
deps = append(deps, srcJars...)
|
||||
deps = append(deps, commonSrcFiles...)
|
||||
|
||||
kotlinName := filepath.Join(ctx.ModuleDir(), ctx.ModuleSubDir(), ctx.ModuleName())
|
||||
kotlinName = strings.ReplaceAll(kotlinName, "/", "__")
|
||||
|
||||
commonSrcsList := kotlinCommonSrcsList(ctx, commonSrcFiles)
|
||||
commonSrcFilesArg := ""
|
||||
if commonSrcsList.Valid() {
|
||||
deps = append(deps, commonSrcsList.Path())
|
||||
commonSrcFilesArg = "--common_srcs " + commonSrcsList.String()
|
||||
}
|
||||
|
||||
ctx.Build(pctx, android.BuildParams{
|
||||
Rule: kotlinc,
|
||||
Description: "kotlinc",
|
||||
@@ -76,13 +98,14 @@ func kotlinCompile(ctx android.ModuleContext, outputFile android.WritablePath,
|
||||
Inputs: srcFiles,
|
||||
Implicits: deps,
|
||||
Args: map[string]string{
|
||||
"classpath": flags.kotlincClasspath.FormJavaClassPath(""),
|
||||
"kotlincFlags": flags.kotlincFlags,
|
||||
"srcJars": strings.Join(srcJars.Strings(), " "),
|
||||
"classesDir": android.PathForModuleOut(ctx, "kotlinc", "classes").String(),
|
||||
"srcJarDir": android.PathForModuleOut(ctx, "kotlinc", "srcJars").String(),
|
||||
"kotlinBuildFile": android.PathForModuleOut(ctx, "kotlinc-build.xml").String(),
|
||||
"emptyDir": android.PathForModuleOut(ctx, "kotlinc", "empty").String(),
|
||||
"classpath": flags.kotlincClasspath.FormJavaClassPath(""),
|
||||
"kotlincFlags": flags.kotlincFlags,
|
||||
"commonSrcFilesArg": commonSrcFilesArg,
|
||||
"srcJars": strings.Join(srcJars.Strings(), " "),
|
||||
"classesDir": android.PathForModuleOut(ctx, "kotlinc", "classes").String(),
|
||||
"srcJarDir": android.PathForModuleOut(ctx, "kotlinc", "srcJars").String(),
|
||||
"kotlinBuildFile": android.PathForModuleOut(ctx, "kotlinc-build.xml").String(),
|
||||
"emptyDir": android.PathForModuleOut(ctx, "kotlinc", "empty").String(),
|
||||
// http://b/69160377 kotlinc only supports -jvm-target 1.6 and 1.8
|
||||
"kotlinJvmTarget": "1.8",
|
||||
"name": kotlinName,
|
||||
@@ -97,7 +120,7 @@ var kapt = pctx.AndroidRemoteStaticRule("kapt", android.RemoteRuleSupports{Goma:
|
||||
`${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
|
||||
`${config.GenKotlinBuildFileCmd} --classpath "$classpath" --name "$name"` +
|
||||
` --srcs "$out.rsp" --srcs "$srcJarDir/list"` +
|
||||
` --out "$kotlinBuildFile" && ` +
|
||||
` $commonSrcFilesArg --out "$kotlinBuildFile" && ` +
|
||||
`${config.KotlincCmd} ${config.KotlincSuppressJDK9Warnings} ${config.JavacHeapFlags} $kotlincFlags ` +
|
||||
`-Xplugin=${config.KotlinKaptJar} ` +
|
||||
`-P plugin:org.jetbrains.kotlin.kapt3:sources=$kaptDir/sources ` +
|
||||
@@ -124,21 +147,31 @@ var kapt = pctx.AndroidRemoteStaticRule("kapt", android.RemoteRuleSupports{Goma:
|
||||
RspfileContent: `$in`,
|
||||
},
|
||||
"kotlincFlags", "encodedJavacFlags", "kaptProcessorPath", "kaptProcessor",
|
||||
"classpath", "srcJars", "srcJarDir", "kaptDir", "kotlinJvmTarget", "kotlinBuildFile", "name",
|
||||
"classesJarOut")
|
||||
"classpath", "srcJars", "commonSrcFilesArg", "srcJarDir", "kaptDir", "kotlinJvmTarget",
|
||||
"kotlinBuildFile", "name", "classesJarOut")
|
||||
|
||||
// kotlinKapt performs Kotlin-compatible annotation processing. It takes .kt and .java sources and srcjars, and runs
|
||||
// annotation processors over all of them, producing a srcjar of generated code in outputFile. The srcjar should be
|
||||
// added as an additional input to kotlinc and javac rules, and the javac rule should have annotation processing
|
||||
// disabled.
|
||||
func kotlinKapt(ctx android.ModuleContext, srcJarOutputFile, resJarOutputFile android.WritablePath,
|
||||
srcFiles, srcJars android.Paths,
|
||||
srcFiles, commonSrcFiles, srcJars android.Paths,
|
||||
flags javaBuilderFlags) {
|
||||
|
||||
srcFiles = append(android.Paths(nil), srcFiles...)
|
||||
|
||||
var deps android.Paths
|
||||
deps = append(deps, flags.kotlincClasspath...)
|
||||
deps = append(deps, srcJars...)
|
||||
deps = append(deps, flags.processorPath...)
|
||||
deps = append(deps, commonSrcFiles...)
|
||||
|
||||
commonSrcsList := kotlinCommonSrcsList(ctx, commonSrcFiles)
|
||||
commonSrcFilesArg := ""
|
||||
if commonSrcsList.Valid() {
|
||||
deps = append(deps, commonSrcsList.Path())
|
||||
commonSrcFilesArg = "--common_srcs " + commonSrcsList.String()
|
||||
}
|
||||
|
||||
kaptProcessorPath := flags.processorPath.FormRepeatedClassPath("-P plugin:org.jetbrains.kotlin.kapt3:apclasspath=")
|
||||
|
||||
@@ -168,6 +201,7 @@ func kotlinKapt(ctx android.ModuleContext, srcJarOutputFile, resJarOutputFile an
|
||||
Args: map[string]string{
|
||||
"classpath": flags.kotlincClasspath.FormJavaClassPath(""),
|
||||
"kotlincFlags": flags.kotlincFlags,
|
||||
"commonSrcFilesArg": commonSrcFilesArg,
|
||||
"srcJars": strings.Join(srcJars.Strings(), " "),
|
||||
"srcJarDir": android.PathForModuleOut(ctx, "kapt", "srcJars").String(),
|
||||
"kotlinBuildFile": android.PathForModuleOut(ctx, "kapt", "build.xml").String(),
|
||||
|
Reference in New Issue
Block a user