summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--android/neverallow.go24
-rw-r--r--android/neverallow_test.go10
2 files changed, 33 insertions, 1 deletions
diff --git a/android/neverallow.go b/android/neverallow.go
index 547230c08..04ec27d20 100644
--- a/android/neverallow.go
+++ b/android/neverallow.go
@@ -17,6 +17,7 @@ package android
import (
"path/filepath"
"reflect"
+ "regexp"
"strconv"
"strings"
@@ -147,7 +148,8 @@ func createLibcoreRules() []Rule {
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 @@ func (m *startsWithMatcher) String() string {
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 @@ func StartsWith(prefix string) ValueMatcher {
return &startsWithMatcher{prefix}
}
+func Regexp(re string) ValueMatcher {
+ r, err := regexp.Compile(re)
+ if err != nil {
+ panic(err)
+ }
+ return &regexMatcher{r}
+}
+
// assorted utils
func cleanPaths(paths []string) []string {
diff --git a/android/neverallow_test.go b/android/neverallow_test.go
index 41e5c6fed..0373b7923 100644
--- a/android/neverallow_test.go
+++ b/android/neverallow_test.go
@@ -227,6 +227,16 @@ var neverallowTests = []struct {
},
},
{
+ name: "sdk_version: \"none\" on android_*stubs_current stub",
+ fs: map[string][]byte{
+ "frameworks/base/Android.bp": []byte(`
+ java_library {
+ name: "android_stubs_current",
+ sdk_version: "none",
+ }`),
+ },
+ },
+ {
name: "sdk_version: \"none\" outside core libraries",
fs: map[string][]byte{
"Android.bp": []byte(`