bp2build: fix exclude_srcs in subpackages.
In a non-top level Android.bp file, exclude_srcs was not working at all
due to a bug in expandSrcsForBazel. GlobFiles was expanding a glob
relative to root, but the expandedExcludes list was relative to the
module dir, causing the glob function to not consider the
expandedExcludes list at all.
Add tests to demonstrate that this is working now.
Test: TH
Bug: 186388919
Change-Id: Ice8254231d085b39126e91b823a09ec328ee0ae0
diff --git a/android/bazel_paths.go b/android/bazel_paths.go
index 63e2c50..4280bc3 100644
--- a/android/bazel_paths.go
+++ b/android/bazel_paths.go
@@ -243,6 +243,14 @@
labels := bazel.LabelList{
Includes: []bazel.Label{},
}
+
+ // expandedExcludes contain module-dir relative paths, but root-relative paths
+ // are needed for GlobFiles later.
+ var rootRelativeExpandedExcludes []string
+ for _, e := range expandedExcludes {
+ rootRelativeExpandedExcludes = append(rootRelativeExpandedExcludes, filepath.Join(ctx.ModuleDir(), e))
+ }
+
for _, p := range paths {
if m, tag := SrcIsModuleWithTag(p); m != "" {
l := getOtherModuleLabel(ctx, m, tag)
@@ -253,7 +261,10 @@
} else {
var expandedPaths []bazel.Label
if pathtools.IsGlob(p) {
- globbedPaths := GlobFiles(ctx, pathForModuleSrc(ctx, p).String(), expandedExcludes)
+ // e.g. turn "math/*.c" in
+ // external/arm-optimized-routines to external/arm-optimized-routines/math/*.c
+ rootRelativeGlobPath := pathForModuleSrc(ctx, p).String()
+ globbedPaths := GlobFiles(ctx, rootRelativeGlobPath, rootRelativeExpandedExcludes)
globbedPaths = PathsWithModuleSrcSubDir(ctx, globbedPaths, "")
for _, path := range globbedPaths {
s := path.Rel()