From 10e926bc8d02ff37a631aeaea1784921e164df6f Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Thu, 16 Jul 2020 21:38:56 +0900 Subject: [PATCH] apex_set is force disabled when necessary prebuilt_apex has been disabled when the device is configured for flattened APEXes, sanitized, instrumented, or built unbundled. However, apex_set which is another type of APEX prebuilt wasn't disabled for the same conditions. This change fixes the discripency. apex_set modules are also force disabled when the prebuilts are not expected. Bug: 161316762 Bug: 160933444 Test: OVERRIDE_TARGET_FLATTEN_APEX=true m The built image has only the flattened APEXes and the device boots Change-Id: I6c90dfb28d565861a473a1bdce93269ec370601d --- apex/apex.go | 2 +- apex/prebuilt.go | 109 ++++++++++++++++++++++++++++------------------- 2 files changed, 66 insertions(+), 45 deletions(-) diff --git a/apex/apex.go b/apex/apex.go index b29017d1f..045ae828f 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -2112,7 +2112,7 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { case android.PrebuiltDepTag: // If the prebuilt is force disabled, remember to delete the prebuilt file // that might have been installed in the previous builds - if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() { + if prebuilt, ok := child.(prebuilt); ok && prebuilt.isForceDisabled() { a.prebuiltFileToDelete = prebuilt.InstallFilename() } } diff --git a/apex/prebuilt.go b/apex/prebuilt.go index bf574dc65..d459f8755 100644 --- a/apex/prebuilt.go +++ b/apex/prebuilt.go @@ -21,6 +21,7 @@ import ( "android/soong/android" "android/soong/java" + "github.com/google/blueprint" "github.com/google/blueprint/proptools" @@ -39,9 +40,55 @@ var ( "abis", "allow-prereleased", "sdk-version") ) +type prebuilt interface { + isForceDisabled() bool + InstallFilename() string +} + +type prebuiltCommon struct { + prebuilt android.Prebuilt + properties prebuiltCommonProperties +} + +type prebuiltCommonProperties struct { + ForceDisable bool `blueprint:"mutated"` +} + +func (p *prebuiltCommon) Prebuilt() *android.Prebuilt { + return &p.prebuilt +} + +func (p *prebuiltCommon) isForceDisabled() bool { + return p.properties.ForceDisable +} + +func (p *prebuiltCommon) checkForceDisable(ctx android.ModuleContext) bool { + // If the device is configured to use flattened APEX, force disable the prebuilt because + // the prebuilt is a non-flattened one. + forceDisable := ctx.Config().FlattenApex() + + // Force disable the prebuilts when we are doing unbundled build. We do unbundled build + // to build the prebuilts themselves. + forceDisable = forceDisable || ctx.Config().UnbundledBuild() + + // Force disable the prebuilts when coverage is enabled. + forceDisable = forceDisable || ctx.DeviceConfig().NativeCoverageEnabled() + forceDisable = forceDisable || ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") + + // b/137216042 don't use prebuilts when address sanitizer is on + forceDisable = forceDisable || android.InList("address", ctx.Config().SanitizeDevice()) || + android.InList("hwaddress", ctx.Config().SanitizeDevice()) + + if forceDisable && p.prebuilt.SourceExists() { + p.properties.ForceDisable = true + return true + } + return false +} + type Prebuilt struct { android.ModuleBase - prebuilt android.Prebuilt + prebuiltCommon properties PrebuiltProperties @@ -57,8 +104,7 @@ type Prebuilt struct { type PrebuiltProperties struct { // the path to the prebuilt .apex file to import. - Source string `blueprint:"mutated"` - ForceDisable bool `blueprint:"mutated"` + Source string `blueprint:"mutated"` Src *string Arch struct { @@ -93,10 +139,6 @@ func (p *Prebuilt) installable() bool { return p.properties.Installable == nil || proptools.Bool(p.properties.Installable) } -func (p *Prebuilt) isForceDisabled() bool { - return p.properties.ForceDisable -} - func (p *Prebuilt) OutputFiles(tag string) (android.Paths, error) { switch tag { case "": @@ -110,12 +152,8 @@ func (p *Prebuilt) InstallFilename() string { return proptools.StringDefault(p.properties.Filename, p.BaseModuleName()+imageApexSuffix) } -func (p *Prebuilt) Prebuilt() *android.Prebuilt { - return &p.prebuilt -} - func (p *Prebuilt) Name() string { - return p.prebuilt.Name(p.ModuleBase.Name()) + return p.prebuiltCommon.prebuilt.Name(p.ModuleBase.Name()) } // prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex. @@ -128,27 +166,6 @@ func PrebuiltFactory() android.Module { } func (p *Prebuilt) DepsMutator(ctx android.BottomUpMutatorContext) { - // If the device is configured to use flattened APEX, force disable the prebuilt because - // the prebuilt is a non-flattened one. - forceDisable := ctx.Config().FlattenApex() - - // Force disable the prebuilts when we are doing unbundled build. We do unbundled build - // to build the prebuilts themselves. - forceDisable = forceDisable || ctx.Config().UnbundledBuild() - - // Force disable the prebuilts when coverage is enabled. - forceDisable = forceDisable || ctx.DeviceConfig().NativeCoverageEnabled() - forceDisable = forceDisable || ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") - - // b/137216042 don't use prebuilts when address sanitizer is on - forceDisable = forceDisable || android.InList("address", ctx.Config().SanitizeDevice()) || - android.InList("hwaddress", ctx.Config().SanitizeDevice()) - - if forceDisable && p.prebuilt.SourceExists() { - p.properties.ForceDisable = true - return - } - // This is called before prebuilt_select and prebuilt_postdeps mutators // The mutators requires that src to be set correctly for each arch so that // arch variants are disabled when src is not provided for the arch. @@ -177,10 +194,6 @@ func (p *Prebuilt) DepsMutator(ctx android.BottomUpMutatorContext) { } func (p *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) { - if p.properties.ForceDisable { - return - } - // TODO(jungjw): Check the key validity. p.inputApex = p.Prebuilt().SingleSourcePath(ctx) p.installDir = android.PathForModuleInstall(ctx, "apex") @@ -194,6 +207,12 @@ func (p *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) { Input: p.inputApex, Output: p.outputApex, }) + + if p.prebuiltCommon.checkForceDisable(ctx) { + p.SkipInstall() + return + } + if p.installable() { ctx.InstallFile(p.installDir, p.installFilename, p.inputApex) } @@ -227,7 +246,7 @@ func (p *Prebuilt) AndroidMkEntries() []android.AndroidMkEntries { type ApexSet struct { android.ModuleBase - prebuilt android.Prebuilt + prebuiltCommon properties ApexSetProperties @@ -270,12 +289,8 @@ func (a *ApexSet) InstallFilename() string { return proptools.StringDefault(a.properties.Filename, a.BaseModuleName()+imageApexSuffix) } -func (a *ApexSet) Prebuilt() *android.Prebuilt { - return &a.prebuilt -} - func (a *ApexSet) Name() string { - return a.prebuilt.Name(a.ModuleBase.Name()) + return a.prebuiltCommon.prebuilt.Name(a.ModuleBase.Name()) } func (a *ApexSet) Overrides() []string { @@ -297,7 +312,7 @@ func (a *ApexSet) GenerateAndroidBuildActions(ctx android.ModuleContext) { ctx.ModuleErrorf("filename should end in %s for apex_set", imageApexSuffix) } - apexSet := a.prebuilt.SingleSourcePath(ctx) + apexSet := a.prebuiltCommon.prebuilt.SingleSourcePath(ctx) a.outputApex = android.PathForModuleOut(ctx, a.installFilename) ctx.Build(pctx, android.BuildParams{ @@ -311,6 +326,12 @@ func (a *ApexSet) GenerateAndroidBuildActions(ctx android.ModuleContext) { "sdk-version": ctx.Config().PlatformSdkVersion(), }, }) + + if a.prebuiltCommon.checkForceDisable(ctx) { + a.SkipInstall() + return + } + a.installDir = android.PathForModuleInstall(ctx, "apex") if a.installable() { ctx.InstallFile(a.installDir, a.installFilename, a.outputApex)