Merge "Allow defining neverallow in packages other than android."

This commit is contained in:
satayev
2020-04-15 13:45:42 +00:00
committed by Gerrit Code Review
3 changed files with 12 additions and 12 deletions

View File

@@ -103,7 +103,7 @@ var postDeps = []RegisterMutatorFunc{
registerPathDepsMutator, registerPathDepsMutator,
RegisterPrebuiltsPostDepsMutators, RegisterPrebuiltsPostDepsMutators,
RegisterVisibilityRuleEnforcer, RegisterVisibilityRuleEnforcer,
registerNeverallowMutator, RegisterNeverallowMutator,
RegisterOverridePostDepsMutators, RegisterOverridePostDepsMutators,
} }

View File

@@ -42,7 +42,7 @@ import (
// counts as a match // counts as a match
// - it has none of the "Without" properties matched (same rules as above) // - it has none of the "Without" properties matched (same rules as above)
func registerNeverallowMutator(ctx RegisterMutatorsContext) { func RegisterNeverallowMutator(ctx RegisterMutatorsContext) {
ctx.BottomUp("neverallow", neverallowMutator).Parallel() ctx.BottomUp("neverallow", neverallowMutator).Parallel()
} }
@@ -247,7 +247,7 @@ func neverallowMutator(ctx BottomUpMutatorContext) {
} }
type ValueMatcher interface { type ValueMatcher interface {
test(string) bool Test(string) bool
String() string String() string
} }
@@ -255,7 +255,7 @@ type equalMatcher struct {
expected string expected string
} }
func (m *equalMatcher) test(value string) bool { func (m *equalMatcher) Test(value string) bool {
return m.expected == value return m.expected == value
} }
@@ -266,7 +266,7 @@ func (m *equalMatcher) String() string {
type anyMatcher struct { type anyMatcher struct {
} }
func (m *anyMatcher) test(value string) bool { func (m *anyMatcher) Test(value string) bool {
return true return true
} }
@@ -280,7 +280,7 @@ type startsWithMatcher struct {
prefix string prefix string
} }
func (m *startsWithMatcher) test(value string) bool { func (m *startsWithMatcher) Test(value string) bool {
return strings.HasPrefix(value, m.prefix) return strings.HasPrefix(value, m.prefix)
} }
@@ -292,7 +292,7 @@ type regexMatcher struct {
re *regexp.Regexp re *regexp.Regexp
} }
func (m *regexMatcher) test(value string) bool { func (m *regexMatcher) Test(value string) bool {
return m.re.MatchString(value) return m.re.MatchString(value)
} }
@@ -302,7 +302,7 @@ func (m *regexMatcher) String() string {
type isSetMatcher struct{} type isSetMatcher struct{}
func (m *isSetMatcher) test(value string) bool { func (m *isSetMatcher) Test(value string) bool {
return value != "" return value != ""
} }
@@ -573,7 +573,7 @@ func hasProperty(properties []interface{}, prop ruleProperty) bool {
} }
check := func(value string) bool { check := func(value string) bool {
return prop.matcher.test(value) return prop.matcher.Test(value)
} }
if matchValue(propertiesValue, check) { if matchValue(propertiesValue, check) {
@@ -630,6 +630,6 @@ func neverallowRules(config Config) []Rule {
// Overrides the default neverallow rules for the supplied config. // Overrides the default neverallow rules for the supplied config.
// //
// For testing only. // For testing only.
func setTestNeverallowRules(config Config, testRules []Rule) { func SetTestNeverallowRules(config Config, testRules []Rule) {
config.Once(neverallowRulesKey, func() interface{} { return testRules }) config.Once(neverallowRulesKey, func() interface{} { return testRules })
} }

View File

@@ -313,7 +313,7 @@ func TestNeverallow(t *testing.T) {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
// If the test has its own rules then use them instead of the default ones. // If the test has its own rules then use them instead of the default ones.
if test.rules != nil { if test.rules != nil {
setTestNeverallowRules(config, test.rules) SetTestNeverallowRules(config, test.rules)
} }
_, errs := testNeverallow(config) _, errs := testNeverallow(config)
CheckErrorsAgainstExpectations(t, errs, test.expectedErrors) CheckErrorsAgainstExpectations(t, errs, test.expectedErrors)
@@ -327,7 +327,7 @@ func testNeverallow(config Config) (*TestContext, []error) {
ctx.RegisterModuleType("java_library", newMockJavaLibraryModule) ctx.RegisterModuleType("java_library", newMockJavaLibraryModule)
ctx.RegisterModuleType("java_library_host", newMockJavaLibraryModule) ctx.RegisterModuleType("java_library_host", newMockJavaLibraryModule)
ctx.RegisterModuleType("java_device_for_host", newMockJavaLibraryModule) ctx.RegisterModuleType("java_device_for_host", newMockJavaLibraryModule)
ctx.PostDepsMutators(registerNeverallowMutator) ctx.PostDepsMutators(RegisterNeverallowMutator)
ctx.Register(config) ctx.Register(config)
_, errs := ctx.ParseBlueprintsFiles("Android.bp") _, errs := ctx.ParseBlueprintsFiles("Android.bp")