diff options
author | 2021-03-18 15:41:29 +0000 | |
---|---|---|
committer | 2021-03-22 08:43:55 +0000 | |
commit | 4c3e8e2d67b0ace466aa78c3a82847833c779682 (patch) | |
tree | 4c125ee5be41bc6214d2a7791457ef6de1f0f2a8 /sdk/sdk.go | |
parent | 50e49818a3339039faf6c3142db7da175770b486 (diff) |
Ensure that DepIsInSameApex is not called for ExcludeFromApexContentsTag
The ExcludeFromApexContentsTag marker interface was added to avoid
every implementation of DepIsInSameApex() from having to deal with the
special tags, like PrebuiltDepTag. Unfortunately, when adding that
not all calls to DepIsInSameApex() were protected which meant that the
BootImageModule, which panics if it doesn't recognize a tag, was
causing failures. This change documents the need and improves the
consistency.
A follow up change will add a test for this.
Bug: 182992071
Test: m nothing
Change-Id: If0bf9a7447ebf7a0bb0c88e91951a7220d4af45c
Diffstat (limited to 'sdk/sdk.go')
-rw-r--r-- | sdk/sdk.go | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/sdk/sdk.go b/sdk/sdk.go index 6ca851217..e561529b8 100644 --- a/sdk/sdk.go +++ b/sdk/sdk.go @@ -445,20 +445,26 @@ func memberInterVersionMutator(mctx android.BottomUpMutatorContext) { } } +// An interface that encapsulates all the functionality needed to manage the sdk dependencies. +// +// It is a mixture of apex and sdk module functionality. +type sdkAndApexModule interface { + android.Module + android.DepIsInSameApex + android.RequiredSdks +} + // Step 4: transitively ripple down the SDK requirements from the root modules like APEX to its // descendants func sdkDepsMutator(mctx android.TopDownMutatorContext) { - if parent, ok := mctx.Module().(interface { - android.DepIsInSameApex - android.RequiredSdks - }); ok { + if parent, ok := mctx.Module().(sdkAndApexModule); ok { // Module types for Mainline modules (e.g. APEX) are expected to implement RequiredSdks() // by reading its own properties like `uses_sdks`. requiredSdks := parent.RequiredSdks() if len(requiredSdks) > 0 { mctx.VisitDirectDeps(func(m android.Module) { // Only propagate required sdks from the apex onto its contents. - if dep, ok := m.(android.SdkAware); ok && parent.DepIsInSameApex(mctx, dep) { + if dep, ok := m.(android.SdkAware); ok && android.IsDepInSameApex(mctx, parent, dep) { dep.BuildWithSdks(requiredSdks) } }) @@ -497,10 +503,7 @@ func sdkDepsReplaceMutator(mctx android.BottomUpMutatorContext) { // Step 6: ensure that the dependencies outside of the APEX are all from the required SDKs func sdkRequirementsMutator(mctx android.TopDownMutatorContext) { - if m, ok := mctx.Module().(interface { - android.DepIsInSameApex - android.RequiredSdks - }); ok { + if m, ok := mctx.Module().(sdkAndApexModule); ok { requiredSdks := m.RequiredSdks() if len(requiredSdks) == 0 { return @@ -519,9 +522,18 @@ func sdkRequirementsMutator(mctx android.TopDownMutatorContext) { return } - // If the dep is outside of the APEX, but is not in any of the - // required SDKs, we know that the dep is a violation. + // If the dep is outside of the APEX, but is not in any of the required SDKs, we know that the + // dep is a violation. if sa, ok := dep.(android.SdkAware); ok { + // It is not an error if a dependency that is excluded from the apex due to the tag is not + // in one of the required SDKs. That is because all of the existing tags that implement it + // do not depend on modules which can or should belong to an sdk_snapshot. + if _, ok := tag.(android.ExcludeFromApexContentsTag); ok { + // The tag defines a dependency that never requires the child module to be part of the + // same apex. + return + } + if !m.DepIsInSameApex(mctx, dep) && !requiredSdks.Contains(sa.ContainingSdk()) { mctx.ModuleErrorf("depends on %q (in SDK %q) that isn't part of the required SDKs: %v", sa.Name(), sa.ContainingSdk(), requiredSdks) |