Merge "Support arch variants in java's StaticLibs in bp2build"

This commit is contained in:
Romain Jobredeaux
2023-04-05 13:32:29 +00:00
committed by Gerrit Code Review
2 changed files with 28 additions and 7 deletions

View File

@@ -740,7 +740,7 @@ func TestJavaLibraryKotlinCommonSrcs(t *testing.T) {
}) })
} }
func TestJavaLibraryArchVariantLibs(t *testing.T) { func TestJavaLibraryArchVariantDeps(t *testing.T) {
runJavaLibraryTestCase(t, Bp2buildTestCase{ runJavaLibraryTestCase(t, Bp2buildTestCase{
Description: "java_library with arch variant libs", Description: "java_library with arch variant libs",
Blueprint: `java_library { Blueprint: `java_library {
@@ -750,6 +750,7 @@ func TestJavaLibraryArchVariantLibs(t *testing.T) {
target: { target: {
android: { android: {
libs: ["java-lib-3"], libs: ["java-lib-3"],
static_libs: ["java-lib-4"],
}, },
}, },
bazel_module: { bp2build_available: true }, bazel_module: { bp2build_available: true },
@@ -762,12 +763,23 @@ func TestJavaLibraryArchVariantLibs(t *testing.T) {
java_library{ java_library{
name: "java-lib-3", name: "java-lib-3",
} }
java_library{
name: "java-lib-4",
}
`, `,
ExpectedBazelTargets: []string{ ExpectedBazelTargets: []string{
MakeBazelTarget("java_library", "java-lib-1", AttrNameToString{ MakeBazelTarget("java_library", "java-lib-1", AttrNameToString{
"srcs": `["a.java"]`, "srcs": `["a.java"]`,
"exports": `select({
"//build/bazel/platforms/os:android": [":java-lib-4"],
"//conditions:default": [],
})`,
"deps": `[":java-lib-2-neverlink"] + select({ "deps": `[":java-lib-2-neverlink"] + select({
"//build/bazel/platforms/os:android": [":java-lib-3-neverlink"], "//build/bazel/platforms/os:android": [
":java-lib-3-neverlink",
":java-lib-4",
],
"//conditions:default": [], "//conditions:default": [],
})`, })`,
}), }),
@@ -776,6 +788,8 @@ func TestJavaLibraryArchVariantLibs(t *testing.T) {
MakeNeverlinkDuplicateTarget("java_library", "java-lib-2"), MakeNeverlinkDuplicateTarget("java_library", "java-lib-2"),
MakeBazelTarget("java_library", "java-lib-3", AttrNameToString{}), MakeBazelTarget("java_library", "java-lib-3", AttrNameToString{}),
MakeNeverlinkDuplicateTarget("java_library", "java-lib-3"), MakeNeverlinkDuplicateTarget("java_library", "java-lib-3"),
MakeBazelTarget("java_library", "java-lib-4", AttrNameToString{}),
MakeNeverlinkDuplicateTarget("java_library", "java-lib-4"),
}, },
}) })
} }

View File

@@ -2905,10 +2905,6 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext)
} }
} }
if m.properties.Static_libs != nil {
staticDeps.Append(android.BazelLabelForModuleDeps(ctx, android.LastUniqueStrings(android.CopyOf(m.properties.Static_libs))))
}
protoDepLabel := bp2buildProto(ctx, &m.Module, srcPartitions[protoSrcPartition]) protoDepLabel := bp2buildProto(ctx, &m.Module, srcPartitions[protoSrcPartition])
// Soong does not differentiate between a java_library and the Bazel equivalent of // Soong does not differentiate between a java_library and the Bazel equivalent of
// a java_proto_library + proto_library pair. Instead, in Soong proto sources are // a java_proto_library + proto_library pair. Instead, in Soong proto sources are
@@ -2920,7 +2916,18 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext)
depLabels := &javaDependencyLabels{} depLabels := &javaDependencyLabels{}
depLabels.Deps = deps depLabels.Deps = deps
depLabels.StaticDeps = bazel.MakeLabelListAttribute(staticDeps)
for axis, configToProps := range archVariantProps {
for config, _props := range configToProps {
if archProps, ok := _props.(*CommonProperties); ok {
archStaticLibs := android.BazelLabelForModuleDeps(
ctx,
android.LastUniqueStrings(android.CopyOf(archProps.Static_libs)))
depLabels.StaticDeps.SetSelectValue(axis, config, archStaticLibs)
}
}
}
depLabels.StaticDeps.Value.Append(staticDeps)
hasKotlin := !kotlinSrcs.IsEmpty() hasKotlin := !kotlinSrcs.IsEmpty()
commonAttrs.kotlinAttributes = &kotlinAttributes{ commonAttrs.kotlinAttributes = &kotlinAttributes{