Expand neverallow for sdk_version: none
Allow the platform stubs to specify sdk_version: none,
and add generic support for a regexp matcher.
Bug: 144149403
Test: m
Change-Id: Icaece0d9797bace8ae9741f7a029b9ea57fcbbb9
diff --git a/android/neverallow.go b/android/neverallow.go
index 547230c..04ec27d 100644
--- a/android/neverallow.go
+++ b/android/neverallow.go
@@ -17,6 +17,7 @@
import (
"path/filepath"
"reflect"
+ "regexp"
"strconv"
"strings"
@@ -147,7 +148,8 @@
rules := []Rule{
NeverAllow().
NotIn(coreLibraryProjects...).
- With("sdk_version", "none"),
+ With("sdk_version", "none").
+ WithoutMatcher("name", Regexp("^android_.*stubs_current$")),
}
return rules
@@ -286,6 +288,18 @@
return ".starts-with(" + m.prefix + ")"
}
+type regexMatcher struct {
+ re *regexp.Regexp
+}
+
+func (m *regexMatcher) test(value string) bool {
+ return m.re.MatchString(value)
+}
+
+func (m *regexMatcher) String() string {
+ return ".regexp(" + m.re.String() + ")"
+}
+
type isSetMatcher struct{}
func (m *isSetMatcher) test(value string) bool {
@@ -501,6 +515,14 @@
return &startsWithMatcher{prefix}
}
+func Regexp(re string) ValueMatcher {
+ r, err := regexp.Compile(re)
+ if err != nil {
+ panic(err)
+ }
+ return ®exMatcher{r}
+}
+
// assorted utils
func cleanPaths(paths []string) []string {