Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1db2ff3e authored by Alix Espino's avatar Alix Espino Committed by Gerrit Code Review
Browse files

Merge "arch variant support for libs property"

parents 8733a89c 495cc8a6
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
@@ -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"),
		},
	})
}
+13 −7
Original line number Diff line number Diff line
@@ -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 {
	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"
			deps.Add(&neverlinkLabel)
					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{