diff --git a/android/module.go b/android/module.go index 06079cae9..564c54662 100644 --- a/android/module.go +++ b/android/module.go @@ -2099,15 +2099,6 @@ func (m *moduleContext) CheckbuildFile(srcPath Path) { m.checkbuildFiles = append(m.checkbuildFiles, srcPath) } -func findStringInSlice(str string, slice []string) int { - for i, s := range slice { - if s == str { - return i - } - } - return -1 -} - // SrcIsModule decodes module references in the format ":name" into the module name, or empty string if the input // was not a module reference. func SrcIsModule(s string) (module string) { diff --git a/android/paths.go b/android/paths.go index 066baf2d9..d13b6d86e 100644 --- a/android/paths.go +++ b/android/paths.go @@ -380,6 +380,18 @@ func (e missingDependencyError) Error() string { } func expandOneSrcPath(ctx ModuleContext, s string, expandedExcludes []string) (Paths, error) { + excludePaths := func(paths Paths) Paths { + if len(expandedExcludes) == 0 { + return paths + } + remainder := make(Paths, 0, len(paths)) + for _, p := range paths { + if !InList(p.String(), expandedExcludes) { + remainder = append(remainder, p) + } + } + return remainder + } if m, t := SrcIsModuleWithTag(s); m != "" { module := ctx.GetDirectDepWithTag(m, sourceOrOutputDepTag(t)) if module == nil { @@ -390,20 +402,11 @@ func expandOneSrcPath(ctx ModuleContext, s string, expandedExcludes []string) (P if err != nil { return nil, fmt.Errorf("path dependency %q: %s", s, err) } - return outputFiles, nil + return excludePaths(outputFiles), nil } else if t != "" { return nil, fmt.Errorf("path dependency %q is not an output file producing module", s) } else if srcProducer, ok := module.(SourceFileProducer); ok { - moduleSrcs := srcProducer.Srcs() - for _, e := range expandedExcludes { - for j := 0; j < len(moduleSrcs); j++ { - if moduleSrcs[j].String() == e { - moduleSrcs = append(moduleSrcs[:j], moduleSrcs[j+1:]...) - j-- - } - } - } - return moduleSrcs, nil + return excludePaths(srcProducer.Srcs()), nil } else { return nil, fmt.Errorf("path dependency %q is not a source file producing module", s) } @@ -418,8 +421,7 @@ func expandOneSrcPath(ctx ModuleContext, s string, expandedExcludes []string) (P reportPathErrorf(ctx, "module source path %q does not exist", p) } - j := findStringInSlice(p.String(), expandedExcludes) - if j >= 0 { + if InList(p.String(), expandedExcludes) { return nil, nil } return Paths{p}, nil diff --git a/android/paths_test.go b/android/paths_test.go index 9b45d3f3a..a9cd22bce 100644 --- a/android/paths_test.go +++ b/android/paths_test.go @@ -1090,6 +1090,21 @@ func TestPathsForModuleSrc(t *testing.T) { srcs: []string{buildDir + "/.intermediates/ofp/b/gen/c"}, rels: []string{"gen/c"}, }, + { + name: "output file provider with exclude", + bp: ` + test { + name: "foo", + srcs: [":b", ":c"], + exclude_srcs: [":c"] + } + output_file_provider { + name: "c", + outs: ["gen/c"], + }`, + srcs: []string{buildDir + "/.intermediates/ofp/b/gen/b"}, + rels: []string{"gen/b"}, + }, { name: "special characters glob", bp: `