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

Commit 9c06ef35 authored by Romain Jobredeaux's avatar Romain Jobredeaux
Browse files

bp2build support for framework-res

Change-Id: I5b32a702e02b5f1ec08d5608d766a8a0c08d845c
Bug: 276928228
Bug: 297356405
parent c9e585ea
Loading
Loading
Loading
Loading
+1 −5
Original line number Diff line number Diff line
@@ -230,6 +230,7 @@ var (
		"frameworks/av/services/minijail":                    Bp2BuildDefaultTrueRecursively,
		"frameworks/base/apex/jobscheduler/service/jni":      Bp2BuildDefaultTrueRecursively,
		"frameworks/base/core/java":                          Bp2BuildDefaultTrue,
		"frameworks/base/core/res":                           Bp2BuildDefaultTrueRecursively,
		"frameworks/base/libs/androidfw":                     Bp2BuildDefaultTrue,
		"frameworks/base/libs/services":                      Bp2BuildDefaultTrue,
		"frameworks/base/media/tests/MediaDump":              Bp2BuildDefaultTrue,
@@ -563,10 +564,6 @@ var (
		// ext
		"tagsoup",

		// framework-res
		"remote-color-resources-compile-public",
		"remote-color-resources-compile-colors",

		// framework-minus-apex
		"ImmutabilityAnnotationProcessor",
		"android.mime.types.minimized",
@@ -578,7 +575,6 @@ var (
		"apache-commons-math",
		"cbor-java",
		"icu4j_calendar_astronomer",
		"remote-color-resources-compile-public",
		"statslog-art-java-gen",

		"AndroidCommonLint",
+3 −0
Original line number Diff line number Diff line
@@ -442,6 +442,9 @@ func getOtherModuleLabel(ctx BazelConversionPathContext, dep, tag string,
	otherLabel := labelFromModule(ctx, m)

	// TODO(b/165114590): Convert tag (":name{.tag}") to corresponding Bazel implicit output targets.
	if tag != "" && m.Name() == "framework-res" {
		otherLabel += tag
	}

	if samePackage(label, otherLabel) {
		otherLabel = bazelShortLabel(otherLabel)
+38 −0
Original line number Diff line number Diff line
@@ -478,3 +478,41 @@ android_app {
			}),
		}})
}

func TestFrameworkResConversion(t *testing.T) {
	runAndroidAppTestCase(t, Bp2buildTestCase{
		Description:                "Framework Res custom conversion",
		ModuleTypeUnderTest:        "android_app",
		ModuleTypeUnderTestFactory: java.AndroidAppFactory,
		Filesystem: map[string]string{
			"res/values/attrs.xml": "",
			"resource_zip.zip":     "",
		},
		Blueprint: `
android_app {
	name: "framework-res",
	resource_zips: [
		"resource_zip.zip",
	],
	certificate: "platform",
}

filegroup {
	name: "framework-res-package-jar",
	srcs: [":framework-res{.export-package.apk}"],
}
`,
		ExpectedBazelTargets: []string{
			MakeBazelTarget("framework_resources", "framework-res", AttrNameToString{
				"certificate_name":       `"platform"`,
				"manifest":               `"AndroidManifest.xml"`,
				"resource_files":         `["res/values/attrs.xml"]`,
				"resource_zips":          `["resource_zip.zip"]`,
				"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
			}),
			MakeBazelTargetNoRestrictions("filegroup", "framework-res-package-jar", AttrNameToString{
				"srcs": `[":framework-res.export-package.apk"]`,
			}),
		}})

}
+11 −0
Original line number Diff line number Diff line
@@ -267,11 +267,22 @@ func platformMappingSingleProduct(
		defaultAppCertificateFilegroup = "@//" + filepath.Dir(proptools.String(productVariables.DefaultAppCertificate)) + ":generated_android_certificate_directory"
	}

	// TODO: b/301598690 - commas can't be escaped in a string-list passed in a platform mapping,
	// so commas are switched for ":" here, and must be back-substituted into commas
	// wherever the AAPTCharacteristics product config variable is used.
	AAPTConfig := []string{}
	for _, conf := range productVariables.AAPTConfig {
		AAPTConfig = append(AAPTConfig, strings.Replace(conf, ",", ":", -1))
	}

	for _, suffix := range bazelPlatformSuffixes {
		result.WriteString("  ")
		result.WriteString(label.String())
		result.WriteString(suffix)
		result.WriteString("\n")
		result.WriteString(fmt.Sprintf("    --//build/bazel/product_config:aapt_characteristics=%s\n", proptools.String(productVariables.AAPTCharacteristics)))
		result.WriteString(fmt.Sprintf("    --//build/bazel/product_config:aapt_config=%s\n", strings.Join(AAPTConfig, ",")))
		result.WriteString(fmt.Sprintf("    --//build/bazel/product_config:aapt_preferred_config=%s\n", proptools.String(productVariables.AAPTPreferredConfig)))
		result.WriteString(fmt.Sprintf("    --//build/bazel/product_config:always_use_prebuilt_sdks=%t\n", proptools.Bool(productVariables.Always_use_prebuilt_sdks)))
		result.WriteString(fmt.Sprintf("    --//build/bazel/product_config:arc=%t\n", proptools.Bool(productVariables.Arc)))
		result.WriteString(fmt.Sprintf("    --//build/bazel/product_config:apex_global_min_sdk_version_override=%s\n", proptools.String(productVariables.ApexGlobalMinSdkVersionOverride)))
+12 −0
Original line number Diff line number Diff line
@@ -1223,6 +1223,7 @@ func AARImportFactory() android.Module {
type bazelAapt struct {
	Manifest       bazel.Label
	Resource_files bazel.LabelListAttribute
	Resource_zips  bazel.LabelListAttribute
	Assets_dir     bazel.StringAttribute
	Assets         bazel.LabelListAttribute
}
@@ -1267,9 +1268,20 @@ func (a *aapt) convertAaptAttrsWithBp2Build(ctx android.Bp2buildMutatorContext)
		assets = bazel.MakeLabelList(android.RootToModuleRelativePaths(ctx, androidResourceGlob(ctx, dir)))

	}
	var resourceZips bazel.LabelList
	if len(a.aaptProperties.Resource_zips) > 0 {
		if ctx.ModuleName() == "framework-res" {
			resourceZips = android.BazelLabelForModuleSrc(ctx, a.aaptProperties.Resource_zips)
		} else {
			//TODO: b/301593550 - Implement support for this
			ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_PROPERTY_UNSUPPORTED, "resource_zips")
			return &bazelAapt{}, false
		}
	}
	return &bazelAapt{
		android.BazelLabelForModuleSrcSingle(ctx, manifest),
		bazel.MakeLabelListAttribute(resourceFiles),
		bazel.MakeLabelListAttribute(resourceZips),
		assetsDir,
		bazel.MakeLabelListAttribute(assets),
	}, true
Loading