summaryrefslogtreecommitdiff
path: root/java/base.go
diff options
context:
space:
mode:
author Colin Cross <ccross@android.com> 2024-07-26 12:02:36 -0700
committer Colin Cross <ccross@android.com> 2024-07-30 14:46:13 -0700
commit7707b246efe17400aa27e843a507232bd02efd66 (patch)
tree7f5b41b4c6d11b92141159f2dcd78e6420a8bd5c /java/base.go
parentbd73d0db41ac84144c60e7719df106bda8efb663 (diff)
Don't hold on to WritablePath
Since only a single rule can write to a given WritablePath, it is unecessary to hold on to the WritablePath once the rule has been created. Keeping a WritablePath causes complications, as it prevents using the input Path as the output when no modifications to the input file are necessary. The normal pattern should be to create a WritablePath using PathForModuleOut, build the rule that writes to the WritablePath, and then store the WritablePath as a Path for use as an input to any future rules. WithoutRel previously only existed on OutputPath, which required keeping the output path of the module as an OutputPath for as long as possible in order to call WithoutRel on it at the end of the module. Add WithoutRel to Path, make it always return a Path type, and implement it on all the types that implement Path by using a helper in basePath. Replace long-lived WritablePaths with Paths. Test: all soong tests pass Flag: EXEMPT refactor Change-Id: I40f28075ce151e4be80d6cfc7ec173dfa46f9bbf
Diffstat (limited to 'java/base.go')
-rw-r--r--java/base.go49
1 files changed, 21 insertions, 28 deletions
diff --git a/java/base.go b/java/base.go
index 02dc3e35b..44bc75946 100644
--- a/java/base.go
+++ b/java/base.go
@@ -1303,7 +1303,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath
return
}
- kotlinJarPath := j.repackageFlagsIfNecessary(ctx, kotlinJar.OutputPath, jarName, "kotlinc")
+ kotlinJarPath := j.repackageFlagsIfNecessary(ctx, kotlinJar, jarName, "kotlinc")
// Make javac rule depend on the kotlinc rule
flags.classpath = append(classpath{kotlinHeaderJar}, flags.classpath...)
@@ -1505,7 +1505,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath
// 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
+ var outputFile android.Path
if len(jars) == 1 && !manifest.Valid() {
// Optimization: skip the combine step as there is nothing to do
@@ -1521,36 +1521,28 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath
// to the copy rules.
stub, _ := moduleStubLinkType(ctx.ModuleName())
- // Transform the single path to the jar into an OutputPath as that is required by the following
- // code.
- if moduleOutPath, ok := jars[0].(android.ModuleOutPath); ok && !stub {
- // The path contains an embedded OutputPath so reuse that.
- outputFile = moduleOutPath.OutputPath
- } else if outputPath, ok := jars[0].(android.OutputPath); ok && !stub {
- // The path is an OutputPath so reuse it directly.
- outputFile = outputPath
- } else {
- // The file is not in the out directory so create an OutputPath into which it can be copied
- // and which the following code can use to refer to it.
+ if stub {
combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
ctx.Build(pctx, android.BuildParams{
Rule: android.Cp,
Input: jars[0],
Output: combinedJar,
})
- outputFile = combinedJar.OutputPath
+ outputFile = combinedJar
+ } else {
+ outputFile = jars[0]
}
} else {
combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest,
false, nil, nil)
- outputFile = combinedJar.OutputPath
+ outputFile = combinedJar
}
// jarjar implementation jar if necessary
if j.expandJarjarRules != nil {
// Transform classes.jar into classes-jarjar.jar
- jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName).OutputPath
+ jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName)
TransformJarJar(ctx, jarjarFile, outputFile, j.expandJarjarRules)
outputFile = jarjarFile
@@ -1575,15 +1567,16 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath
// will check that the jar only contains the permitted packages. The new location will become
// the output file of this module.
inputFile := outputFile
- outputFile = android.PathForModuleOut(ctx, "package-check", jarName).OutputPath
+ packageCheckOutputFile := android.PathForModuleOut(ctx, "package-check", jarName)
ctx.Build(pctx, android.BuildParams{
Rule: android.Cp,
Input: inputFile,
- Output: outputFile,
+ Output: packageCheckOutputFile,
// Make sure that any dependency on the output file will cause ninja to run the package check
// rule.
Validation: pkgckFile,
})
+ outputFile = packageCheckOutputFile
// Check packages and create a timestamp file when complete.
CheckJarPackages(ctx, pkgckFile, outputFile, j.properties.Permitted_packages)
@@ -1618,7 +1611,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath
implementationAndResourcesJar := outputFile
if j.resourceJar != nil {
jars := android.Paths{j.resourceJar, implementationAndResourcesJar}
- combinedJar := android.PathForModuleOut(ctx, "withres", jarName).OutputPath
+ combinedJar := android.PathForModuleOut(ctx, "withres", jarName)
TransformJarsToJar(ctx, combinedJar, "for resources", jars, manifest,
false, nil, nil)
implementationAndResourcesJar = combinedJar
@@ -1645,7 +1638,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath
android.PathForSource(ctx, "build/make/core/proguard.jacoco.flags"))
}
// Dex compilation
- var dexOutputFile android.OutputPath
+ var dexOutputFile android.Path
params := &compileDexParams{
flags: flags,
sdkVersion: j.SdkVersion(ctx),
@@ -1672,17 +1665,17 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath
// If r8/d8 provides a profile that matches the optimized dex, use that for dexpreopt.
if dexArtProfileOutput != nil {
- j.dexpreopter.SetRewrittenProfile(*dexArtProfileOutput)
+ j.dexpreopter.SetRewrittenProfile(dexArtProfileOutput)
}
// merge dex jar with resources if necessary
if j.resourceJar != nil {
jars := android.Paths{dexOutputFile, j.resourceJar}
- combinedJar := android.PathForModuleOut(ctx, "dex-withres", jarName).OutputPath
+ combinedJar := android.PathForModuleOut(ctx, "dex-withres", jarName)
TransformJarsToJar(ctx, combinedJar, "for dex resources", jars, android.OptionalPath{},
false, nil, nil)
if *j.dexProperties.Uncompress_dex {
- combinedAlignedJar := android.PathForModuleOut(ctx, "dex-withres-aligned", jarName).OutputPath
+ combinedAlignedJar := android.PathForModuleOut(ctx, "dex-withres-aligned", jarName)
TransformZipAlign(ctx, combinedAlignedJar, combinedJar, nil)
dexOutputFile = combinedAlignedJar
} else {
@@ -1842,7 +1835,7 @@ func enableErrorproneFlags(flags javaBuilderFlags) javaBuilderFlags {
}
func (j *Module) compileJavaClasses(ctx android.ModuleContext, jarName string, idx int,
- srcFiles, srcJars android.Paths, flags javaBuilderFlags, extraJarDeps android.Paths) android.WritablePath {
+ srcFiles, srcJars android.Paths, flags javaBuilderFlags, extraJarDeps android.Paths) android.Path {
kzipName := pathtools.ReplaceExtension(jarName, "kzip")
annoSrcJar := android.PathForModuleOut(ctx, "javac", "anno.srcjar")
@@ -1852,7 +1845,7 @@ func (j *Module) compileJavaClasses(ctx android.ModuleContext, jarName string, i
jarName += strconv.Itoa(idx)
}
- classes := android.PathForModuleOut(ctx, "javac", jarName).OutputPath
+ classes := android.PathForModuleOut(ctx, "javac", jarName)
TransformJavaToClasses(ctx, classes, idx, srcFiles, srcJars, annoSrcJar, flags, extraJarDeps)
if ctx.Config().EmitXrefRules() && ctx.Module() == ctx.PrimaryModule() {
@@ -1947,10 +1940,10 @@ func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars
}
func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags,
- classesJar android.Path, jarName string, specs string) android.OutputPath {
+ classesJar android.Path, jarName string, specs string) android.Path {
jacocoReportClassesFile := android.PathForModuleOut(ctx, "jacoco-report-classes", jarName)
- instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName).OutputPath
+ instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName)
jacocoInstrumentJar(ctx, instrumentedJar, jacocoReportClassesFile, classesJar, specs)
@@ -2714,7 +2707,7 @@ func getJarJarRuleText(provider *JarJarProviderData) string {
}
// 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 {
+func (j *Module) repackageFlagsIfNecessary(ctx android.ModuleContext, infile android.Path, jarName, info string) android.Path {
if j.repackageJarjarRules == nil {
return infile
}