Simple refactoring of prefix related functions.
Rename the two prefix-in-list funcs so that their usages are clearer.
Also find and replace all the code that essentially does either.
This introduces additional loops in some places, but I think the added
readability and simplicity outweighs the performance degradation, which
should be negligible anyway.
Test: m nothing
Test: TreeHugger
Change-Id: I37e2276ca0c815105ed0031f23c0b1264b480e4f
diff --git a/cc/cflag_artifacts.go b/cc/cflag_artifacts.go
index b61f2a8..855ff25 100644
--- a/cc/cflag_artifacts.go
+++ b/cc/cflag_artifacts.go
@@ -41,12 +41,7 @@
// filter.
func allowedDir(subdir string) bool {
subdir += "/"
- for _, prefix := range TrackedCFlagsDir {
- if strings.HasPrefix(subdir, prefix) {
- return true
- }
- }
- return false
+ return android.HasAnyPrefix(subdir, TrackedCFlagsDir)
}
func (s *cflagArtifactsText) genFlagFilename(flag string) string {
diff --git a/cc/compiler.go b/cc/compiler.go
index 1ced451..c1a8d96 100644
--- a/cc/compiler.go
+++ b/cc/compiler.go
@@ -241,12 +241,7 @@
// Return true if the module is in the WarningAllowedProjects.
func warningsAreAllowed(subdir string) bool {
subdir += "/"
- for _, prefix := range config.WarningAllowedProjects {
- if strings.HasPrefix(subdir, prefix) {
- return true
- }
- }
- return false
+ return android.HasAnyPrefix(subdir, config.WarningAllowedProjects)
}
func addToModuleList(ctx ModuleContext, key android.OnceKey, module string) {
@@ -515,7 +510,7 @@
// Exclude directories from manual binder interface whitelisting.
//TODO(b/145621474): Move this check into IInterface.h when clang-tidy no longer uses absolute paths.
- if android.PrefixInList(ctx.ModuleDir(), allowedManualInterfacePaths) {
+ if android.HasAnyPrefix(ctx.ModuleDir(), allowedManualInterfacePaths) {
flags.Local.CFlags = append(flags.Local.CFlags, "-DDO_NOT_CHECK_MANUAL_BINDER_INTERFACES")
}
@@ -604,16 +599,12 @@
func isThirdParty(path string) bool {
thirdPartyDirPrefixes := []string{"external/", "vendor/", "hardware/"}
- for _, prefix := range thirdPartyDirPrefixes {
- if strings.HasPrefix(path, prefix) {
- for _, prefix := range thirdPartyDirPrefixExceptions {
- if prefix.MatchString(path) {
- return false
- }
+ if android.HasAnyPrefix(path, thirdPartyDirPrefixes) {
+ for _, prefix := range thirdPartyDirPrefixExceptions {
+ if prefix.MatchString(path) {
+ return false
}
- break
}
}
-
return true
}
diff --git a/cc/library.go b/cc/library.go
index 0bddab5..bca9a96 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -281,11 +281,9 @@
}
func (f *flagExporter) reexportFlags(flags ...string) {
- for _, flag := range flags {
- if strings.HasPrefix(flag, "-I") || strings.HasPrefix(flag, "-isystem") {
- panic(fmt.Errorf("Exporting invalid flag %q: "+
- "use reexportDirs or reexportSystemDirs to export directories", flag))
- }
+ if android.PrefixInList(flags, "-I") || android.PrefixInList(flags, "-isystem") {
+ panic(fmt.Errorf("Exporting invalid flag %q: "+
+ "use reexportDirs or reexportSystemDirs to export directories", flag))
}
f.flags = append(f.flags, flags...)
}