Merge changes Ib238a83a,I9ed6a649 into main

* changes:
  Use rsp for kotlin classpath
  Move kotlin stdlib after javac jars
This commit is contained in:
Colin Cross
2024-08-08 18:11:59 +00:00
committed by Gerrit Code Review
3 changed files with 28 additions and 17 deletions

View File

@@ -1211,6 +1211,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath
var kotlinJars android.Paths var kotlinJars android.Paths
var kotlinHeaderJars android.Paths var kotlinHeaderJars android.Paths
var kotlinExtraJars android.Paths
// Prepend extraClasspathJars to classpath so that the resource processor R.jar comes before // Prepend extraClasspathJars to classpath so that the resource processor R.jar comes before
// any dependencies so that it can override any non-final R classes from dependencies with the // any dependencies so that it can override any non-final R classes from dependencies with the
@@ -1321,17 +1322,8 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath
kotlinJars = append(kotlinJars, kotlinJarPath) kotlinJars = append(kotlinJars, kotlinJarPath)
kotlinHeaderJars = append(kotlinHeaderJars, kotlinHeaderJar) kotlinHeaderJars = append(kotlinHeaderJars, kotlinHeaderJar)
kotlinExtraJars = append(kotlinExtraJars, deps.kotlinStdlib...)
// Jar kotlin classes into the final jar after javac kotlinExtraJars = append(kotlinExtraJars, deps.kotlinAnnotations...)
if BoolDefault(j.properties.Static_kotlin_stdlib, true) {
kotlinJars = append(kotlinJars, deps.kotlinStdlib...)
kotlinJars = append(kotlinJars, deps.kotlinAnnotations...)
kotlinHeaderJars = append(kotlinHeaderJars, deps.kotlinStdlib...)
kotlinHeaderJars = append(kotlinHeaderJars, deps.kotlinAnnotations...)
} else {
flags.dexClasspath = append(flags.dexClasspath, deps.kotlinStdlib...)
flags.dexClasspath = append(flags.dexClasspath, deps.kotlinAnnotations...)
}
} }
jars := slices.Clone(kotlinJars) jars := slices.Clone(kotlinJars)
@@ -1349,7 +1341,11 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath
// allow for the use of annotation processors that do function correctly // allow for the use of annotation processors that do function correctly
// with sharding enabled. See: b/77284273. // with sharding enabled. See: b/77284273.
} }
extraJars := append(slices.Clone(kotlinHeaderJars), extraCombinedJars...) extraJars := slices.Clone(kotlinHeaderJars)
if BoolDefault(j.properties.Static_kotlin_stdlib, true) {
extraJars = append(extraJars, kotlinExtraJars...)
}
extraJars = append(extraJars, extraCombinedJars...)
var combinedHeaderJarFile android.Path var combinedHeaderJarFile android.Path
headerJarFileWithoutDepsOrJarjar, combinedHeaderJarFile = headerJarFileWithoutDepsOrJarjar, combinedHeaderJarFile =
j.compileJavaHeader(ctx, uniqueJavaFiles, srcJars, deps, flags, jarName, extraJars) j.compileJavaHeader(ctx, uniqueJavaFiles, srcJars, deps, flags, jarName, extraJars)
@@ -1427,6 +1423,13 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath
} }
} }
// Jar kotlin classes into the final jar after javac
if BoolDefault(j.properties.Static_kotlin_stdlib, true) {
jars = append(jars, kotlinExtraJars...)
} else {
flags.dexClasspath = append(flags.dexClasspath, kotlinExtraJars...)
}
jars = append(jars, extraCombinedJars...) jars = append(jars, extraCombinedJars...)
j.srcJarArgs, j.srcJarDeps = resourcePathsToJarArgs(srcFiles), srcFiles j.srcJarArgs, j.srcJarDeps = resourcePathsToJarArgs(srcFiles), srcFiles

View File

@@ -101,6 +101,10 @@ func kotlinCompile(ctx android.ModuleContext, outputFile, headerOutputFile andro
commonSrcFilesArg = "--common_srcs " + commonSrcsList.String() commonSrcFilesArg = "--common_srcs " + commonSrcsList.String()
} }
classpathRspFile := android.PathForModuleOut(ctx, "kotlinc", "classpath.rsp")
android.WriteFileRule(ctx, classpathRspFile, strings.Join(flags.kotlincClasspath.Strings(), " "))
deps = append(deps, classpathRspFile)
ctx.Build(pctx, android.BuildParams{ ctx.Build(pctx, android.BuildParams{
Rule: kotlinc, Rule: kotlinc,
Description: "kotlinc", Description: "kotlinc",
@@ -109,7 +113,7 @@ func kotlinCompile(ctx android.ModuleContext, outputFile, headerOutputFile andro
Inputs: srcFiles, Inputs: srcFiles,
Implicits: deps, Implicits: deps,
Args: map[string]string{ Args: map[string]string{
"classpath": flags.kotlincClasspath.FormJavaClassPath(""), "classpath": classpathRspFile.String(),
"kotlincFlags": flags.kotlincFlags, "kotlincFlags": flags.kotlincFlags,
"commonSrcFilesArg": commonSrcFilesArg, "commonSrcFilesArg": commonSrcFilesArg,
"srcJars": strings.Join(srcJars.Strings(), " "), "srcJars": strings.Join(srcJars.Strings(), " "),
@@ -205,6 +209,10 @@ func kotlinKapt(ctx android.ModuleContext, srcJarOutputFile, resJarOutputFile an
kotlinName := filepath.Join(ctx.ModuleDir(), ctx.ModuleSubDir(), ctx.ModuleName()) kotlinName := filepath.Join(ctx.ModuleDir(), ctx.ModuleSubDir(), ctx.ModuleName())
kotlinName = strings.ReplaceAll(kotlinName, "/", "__") kotlinName = strings.ReplaceAll(kotlinName, "/", "__")
classpathRspFile := android.PathForModuleOut(ctx, "kapt", "classpath.rsp")
android.WriteFileRule(ctx, classpathRspFile, strings.Join(flags.kotlincClasspath.Strings(), "\n"))
deps = append(deps, classpathRspFile)
// First run kapt to generate .java stubs from .kt files // First run kapt to generate .java stubs from .kt files
kaptStubsJar := android.PathForModuleOut(ctx, "kapt", "stubs.jar") kaptStubsJar := android.PathForModuleOut(ctx, "kapt", "stubs.jar")
ctx.Build(pctx, android.BuildParams{ ctx.Build(pctx, android.BuildParams{
@@ -214,7 +222,7 @@ func kotlinKapt(ctx android.ModuleContext, srcJarOutputFile, resJarOutputFile an
Inputs: srcFiles, Inputs: srcFiles,
Implicits: deps, Implicits: deps,
Args: map[string]string{ Args: map[string]string{
"classpath": flags.kotlincClasspath.FormJavaClassPath(""), "classpath": classpathRspFile.String(),
"kotlincFlags": flags.kotlincFlags, "kotlincFlags": flags.kotlincFlags,
"commonSrcFilesArg": commonSrcFilesArg, "commonSrcFilesArg": commonSrcFilesArg,
"srcJars": strings.Join(srcJars.Strings(), " "), "srcJars": strings.Join(srcJars.Strings(), " "),

View File

@@ -37,7 +37,7 @@ def parse_args():
parser.add_argument('--out', dest='out', parser.add_argument('--out', dest='out',
help='file to which the module.xml contents will be written.') help='file to which the module.xml contents will be written.')
parser.add_argument('--classpath', dest='classpath', action='append', default=[], parser.add_argument('--classpath', dest='classpath', action='append', default=[],
help='classpath to pass to kotlinc.') help='file containing classpath to pass to kotlinc.')
parser.add_argument('--name', dest='name', parser.add_argument('--name', dest='name',
help='name of the module.') help='name of the module.')
parser.add_argument('--out_dir', dest='out_dir', parser.add_argument('--out_dir', dest='out_dir',
@@ -65,8 +65,8 @@ def main():
f.write(' <module name="%s" type="java-production" outputDir="%s">\n' % (args.name, args.out_dir or '')) f.write(' <module name="%s" type="java-production" outputDir="%s">\n' % (args.name, args.out_dir or ''))
# Print classpath entries # Print classpath entries
for c in args.classpath: for classpath_rsp_file in args.classpath:
for entry in c.split(':'): for entry in NinjaRspFileReader(classpath_rsp_file):
path = os.path.abspath(entry) path = os.path.abspath(entry)
f.write(' <classpath path="%s"/>\n' % path) f.write(' <classpath path="%s"/>\n' % path)