diff options
author | 2024-07-26 12:02:36 -0700 | |
---|---|---|
committer | 2024-07-30 14:46:13 -0700 | |
commit | 7707b246efe17400aa27e843a507232bd02efd66 (patch) | |
tree | 7f5b41b4c6d11b92141159f2dcd78e6420a8bd5c /java/aar.go | |
parent | bd73d0db41ac84144c60e7719df106bda8efb663 (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/aar.go')
-rw-r--r-- | java/aar.go | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/java/aar.go b/java/aar.go index b69b7c262..4a60f908a 100644 --- a/java/aar.go +++ b/java/aar.go @@ -991,17 +991,17 @@ type AARImport struct { properties AARImportProperties - headerJarFile android.WritablePath - implementationJarFile android.WritablePath - implementationAndResourcesJarFile android.WritablePath - proguardFlags android.WritablePath - exportPackage android.WritablePath + headerJarFile android.Path + implementationJarFile android.Path + implementationAndResourcesJarFile android.Path + proguardFlags android.Path + exportPackage android.Path transitiveAaptResourcePackagesFile android.Path - extraAaptPackagesFile android.WritablePath + extraAaptPackagesFile android.Path manifest android.Path - assetsPackage android.WritablePath - rTxt android.WritablePath - rJar android.WritablePath + assetsPackage android.Path + rTxt android.Path + rJar android.Path resourcesNodesDepSet *android.DepSet[*resourcesNode] manifestsDepSet *android.DepSet[android.Path] @@ -1166,14 +1166,14 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { a.manifest = extractedManifest } - a.rTxt = extractedAARDir.Join(ctx, "R.txt") - a.assetsPackage = android.PathForModuleOut(ctx, "assets.zip") - a.proguardFlags = extractedAARDir.Join(ctx, "proguard.txt") + rTxt := extractedAARDir.Join(ctx, "R.txt") + assetsPackage := android.PathForModuleOut(ctx, "assets.zip") + proguardFlags := extractedAARDir.Join(ctx, "proguard.txt") transitiveProguardFlags, transitiveUnconditionalExportedFlags := collectDepProguardSpecInfo(ctx) android.SetProvider(ctx, ProguardSpecInfoProvider, ProguardSpecInfo{ ProguardFlagsFiles: android.NewDepSet[android.Path]( android.POSTORDER, - android.Paths{a.proguardFlags}, + android.Paths{proguardFlags}, transitiveProguardFlags, ), UnconditionallyExportedProguardFlags: android.NewDepSet[android.Path]( @@ -1186,15 +1186,19 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { ctx.Build(pctx, android.BuildParams{ Rule: unzipAAR, Input: a.aarPath, - Outputs: android.WritablePaths{classpathFile, a.proguardFlags, extractedManifest, a.assetsPackage, a.rTxt}, + Outputs: android.WritablePaths{classpathFile, proguardFlags, extractedManifest, assetsPackage, rTxt}, Description: "unzip AAR", Args: map[string]string{ "outDir": extractedAARDir.String(), "combinedClassesJar": classpathFile.String(), - "assetsPackage": a.assetsPackage.String(), + "assetsPackage": assetsPackage.String(), }, }) + a.proguardFlags = proguardFlags + a.assetsPackage = assetsPackage + a.rTxt = rTxt + // Always set --pseudo-localize, it will be stripped out later for release // builds that don't want it. compileFlags := []string{"--pseudo-localize"} @@ -1202,10 +1206,10 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { flata := compiledResDir.Join(ctx, "gen_res.flata") aapt2CompileZip(ctx, flata, a.aarPath, "res", compileFlags) - a.exportPackage = android.PathForModuleOut(ctx, "package-res.apk") + exportPackage := android.PathForModuleOut(ctx, "package-res.apk") proguardOptionsFile := android.PathForModuleGen(ctx, "proguard.options") aaptRTxt := android.PathForModuleOut(ctx, "R.txt") - a.extraAaptPackagesFile = android.PathForModuleOut(ctx, "extra_packages") + extraAaptPackagesFile := android.PathForModuleOut(ctx, "extra_packages") var linkDeps android.Paths @@ -1241,13 +1245,16 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { } transitiveAssets := android.ReverseSliceInPlace(staticDeps.assets()) - aapt2Link(ctx, a.exportPackage, nil, proguardOptionsFile, aaptRTxt, + aapt2Link(ctx, exportPackage, nil, proguardOptionsFile, aaptRTxt, linkFlags, linkDeps, nil, overlayRes, transitiveAssets, nil, nil) + a.exportPackage = exportPackage - a.rJar = android.PathForModuleOut(ctx, "busybox/R.jar") - resourceProcessorBusyBoxGenerateBinaryR(ctx, a.rTxt, a.manifest, a.rJar, nil, true, nil, false) + rJar := android.PathForModuleOut(ctx, "busybox/R.jar") + resourceProcessorBusyBoxGenerateBinaryR(ctx, a.rTxt, a.manifest, rJar, nil, true, nil, false) + a.rJar = rJar - aapt2ExtractExtraPackages(ctx, a.extraAaptPackagesFile, a.rJar) + aapt2ExtractExtraPackages(ctx, extraAaptPackagesFile, a.rJar) + a.extraAaptPackagesFile = extraAaptPackagesFile resourcesNodesDepSetBuilder := android.NewDepSetBuilder[*resourcesNode](android.TOPOLOGICAL) resourcesNodesDepSetBuilder.Direct(&resourcesNode{ @@ -1330,8 +1337,9 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { if len(staticHeaderJars) > 0 { combineJars := append(android.Paths{classpathFile}, staticHeaderJars...) - a.headerJarFile = android.PathForModuleOut(ctx, "turbine-combined", jarName) - TransformJarsToJar(ctx, a.headerJarFile, "combine header jars", combineJars, android.OptionalPath{}, false, nil, nil) + headerJarFile := android.PathForModuleOut(ctx, "turbine-combined", jarName) + TransformJarsToJar(ctx, headerJarFile, "combine header jars", combineJars, android.OptionalPath{}, false, nil, nil) + a.headerJarFile = headerJarFile } else { a.headerJarFile = classpathFile } |