From 7607dd35648950a5a3df57721a5e5dde4116b293 Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Sun, 5 Jul 2020 10:23:14 +0900 Subject: [PATCH] Apply "excludes" for OutputFileProducer "excludes" should be applied both SourceFileProducer and OutputFileProducer. But we've been missing the latter. (see android/paths_test.go) There's one more to note. Previously, the exclusion was done by modifying slice directly, which caused some problem(b/76179848). The fix was returning a copy from Srcs() method. But there're still many implementors which just return internal slices directly. This change creates a new array when it needs to exclude something from returned slice. Bug: n/a Test: m (soong test added) Change-Id: I1ba91e490cb55fc243020681667278cdc75f59df --- android/module.go | 9 --------- android/paths.go | 28 +++++++++++++++------------- android/paths_test.go | 15 +++++++++++++++ 3 files changed, 30 insertions(+), 22 deletions(-) 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 d8d51a777..887b3a396 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: `