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:
@@ -272,6 +272,9 @@ var (
|
||||
"prebuilts/tools": Bp2BuildDefaultTrue,
|
||||
"prebuilts/tools/common/m2": Bp2BuildDefaultTrue,
|
||||
|
||||
"sdk/eventanalyzer": Bp2BuildDefaultTrue,
|
||||
"sdk/dumpeventlog": Bp2BuildDefaultTrue,
|
||||
|
||||
"system/apex": Bp2BuildDefaultFalse, // TODO(b/207466993): flaky failures
|
||||
"system/apex/apexer": Bp2BuildDefaultTrue,
|
||||
"system/apex/libs": Bp2BuildDefaultTrueRecursively,
|
||||
|
@@ -29,6 +29,7 @@ func runJavaBinaryHostTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("cc_library_host_shared", cc.LibraryHostSharedFactory)
|
||||
ctx.RegisterModuleType("java_library", java.LibraryFactory)
|
||||
ctx.RegisterModuleType("java_import_host", java.ImportFactory)
|
||||
}, tc)
|
||||
}
|
||||
|
||||
@@ -102,3 +103,34 @@ java_library {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestJavaBinaryHostLibs(t *testing.T) {
|
||||
runJavaBinaryHostTestCase(t, Bp2buildTestCase{
|
||||
Description: "java_binary_host with srcs, libs.",
|
||||
Filesystem: fs,
|
||||
Blueprint: `java_binary_host {
|
||||
name: "java-binary-host-libs",
|
||||
libs: ["java-lib-dep-1"],
|
||||
manifest: "test.mf",
|
||||
srcs: ["a.java"],
|
||||
}
|
||||
|
||||
java_import_host{
|
||||
name: "java-lib-dep-1",
|
||||
jars: ["foo.jar"],
|
||||
bazel_module: { bp2build_available: false },
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("java_binary", "java-binary-host-libs", AttrNameToString{
|
||||
"main_class": `"com.android.test.MainClass"`,
|
||||
"srcs": `["a.java"]`,
|
||||
"deps": `[":java-lib-dep-1-neverlink"]`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
@@ -48,6 +48,10 @@ java_import {
|
||||
MakeBazelTarget("java_import", "example_import", AttrNameToString{
|
||||
"jars": `["import.jar"]`,
|
||||
}),
|
||||
MakeBazelTarget("java_library", "example_import-neverlink", AttrNameToString{
|
||||
"exports": `[":example_import"]`,
|
||||
"neverlink": `True`,
|
||||
}),
|
||||
}})
|
||||
}
|
||||
|
||||
@@ -81,5 +85,35 @@ java_import {
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
MakeBazelTarget("java_library", "example_import-neverlink", AttrNameToString{
|
||||
"exports": `[":example_import"]`,
|
||||
"neverlink": `True`,
|
||||
}),
|
||||
}})
|
||||
}
|
||||
|
||||
func TestJavaImportHost(t *testing.T) {
|
||||
runJavaImportTestCase(t, Bp2buildTestCase{
|
||||
Description: "Java import host- simple example",
|
||||
ModuleTypeUnderTest: "java_import_host",
|
||||
ModuleTypeUnderTestFactory: java.ImportFactory,
|
||||
Filesystem: map[string]string{
|
||||
"import.jar": "",
|
||||
},
|
||||
Blueprint: `
|
||||
java_import_host {
|
||||
name: "example_import",
|
||||
jars: ["import.jar"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("java_import", "example_import", AttrNameToString{
|
||||
"jars": `["import.jar"]`,
|
||||
}),
|
||||
MakeBazelTarget("java_library", "example_import-neverlink", AttrNameToString{
|
||||
"exports": `[":example_import"]`,
|
||||
"neverlink": `True`,
|
||||
}),
|
||||
}})
|
||||
}
|
||||
|
28
java/java.go
28
java/java.go
@@ -2384,8 +2384,19 @@ 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") {
|
||||
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 {
|
||||
staticDeps.Append(android.BazelLabelForModuleDeps(ctx, android.LastUniqueStrings(android.CopyOf(m.properties.Static_libs))))
|
||||
@@ -2411,6 +2422,7 @@ type javaLibraryAttributes struct {
|
||||
*javaCommonAttributes
|
||||
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 {
|
||||
@@ -2523,6 +2536,7 @@ func javaBinaryHostBp2Build(ctx android.TopDownMutatorContext, m *Binary) {
|
||||
|
||||
type bazelJavaImportAttributes struct {
|
||||
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)
|
||||
|
Reference in New Issue
Block a user