Bp2build Java libs for java_binary -> java_import edge

Since Bazel's java_import requires a jars attribute to be specified,
the generated neverlink-duplicated module is of type java_library

Change-Id: I14a866dfc583507a9462add50d95060cbfe540c5
Bug: 244210934
Test: m bp2build, go test ./bp2build, manual inspection of generated Build and jar files
This commit is contained in:
Alix
2022-09-27 15:36:01 +00:00
parent 9b019134c2
commit b4e09a0ada
4 changed files with 99 additions and 6 deletions

View File

@@ -2384,7 +2384,18 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext)
}
if m.properties.Libs != nil {
deps.Append(android.BazelLabelForModuleDeps(ctx, android.LastUniqueStrings(android.CopyOf(m.properties.Libs))))
// TODO 244210934 ALIX Check if this else statement breaks presubmits get rid of it if it doesn't
if strings.HasPrefix(ctx.ModuleType(), "java_binary") {
for _, d := range m.properties.Libs {
neverlinkLabel := android.BazelLabelForModuleDepSingle(ctx, d)
neverlinkLabel.Label = neverlinkLabel.Label + "-neverlink"
deps.Add(&neverlinkLabel)
}
} else {
deps.Append(android.BazelLabelForModuleDeps(ctx, android.LastUniqueStrings(android.CopyOf(m.properties.Libs))))
}
}
if m.properties.Static_libs != nil {
@@ -2409,8 +2420,9 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext)
type javaLibraryAttributes struct {
*javaCommonAttributes
Deps bazel.LabelListAttribute
Exports bazel.LabelListAttribute
Deps bazel.LabelListAttribute
Exports bazel.LabelListAttribute
Neverlink bazel.BoolAttribute
}
func javaLibraryBp2Build(ctx android.TopDownMutatorContext, m *Library) {
@@ -2440,7 +2452,8 @@ func javaLibraryBp2Build(ctx android.TopDownMutatorContext, m *Library) {
Bzl_load_location: "//build/bazel/rules/java:library.bzl",
}
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, attrs)
name := m.Name()
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name}, attrs)
}
type javaBinaryHostAttributes struct {
@@ -2522,7 +2535,8 @@ func javaBinaryHostBp2Build(ctx android.TopDownMutatorContext, m *Binary) {
}
type bazelJavaImportAttributes struct {
Jars bazel.LabelListAttribute
Jars bazel.LabelListAttribute
Exports bazel.LabelListAttribute
}
// java_import bp2Build converter.
@@ -2543,7 +2557,17 @@ func (i *Import) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
}
props := bazel.BazelTargetModuleProperties{Rule_class: "java_import"}
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: android.RemoveOptionalPrebuiltPrefix(i.Name())}, attrs)
name := android.RemoveOptionalPrebuiltPrefix(i.Name())
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name}, attrs)
neverlink := true
neverlinkAttrs := &javaLibraryAttributes{
Neverlink: bazel.BoolAttribute{Value: &neverlink},
Exports: bazel.MakeSingleLabelListAttribute(bazel.Label{Label: ":" + name}),
}
ctx.CreateBazelTargetModule(bazel.BazelTargetModuleProperties{Rule_class: "java_library"}, android.CommonAttributes{Name: name + "-neverlink"}, neverlinkAttrs)
}
var _ android.MixedBuildBuildable = (*Import)(nil)