Merge changes I8d060594,I2b6a57ae into main am: 5d55b66861

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2980832

Change-Id: If904b08b58a76b4d82ca3926e4d23d89ffcc588f
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Colin Cross 2024-02-29 19:33:08 +00:00 committed by Automerger Merge Worker
commit 8b64ad9506
3 changed files with 57 additions and 14 deletions

View file

@ -931,8 +931,8 @@ func TestAndroidResourceProcessor(t *testing.T) {
"out/soong/.intermediates/direct_import/android_common/aar/classes-combined.jar",
},
appCombined: []string{
"out/soong/.intermediates/app/android_common/busybox/R.jar",
"out/soong/.intermediates/app/android_common/javac/app.jar",
"out/soong/.intermediates/app/android_common/busybox/R.jar",
"out/soong/.intermediates/direct/android_common/combined/direct.jar",
"out/soong/.intermediates/direct_import/android_common/aar/classes-combined.jar",
},
@ -1037,8 +1037,8 @@ func TestAndroidResourceProcessor(t *testing.T) {
"out/soong/.intermediates/direct_import/android_common/aar/classes-combined.jar",
},
appCombined: []string{
"out/soong/.intermediates/app/android_common/busybox/R.jar",
"out/soong/.intermediates/app/android_common/javac/app.jar",
"out/soong/.intermediates/app/android_common/busybox/R.jar",
"out/soong/.intermediates/direct/android_common/combined/direct.jar",
"out/soong/.intermediates/direct_import/android_common/aar/classes-combined.jar",
},

View file

@ -1307,7 +1307,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath
}
}
jars := append(android.Paths(nil), kotlinJars...)
jars := slices.Clone(kotlinJars)
j.compiledSrcJars = srcJars
@ -1322,7 +1322,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath
// allow for the use of annotation processors that do function correctly
// with sharding enabled. See: b/77284273.
}
extraJars := append(android.CopyOf(extraCombinedJars), kotlinHeaderJars...)
extraJars := append(slices.Clone(kotlinHeaderJars), extraCombinedJars...)
headerJarFileWithoutDepsOrJarjar, j.headerJarFile, j.repackagedHeaderJarFile =
j.compileJavaHeader(ctx, uniqueJavaFiles, srcJars, deps, flags, jarName, extraJars)
if ctx.Failed() {
@ -1396,6 +1396,8 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath
}
}
jars = append(jars, extraCombinedJars...)
j.srcJarArgs, j.srcJarDeps = resourcePathsToJarArgs(srcFiles), srcFiles
var includeSrcJar android.WritablePath
@ -1482,8 +1484,6 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath
jars = append(jars, servicesJar)
}
jars = append(android.CopyOf(extraCombinedJars), jars...)
// Combine the classes built from sources, any manifests, and any static libraries into
// classes.jar. If there is only one input jar this step will be skipped.
var outputFile android.OutputPath

View file

@ -212,6 +212,14 @@ var (
CommandDeps: []string{"${config.MergeZipsCmd}"},
},
"jarArgs")
combineJarRsp = pctx.AndroidStaticRule("combineJarRsp",
blueprint.RuleParams{
Command: `${config.MergeZipsCmd} --ignore-duplicates -j $jarArgs $out @$out.rsp`,
CommandDeps: []string{"${config.MergeZipsCmd}"},
Rspfile: "$out.rsp",
RspfileContent: "$in",
},
"jarArgs")
jarjar = pctx.AndroidStaticRule("jarjar",
blueprint.RuleParams{
@ -418,7 +426,7 @@ func emitXrefRule(ctx android.ModuleContext, xrefFile android.WritablePath, idx
})
}
func turbineFlags(ctx android.ModuleContext, flags javaBuilderFlags) (string, android.Paths) {
func turbineFlags(ctx android.ModuleContext, flags javaBuilderFlags, dir string) (string, android.Paths) {
var deps android.Paths
classpath := flags.classpath
@ -443,13 +451,21 @@ func turbineFlags(ctx android.ModuleContext, flags javaBuilderFlags) (string, an
deps = append(deps, classpath...)
turbineFlags := bootClasspath + " " + classpath.FormTurbineClassPath("--classpath ")
const flagsLimit = 32 * 1024
if len(turbineFlags) > flagsLimit {
flagsRspFile := android.PathForModuleOut(ctx, dir, "turbine-flags.rsp")
android.WriteFileRule(ctx, flagsRspFile, turbineFlags)
turbineFlags = "@" + flagsRspFile.String()
deps = append(deps, flagsRspFile)
}
return turbineFlags, deps
}
func TransformJavaToHeaderClasses(ctx android.ModuleContext, outputFile android.WritablePath,
srcFiles, srcJars android.Paths, flags javaBuilderFlags) {
turbineFlags, deps := turbineFlags(ctx, flags)
turbineFlags, deps := turbineFlags(ctx, flags, "turbine")
deps = append(deps, srcJars...)
@ -481,7 +497,7 @@ func TransformJavaToHeaderClasses(ctx android.ModuleContext, outputFile android.
func TurbineApt(ctx android.ModuleContext, outputSrcJar, outputResJar android.WritablePath,
srcFiles, srcJars android.Paths, flags javaBuilderFlags) {
turbineFlags, deps := turbineFlags(ctx, flags)
turbineFlags, deps := turbineFlags(ctx, flags, "kapt")
deps = append(deps, srcJars...)
@ -534,14 +550,14 @@ func transformJavaToClasses(ctx android.ModuleContext, outputFile android.Writab
deps = append(deps, srcJars...)
classpath := flags.classpath
javacClasspath := flags.classpath
var bootClasspath string
if flags.javaVersion.usesJavaModules() {
var systemModuleDeps android.Paths
bootClasspath, systemModuleDeps = flags.systemModules.FormJavaSystemModulesPath(ctx.Device())
deps = append(deps, systemModuleDeps...)
classpath = append(flags.java9Classpath, classpath...)
javacClasspath = append(flags.java9Classpath, javacClasspath...)
} else {
deps = append(deps, flags.bootClasspath...)
if len(flags.bootClasspath) == 0 && ctx.Device() {
@ -553,7 +569,19 @@ func transformJavaToClasses(ctx android.ModuleContext, outputFile android.Writab
}
}
deps = append(deps, classpath...)
classpathArg := javacClasspath.FormJavaClassPath("-classpath")
// Keep the command line under the MAX_ARG_STRLEN limit by putting the classpath argument into an rsp file
// if it is too long.
const classpathLimit = 64 * 1024
if len(classpathArg) > classpathLimit {
classpathRspFile := outputFile.ReplaceExtension(ctx, "classpath")
android.WriteFileRule(ctx, classpathRspFile, classpathArg)
deps = append(deps, classpathRspFile)
classpathArg = "@" + classpathRspFile.String()
}
deps = append(deps, javacClasspath...)
deps = append(deps, flags.processorPath...)
processor := "-proc:none"
@ -584,7 +612,7 @@ func transformJavaToClasses(ctx android.ModuleContext, outputFile android.Writab
Args: map[string]string{
"javacFlags": flags.javacFlags,
"bootClasspath": bootClasspath,
"classpath": classpath.FormJavaClassPath("-classpath"),
"classpath": classpathArg,
"processorpath": flags.processorPath.FormJavaClassPath("-processorpath"),
"processor": processor,
"srcJars": strings.Join(srcJars.Strings(), " "),
@ -643,8 +671,23 @@ func TransformJarsToJar(ctx android.ModuleContext, outputFile android.WritablePa
jarArgs = append(jarArgs, "-D")
}
rule := combineJar
// Keep the command line under the MAX_ARG_STRLEN limit by putting the list of jars into an rsp file
// if it is too long.
const jarsLengthLimit = 64 * 1024
jarsLength := 0
for i, jar := range jars {
if i != 0 {
jarsLength += 1
}
jarsLength += len(jar.String())
}
if jarsLength > jarsLengthLimit {
rule = combineJarRsp
}
ctx.Build(pctx, android.BuildParams{
Rule: combineJar,
Rule: rule,
Description: desc,
Output: outputFile,
Inputs: jars,