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
diff --git a/android/paths.go b/android/paths.go
index d8d51a7..887b3a3 100644
--- a/android/paths.go
+++ b/android/paths.go
@@ -380,6 +380,18 @@
}
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 @@
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 @@
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