Merge "Manifest Fixer Params code refactor" am: 7761de5d4e

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1979469

Change-Id: I9264bd97390c558ea728126bf16d0103f1f43949
This commit is contained in:
Gurpreet Singh 2022-02-10 18:35:46 +00:00 committed by Automerger Merge Worker
commit bdf5b8030e
3 changed files with 21 additions and 35 deletions

View file

@ -398,18 +398,8 @@ func (a *apexBundle) buildBundleConfig(ctx android.ModuleContext) android.Output
}
func markManifestTestOnly(ctx android.ModuleContext, androidManifestFile android.Path) android.Path {
return java.ManifestFixer(java.ManifestFixerParams{
Ctx: ctx,
Manifest: androidManifestFile,
SdkContext: nil,
ClassLoaderContexts: nil,
IsLibrary: false,
UseEmbeddedNativeLibs: false,
UsesNonSdkApis: false,
UseEmbeddedDex: false,
HasNoCode: false,
TestOnly: true,
LoggingParent: "",
return java.ManifestFixer(ctx, androidManifestFile, java.ManifestFixerParams{
TestOnly: true,
})
}

View file

@ -280,9 +280,7 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext android.SdkCon
manifestFile := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml")
manifestSrcPath := android.PathForModuleSrc(ctx, manifestFile)
manifestPath := ManifestFixer(ManifestFixerParams{
Ctx: ctx,
Manifest: manifestSrcPath,
manifestPath := ManifestFixer(ctx, manifestSrcPath, ManifestFixerParams{
SdkContext: sdkContext,
ClassLoaderContexts: classLoaderContexts,
IsLibrary: a.isLibrary,
@ -290,7 +288,6 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext android.SdkCon
UsesNonSdkApis: a.usesNonSdkApis,
UseEmbeddedDex: a.useEmbeddedDex,
HasNoCode: a.hasNoCode,
TestOnly: false,
LoggingParent: a.LoggingParent,
})

View file

@ -56,8 +56,6 @@ func targetSdkVersionForManifestFixer(ctx android.ModuleContext, sdkContext andr
}
type ManifestFixerParams struct {
Ctx android.ModuleContext
Manifest android.Path
SdkContext android.SdkContext
ClassLoaderContexts dexpreopt.ClassLoaderContextMap
IsLibrary bool
@ -70,20 +68,21 @@ type ManifestFixerParams struct {
}
// Uses manifest_fixer.py to inject minSdkVersion, etc. into an AndroidManifest.xml
func ManifestFixer(params ManifestFixerParams) android.Path {
func ManifestFixer(ctx android.ModuleContext, manifest android.Path,
params ManifestFixerParams) android.Path {
var args []string
if params.IsLibrary {
args = append(args, "--library")
} else if params.SdkContext != nil {
minSdkVersion, err := params.SdkContext.MinSdkVersion(params.Ctx).EffectiveVersion(params.Ctx)
minSdkVersion, err := params.SdkContext.MinSdkVersion(ctx).EffectiveVersion(ctx)
if err != nil {
params.Ctx.ModuleErrorf("invalid minSdkVersion: %s", err)
ctx.ModuleErrorf("invalid minSdkVersion: %s", err)
}
if minSdkVersion.FinalOrFutureInt() >= 23 {
args = append(args, fmt.Sprintf("--extract-native-libs=%v", !params.UseEmbeddedNativeLibs))
} else if params.UseEmbeddedNativeLibs {
params.Ctx.ModuleErrorf("module attempted to store uncompressed native libraries, but minSdkVersion=%d doesn't support it",
ctx.ModuleErrorf("module attempted to store uncompressed native libraries, but minSdkVersion=%d doesn't support it",
minSdkVersion)
}
}
@ -124,38 +123,38 @@ func ManifestFixer(params ManifestFixerParams) android.Path {
var argsMapper = make(map[string]string)
if params.SdkContext != nil {
targetSdkVersion := targetSdkVersionForManifestFixer(params.Ctx, params.SdkContext)
targetSdkVersion := targetSdkVersionForManifestFixer(ctx, params.SdkContext)
args = append(args, "--targetSdkVersion ", targetSdkVersion)
if UseApiFingerprint(params.Ctx) && params.Ctx.ModuleName() != "framework-res" {
targetSdkVersion = params.Ctx.Config().PlatformSdkCodename() + fmt.Sprintf(".$$(cat %s)", ApiFingerprintPath(params.Ctx).String())
deps = append(deps, ApiFingerprintPath(params.Ctx))
if UseApiFingerprint(ctx) && ctx.ModuleName() != "framework-res" {
targetSdkVersion = ctx.Config().PlatformSdkCodename() + fmt.Sprintf(".$$(cat %s)", ApiFingerprintPath(ctx).String())
deps = append(deps, ApiFingerprintPath(ctx))
}
minSdkVersion, err := params.SdkContext.MinSdkVersion(params.Ctx).EffectiveVersionString(params.Ctx)
minSdkVersion, err := params.SdkContext.MinSdkVersion(ctx).EffectiveVersionString(ctx)
if err != nil {
params.Ctx.ModuleErrorf("invalid minSdkVersion: %s", err)
ctx.ModuleErrorf("invalid minSdkVersion: %s", err)
}
if UseApiFingerprint(params.Ctx) && params.Ctx.ModuleName() != "framework-res" {
minSdkVersion = params.Ctx.Config().PlatformSdkCodename() + fmt.Sprintf(".$$(cat %s)", ApiFingerprintPath(params.Ctx).String())
deps = append(deps, ApiFingerprintPath(params.Ctx))
if UseApiFingerprint(ctx) && ctx.ModuleName() != "framework-res" {
minSdkVersion = ctx.Config().PlatformSdkCodename() + fmt.Sprintf(".$$(cat %s)", ApiFingerprintPath(ctx).String())
deps = append(deps, ApiFingerprintPath(ctx))
}
if err != nil {
params.Ctx.ModuleErrorf("invalid minSdkVersion: %s", err)
ctx.ModuleErrorf("invalid minSdkVersion: %s", err)
}
args = append(args, "--minSdkVersion ", minSdkVersion)
args = append(args, "--raise-min-sdk-version")
}
fixedManifest := android.PathForModuleOut(params.Ctx, "manifest_fixer", "AndroidManifest.xml")
fixedManifest := android.PathForModuleOut(ctx, "manifest_fixer", "AndroidManifest.xml")
argsMapper["args"] = strings.Join(args, " ")
params.Ctx.Build(pctx, android.BuildParams{
ctx.Build(pctx, android.BuildParams{
Rule: manifestFixerRule,
Description: "fix manifest",
Input: params.Manifest,
Input: manifest,
Implicits: deps,
Output: fixedManifest,
Args: argsMapper,