diff options
| author | Alix <agespino@google.com> | 2022-09-27 15:36:01 +0000 |
|---|---|---|
| committer | Alix <agespino@google.com> | 2022-10-28 20:26:38 +0000 |
| commit | b4e09a0ada621f6dff48c19eb04798301f377925 (patch) | |
| tree | 43ec9c68220b0e79cefc478d83271c7b7f8ca67a /java/java.go | |
| parent | 9b019134c2fd6c622ba4f2503aec3aae6fbb3e68 (diff) | |
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
Diffstat (limited to 'java/java.go')
| -rw-r--r-- | java/java.go | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/java/java.go b/java/java.go index 5091d26a2..c8bb22fee 100644 --- a/java/java.go +++ b/java/java.go @@ -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) |
