Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 958dd4f6 authored by Paul Duffin's avatar Paul Duffin Committed by Gerrit Code Review
Browse files

Merge "Explicitly specify visibility in sdk/module_exports snapshot"

parents 973f4670 d99d9972
Loading
Loading
Loading
Loading
+16 −3
Original line number Diff line number Diff line
@@ -441,12 +441,19 @@ func visibilityRuleEnforcer(ctx TopDownMutatorContext) {
		}

		rule := effectiveVisibilityRules(ctx.Config(), depQualified)
		if rule != nil && !rule.matches(qualified) {
		if !rule.matches(qualified) {
			ctx.ModuleErrorf("depends on %s which is not visible to this module", depQualified)
		}
	})
}

// Default visibility is public.
var defaultVisibility = compositeRule{publicRule{}}

// Return the effective visibility rules.
//
// If no rules have been specified this will return the default visibility rule
// which is currently //visibility:public.
func effectiveVisibilityRules(config Config, qualified qualifiedModuleName) compositeRule {
	moduleToVisibilityRule := moduleToVisibilityRuleMap(config)
	value, ok := moduleToVisibilityRule.Load(qualified)
@@ -456,6 +463,12 @@ func effectiveVisibilityRules(config Config, qualified qualifiedModuleName) comp
	} else {
		rule = packageDefaultVisibility(config, qualified)
	}

	// If no rule is specified then return the default visibility rule to avoid
	// every caller having to treat nil as public.
	if rule == nil {
		rule = defaultVisibility
	}
	return rule
}

@@ -499,7 +512,7 @@ func EffectiveVisibilityRules(ctx BaseModuleContext, module Module) []string {
	// 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 != nil && !rule.matches(qualified) {
	if !rule.matches(qualified) {
		if len(rule) == 1 {
			if _, ok := rule[0].(privateRule); ok {
				// If the rule is //visibility:private we can't append another
@@ -508,7 +521,7 @@ func EffectiveVisibilityRules(ctx BaseModuleContext, module Module) []string {
				// 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 = compositeRule{}
				rule = nil
			}
		}
		rule = append(rule, packageRule{dir})
+79 −0

File changed.

Preview size limit exceeded, changes collapsed.

+3 −0
Original line number Diff line number Diff line
@@ -49,17 +49,20 @@ func TestModuleExportsSnapshot(t *testing.T) {
java_import {
    name: "myexports_myjavalib@current",
    sdk_member_name: "myjavalib",
    visibility: ["//visibility:public"],
    jars: ["java/myjavalib.jar"],
}

java_import {
    name: "myjavalib",
    prefer: false,
    visibility: ["//visibility:public"],
    jars: ["java/myjavalib.jar"],
}

module_exports_snapshot {
    name: "myexports@current",
    visibility: ["//visibility:public"],
    java_libs: ["myexports_myjavalib@current"],
}
`))
+69 −0

File changed.

Preview size limit exceeded, changes collapsed.