summaryrefslogtreecommitdiff
path: root/java/base.go
diff options
context:
space:
mode:
author Zi Wang <mrziwang@google.com> 2024-04-02 16:44:02 +0000
committer Android Build Cherrypicker Worker <android-build-cherrypicker-worker@google.com> 2024-04-02 16:44:02 +0000
commitddb2ee512cfc87d0c1710ba3845a0a44611f958f (patch)
tree7c90f2cff32b057b7922256c3f71d473a6c02143 /java/base.go
parentf16c5a0a7db488497884dbe8fcc6f16790b4ff82 (diff)
Move jarjar repackage action before combine action
With this change, the jarjar repackage actions are only on the local classes of each module instead of the combined jar that contains the static libs. The static libs don't need jarjar repackage action on this module level because it has been repackaged when building itself. This change also removes the skip_jarjar_repackage property since it's incompatible with this change. Actually skipping jarjar repackage on a dep may result in incomplete repackage on the module output. Test: CI and observing the build time of SystemUIGoogle Bug: 328067025 Ignore-AOSP-First: Will cp to aosp (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:78ffdd47a658dec4bf79e63d11a5f0f3b94876a4) Merged-In: I476d959af025c46d2ba6d3f48ea378a086666a33 Change-Id: I476d959af025c46d2ba6d3f48ea378a086666a33
Diffstat (limited to 'java/base.go')
-rw-r--r--java/base.go42
1 files changed, 21 insertions, 21 deletions
diff --git a/java/base.go b/java/base.go
index 9bb133dc3..e2f20cee5 100644
--- a/java/base.go
+++ b/java/base.go
@@ -94,9 +94,6 @@ type CommonProperties struct {
// if not blank, used as prefix to generate repackage rule
Jarjar_prefix *string
- // if set to true, skip the jarjar repackaging
- Skip_jarjar_repackage *bool
-
// If not blank, set the java version passed to javac as -source and -target
Java_version *string
@@ -1103,13 +1100,11 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath
jarjarProviderData := j.collectJarJarRules(ctx)
if jarjarProviderData != nil {
android.SetProvider(ctx, JarJarProvider, *jarjarProviderData)
- if !proptools.Bool(j.properties.Skip_jarjar_repackage) {
- text := getJarJarRuleText(jarjarProviderData)
- if text != "" {
- ruleTextFile := android.PathForModuleOut(ctx, "repackaged-jarjar", "repackaging.txt")
- android.WriteFileRule(ctx, ruleTextFile, text)
- j.repackageJarjarRules = ruleTextFile
- }
+ text := getJarJarRuleText(jarjarProviderData)
+ if text != "" {
+ ruleTextFile := android.PathForModuleOut(ctx, "repackaged-jarjar", "repackaging.txt")
+ android.WriteFileRule(ctx, ruleTextFile, text)
+ j.repackageJarjarRules = ruleTextFile
}
}
@@ -1294,10 +1289,12 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath
return
}
+ kotlinJarPath := j.repackageFlagsIfNecessary(ctx, kotlinJar.OutputPath, jarName, "kotlinc")
+
// Make javac rule depend on the kotlinc rule
flags.classpath = append(classpath{kotlinHeaderJar}, flags.classpath...)
- kotlinJars = append(kotlinJars, kotlinJar)
+ kotlinJars = append(kotlinJars, kotlinJarPath)
kotlinHeaderJars = append(kotlinHeaderJars, kotlinHeaderJar)
// Jar kotlin classes into the final jar after javac
@@ -1377,6 +1374,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath
for idx, shardSrc := range shardSrcs {
classes := j.compileJavaClasses(ctx, jarName, idx, shardSrc,
nil, flags, extraJarDeps)
+ classes = j.repackageFlagsIfNecessary(ctx, classes, jarName, "javac-"+strconv.Itoa(idx))
jars = append(jars, classes)
}
}
@@ -1389,11 +1387,13 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath
for idx, shardSrcJars := range shardSrcJarsList {
classes := j.compileJavaClasses(ctx, jarName, startIdx+idx,
nil, shardSrcJars, flags, extraJarDeps)
+ classes = j.repackageFlagsIfNecessary(ctx, classes, jarName, "javac-"+strconv.Itoa(startIdx+idx))
jars = append(jars, classes)
}
}
} else {
classes := j.compileJavaClasses(ctx, jarName, -1, uniqueJavaFiles, srcJars, flags, extraJarDeps)
+ classes = j.repackageFlagsIfNecessary(ctx, classes, jarName, "javac")
jars = append(jars, classes)
}
if ctx.Failed() {
@@ -1552,16 +1552,6 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath
}
}
- // Automatic jarjar rules propagation
- if j.repackageJarjarRules != nil {
- repackagedJarjarFile := android.PathForModuleOut(ctx, "repackaged-jarjar", jarName).OutputPath
- TransformJarJar(ctx, repackagedJarjarFile, outputFile, j.repackageJarjarRules)
- outputFile = repackagedJarjarFile
- if ctx.Failed() {
- return
- }
- }
-
// Check package restrictions if necessary.
if len(j.properties.Permitted_packages) > 0 {
// Time stamp file created by the package check rule.
@@ -2686,6 +2676,16 @@ func getJarJarRuleText(provider *JarJarProviderData) string {
return result
}
+// Repackage the flags if the jarjar rule txt for the flags is generated
+func (j *Module) repackageFlagsIfNecessary(ctx android.ModuleContext, infile android.WritablePath, jarName, info string) android.WritablePath {
+ if j.repackageJarjarRules == nil {
+ return infile
+ }
+ repackagedJarjarFile := android.PathForModuleOut(ctx, "repackaged-jarjar", info+jarName)
+ TransformJarJar(ctx, repackagedJarjarFile, infile, j.repackageJarjarRules)
+ return repackagedJarjarFile
+}
+
func addPlugins(deps *deps, pluginJars android.Paths, pluginClasses ...string) {
deps.processorPath = append(deps.processorPath, pluginJars...)
deps.processorClasses = append(deps.processorClasses, pluginClasses...)