summaryrefslogtreecommitdiff
path: root/android/module.go
diff options
context:
space:
mode:
author Liz Kammer <eakammer@google.com> 2023-07-17 17:44:08 -0400
committer Liz Kammer <eakammer@google.com> 2023-07-24 13:01:22 -0400
commit5f5dbaad65ec2add5925bada94b1289bc84662ad (patch)
tree10f8d785103a095ea0de9e397392defd5ff235c1 /android/module.go
parent1c535124d5c7a04a7dc449db1686e4f9de5e30c2 (diff)
Handle xsd config more like other partitions
This is prep work to add additional special handling for genrule generated headers as there will be similar partitioning for those headers. Test: go test soong tests Change-Id: Ib63e7e4f7554b2b7b7bc78b2825b20c05403216a
Diffstat (limited to 'android/module.go')
-rw-r--r--android/module.go51
1 files changed, 17 insertions, 34 deletions
diff --git a/android/module.go b/android/module.go
index 384776a65..4c781f6fe 100644
--- a/android/module.go
+++ b/android/module.go
@@ -4029,43 +4029,26 @@ type XsdConfigBp2buildTargets interface {
JavaBp2buildTargetName() string
}
-// PartitionXsdSrcs partitions srcs into xsd_config modules and others
-// Since xsd_config are soong modules, we cannot use file extension for partitioning
-func PartitionXsdSrcs(ctx BazelConversionPathContext, srcs []string) ([]string, []string) {
- //isXsd returns true if src is a soong module of type xsd_config
- isXsd := func(src string) bool {
- mod, exists := ctx.ModuleFromName(src)
+// XsdModuleToTargetName is a function that takes an XsdConfigBp2buildTarget
+type XsdModuleToTargetName func(xsd XsdConfigBp2buildTargets) string
+
+// XsdLabelMapper returns a bazel.LabelMapper for partitioning XSD sources/headers given an
+// XsdModuleToTargetName function.
+func XsdLabelMapper(targetName XsdModuleToTargetName) bazel.LabelMapper {
+ return func(ctx bazel.OtherModuleContext, label bazel.Label) (string, bool) {
+ mod, exists := ctx.ModuleFromName(label.OriginalModuleName)
if !exists {
- return false
+ return label.Label, false
}
- _, _isXsd := mod.(XsdConfigBp2buildTargets)
- return _isXsd
- }
- nonXsd := []string{}
- xsd := []string{}
-
- for _, src := range srcs {
- if isXsd(src) {
- xsd = append(xsd, src)
- } else {
- nonXsd = append(nonXsd, src)
+ xsdMod, isXsd := mod.(XsdConfigBp2buildTargets)
+ if !isXsd {
+ return label.Label, false
}
- }
-
- return nonXsd, xsd
-}
-// Replaces //a/b/my_xsd_config with //a/b/my_xsd_config-{cpp|java}
-// The new target name is provided by the `targetName` callback function
-func XsdConfigBp2buildTarget(ctx BazelConversionPathContext, mod blueprint.Module, targetName func(xsd XsdConfigBp2buildTargets) string) string {
- xsd, isXsd := mod.(XsdConfigBp2buildTargets)
- if !isXsd {
- ctx.ModuleErrorf("xsdConfigJavaTarget called on %v, which is not an xsd_config", mod)
+ // Remove the base module name
+ ret := strings.TrimSuffix(label.Label, mod.Name())
+ // Append the language specific target name
+ ret += targetName(xsdMod)
+ return ret, true
}
- ret := BazelModuleLabel(ctx, mod)
- // Remove the base module name
- ret = strings.TrimSuffix(ret, mod.Name())
- // Append the language specific target name
- ret += targetName(xsd)
- return ret
}