bp2build support for framework-res

Change-Id: I5b32a702e02b5f1ec08d5608d766a8a0c08d845c
Bug: 276928228
Bug: 297356405
This commit is contained in:
Romain Jobredeaux 2023-08-21 18:05:29 -04:00
parent c9e585eabf
commit 9c06ef353b
6 changed files with 83 additions and 9 deletions

View file

@ -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",

View file

@ -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)

View file

@ -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"]`,
}),
}})
}

View file

@ -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)))

View file

@ -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

View file

@ -1683,6 +1683,13 @@ func convertWithBp2build(ctx android.Bp2buildMutatorContext, a *AndroidApp) (boo
Updatable: a.appProperties.Updatable,
}
// As framework-res has no sources, no deps in the Bazel sense, and java compilation, dexing and optimization is skipped by
// Soong specifically for it, return early here before any of the conversion work for the above is attempted.
if ctx.ModuleName() == "framework-res" {
appAttrs.bazelAapt = aapt
return true, android.CommonAttributes{Name: a.Name(), SkipData: proptools.BoolPtr(true)}, appAttrs
}
// Optimization is..
// - enabled by default for android_app, android_test_helper_app
// - disabled by default for android_test
@ -1784,11 +1791,18 @@ func convertWithBp2build(ctx android.Bp2buildMutatorContext, a *AndroidApp) (boo
// ConvertWithBp2build is used to convert android_app to Bazel.
func (a *AndroidApp) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) {
if ok, commonAttrs, appAttrs := convertWithBp2build(ctx, a); ok {
props := bazel.BazelTargetModuleProperties{
Rule_class: "android_binary",
Bzl_load_location: "//build/bazel/rules/android:android_binary.bzl",
var props bazel.BazelTargetModuleProperties
if ctx.ModuleName() == "framework-res" {
props = bazel.BazelTargetModuleProperties{
Rule_class: "framework_resources",
Bzl_load_location: "//build/bazel/rules/android:framework_resources.bzl",
}
} else {
props = bazel.BazelTargetModuleProperties{
Rule_class: "android_binary",
Bzl_load_location: "//build/bazel/rules/android:android_binary.bzl",
}
}
ctx.CreateBazelTargetModule(props, commonAttrs, appAttrs)
}