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

Commit 895bc946 authored by Alix Espino's avatar Alix Espino Committed by Gerrit Code Review
Browse files

Merge "Bp2build for android_app minsdkversion property"

parents 54fb18d4 e5085ebb
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -710,6 +710,10 @@ var (
		// for building com.android.neuralnetworks
		"libimapper_stablec",
		"libimapper_providerutils",

		// min_sdk_version in android_app
		"CtsShimUpgrade",
		"fake-framework",
	}

	Bp2buildModuleTypeAlwaysConvertList = []string{
+47 −0
Original line number Diff line number Diff line
@@ -344,3 +344,50 @@ android_app {
			}),
		}})
}

func TestAndroidAppMinSdkProvided(t *testing.T) {
	runAndroidAppTestCase(t, Bp2buildTestCase{
		Description:                "Android app with value for min_sdk_version",
		ModuleTypeUnderTest:        "android_app",
		ModuleTypeUnderTestFactory: java.AndroidAppFactory,
		Filesystem:                 map[string]string{},
		Blueprint: simpleModuleDoNotConvertBp2build("filegroup", "foocert") + `
android_app {
        name: "foo",
        sdk_version: "current",
				min_sdk_version: "24",
}
`,
		ExpectedBazelTargets: []string{
			MakeBazelTarget("android_binary", "foo", AttrNameToString{
				"manifest":       `"AndroidManifest.xml"`,
				"resource_files": `[]`,
				"manifest_values": `{
        "minSdkVersion": "24",
    }`,
			}),
		}})
}

func TestAndroidAppMinSdkDefaultToSdkVersion(t *testing.T) {
	runAndroidAppTestCase(t, Bp2buildTestCase{
		Description:                "Android app with value for sdk_version",
		ModuleTypeUnderTest:        "android_app",
		ModuleTypeUnderTestFactory: java.AndroidAppFactory,
		Filesystem:                 map[string]string{},
		Blueprint: simpleModuleDoNotConvertBp2build("filegroup", "foocert") + `
android_app {
        name: "foo",
        sdk_version: "30",
}
`,
		ExpectedBazelTargets: []string{
			MakeBazelTarget("android_binary", "foo", AttrNameToString{
				"manifest":       `"AndroidManifest.xml"`,
				"resource_files": `[]`,
				"manifest_values": `{
        "minSdkVersion": "30",
    }`,
			}),
		}})
}
+16 −0
Original line number Diff line number Diff line
@@ -1495,6 +1495,10 @@ func androidAppCertificateBp2Build(ctx android.TopDownMutatorContext, module *An
	ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name()}, attrs)
}

type manifestValueAttribute struct {
	MinSdkVersion *string
}

type bazelAndroidAppAttributes struct {
	*javaCommonAttributes
	*bazelAapt
@@ -1502,6 +1506,7 @@ type bazelAndroidAppAttributes struct {
	Custom_package   *string
	Certificate      bazel.LabelAttribute
	Certificate_name bazel.StringAttribute
	Manifest_values  *manifestValueAttribute
}

// ConvertWithBp2build is used to convert android_app to Bazel.
@@ -1516,11 +1521,22 @@ func (a *AndroidApp) ConvertWithBp2build(ctx android.TopDownMutatorContext) {

	certificate, certificateName := android.BazelStringOrLabelFromProp(ctx, a.overridableAppProperties.Certificate)

	manifestValues := &manifestValueAttribute{}
	// MinSdkVersion(ctx) calls SdkVersion(ctx) if no value for min_sdk_version is set
	minSdkSpec := a.MinSdkVersion(ctx)
	if !minSdkSpec.ApiLevel.IsPreview() && minSdkSpec.Valid() {
		minSdkStr, err := minSdkSpec.EffectiveVersionString(ctx)
		if err == nil {
			manifestValues.MinSdkVersion = &minSdkStr
		}
	}

	appAttrs := &bazelAndroidAppAttributes{
		// TODO(b/209576404): handle package name override by product variable PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES
		Custom_package:   a.overridableAppProperties.Package_name,
		Certificate:      certificate,
		Certificate_name: certificateName,
		Manifest_values:  manifestValues,
	}

	props := bazel.BazelTargetModuleProperties{