From b9e7a3ca7afeba46322749b6a3cab10363af76f2 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Thu, 6 May 2021 15:53:19 +0100 Subject: [PATCH] Make licenseModule SdkAware Making licenseModule SdkAware caused two breakages in the build. The breakages were both caused by having an SdkAware module that was depended upon by a versioned sdk snapshot but which was not itself versioned and so did not have the member_name property set. That occured because some default licenses have been added to the packages containing prebuilts, e.g. prebuilts_runtime_license in prebuilts/runtime/Android.bp. They apply to both the versioned and unversioned members. Once license support has been added to the sdk most of those will be removed and replaced with properly versioned license modules. However, in the meantime it is necessary to support that. This change avoids the issue by checking to see whether the module is itself versioned before relying on the member_name property. It also improves the error message when a panic is recovered to make it easier to identify where it originates. Bug: 181569894 Test: m nothing Change-Id: I0e7da2e0c4a30a6f814c2faab821b185aaed2135 --- android/license.go | 2 ++ android/sdk.go | 10 ++++++++++ sdk/sdk.go | 6 +++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/android/license.go b/android/license.go index 3bc6199b2..cb375a2e5 100644 --- a/android/license.go +++ b/android/license.go @@ -51,6 +51,7 @@ type licenseProperties struct { type licenseModule struct { ModuleBase DefaultableModuleBase + SdkBase properties licenseProperties } @@ -75,6 +76,7 @@ func LicenseFactory() Module { // The visibility property needs to be checked and parsed by the visibility module. setPrimaryVisibilityProperty(module, "visibility", &module.properties.Visibility) + InitSdkAwareModule(module) initAndroidModuleBase(module) InitDefaultableModule(module) diff --git a/android/sdk.go b/android/sdk.go index 8992bab35..95924561a 100644 --- a/android/sdk.go +++ b/android/sdk.go @@ -41,6 +41,11 @@ type sdkAwareWithoutModule interface { sdkBase() *SdkBase MakeMemberOf(sdk SdkRef) IsInAnySdk() bool + + // IsVersioned determines whether the module is versioned, i.e. has a name of the form + // @ + IsVersioned() bool + ContainingSdk() SdkRef MemberName() string BuildWithSdks(sdks SdkRefs) @@ -140,6 +145,11 @@ func (s *SdkBase) IsInAnySdk() bool { return s.properties.ContainingSdk != nil } +// IsVersioned returns true if this module is versioned. +func (s *SdkBase) IsVersioned() bool { + return strings.Contains(s.module.Name(), "@") +} + // ContainingSdk returns the SDK that this module is a member of func (s *SdkBase) ContainingSdk() SdkRef { if s.properties.ContainingSdk != nil { diff --git a/sdk/sdk.go b/sdk/sdk.go index 2f56de69d..624c0fa9b 100644 --- a/sdk/sdk.go +++ b/sdk/sdk.go @@ -444,7 +444,7 @@ func memberDepsMutator(mctx android.TopDownMutatorContext) { // built with libfoo.mysdk.11 and libfoo.mysdk.12, respectively depending on which sdk they are // using. func memberInterVersionMutator(mctx android.BottomUpMutatorContext) { - if m, ok := mctx.Module().(android.SdkAware); ok && m.IsInAnySdk() { + if m, ok := mctx.Module().(android.SdkAware); ok && m.IsInAnySdk() && m.IsVersioned() { if !m.ContainingSdk().Unversioned() { memberName := m.MemberName() tag := sdkMemberVersionedDepTag{member: memberName, version: m.ContainingSdk().Version} @@ -483,7 +483,7 @@ func sdkDepsMutator(mctx android.TopDownMutatorContext) { // Step 5: if libfoo.mysdk.11 is in the context where version 11 of mysdk is requested, the // versioned module is used instead of the un-versioned (in-development) module libfoo func sdkDepsReplaceMutator(mctx android.BottomUpMutatorContext) { - if versionedSdkMember, ok := mctx.Module().(android.SdkAware); ok && versionedSdkMember.IsInAnySdk() { + if versionedSdkMember, ok := mctx.Module().(android.SdkAware); ok && versionedSdkMember.IsInAnySdk() && versionedSdkMember.IsVersioned() { if sdk := versionedSdkMember.ContainingSdk(); !sdk.Unversioned() { // Only replace dependencies to with // if the depending module requires it. e.g. @@ -499,7 +499,7 @@ func sdkDepsReplaceMutator(mctx android.BottomUpMutatorContext) { // TODO(b/183204176): Remove this after fixing. defer func() { if r := recover(); r != nil { - mctx.ModuleErrorf("%s", r) + mctx.ModuleErrorf("sdkDepsReplaceMutator %s", r) } }()