Allow passing --legacy in aaptflags
--legacy will soon no longer be passed by default to all aapt2 compiles. Allow it to be specified in aaptflags by passing it to aapt2 compile when it is present and filtering it out from the flags passed to aapt2 link. Bug: 135597368 Test: m java Change-Id: Ib65d1a9b7c32ae4ff5ab6f58e66aedfb5f296712
This commit is contained in:
parent
fedc47141e
commit
a0ba2f5858
2 changed files with 26 additions and 20 deletions
|
@ -60,7 +60,9 @@ var aapt2CompileRule = pctx.AndroidStaticRule("aapt2Compile",
|
|||
},
|
||||
"outDir", "cFlags")
|
||||
|
||||
func aapt2Compile(ctx android.ModuleContext, dir android.Path, paths android.Paths) android.WritablePaths {
|
||||
func aapt2Compile(ctx android.ModuleContext, dir android.Path, paths android.Paths,
|
||||
flags []string) android.WritablePaths {
|
||||
|
||||
shards := shardPaths(paths, AAPT2_SHARD_SIZE)
|
||||
|
||||
ret := make(android.WritablePaths, 0, len(paths))
|
||||
|
@ -81,9 +83,7 @@ func aapt2Compile(ctx android.ModuleContext, dir android.Path, paths android.Pat
|
|||
Outputs: outPaths,
|
||||
Args: map[string]string{
|
||||
"outDir": android.PathForModuleOut(ctx, "aapt2", dir.String()).String(),
|
||||
// Always set --pseudo-localize, it will be stripped out later for release
|
||||
// builds that don't want it.
|
||||
"cFlags": "--pseudo-localize",
|
||||
"cFlags": strings.Join(flags, " "),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
@ -104,7 +104,9 @@ var aapt2CompileZipRule = pctx.AndroidStaticRule("aapt2CompileZip",
|
|||
},
|
||||
}, "cFlags", "resZipDir", "zipSyncFlags")
|
||||
|
||||
func aapt2CompileZip(ctx android.ModuleContext, flata android.WritablePath, zip android.Path, zipPrefix string) {
|
||||
func aapt2CompileZip(ctx android.ModuleContext, flata android.WritablePath, zip android.Path, zipPrefix string,
|
||||
flags []string) {
|
||||
|
||||
if zipPrefix != "" {
|
||||
zipPrefix = "--zip-prefix " + zipPrefix
|
||||
}
|
||||
|
@ -114,9 +116,7 @@ func aapt2CompileZip(ctx android.ModuleContext, flata android.WritablePath, zip
|
|||
Input: zip,
|
||||
Output: flata,
|
||||
Args: map[string]string{
|
||||
// Always set --pseudo-localize, it will be stripped out later for release
|
||||
// builds that don't want it.
|
||||
"cFlags": "--pseudo-localize",
|
||||
"cFlags": strings.Join(flags, " "),
|
||||
"resZipDir": android.PathForModuleOut(ctx, "aapt2", "reszip", flata.Base()).String(),
|
||||
"zipSyncFlags": zipPrefix,
|
||||
},
|
||||
|
|
30
java/aar.go
30
java/aar.go
|
@ -111,8 +111,9 @@ func (a *aapt) ExportedManifests() android.Paths {
|
|||
return a.transitiveManifestPaths
|
||||
}
|
||||
|
||||
func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext sdkContext, manifestPath android.Path) (flags []string,
|
||||
deps android.Paths, resDirs, overlayDirs []globbedResourceDir, rroDirs []rroDir, resZips android.Paths) {
|
||||
func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext sdkContext,
|
||||
manifestPath android.Path) (compileFlags, linkFlags []string, linkDeps android.Paths,
|
||||
resDirs, overlayDirs []globbedResourceDir, rroDirs []rroDir, resZips android.Paths) {
|
||||
|
||||
hasVersionCode := false
|
||||
hasVersionName := false
|
||||
|
@ -124,8 +125,6 @@ func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext sdkContext, mani
|
|||
}
|
||||
}
|
||||
|
||||
var linkFlags []string
|
||||
|
||||
// Flags specified in Android.bp
|
||||
linkFlags = append(linkFlags, a.aaptProperties.Aaptflags...)
|
||||
|
||||
|
@ -136,8 +135,6 @@ func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext sdkContext, mani
|
|||
resourceDirs := android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Resource_dirs, "res")
|
||||
resourceZips := android.PathsForModuleSrc(ctx, a.aaptProperties.Resource_zips)
|
||||
|
||||
var linkDeps android.Paths
|
||||
|
||||
// Glob directories into lists of paths
|
||||
for _, dir := range resourceDirs {
|
||||
resDirs = append(resDirs, globbedResourceDir{
|
||||
|
@ -185,7 +182,13 @@ func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext sdkContext, mani
|
|||
linkFlags = append(linkFlags, "--version-name ", versionName)
|
||||
}
|
||||
|
||||
return linkFlags, linkDeps, resDirs, overlayDirs, rroDirs, resourceZips
|
||||
linkFlags, compileFlags = android.FilterList(linkFlags, []string{"--legacy"})
|
||||
|
||||
// Always set --pseudo-localize, it will be stripped out later for release
|
||||
// builds that don't want it.
|
||||
compileFlags = append(compileFlags, "--pseudo-localize")
|
||||
|
||||
return compileFlags, linkFlags, linkDeps, resDirs, overlayDirs, rroDirs, resourceZips
|
||||
}
|
||||
|
||||
func (a *aapt) deps(ctx android.BottomUpMutatorContext, sdkDep sdkDep) {
|
||||
|
@ -220,7 +223,7 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, ex
|
|||
a.mergedManifestFile = manifestPath
|
||||
}
|
||||
|
||||
linkFlags, linkDeps, resDirs, overlayDirs, rroDirs, resZips := a.aapt2Flags(ctx, sdkContext, manifestPath)
|
||||
compileFlags, linkFlags, linkDeps, resDirs, overlayDirs, rroDirs, resZips := a.aapt2Flags(ctx, sdkContext, manifestPath)
|
||||
|
||||
rroDirs = append(rroDirs, staticRRODirs...)
|
||||
linkFlags = append(linkFlags, libFlags...)
|
||||
|
@ -239,12 +242,12 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, ex
|
|||
|
||||
var compiledResDirs []android.Paths
|
||||
for _, dir := range resDirs {
|
||||
compiledResDirs = append(compiledResDirs, aapt2Compile(ctx, dir.dir, dir.files).Paths())
|
||||
compiledResDirs = append(compiledResDirs, aapt2Compile(ctx, dir.dir, dir.files, compileFlags).Paths())
|
||||
}
|
||||
|
||||
for i, zip := range resZips {
|
||||
flata := android.PathForModuleOut(ctx, fmt.Sprintf("reszip.%d.flata", i))
|
||||
aapt2CompileZip(ctx, flata, zip, "")
|
||||
aapt2CompileZip(ctx, flata, zip, "", compileFlags)
|
||||
compiledResDirs = append(compiledResDirs, android.Paths{flata})
|
||||
}
|
||||
|
||||
|
@ -273,7 +276,7 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, ex
|
|||
}
|
||||
|
||||
for _, dir := range overlayDirs {
|
||||
compiledOverlay = append(compiledOverlay, aapt2Compile(ctx, dir.dir, dir.files).Paths()...)
|
||||
compiledOverlay = append(compiledOverlay, aapt2Compile(ctx, dir.dir, dir.files, compileFlags).Paths()...)
|
||||
}
|
||||
|
||||
var splitPackages android.WritablePaths
|
||||
|
@ -598,9 +601,12 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||
},
|
||||
})
|
||||
|
||||
// Always set --pseudo-localize, it will be stripped out later for release
|
||||
// builds that don't want it.
|
||||
compileFlags := []string{"--pseudo-localize"}
|
||||
compiledResDir := android.PathForModuleOut(ctx, "flat-res")
|
||||
flata := compiledResDir.Join(ctx, "gen_res.flata")
|
||||
aapt2CompileZip(ctx, flata, aar, "res")
|
||||
aapt2CompileZip(ctx, flata, aar, "res", compileFlags)
|
||||
|
||||
a.exportPackage = android.PathForModuleOut(ctx, "package-res.apk")
|
||||
srcJar := android.PathForModuleGen(ctx, "R.jar")
|
||||
|
|
Loading…
Reference in a new issue