Manifest Fixer Params code refactor
This CL refactors the code related to ManifestFixer parameters. The required parameters android.ModuleContext, manifest android.Path are passed separately as the parameters and the optional parameters are kept as part of the ManifestFixerParams struct. By default, the member variable of struct have the zero (nil, false, empty string) values. Hence, it is only required to pass the parameters of interest at the time of function call to ManifestFixer. Manual testing done to check the working of the code. Test: m nothing && m test_com.android.sdkext Test: manually tested the generation of AndroidManifest in the out directory with the testOnly attribute Test: atest manifest_fixer_test --host To test the existing unittests are not breaking. Change-Id: I20cb6c06c57f8fe7811050288bcb03945dc0425b
This commit is contained in:
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
|
@@ -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,
|
||||
})
|
||||
|
||||
|
@@ -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,
|
||||
|
Reference in New Issue
Block a user