diff --git a/java/dex.go b/java/dex.go index 055d47983..24600c20f 100644 --- a/java/dex.go +++ b/java/dex.go @@ -263,10 +263,10 @@ func (d *dexer) r8Flags(ctx android.ModuleContext, flags javaBuilderFlags) (r8Fl } func (d *dexer) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, minSdkVersion sdkSpec, - classesJar android.Path, jarName string) android.ModuleOutPath { + classesJar android.Path, jarName string) android.OutputPath { // Compile classes.jar into classes.dex and then javalib.jar - javalibJar := android.PathForModuleOut(ctx, "dex", jarName) + javalibJar := android.PathForModuleOut(ctx, "dex", jarName).OutputPath outDir := android.PathForModuleOut(ctx, "dex") zipFlags := "--ignore_missing_files" @@ -329,7 +329,7 @@ func (d *dexer) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, mi }) } if proptools.Bool(d.dexProperties.Uncompress_dex) { - alignedJavalibJar := android.PathForModuleOut(ctx, "aligned", jarName) + alignedJavalibJar := android.PathForModuleOut(ctx, "aligned", jarName).OutputPath TransformZipAlign(ctx, alignedJavalibJar, javalibJar) javalibJar = alignedJavalibJar } diff --git a/java/dexpreopt.go b/java/dexpreopt.go index ac00592a7..da621003a 100644 --- a/java/dexpreopt.go +++ b/java/dexpreopt.go @@ -118,7 +118,7 @@ func odexOnSystemOther(ctx android.ModuleContext, installPath android.InstallPat return dexpreopt.OdexOnSystemOtherByName(ctx.ModuleName(), android.InstallPathToOnDevicePath(ctx, installPath), dexpreopt.GetGlobalConfig(ctx)) } -func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.ModuleOutPath) { +func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.WritablePath) { // TODO(b/148690468): The check on d.installPath is to bail out in cases where // the dexpreopter struct hasn't been fully initialized before we're called, // e.g. in aar.go. This keeps the behaviour that dexpreopting is effectively diff --git a/java/hiddenapi.go b/java/hiddenapi.go index 2cd025e43..eafbf5df0 100644 --- a/java/hiddenapi.go +++ b/java/hiddenapi.go @@ -89,8 +89,8 @@ type hiddenAPIIntf interface { var _ hiddenAPIIntf = (*hiddenAPI)(nil) -func (h *hiddenAPI) hiddenAPI(ctx android.ModuleContext, name string, primary bool, dexJar android.ModuleOutPath, - implementationJar android.Path, uncompressDex bool) android.ModuleOutPath { +func (h *hiddenAPI) hiddenAPI(ctx android.ModuleContext, name string, primary bool, dexJar android.OutputPath, + implementationJar android.Path, uncompressDex bool) android.OutputPath { if !ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") { // Modules whose names are of the format -hiddenapi provide hiddenapi information @@ -116,7 +116,7 @@ func (h *hiddenAPI) hiddenAPI(ctx android.ModuleContext, name string, primary bo // hiddenapi information for a module on the boot jars list then encode // the gathered information in the generated dex file. if name == bootJarName { - hiddenAPIJar := android.PathForModuleOut(ctx, "hiddenapi", name+".jar") + hiddenAPIJar := android.PathForModuleOut(ctx, "hiddenapi", name+".jar").OutputPath // More than one library with the same classes can be encoded but only one can // be added to the global set of flags, otherwise it will result in duplicate diff --git a/java/java.go b/java/java.go index 59ec94d5b..d49b64f66 100644 --- a/java/java.go +++ b/java/java.go @@ -1689,35 +1689,44 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { // 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.ModuleOutPath + var outputFile android.OutputPath if len(jars) == 1 && !manifest.Valid() { + // Optimization: skip the combine step as there is nothing to do + // TODO(ccross): this leaves any module-info.class files, but those should only come from + // prebuilt dependencies until we support modules in the platform build, so there shouldn't be + // any if len(jars) == 1. + + // 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 { - // Optimization: skip the combine step if there is nothing to do - // TODO(ccross): this leaves any module-info.class files, but those should only come from - // prebuilt dependencies until we support modules in the platform build, so there shouldn't be - // any if len(jars) == 1. - outputFile = moduleOutPath + // The path contains an embedded OutputPath so reuse that. + outputFile = moduleOutPath.OutputPath + } else if outputPath, ok := jars[0].(android.OutputPath); ok { + // 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. combinedJar := android.PathForModuleOut(ctx, "combined", jarName) ctx.Build(pctx, android.BuildParams{ Rule: android.Cp, Input: jars[0], Output: combinedJar, }) - outputFile = combinedJar + outputFile = combinedJar.OutputPath } } else { combinedJar := android.PathForModuleOut(ctx, "combined", jarName) TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest, false, nil, nil) - outputFile = combinedJar + outputFile = combinedJar.OutputPath } // jarjar implementation jar if necessary if j.expandJarjarRules != nil { // Transform classes.jar into classes-jarjar.jar - jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName) + jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName).OutputPath TransformJarJar(ctx, jarjarFile, outputFile, j.expandJarjarRules) outputFile = jarjarFile @@ -1762,7 +1771,7 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { implementationAndResourcesJar := outputFile if j.resourceJar != nil { jars := android.Paths{j.resourceJar, implementationAndResourcesJar} - combinedJar := android.PathForModuleOut(ctx, "withres", jarName) + combinedJar := android.PathForModuleOut(ctx, "withres", jarName).OutputPath TransformJarsToJar(ctx, combinedJar, "for resources", jars, manifest, false, nil, nil) implementationAndResourcesJar = combinedJar @@ -1788,7 +1797,7 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { android.PathForSource(ctx, "build/make/core/proguard.jacoco.flags")) } // Dex compilation - var dexOutputFile android.ModuleOutPath + var dexOutputFile android.OutputPath dexOutputFile = j.dexer.compileDex(ctx, flags, j.minSdkVersion(), outputFile, jarName) if ctx.Failed() { return @@ -1807,11 +1816,11 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { // merge dex jar with resources if necessary if j.resourceJar != nil { jars := android.Paths{dexOutputFile, j.resourceJar} - combinedJar := android.PathForModuleOut(ctx, "dex-withres", jarName) + combinedJar := android.PathForModuleOut(ctx, "dex-withres", jarName).OutputPath 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) + combinedAlignedJar := android.PathForModuleOut(ctx, "dex-withres-aligned", jarName).OutputPath TransformZipAlign(ctx, combinedAlignedJar, combinedJar) dexOutputFile = combinedAlignedJar } else { @@ -1875,7 +1884,7 @@ func (j *Module) compileJavaClasses(ctx android.ModuleContext, jarName string, i jarName += strconv.Itoa(idx) } - classes := android.PathForModuleOut(ctx, "javac", jarName) + classes := android.PathForModuleOut(ctx, "javac", jarName).OutputPath TransformJavaToClasses(ctx, classes, idx, srcFiles, srcJars, flags, extraJarDeps) if ctx.Config().EmitXrefRules() { @@ -1955,12 +1964,12 @@ func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars } func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags, - classesJar android.Path, jarName string) android.ModuleOutPath { + classesJar android.Path, jarName string) android.OutputPath { specs := j.jacocoModuleToZipCommand(ctx) jacocoReportClassesFile := android.PathForModuleOut(ctx, "jacoco-report-classes", jarName) - instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName) + instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName).OutputPath jacocoInstrumentJar(ctx, instrumentedJar, jacocoReportClassesFile, classesJar, specs) @@ -2937,7 +2946,7 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { } j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex - var dexOutputFile android.ModuleOutPath + var dexOutputFile android.OutputPath dexOutputFile = j.dexer.compileDex(ctx, flags, j.minSdkVersion(), outputFile, jarName) if ctx.Failed() { return