Merge "Report visibility errors in both check and gather phases" am: e661212b76
Change-Id: I80a609915802545a340a4c8b7227712f29eac128
This commit is contained in:
@@ -246,14 +246,8 @@ func checkRules(ctx BaseModuleContext, currentPkg, property string, visibility [
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range visibility {
|
for _, v := range visibility {
|
||||||
ok, pkg, name := splitRule(v, currentPkg)
|
ok, pkg, name := splitRule(ctx, v, currentPkg, property)
|
||||||
if !ok {
|
if !ok {
|
||||||
// Visibility rule is invalid so ignore it. Keep going rather than aborting straight away to
|
|
||||||
// ensure all the rules on this module are checked.
|
|
||||||
ctx.PropertyErrorf(property,
|
|
||||||
"invalid visibility pattern %q must match"+
|
|
||||||
" //<package>:<module>, //<package> or :<module>",
|
|
||||||
v)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,21 +295,24 @@ func visibilityRuleGatherer(ctx BottomUpMutatorContext) {
|
|||||||
|
|
||||||
// Parse the visibility rules that control access to the module and store them by id
|
// Parse the visibility rules that control access to the module and store them by id
|
||||||
// for use when enforcing the rules.
|
// for use when enforcing the rules.
|
||||||
if visibility := m.visibility(); visibility != nil {
|
primaryProperty := m.base().primaryVisibilityProperty
|
||||||
rule := parseRules(ctx, currentPkg, m.visibility())
|
if primaryProperty != nil {
|
||||||
if rule != nil {
|
if visibility := primaryProperty.getStrings(); visibility != nil {
|
||||||
moduleToVisibilityRuleMap(ctx.Config()).Store(qualifiedModuleId, rule)
|
rule := parseRules(ctx, currentPkg, primaryProperty.getName(), visibility)
|
||||||
|
if rule != nil {
|
||||||
|
moduleToVisibilityRuleMap(ctx.Config()).Store(qualifiedModuleId, rule)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseRules(ctx BaseModuleContext, currentPkg string, visibility []string) compositeRule {
|
func parseRules(ctx BaseModuleContext, currentPkg, property string, visibility []string) compositeRule {
|
||||||
rules := make(compositeRule, 0, len(visibility))
|
rules := make(compositeRule, 0, len(visibility))
|
||||||
hasPrivateRule := false
|
hasPrivateRule := false
|
||||||
hasPublicRule := false
|
hasPublicRule := false
|
||||||
hasNonPrivateRule := false
|
hasNonPrivateRule := false
|
||||||
for _, v := range visibility {
|
for _, v := range visibility {
|
||||||
ok, pkg, name := splitRule(v, currentPkg)
|
ok, pkg, name := splitRule(ctx, v, currentPkg, property)
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -376,10 +373,16 @@ func isAllowedFromOutsideVendor(pkg string, name string) bool {
|
|||||||
return !isAncestor("vendor", pkg)
|
return !isAncestor("vendor", pkg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func splitRule(ruleExpression string, currentPkg string) (bool, string, string) {
|
func splitRule(ctx BaseModuleContext, ruleExpression string, currentPkg, property string) (bool, string, string) {
|
||||||
// Make sure that the rule is of the correct format.
|
// Make sure that the rule is of the correct format.
|
||||||
matches := visibilityRuleRegexp.FindStringSubmatch(ruleExpression)
|
matches := visibilityRuleRegexp.FindStringSubmatch(ruleExpression)
|
||||||
if ruleExpression == "" || matches == nil {
|
if ruleExpression == "" || matches == nil {
|
||||||
|
// Visibility rule is invalid so ignore it. Keep going rather than aborting straight away to
|
||||||
|
// ensure all the rules on this module are checked.
|
||||||
|
ctx.PropertyErrorf(property,
|
||||||
|
"invalid visibility pattern %q must match"+
|
||||||
|
" //<package>:<module>, //<package> or :<module>",
|
||||||
|
ruleExpression)
|
||||||
return false, "", ""
|
return false, "", ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user