Bp2Build for libs property in java_library

Bp2build for both *->java_library and java_library->* edges.

Change-Id: I2540c9af2ae2fe7677767d507647b1c6669b9bb7
Bug: 244210934
Test: ./bp2build testcase, manually inspected build files for hamcrest-library, hamcrest targets
This commit is contained in:
Alix
2022-10-31 19:08:18 +00:00
parent 7d78bad7e2
commit 341484b3da
5 changed files with 58 additions and 6 deletions

View File

@@ -2606,7 +2606,7 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext)
if m.properties.Libs != nil {
// 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") {
if strings.HasPrefix(ctx.ModuleType(), "java_binary") || strings.HasPrefix(ctx.ModuleType(), "java_library") {
for _, d := range m.properties.Libs {
neverlinkLabel := android.BazelLabelForModuleDepSingle(ctx, d)
neverlinkLabel.Label = neverlinkLabel.Label + "-neverlink"
@@ -2674,12 +2674,21 @@ func javaLibraryBp2Build(ctx android.TopDownMutatorContext, m *Library) {
Deps: deps,
Exports: depLabels.StaticDeps,
}
name := m.Name()
if !bp2BuildInfo.hasKotlinSrcs && len(m.properties.Common_srcs) == 0 {
props = bazel.BazelTargetModuleProperties{
Rule_class: "java_library",
Bzl_load_location: "//build/bazel/rules/java:library.bzl",
}
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name}, attrs)
neverlinkProp := true
neverLinkAttrs := &javaLibraryAttributes{
Exports: bazel.MakeSingleLabelListAttribute(bazel.Label{Label: ":" + name}),
Neverlink: bazel.BoolAttribute{Value: &neverlinkProp},
}
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name + "-neverlink"}, neverLinkAttrs)
} else {
attrs.Common_srcs = bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, m.properties.Common_srcs))
@@ -2687,10 +2696,10 @@ func javaLibraryBp2Build(ctx android.TopDownMutatorContext, m *Library) {
Rule_class: "kt_jvm_library",
Bzl_load_location: "@rules_kotlin//kotlin:jvm_library.bzl",
}
// TODO (b/244210934): create neverlink-duplicate target once kt_jvm_library supports neverlink attribute
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name}, attrs)
}
name := m.Name()
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name}, attrs)
}
type javaBinaryHostAttributes struct {