summaryrefslogtreecommitdiff
path: root/sdk/sdk.go
diff options
context:
space:
mode:
author Treehugger Robot <treehugger-gerrit@google.com> 2019-10-18 00:30:18 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2019-10-18 00:30:18 +0000
commitc5bba642f17068ea3f481e3fbcbd3a6ba54abac9 (patch)
tree00a219f53aae65813cd7e415098de057a8ed9f24 /sdk/sdk.go
parent81a4016f619ad7722216f2a2fc58fe0aea5a54ae (diff)
parenta7bc8ad0b9ec3f762e45af4d60b96922782616cf (diff)
Merge "Prohibit dependencies outside of uses_sdks"
Diffstat (limited to 'sdk/sdk.go')
-rw-r--r--sdk/sdk.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/sdk/sdk.go b/sdk/sdk.go
index e4d520be1..d189043f8 100644
--- a/sdk/sdk.go
+++ b/sdk/sdk.go
@@ -122,6 +122,7 @@ func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
// should have been mutated for the apex before the SDK requirements are set.
ctx.TopDown("SdkDepsMutator", sdkDepsMutator).Parallel()
ctx.BottomUp("SdkDepsReplaceMutator", sdkDepsReplaceMutator).Parallel()
+ ctx.TopDown("SdkRequirementCheck", sdkRequirementsMutator).Parallel()
}
type dependencyTag struct {
@@ -228,3 +229,31 @@ func sdkDepsReplaceMutator(mctx android.BottomUpMutatorContext) {
}
}
}
+
+// Step 6: ensure that the dependencies from outside of the APEX are all from the required SDKs
+func sdkRequirementsMutator(mctx android.TopDownMutatorContext) {
+ if m, ok := mctx.Module().(interface {
+ DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool
+ RequiredSdks() android.SdkRefs
+ }); ok {
+ requiredSdks := m.RequiredSdks()
+ if len(requiredSdks) == 0 {
+ return
+ }
+ mctx.VisitDirectDeps(func(dep android.Module) {
+ if mctx.OtherModuleDependencyTag(dep) == android.DefaultsDepTag {
+ // dependency to defaults is always okay
+ return
+ }
+
+ // If the dep is from 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 {
+ 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)
+ }
+ }
+ })
+ }
+}