summaryrefslogtreecommitdiff
path: root/java/kotlin.go
diff options
context:
space:
mode:
Diffstat (limited to 'java/kotlin.go')
-rw-r--r--java/kotlin.go49
1 files changed, 48 insertions, 1 deletions
diff --git a/java/kotlin.go b/java/kotlin.go
index c28bc3f54..f42d16304 100644
--- a/java/kotlin.go
+++ b/java/kotlin.go
@@ -64,6 +64,28 @@ var kotlinc = pctx.AndroidRemoteStaticRule("kotlinc", android.RemoteRuleSupports
"kotlincFlags", "classpath", "srcJars", "commonSrcFilesArg", "srcJarDir", "classesDir",
"headerClassesDir", "headerJar", "kotlinJvmTarget", "kotlinBuildFile", "emptyDir", "name")
+var kotlinKytheExtract = pctx.AndroidStaticRule("kotlinKythe",
+ blueprint.RuleParams{
+ Command: `rm -rf "$srcJarDir" && mkdir -p "$srcJarDir" && ` +
+ `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" -f "*.kt" $srcJars && ` +
+ `${config.KotlinKytheExtractor} -corpus ${kytheCorpus} --srcs @$out.rsp --srcs @"$srcJarDir/list" $commonSrcFilesList --cp @$classpath -o $out --kotlin_out $outJar ` +
+ // wrap the additional kotlin args.
+ // Skip Xbuild file, pass the cp explicitly.
+ // Skip header jars, those should not have an effect on kythe results.
+ ` --args '${config.KotlincGlobalFlags} ` +
+ ` ${config.KotlincSuppressJDK9Warnings} ${config.JavacHeapFlags} ` +
+ ` $kotlincFlags -jvm-target $kotlinJvmTarget ` +
+ `${config.KotlincKytheGlobalFlags}'`,
+ CommandDeps: []string{
+ "${config.KotlinKytheExtractor}",
+ "${config.ZipSyncCmd}",
+ },
+ Rspfile: "$out.rsp",
+ RspfileContent: "$in",
+ },
+ "classpath", "kotlincFlags", "commonSrcFilesList", "kotlinJvmTarget", "outJar", "srcJars", "srcJarDir",
+)
+
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
@@ -81,7 +103,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, headerOutputFile android.WritablePath,
+func (j *Module) kotlinCompile(ctx android.ModuleContext, outputFile, headerOutputFile android.WritablePath,
srcFiles, commonSrcFiles, srcJars android.Paths,
flags javaBuilderFlags) {
@@ -127,6 +149,31 @@ func kotlinCompile(ctx android.ModuleContext, outputFile, headerOutputFile andro
"name": kotlinName,
},
})
+
+ // Emit kythe xref rule
+ if (ctx.Config().EmitXrefRules()) && ctx.Module() == ctx.PrimaryModule() {
+ extractionFile := outputFile.ReplaceExtension(ctx, "kzip")
+ args := map[string]string{
+ "classpath": classpathRspFile.String(),
+ "kotlincFlags": flags.kotlincFlags,
+ "kotlinJvmTarget": flags.javaVersion.StringForKotlinc(),
+ "outJar": outputFile.String(),
+ "srcJars": strings.Join(srcJars.Strings(), " "),
+ "srcJarDir": android.PathForModuleOut(ctx, "kotlinc", "srcJars.xref").String(),
+ }
+ if commonSrcsList.Valid() {
+ args["commonSrcFilesList"] = "--common_srcs @" + commonSrcsList.String()
+ }
+ ctx.Build(pctx, android.BuildParams{
+ Rule: kotlinKytheExtract,
+ Description: "kotlinKythe",
+ Output: extractionFile,
+ Inputs: srcFiles,
+ Implicits: deps,
+ Args: args,
+ })
+ j.kytheKotlinFiles = append(j.kytheKotlinFiles, extractionFile)
+ }
}
var kaptStubs = pctx.AndroidRemoteStaticRule("kaptStubs", android.RemoteRuleSupports{Goma: true},