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

Commit e91d0303 authored by Sam Delmerico's avatar Sam Delmerico
Browse files

bp2build supports arch variant srcs for java_library

Bug: 209577426
Test: build/bazel/ci/bp2build.sh
Change-Id: I6799bda904d286616e580f2395601ce4f764180f
parent 881d7202
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -489,6 +489,7 @@ var (
		"host-libprotobuf-java-nano",   // b/217236083, java_library cannot have deps without srcs
		"error_prone_core",             // b/217236083, java_library cannot have deps without srcs
		"bouncycastle-host",            // b/217236083, java_library cannot have deps without srcs
		"mockito-robolectric-prebuilt", // b/217236083, java_library cannot have deps without srcs

		"apex_manifest_proto_java", // b/215230097, we don't handle .proto files in java_library srcs attribute

@@ -558,6 +559,8 @@ var (
		"dex2oat-script", // depends on unconverted modules: dex2oat

		"error_prone_checkerframework_dataflow_nullaway", // TODO(b/219908977): "Error in fail: deps not allowed without srcs; move to runtime_deps?"

		"libprotobuf-java-nano", // b/220869005, depends on non-public_current SDK
	}

	// Per-module denylist of cc_library modules to only generate the static
+39 −0
Original line number Diff line number Diff line
@@ -94,3 +94,42 @@ android_app {
			}),
		}})
}

func TestAndroidAppArchVariantSrcs(t *testing.T) {
	runAndroidAppTestCase(t, bp2buildTestCase{
		description:                "Android app - arch variant srcs",
		moduleTypeUnderTest:        "android_app",
		moduleTypeUnderTestFactory: java.AndroidAppFactory,
		filesystem: map[string]string{
			"arm.java":            "",
			"x86.java":            "",
			"res/res.png":         "",
			"AndroidManifest.xml": "",
		},
		blueprint: `
android_app {
        name: "TestApp",
        sdk_version: "current",
        arch: {
			arm: {
				srcs: ["arm.java"],
			},
			x86: {
				srcs: ["x86.java"],
			}
		}
}
`,
		expectedBazelTargets: []string{
			makeBazelTarget("android_binary", "TestApp", attrNameToString{
				"srcs": `select({
        "//build/bazel/platforms/arch:arm": ["arm.java"],
        "//build/bazel/platforms/arch:x86": ["x86.java"],
        "//conditions:default": [],
    })`,
				"manifest":       `"AndroidManifest.xml"`,
				"resource_files": `["res/res.png"]`,
				"deps":           `["//prebuilts/sdk:public_current_android_sdk_java_import"]`,
			}),
		}})
}
+10 −2
Original line number Diff line number Diff line
@@ -2011,8 +2011,16 @@ type javaLibraryAttributes struct {
}

func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext) *javaLibraryAttributes {
	//TODO(b/209577426): Support multiple arch variants
	srcs := bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrcExcludes(ctx, m.properties.Srcs, m.properties.Exclude_srcs))
	var srcs bazel.LabelListAttribute
	archVariantProps := m.GetArchVariantProperties(ctx, &CommonProperties{})
	for axis, configToProps := range archVariantProps {
		for config, _props := range configToProps {
			if archProps, ok := _props.(*CommonProperties); ok {
				archSrcs := android.BazelLabelForModuleSrcExcludes(ctx, archProps.Srcs, archProps.Exclude_srcs)
				srcs.SetSelectValue(axis, config, archSrcs)
			}
		}
	}

	javaSrcPartition := "java"
	protoSrcPartition := "proto"