Merge "Simple refactoring of prefix related functions."
This commit is contained in:
commit
36b6aec26a
|
@ -1521,12 +1521,7 @@ func decodeTargetProductVariables(config *config) (map[OsType][]Target, error) {
|
||||||
|
|
||||||
// hasArmAbi returns true if arch has at least one arm ABI
|
// hasArmAbi returns true if arch has at least one arm ABI
|
||||||
func hasArmAbi(arch Arch) bool {
|
func hasArmAbi(arch Arch) bool {
|
||||||
for _, abi := range arch.Abi {
|
return PrefixInList(arch.Abi, "arm")
|
||||||
if strings.HasPrefix(abi, "arm") {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// hasArmArch returns true if targets has at least non-native_bridge arm Android arch
|
// hasArmArch returns true if targets has at least non-native_bridge arm Android arch
|
||||||
|
|
|
@ -890,11 +890,7 @@ func (c *config) EnforceRROForModule(name string) bool {
|
||||||
func (c *config) EnforceRROExcludedOverlay(path string) bool {
|
func (c *config) EnforceRROExcludedOverlay(path string) bool {
|
||||||
excluded := c.productVariables.EnforceRROExcludedOverlays
|
excluded := c.productVariables.EnforceRROExcludedOverlays
|
||||||
if excluded != nil {
|
if excluded != nil {
|
||||||
for _, exclude := range excluded {
|
return HasAnyPrefix(path, excluded)
|
||||||
if strings.HasPrefix(path, exclude) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -1050,12 +1046,12 @@ func (c *deviceConfig) ClangCoverageEnabled() 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 InList("*", c.config.productVariables.CoveragePaths) || PrefixInList(path, c.config.productVariables.CoveragePaths) {
|
if InList("*", c.config.productVariables.CoveragePaths) || HasAnyPrefix(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 HasAnyPrefix(path, c.config.productVariables.CoverageExcludePaths) {
|
||||||
coverage = false
|
coverage = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1128,21 +1124,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 HasAnyPrefix(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 HasAnyPrefix(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 HasAnyPrefix(path, c.productVariables.CFIIncludePaths)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *config) VendorConfig(name string) VendorConfig {
|
func (c *config) VendorConfig(name string) VendorConfig {
|
||||||
|
|
|
@ -407,8 +407,8 @@ func (r *rule) String() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *rule) appliesToPath(dir string) bool {
|
func (r *rule) appliesToPath(dir string) bool {
|
||||||
includePath := len(r.paths) == 0 || hasAnyPrefix(dir, r.paths)
|
includePath := len(r.paths) == 0 || HasAnyPrefix(dir, r.paths)
|
||||||
excludePath := hasAnyPrefix(dir, r.unlessPaths)
|
excludePath := HasAnyPrefix(dir, r.unlessPaths)
|
||||||
return includePath && !excludePath
|
return includePath && !excludePath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -474,15 +474,6 @@ func fieldNamesForProperties(propertyNames string) []string {
|
||||||
return names
|
return names
|
||||||
}
|
}
|
||||||
|
|
||||||
func hasAnyPrefix(s string, prefixes []string) bool {
|
|
||||||
for _, prefix := range prefixes {
|
|
||||||
if strings.HasPrefix(s, prefix) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func hasAnyProperty(properties []interface{}, props []ruleProperty) bool {
|
func hasAnyProperty(properties []interface{}, props []ruleProperty) bool {
|
||||||
for _, v := range props {
|
for _, v := range props {
|
||||||
if hasProperty(properties, v) {
|
if hasProperty(properties, v) {
|
||||||
|
|
|
@ -122,7 +122,7 @@ func InList(s string, list []string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if the given string s is prefixed with any string in the given prefix list.
|
// Returns true if the given string s is prefixed with any string in the given prefix list.
|
||||||
func PrefixInList(s string, prefixList []string) bool {
|
func HasAnyPrefix(s string, prefixList []string) bool {
|
||||||
for _, prefix := range prefixList {
|
for _, prefix := range prefixList {
|
||||||
if strings.HasPrefix(s, prefix) {
|
if strings.HasPrefix(s, prefix) {
|
||||||
return true
|
return true
|
||||||
|
@ -132,7 +132,7 @@ func PrefixInList(s string, prefixList []string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if any string in the given list has the given prefix.
|
// Returns true if any string in the given list has the given prefix.
|
||||||
func PrefixedStringInList(list []string, prefix string) bool {
|
func PrefixInList(list []string, prefix string) bool {
|
||||||
for _, s := range list {
|
for _, s := range list {
|
||||||
if strings.HasPrefix(s, prefix) {
|
if strings.HasPrefix(s, prefix) {
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -252,7 +252,7 @@ func TestPrefixInList(t *testing.T) {
|
||||||
|
|
||||||
for _, testCase := range testcases {
|
for _, testCase := range testcases {
|
||||||
t.Run(testCase.str, func(t *testing.T) {
|
t.Run(testCase.str, func(t *testing.T) {
|
||||||
out := PrefixInList(testCase.str, prefixes)
|
out := HasAnyPrefix(testCase.str, prefixes)
|
||||||
if out != testCase.expected {
|
if out != testCase.expected {
|
||||||
t.Errorf("incorrect output:")
|
t.Errorf("incorrect output:")
|
||||||
t.Errorf(" str: %#v", testCase.str)
|
t.Errorf(" str: %#v", testCase.str)
|
||||||
|
|
|
@ -41,12 +41,7 @@ type cflagArtifactsText struct {
|
||||||
// filter.
|
// filter.
|
||||||
func allowedDir(subdir string) bool {
|
func allowedDir(subdir string) bool {
|
||||||
subdir += "/"
|
subdir += "/"
|
||||||
for _, prefix := range TrackedCFlagsDir {
|
return android.HasAnyPrefix(subdir, TrackedCFlagsDir)
|
||||||
if strings.HasPrefix(subdir, prefix) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *cflagArtifactsText) genFlagFilename(flag string) string {
|
func (s *cflagArtifactsText) genFlagFilename(flag string) string {
|
||||||
|
|
|
@ -241,12 +241,7 @@ func (compiler *baseCompiler) compilerDeps(ctx DepsContext, deps Deps) Deps {
|
||||||
// Return true if the module is in the WarningAllowedProjects.
|
// Return true if the module is in the WarningAllowedProjects.
|
||||||
func warningsAreAllowed(subdir string) bool {
|
func warningsAreAllowed(subdir string) bool {
|
||||||
subdir += "/"
|
subdir += "/"
|
||||||
for _, prefix := range config.WarningAllowedProjects {
|
return android.HasAnyPrefix(subdir, config.WarningAllowedProjects)
|
||||||
if strings.HasPrefix(subdir, prefix) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func addToModuleList(ctx ModuleContext, key android.OnceKey, module string) {
|
func addToModuleList(ctx ModuleContext, key android.OnceKey, module string) {
|
||||||
|
@ -515,7 +510,7 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
|
||||||
|
|
||||||
// Exclude directories from manual binder interface whitelisting.
|
// Exclude directories from manual binder interface whitelisting.
|
||||||
//TODO(b/145621474): Move this check into IInterface.h when clang-tidy no longer uses absolute paths.
|
//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")
|
flags.Local.CFlags = append(flags.Local.CFlags, "-DDO_NOT_CHECK_MANUAL_BINDER_INTERFACES")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -604,16 +599,12 @@ var thirdPartyDirPrefixExceptions = []*regexp.Regexp{
|
||||||
func isThirdParty(path string) bool {
|
func isThirdParty(path string) bool {
|
||||||
thirdPartyDirPrefixes := []string{"external/", "vendor/", "hardware/"}
|
thirdPartyDirPrefixes := []string{"external/", "vendor/", "hardware/"}
|
||||||
|
|
||||||
for _, prefix := range thirdPartyDirPrefixes {
|
if android.HasAnyPrefix(path, thirdPartyDirPrefixes) {
|
||||||
if strings.HasPrefix(path, prefix) {
|
for _, prefix := range thirdPartyDirPrefixExceptions {
|
||||||
for _, prefix := range thirdPartyDirPrefixExceptions {
|
if prefix.MatchString(path) {
|
||||||
if prefix.MatchString(path) {
|
return false
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -281,11 +281,9 @@ func (f *flagExporter) reexportSystemDirs(dirs ...android.Path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *flagExporter) reexportFlags(flags ...string) {
|
func (f *flagExporter) reexportFlags(flags ...string) {
|
||||||
for _, flag := range flags {
|
if android.PrefixInList(flags, "-I") || android.PrefixInList(flags, "-isystem") {
|
||||||
if strings.HasPrefix(flag, "-I") || strings.HasPrefix(flag, "-isystem") {
|
panic(fmt.Errorf("Exporting invalid flag %q: "+
|
||||||
panic(fmt.Errorf("Exporting invalid flag %q: "+
|
"use reexportDirs or reexportSystemDirs to export directories", flag))
|
||||||
"use reexportDirs or reexportSystemDirs to export directories", flag))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
f.flags = append(f.flags, flags...)
|
f.flags = append(f.flags, flags...)
|
||||||
}
|
}
|
||||||
|
|
|
@ -426,7 +426,7 @@ func dexpreoptCommand(ctx android.PathContext, globalSoong *GlobalSoongConfig, g
|
||||||
cmd.FlagWithArg("--copy-dex-files=", "false")
|
cmd.FlagWithArg("--copy-dex-files=", "false")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !anyHavePrefix(preoptFlags, "--compiler-filter=") {
|
if !android.PrefixInList(preoptFlags, "--compiler-filter=") {
|
||||||
var compilerFilter string
|
var compilerFilter string
|
||||||
if contains(global.SystemServerJars, module.Name) {
|
if contains(global.SystemServerJars, module.Name) {
|
||||||
// Jars of system server, use the product option if it is set, speed otherwise.
|
// Jars of system server, use the product option if it is set, speed otherwise.
|
||||||
|
@ -618,32 +618,4 @@ func contains(l []string, s string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove all elements in a from b, returning a new slice
|
|
||||||
func filterOut(a []string, b []string) []string {
|
|
||||||
var ret []string
|
|
||||||
for _, x := range b {
|
|
||||||
if !contains(a, x) {
|
|
||||||
ret = append(ret, x)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
func replace(l []string, from, to string) {
|
|
||||||
for i := range l {
|
|
||||||
if l[i] == from {
|
|
||||||
l[i] = to
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var copyOf = android.CopyOf
|
var copyOf = android.CopyOf
|
||||||
|
|
||||||
func anyHavePrefix(l []string, prefix string) bool {
|
|
||||||
for _, x := range l {
|
|
||||||
if strings.HasPrefix(x, prefix) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
13
java/aar.go
13
java/aar.go
|
@ -134,15 +134,8 @@ func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext sdkContext,
|
||||||
manifestPath android.Path) (compileFlags, linkFlags []string, linkDeps android.Paths,
|
manifestPath android.Path) (compileFlags, linkFlags []string, linkDeps android.Paths,
|
||||||
resDirs, overlayDirs []globbedResourceDir, rroDirs []rroDir, resZips android.Paths) {
|
resDirs, overlayDirs []globbedResourceDir, rroDirs []rroDir, resZips android.Paths) {
|
||||||
|
|
||||||
hasVersionCode := false
|
hasVersionCode := android.PrefixInList(a.aaptProperties.Aaptflags, "--version-code")
|
||||||
hasVersionName := false
|
hasVersionName := android.PrefixInList(a.aaptProperties.Aaptflags, "--version-name")
|
||||||
for _, f := range a.aaptProperties.Aaptflags {
|
|
||||||
if strings.HasPrefix(f, "--version-code") {
|
|
||||||
hasVersionCode = true
|
|
||||||
} else if strings.HasPrefix(f, "--version-name") {
|
|
||||||
hasVersionName = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Flags specified in Android.bp
|
// Flags specified in Android.bp
|
||||||
linkFlags = append(linkFlags, a.aaptProperties.Aaptflags...)
|
linkFlags = append(linkFlags, a.aaptProperties.Aaptflags...)
|
||||||
|
@ -337,7 +330,7 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, ex
|
||||||
|
|
||||||
// Extract assets from the resource package output so that they can be used later in aapt2link
|
// Extract assets from the resource package output so that they can be used later in aapt2link
|
||||||
// for modules that depend on this one.
|
// for modules that depend on this one.
|
||||||
if android.PrefixedStringInList(linkFlags, "-A ") || len(assetPackages) > 0 {
|
if android.PrefixInList(linkFlags, "-A ") || len(assetPackages) > 0 {
|
||||||
assets := android.PathForModuleOut(ctx, "assets.zip")
|
assets := android.PathForModuleOut(ctx, "assets.zip")
|
||||||
ctx.Build(pctx, android.BuildParams{
|
ctx.Build(pctx, android.BuildParams{
|
||||||
Rule: extractAssetsRule,
|
Rule: extractAssetsRule,
|
||||||
|
|
|
@ -273,13 +273,7 @@ func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) {
|
||||||
aaptLinkFlags := []string{}
|
aaptLinkFlags := []string{}
|
||||||
|
|
||||||
// Add TARGET_AAPT_CHARACTERISTICS values to AAPT link flags if they exist and --product flags were not provided.
|
// Add TARGET_AAPT_CHARACTERISTICS values to AAPT link flags if they exist and --product flags were not provided.
|
||||||
hasProduct := false
|
hasProduct := android.PrefixInList(a.aaptProperties.Aaptflags, "--product")
|
||||||
for _, f := range a.aaptProperties.Aaptflags {
|
|
||||||
if strings.HasPrefix(f, "--product") {
|
|
||||||
hasProduct = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !hasProduct && len(ctx.Config().ProductAAPTCharacteristics()) > 0 {
|
if !hasProduct && len(ctx.Config().ProductAAPTCharacteristics()) > 0 {
|
||||||
aaptLinkFlags = append(aaptLinkFlags, "--product", ctx.Config().ProductAAPTCharacteristics())
|
aaptLinkFlags = append(aaptLinkFlags, "--product", ctx.Config().ProductAAPTCharacteristics())
|
||||||
}
|
}
|
||||||
|
|
|
@ -605,11 +605,8 @@ func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
packageName := strings.ReplaceAll(filepath.Dir(src.Rel()), "/", ".")
|
packageName := strings.ReplaceAll(filepath.Dir(src.Rel()), "/", ".")
|
||||||
for _, pkg := range filterPackages {
|
if android.HasAnyPrefix(packageName, filterPackages) {
|
||||||
if strings.HasPrefix(packageName, pkg) {
|
filtered = append(filtered, src)
|
||||||
filtered = append(filtered, src)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return filtered
|
return filtered
|
||||||
|
|
Loading…
Reference in New Issue