summaryrefslogtreecommitdiff
path: root/java/gen.go
diff options
context:
space:
mode:
author Sam Delmerico <delmerico@google.com> 2022-05-24 17:10:02 +0000
committer Sam Delmerico <delmerico@google.com> 2022-08-25 14:47:41 -0400
commit2351eacb19faed3867903e1ddfa2992f7a787d02 (patch)
tree7471023a3c2b892d6b75c0481032749df8ec18db /java/gen.go
parent97bd12745766082ed6b1f6dc3d6f135c237eba49 (diff)
AIDL source generation accounts for Bazel paths
The AIDL source generation rule sets include flags based on the relative path of .aidl sources. For .aidl sources provided by Bazel targets, e.g. in a filegroup, the same directory could be added to the include path twice. Instead we need to ensure that if a Bazel source provides the include path, that we don't add it again from a Soong source. Bug: 229251008 Test: USE_BAZEL_ANALYSIS=1 m api-stubs-docs-non-updatable Change-Id: I4997039003242b43e0e52ccf41729acb4ad11324
Diffstat (limited to 'java/gen.go')
-rw-r--r--java/gen.go28
1 files changed, 23 insertions, 5 deletions
diff --git a/java/gen.go b/java/gen.go
index 1572bf00a..638da255a 100644
--- a/java/gen.go
+++ b/java/gen.go
@@ -15,6 +15,7 @@
package java
import (
+ "path/filepath"
"strconv"
"strings"
@@ -116,12 +117,31 @@ func genLogtags(ctx android.ModuleContext, logtagsFile android.Path) android.Pat
return javaFile
}
-func genAidlIncludeFlags(srcFiles android.Paths) string {
+// genAidlIncludeFlags returns additional include flags based on the relative path
+// of each .aidl file passed in srcFiles. excludeDirs is a list of paths relative to
+// the Android checkout root that should not be included in the returned flags.
+func genAidlIncludeFlags(ctx android.PathContext, srcFiles android.Paths, excludeDirs android.Paths) string {
var baseDirs []string
+ excludeDirsStrings := excludeDirs.Strings()
for _, srcFile := range srcFiles {
if srcFile.Ext() == ".aidl" {
baseDir := strings.TrimSuffix(srcFile.String(), srcFile.Rel())
- if baseDir != "" && !android.InList(baseDir, baseDirs) {
+ baseDir = filepath.Clean(baseDir)
+ baseDirSeen := android.InList(baseDir, baseDirs) || android.InList(baseDir, excludeDirsStrings)
+
+ // For go/bp2build mixed builds, a file may be listed under a
+ // directory in the Bazel output tree that is symlinked to a
+ // directory under the android source tree. We should only
+ // include one copy of this directory so that the AIDL tool
+ // doesn't find multiple definitions of the same AIDL class.
+ // This code comes into effect when filegroups are used in mixed builds.
+ bazelPathPrefix := android.PathForBazelOut(ctx, "").String()
+ bazelBaseDir, err := filepath.Rel(bazelPathPrefix, baseDir)
+ bazelBaseDirSeen := err == nil &&
+ android.InList(bazelBaseDir, baseDirs) ||
+ android.InList(bazelBaseDir, excludeDirsStrings)
+
+ if baseDir != "" && !baseDirSeen && !bazelBaseDirSeen {
baseDirs = append(baseDirs, baseDir)
}
}
@@ -136,8 +156,6 @@ func (j *Module) genSources(ctx android.ModuleContext, srcFiles android.Paths,
var protoSrcs android.Paths
var aidlSrcs android.Paths
- aidlIncludeFlags := genAidlIncludeFlags(srcFiles)
-
for _, srcFile := range srcFiles {
switch srcFile.Ext() {
case ".aidl":
@@ -168,7 +186,7 @@ func (j *Module) genSources(ctx android.ModuleContext, srcFiles android.Paths,
individualFlags[aidlSrc.String()] = flags
}
}
- srcJarFiles := genAidl(ctx, aidlSrcs, flags.aidlFlags+aidlIncludeFlags, individualFlags, flags.aidlDeps)
+ srcJarFiles := genAidl(ctx, aidlSrcs, flags.aidlFlags, individualFlags, flags.aidlDeps)
outSrcFiles = append(outSrcFiles, srcJarFiles...)
}