Merge "arch variant support for libs property"

This commit is contained in:
Alix Espino 2023-01-26 19:11:23 +00:00 committed by Gerrit Code Review
commit 1db2ff3eaf
2 changed files with 53 additions and 7 deletions

View file

@ -715,3 +715,43 @@ func TestJavaLibraryKotlinCommonSrcs(t *testing.T) {
},
})
}
func TestJavaLibraryArchVariantLibs(t *testing.T) {
runJavaLibraryTestCase(t, Bp2buildTestCase{
Description: "java_library with arch variant libs",
Blueprint: `java_library {
name: "java-lib-1",
srcs: ["a.java"],
libs: ["java-lib-2"],
target: {
android: {
libs: ["java-lib-3"],
},
},
bazel_module: { bp2build_available: true },
}
java_library{
name: "java-lib-2",
}
java_library{
name: "java-lib-3",
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("java_library", "java-lib-1", AttrNameToString{
"srcs": `["a.java"]`,
"deps": `[":java-lib-2-neverlink"] + select({
"//build/bazel/platforms/os:android": [":java-lib-3-neverlink"],
"//conditions:default": [],
})`,
}),
MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
MakeBazelTarget("java_library", "java-lib-2", AttrNameToString{}),
MakeNeverlinkDuplicateTarget("java_library", "java-lib-2"),
MakeBazelTarget("java_library", "java-lib-3", AttrNameToString{}),
MakeNeverlinkDuplicateTarget("java_library", "java-lib-3"),
},
})
}

View file

@ -2595,7 +2595,7 @@ type bp2BuildJavaInfo struct {
// to be returned to the calling function.
func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext) (*javaCommonAttributes, *bp2BuildJavaInfo) {
var srcs bazel.LabelListAttribute
var deps bazel.LabelList
var deps bazel.LabelListAttribute
var staticDeps bazel.LabelList
archVariantProps := m.GetArchVariantProperties(ctx, &CommonProperties{})
@ -2701,11 +2701,17 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext)
Javacopts: bazel.MakeStringListAttribute(javacopts),
}
if m.properties.Libs != nil {
for _, d := range m.properties.Libs {
neverlinkLabel := android.BazelLabelForModuleDepSingle(ctx, d)
neverlinkLabel.Label = neverlinkLabel.Label + "-neverlink"
deps.Add(&neverlinkLabel)
for axis, configToProps := range archVariantProps {
for config, _props := range configToProps {
if archProps, ok := _props.(*CommonProperties); ok {
var libLabels []bazel.Label
for _, d := range archProps.Libs {
neverlinkLabel := android.BazelLabelForModuleDepSingle(ctx, d)
neverlinkLabel.Label = neverlinkLabel.Label + "-neverlink"
libLabels = append(libLabels, neverlinkLabel)
}
deps.SetSelectValue(axis, config, bazel.MakeLabelList(libLabels))
}
}
}
@ -2723,7 +2729,7 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext)
staticDeps.Add(protoDepLabel)
depLabels := &javaDependencyLabels{}
depLabels.Deps = bazel.MakeLabelListAttribute(deps)
depLabels.Deps = deps
depLabels.StaticDeps = bazel.MakeLabelListAttribute(staticDeps)
bp2BuildInfo := &bp2BuildJavaInfo{