diff --git a/android/allowlists/allowlists.go b/android/allowlists/allowlists.go index 193493dc9..d823f086f 100644 --- a/android/allowlists/allowlists.go +++ b/android/allowlists/allowlists.go @@ -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", diff --git a/android/bazel_paths.go b/android/bazel_paths.go index 4ac58403c..d8effaa12 100644 --- a/android/bazel_paths.go +++ b/android/bazel_paths.go @@ -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) diff --git a/bp2build/android_app_conversion_test.go b/bp2build/android_app_conversion_test.go index 8ec4b3566..afe6dcd55 100644 --- a/bp2build/android_app_conversion_test.go +++ b/bp2build/android_app_conversion_test.go @@ -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"]`, + }), + }}) + +} diff --git a/bp2build/bp2build_product_config.go b/bp2build/bp2build_product_config.go index b724f5783..091a5f3ac 100644 --- a/bp2build/bp2build_product_config.go +++ b/bp2build/bp2build_product_config.go @@ -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))) diff --git a/java/aar.go b/java/aar.go index 8f5deab39..ad45eedbb 100644 --- a/java/aar.go +++ b/java/aar.go @@ -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 diff --git a/java/app.go b/java/app.go index ed1c1072d..166c22d94 100755 --- a/java/app.go +++ b/java/app.go @@ -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) }