bp2build for java libraries using xsd_config srcs
In Soong, java libraries can use src files generated from xsd_config. In Bazel, instead of providing srcs, java_xsd_config_library will provide a jar. Update bp2build so that all src references to xsd_config modules in srcs get routed to deps and exports attributes This CL creates an interface in build/soong/android to get around a circular dependency issue. The bp2build logic needs to exist in soong-java, but soong-java does have soong-xsdc in its package path. Use the interface and type assertions to special case xsd_config references Bug: 211678537 Test: bp2build test in sibling CL in system/tools/xsdc Change-Id: Ida924bb20b1fd7eb8beeef950b070d37a9c6f3b5
This commit is contained in:
@@ -4014,3 +4014,53 @@ func (s *soongConfigTraceSingleton) GenerateBuildActions(ctx SingletonContext) {
|
||||
WriteFileRule(ctx, outFile, string(j))
|
||||
ctx.Phony("soong_config_trace", outFile)
|
||||
}
|
||||
|
||||
// Interface implemented by xsd_config which has 1:many mappings in bp2build workspace
|
||||
// This interface exists because we want to
|
||||
// 1. Determine the name of the additional targets generated by the primary soong module
|
||||
// 2. Enable distinguishing an xsd_config module from other Soong modules using type assertion
|
||||
type XsdConfigBp2buildTargets interface {
|
||||
CppBp2buildTargetName() string
|
||||
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)
|
||||
if !exists {
|
||||
return 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)
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
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
|
||||
}
|
||||
|
Reference in New Issue
Block a user