Move string list utility functions to android package
am: b4330e222b
Change-Id: Ie94e23c3005da8a9f1597b7582bc9abaa8038016
This commit is contained in:
commit
cda9710157
4 changed files with 49 additions and 57 deletions
|
@ -119,12 +119,12 @@ func RegisterArchFeatures(arch ArchType, features ...string) {
|
||||||
|
|
||||||
func RegisterArchVariantFeatures(arch ArchType, variant string, features ...string) {
|
func RegisterArchVariantFeatures(arch ArchType, variant string, features ...string) {
|
||||||
checkCalledFromInit()
|
checkCalledFromInit()
|
||||||
if variant != "" && !inList(variant, archVariants[arch]) {
|
if variant != "" && !InList(variant, archVariants[arch]) {
|
||||||
panic(fmt.Errorf("Invalid variant %q for arch %q", variant, arch))
|
panic(fmt.Errorf("Invalid variant %q for arch %q", variant, arch))
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, feature := range features {
|
for _, feature := range features {
|
||||||
if !inList(feature, archFeatures[arch]) {
|
if !InList(feature, archFeatures[arch]) {
|
||||||
panic(fmt.Errorf("Invalid feature %q for arch %q variant %q", feature, arch, variant))
|
panic(fmt.Errorf("Invalid feature %q for arch %q variant %q", feature, arch, variant))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -481,13 +481,13 @@ func createArchType(props reflect.Type) reflect.Type {
|
||||||
|
|
||||||
if os.Linux() {
|
if os.Linux() {
|
||||||
target := "Linux_" + archType.Name
|
target := "Linux_" + archType.Name
|
||||||
if !inList(target, targets) {
|
if !InList(target, targets) {
|
||||||
targets = append(targets, target)
|
targets = append(targets, target)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if os.Bionic() {
|
if os.Bionic() {
|
||||||
target := "Bionic_" + archType.Name
|
target := "Bionic_" + archType.Name
|
||||||
if !inList(target, targets) {
|
if !InList(target, targets) {
|
||||||
targets = append(targets, target)
|
targets = append(targets, target)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -690,12 +690,12 @@ func (c *deviceConfig) NativeCoverageEnabled() bool {
|
||||||
func (c *deviceConfig) CoverageEnabledForPath(path string) bool {
|
func (c *deviceConfig) CoverageEnabledForPath(path string) bool {
|
||||||
coverage := false
|
coverage := false
|
||||||
if c.config.ProductVariables.CoveragePaths != nil {
|
if c.config.ProductVariables.CoveragePaths != nil {
|
||||||
if prefixInList(path, *c.config.ProductVariables.CoveragePaths) {
|
if PrefixInList(path, *c.config.ProductVariables.CoveragePaths) {
|
||||||
coverage = true
|
coverage = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if coverage && c.config.ProductVariables.CoverageExcludePaths != nil {
|
if coverage && c.config.ProductVariables.CoverageExcludePaths != nil {
|
||||||
if prefixInList(path, *c.config.ProductVariables.CoverageExcludePaths) {
|
if PrefixInList(path, *c.config.ProductVariables.CoverageExcludePaths) {
|
||||||
coverage = false
|
coverage = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -706,21 +706,21 @@ func (c *config) IntegerOverflowDisabledForPath(path string) bool {
|
||||||
if c.ProductVariables.IntegerOverflowExcludePaths == nil {
|
if c.ProductVariables.IntegerOverflowExcludePaths == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return prefixInList(path, *c.ProductVariables.IntegerOverflowExcludePaths)
|
return PrefixInList(path, *c.ProductVariables.IntegerOverflowExcludePaths)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *config) CFIDisabledForPath(path string) bool {
|
func (c *config) CFIDisabledForPath(path string) bool {
|
||||||
if c.ProductVariables.CFIExcludePaths == nil {
|
if c.ProductVariables.CFIExcludePaths == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return prefixInList(path, *c.ProductVariables.CFIExcludePaths)
|
return PrefixInList(path, *c.ProductVariables.CFIExcludePaths)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *config) CFIEnabledForPath(path string) bool {
|
func (c *config) CFIEnabledForPath(path string) bool {
|
||||||
if c.ProductVariables.CFIIncludePaths == nil {
|
if c.ProductVariables.CFIIncludePaths == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return prefixInList(path, *c.ProductVariables.CFIIncludePaths)
|
return PrefixInList(path, *c.ProductVariables.CFIIncludePaths)
|
||||||
}
|
}
|
||||||
|
|
||||||
func stringSlice(s *[]string) []string {
|
func stringSlice(s *[]string) []string {
|
||||||
|
|
|
@ -54,7 +54,7 @@ func sortedKeys(m map[string][]string) []string {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func indexList(s string, list []string) int {
|
func IndexList(s string, list []string) int {
|
||||||
for i, l := range list {
|
for i, l := range list {
|
||||||
if l == s {
|
if l == s {
|
||||||
return i
|
return i
|
||||||
|
@ -64,11 +64,11 @@ func indexList(s string, list []string) int {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
|
||||||
func inList(s string, list []string) bool {
|
func InList(s string, list []string) bool {
|
||||||
return indexList(s, list) != -1
|
return IndexList(s, list) != -1
|
||||||
}
|
}
|
||||||
|
|
||||||
func prefixInList(s string, list []string) bool {
|
func PrefixInList(s string, list []string) bool {
|
||||||
for _, prefix := range list {
|
for _, prefix := range list {
|
||||||
if strings.HasPrefix(s, prefix) {
|
if strings.HasPrefix(s, prefix) {
|
||||||
return true
|
return true
|
||||||
|
@ -77,6 +77,37 @@ func prefixInList(s string, list []string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FilterList(list []string, filter []string) (remainder []string, filtered []string) {
|
||||||
|
for _, l := range list {
|
||||||
|
if InList(l, filter) {
|
||||||
|
filtered = append(filtered, l)
|
||||||
|
} else {
|
||||||
|
remainder = append(remainder, l)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func RemoveListFromList(list []string, filter_out []string) (result []string) {
|
||||||
|
result = make([]string, 0, len(list))
|
||||||
|
for _, l := range list {
|
||||||
|
if !InList(l, filter_out) {
|
||||||
|
result = append(result, l)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func RemoveFromList(s string, list []string) (bool, []string) {
|
||||||
|
i := IndexList(s, list)
|
||||||
|
if i != -1 {
|
||||||
|
return true, append(list[:i], list[i+1:]...)
|
||||||
|
} else {
|
||||||
|
return false, list
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// FirstUniqueStrings returns all unique elements of a slice of strings, keeping the first copy of
|
// FirstUniqueStrings returns all unique elements of a slice of strings, keeping the first copy of
|
||||||
// each. It modifies the slice contents in place, and returns a subslice of the original slice.
|
// each. It modifies the slice contents in place, and returns a subslice of the original slice.
|
||||||
func FirstUniqueStrings(list []string) []string {
|
func FirstUniqueStrings(list []string) []string {
|
||||||
|
|
49
cc/util.go
49
cc/util.go
|
@ -40,50 +40,11 @@ func libNamesToFlags(names []string) string {
|
||||||
return android.JoinWithPrefix(names, "-l")
|
return android.JoinWithPrefix(names, "-l")
|
||||||
}
|
}
|
||||||
|
|
||||||
func indexList(s string, list []string) int {
|
var indexList = android.IndexList
|
||||||
for i, l := range list {
|
var inList = android.InList
|
||||||
if l == s {
|
var filterList = android.FilterList
|
||||||
return i
|
var removeListFromList = android.RemoveListFromList
|
||||||
}
|
var removeFromList = android.RemoveFromList
|
||||||
}
|
|
||||||
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
|
|
||||||
func inList(s string, list []string) bool {
|
|
||||||
return indexList(s, list) != -1
|
|
||||||
}
|
|
||||||
|
|
||||||
func filterList(list []string, filter []string) (remainder []string, filtered []string) {
|
|
||||||
for _, l := range list {
|
|
||||||
if inList(l, filter) {
|
|
||||||
filtered = append(filtered, l)
|
|
||||||
} else {
|
|
||||||
remainder = append(remainder, l)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func removeListFromList(list []string, filter_out []string) (result []string) {
|
|
||||||
result = make([]string, 0, len(list))
|
|
||||||
for _, l := range list {
|
|
||||||
if !inList(l, filter_out) {
|
|
||||||
result = append(result, l)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func removeFromList(s string, list []string) (bool, []string) {
|
|
||||||
i := indexList(s, list)
|
|
||||||
if i != -1 {
|
|
||||||
return true, append(list[:i], list[i+1:]...)
|
|
||||||
} else {
|
|
||||||
return false, list
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var libNameRegexp = regexp.MustCompile(`^lib(.*)$`)
|
var libNameRegexp = regexp.MustCompile(`^lib(.*)$`)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue