Merge "Expand neverallow for sdk_version: none" into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
846101ace0
@@ -17,6 +17,7 @@ package android
|
|||||||
import (
|
import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -146,7 +147,8 @@ func createLibcoreRules() []Rule {
|
|||||||
rules := []Rule{
|
rules := []Rule{
|
||||||
NeverAllow().
|
NeverAllow().
|
||||||
NotIn(coreLibraryProjects...).
|
NotIn(coreLibraryProjects...).
|
||||||
With("sdk_version", "none"),
|
With("sdk_version", "none").
|
||||||
|
WithoutMatcher("name", Regexp("^android_.*stubs_current$")),
|
||||||
}
|
}
|
||||||
|
|
||||||
return rules
|
return rules
|
||||||
@@ -254,6 +256,18 @@ func (m *startsWithMatcher) String() string {
|
|||||||
return ".starts-with(" + m.prefix + ")"
|
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 ruleProperty struct {
|
type ruleProperty struct {
|
||||||
fields []string // e.x.: Vndk.Enabled
|
fields []string // e.x.: Vndk.Enabled
|
||||||
matcher ValueMatcher
|
matcher ValueMatcher
|
||||||
@@ -457,6 +471,14 @@ func StartsWith(prefix string) ValueMatcher {
|
|||||||
return &startsWithMatcher{prefix}
|
return &startsWithMatcher{prefix}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Regexp(re string) ValueMatcher {
|
||||||
|
r, err := regexp.Compile(re)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return ®exMatcher{r}
|
||||||
|
}
|
||||||
|
|
||||||
// assorted utils
|
// assorted utils
|
||||||
|
|
||||||
func cleanPaths(paths []string) []string {
|
func cleanPaths(paths []string) []string {
|
||||||
|
@@ -226,6 +226,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",
|
name: "sdk_version: \"none\" outside core libraries",
|
||||||
fs: map[string][]byte{
|
fs: map[string][]byte{
|
||||||
|
Reference in New Issue
Block a user