Exclude source->prebuilt deps from visibility enforcement
When both prebuilt and source versions of a module are present in the build an implicit dependency is added from source -> prebuilt. This change excludes that dependency from visibility enforcement as it provides no value and would otherwise require an sdk snapshot to rewrite the visibility of the generated prebuilt modules which would be complicated. The rewriting would include: * Detecting //visibility:public and just passing that straight through. * Detecting //visibility:private and replacing that with the location of the source. * Otherwise, adding the location of the source to the visibility property. This adds a general mechanism to allow any dependency to be excluded from visibility enforcement by simply using a tag that implements the ExcludeFromVisibilityEnforcementTag interface. Bug: 142940300 Test: m nothing Change-Id: I0668ff5aa798152d17faf3aac1bb8eff8d6350c3
This commit is contained in:
@@ -19,6 +19,8 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
)
|
||||
|
||||
// Enforces visibility rules between modules.
|
||||
@@ -190,6 +192,15 @@ func moduleToVisibilityRuleMap(ctx BaseModuleContext) *sync.Map {
|
||||
}).(*sync.Map)
|
||||
}
|
||||
|
||||
// Marker interface that identifies dependencies that are excluded from visibility
|
||||
// enforcement.
|
||||
type ExcludeFromVisibilityEnforcementTag interface {
|
||||
blueprint.DependencyTag
|
||||
|
||||
// Method that differentiates this interface from others.
|
||||
ExcludeFromVisibilityEnforcement()
|
||||
}
|
||||
|
||||
// The rule checker needs to be registered before defaults expansion to correctly check that
|
||||
// //visibility:xxx isn't combined with other packages in the same list in any one module.
|
||||
func RegisterVisibilityRuleChecker(ctx RegisterMutatorsContext) {
|
||||
@@ -389,6 +400,12 @@ func visibilityRuleEnforcer(ctx TopDownMutatorContext) {
|
||||
|
||||
// Visit all the dependencies making sure that this module has access to them all.
|
||||
ctx.VisitDirectDeps(func(dep Module) {
|
||||
// Ignore dependencies that have an ExcludeFromVisibilityEnforcementTag
|
||||
tag := ctx.OtherModuleDependencyTag(dep)
|
||||
if _, ok := tag.(ExcludeFromVisibilityEnforcementTag); ok {
|
||||
return
|
||||
}
|
||||
|
||||
depName := ctx.OtherModuleName(dep)
|
||||
depDir := ctx.OtherModuleDir(dep)
|
||||
depQualified := qualifiedModuleName{depDir, depName}
|
||||
|
Reference in New Issue
Block a user