diff options
author | 2025-02-28 12:05:20 -0800 | |
---|---|---|
committer | 2025-02-28 12:05:20 -0800 | |
commit | 58047e846963c84c2784a685d4c2644bd7c80ff6 (patch) | |
tree | c3b95847c8582b0d33fe7a6d78eed8c3d7a52e24 /android/visibility.go | |
parent | 9cbe288fa7eaf56a62c764bfcba35fc550543208 (diff) | |
parent | 71f1ea3f81feae294a3031799cd638c38610850e (diff) |
Merge changes from topics "EqualModules", "tidyPhonySingleton" into main
* changes:
Convert tidyPhonySingleton, jdepsGeneratorSingleton and genNoticeBuildRules to use ModuleProxy.
Make EqualModules a free function.
Diffstat (limited to 'android/visibility.go')
-rw-r--r-- | android/visibility.go | 72 |
1 files changed, 29 insertions, 43 deletions
diff --git a/android/visibility.go b/android/visibility.go index 4837c7d4b..416a3f15f 100644 --- a/android/visibility.go +++ b/android/visibility.go @@ -58,15 +58,29 @@ const ( var visibilityRuleRegexp = regexp.MustCompile(visibilityRulePattern) type visibilityModuleReference struct { - name qualifiedModuleName - module Module + name qualifiedModuleName + partitionType *string } func createVisibilityModuleReference(name, dir string, module Module) visibilityModuleReference { - return visibilityModuleReference{ - name: createQualifiedModuleName(name, dir), - module: module, + vis := visibilityModuleReference{ + name: createQualifiedModuleName(name, dir), } + if m, ok := module.(PartitionTypeInterface); ok { + pt := m.PartitionType() + vis.partitionType = &pt + } + return vis +} + +func createVisibilityModuleProxyReference(ctx OtherModuleProviderContext, name, dir string, module ModuleProxy) visibilityModuleReference { + vis := visibilityModuleReference{ + name: createQualifiedModuleName(name, dir), + } + if m, ok := OtherModuleProvider(ctx, module, PartitionTypeInfoProvider); ok { + vis.partitionType = &m.PartitionType + } + return vis } // A visibility rule is associated with a module and determines which other modules it is visible @@ -222,9 +236,17 @@ type PartitionTypeInterface interface { PartitionType() string } +type PartitionTypeInfo struct { + // Identifies which partition this is for //visibility:any_system_image (and others) visibility + // checks, and will be used in the future for API surface checks. + PartitionType string +} + +var PartitionTypeInfoProvider = blueprint.NewProvider[PartitionTypeInfo]() + func (r anyPartitionRule) matches(m visibilityModuleReference) bool { - if m2, ok := m.module.(PartitionTypeInterface); ok { - return m2.PartitionType() == r.partitionType + if m.partitionType != nil { + return *m.partitionType == r.partitionType } return false } @@ -647,42 +669,6 @@ func (v *visibilityRuleSet) Strings() []string { return v.rules } -// Get the effective visibility rules, i.e. the actual rules that affect the visibility of the -// property irrespective of where they are defined. -// -// Includes visibility rules specified by package default_visibility and/or on defaults. -// Short hand forms, e.g. //:__subpackages__ are replaced with their full form, e.g. -// //package/containing/rule:__subpackages__. -func EffectiveVisibilityRules(ctx BaseModuleContext, module Module) VisibilityRuleSet { - moduleName := ctx.OtherModuleName(module) - dir := ctx.OtherModuleDir(module) - qualified := qualifiedModuleName{dir, moduleName} - - rule := effectiveVisibilityRules(ctx.Config(), qualified) - - currentModule := createVisibilityModuleReference(moduleName, dir, module) - - // Modules are implicitly visible to other modules in the same package, - // without checking the visibility rules. Here we need to add that visibility - // explicitly. - if !rule.matches(currentModule) { - if len(rule) == 1 { - if _, ok := rule[0].(privateRule); ok { - // If the rule is //visibility:private we can't append another - // visibility to it. Semantically we need to convert it to a package - // visibility rule for the location where the result is used, but since - // modules are implicitly visible within the package we get the same - // result without any rule at all, so just make it an empty list to be - // appended below. - rule = nil - } - } - rule = append(rule, packageRule{dir}) - } - - return &visibilityRuleSet{rule.Strings()} -} - // Clear the default visibility properties so they can be replaced. func clearVisibilityProperties(module Module) { module.base().visibilityPropertyInfo = nil |