summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Gurpreet Singh <gurpreetgs@google.com> 2022-02-10 13:28:35 +0000
committer Gurpreet Singh <gurpreetgs@google.com> 2022-02-10 13:37:50 +0000
commit7deabfacd0a877bd1e4dec31f1ff40e472ab5f14 (patch)
treeb1fc7252397bd0a43f47150906e02817f9c50819
parentdb07f002b8dae61878ed34b62c039da52df6f346 (diff)
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
-rw-r--r--apex/builder.go14
-rw-r--r--java/aar.go5
-rw-r--r--java/android_manifest.go37
3 files changed, 21 insertions, 35 deletions
diff --git a/apex/builder.go b/apex/builder.go
index 1a1f22be2..7c852313c 100644
--- a/apex/builder.go
+++ b/apex/builder.go
@@ -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,
})
}
diff --git a/java/aar.go b/java/aar.go
index 51aad8da0..8e1025361 100644
--- a/java/aar.go
+++ b/java/aar.go
@@ -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,
})
diff --git a/java/android_manifest.go b/java/android_manifest.go
index a5d5b97a0..7772b7090 100644
--- a/java/android_manifest.go
+++ b/java/android_manifest.go
@@ -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,