From b5769c15a314c1a9dea62e3c4b0acd022ca1e23d Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Wed, 12 May 2021 16:16:51 +0100 Subject: [PATCH] Allow module types to force creation of a default APEX variant Bug: 187910671 Test: m droid Change-Id: I797d4ab60d15b526744fe6e4df1b55c8b75b0310 --- android/apex.go | 11 +++++++++++ apex/apex.go | 5 ++--- cc/cc.go | 6 ++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/android/apex.go b/android/apex.go index 60da45bf9..b01b700b8 100644 --- a/android/apex.go +++ b/android/apex.go @@ -203,6 +203,12 @@ type ApexModule interface { // apex_available property of the module. AvailableFor(what string) bool + // AlwaysRequiresPlatformApexVariant allows the implementing module to determine whether an + // APEX mutator should always be created for it. + // + // Returns false by default. + AlwaysRequiresPlatformApexVariant() bool + // Returns true if this module is not available to platform (i.e. apex_available property // doesn't have "//apex_available:platform"), or shouldn't be available to platform, which // is the case when this module depends on other module that isn't available to platform. @@ -423,6 +429,11 @@ func (m *ApexModuleBase) AvailableFor(what string) bool { return CheckAvailableForApex(what, m.ApexProperties.Apex_available) } +// Implements ApexModule +func (m *ApexModuleBase) AlwaysRequiresPlatformApexVariant() bool { + return false +} + // Implements ApexModule func (m *ApexModuleBase) NotAvailableForPlatform() bool { return m.ApexProperties.NotAvailableForPlatform diff --git a/apex/apex.go b/apex/apex.go index 2c0df2785..c8e6cc86b 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -1013,9 +1013,8 @@ func markPlatformAvailability(mctx android.BottomUpMutatorContext) { } }) - // Exception 1: stub libraries and native bridge libraries are always available to platform - if cc, ok := mctx.Module().(*cc.Module); ok && - (cc.IsStubs() || cc.Target().NativeBridge == android.NativeBridgeEnabled) { + // Exception 1: check to see if the module always requires it. + if am.AlwaysRequiresPlatformApexVariant() { availableToPlatform = true } diff --git a/cc/cc.go b/cc/cc.go index 16a49d343..387868174 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -3279,6 +3279,12 @@ func (c *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, return nil } +// Implements android.ApexModule +func (c *Module) AlwaysRequiresPlatformApexVariant() bool { + // stub libraries and native bridge libraries are always available to platform + return c.IsStubs() || c.Target().NativeBridge == android.NativeBridgeEnabled +} + // // Defaults //