diff --git a/apex/apex.go b/apex/apex.go index 21725ff16..7a2a04a19 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -2530,6 +2530,22 @@ func (o *OverrideApex) ConvertWithBp2build(ctx android.TopDownMutatorContext) { if overridableProperties.Compressible != nil { attrs.Compressible = bazel.BoolAttribute{Value: overridableProperties.Compressible} } + + // Package name + // + // e.g. com.android.adbd's package name is com.android.adbd, but + // com.google.android.adbd overrides the package name to com.google.android.adbd + // + // TODO: this can be overridden from the product configuration, see + // getOverrideManifestPackageName and + // PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES. + // + // Instead of generating the BUILD files differently based on the product config + // at the point of conversion, this should be handled by the BUILD file loading + // from the soong_injection's product_vars, so product config is decoupled from bp2build. + if overridableProperties.Package_name != "" { + attrs.Package_name = &overridableProperties.Package_name + } } ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: o.Name()}, &attrs) @@ -3471,6 +3487,7 @@ type bazelApexBundleAttributes struct { Native_shared_libs_32 bazel.LabelListAttribute Native_shared_libs_64 bazel.LabelListAttribute Compressible bazel.BoolAttribute + Package_name *string } type convertedNativeSharedLibs struct { @@ -3565,6 +3582,11 @@ func convertWithBp2build(a *apexBundle, ctx android.TopDownMutatorContext) (baze compressibleAttribute.Value = a.overridableProperties.Compressible } + var packageName *string + if a.overridableProperties.Package_name != "" { + packageName = &a.overridableProperties.Package_name + } + attrs := bazelApexBundleAttributes{ Manifest: manifestLabelAttribute, Android_manifest: androidManifestLabelAttribute, @@ -3579,6 +3601,7 @@ func convertWithBp2build(a *apexBundle, ctx android.TopDownMutatorContext) (baze Binaries: binariesLabelListAttribute, Prebuilts: prebuiltsLabelListAttribute, Compressible: compressibleAttribute, + Package_name: packageName, } props := bazel.BazelTargetModuleProperties{ diff --git a/bp2build/apex_conversion_test.go b/bp2build/apex_conversion_test.go index d15dc0cd8..3f1349f11 100644 --- a/bp2build/apex_conversion_test.go +++ b/bp2build/apex_conversion_test.go @@ -133,6 +133,7 @@ apex { "pretend_prebuilt_1", "pretend_prebuilt_2", ], + package_name: "com.android.apogee.test.package", } `, expectedBazelTargets: []string{ @@ -169,6 +170,7 @@ apex { ]`, "updatable": "False", "compressible": "False", + "package_name": `"com.android.apogee.test.package"`, }), }}) } @@ -782,3 +784,37 @@ override_apex { }), }}) } + +func TestApexBundleSimple_packageNameOverride(t *testing.T) { + runOverrideApexTestCase(t, bp2buildTestCase{ + description: "override_apex - override package name", + moduleTypeUnderTest: "override_apex", + moduleTypeUnderTestFactory: apex.OverrideApexFactory, + filesystem: map[string]string{ + "system/sepolicy/apex/Android.bp": ` +filegroup { + name: "com.android.apogee-file_contexts", + srcs: [ "apogee-file_contexts", ], + bazel_module: { bp2build_available: false }, +}`, + }, + blueprint: ` +apex { + name: "com.android.apogee", + bazel_module: { bp2build_available: false }, +} + +override_apex { + name: "com.google.android.apogee", + base: ":com.android.apogee", + package_name: "com.google.android.apogee", +} +`, + expectedBazelTargets: []string{ + makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{ + "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, + "manifest": `"apex_manifest.json"`, + "package_name": `"com.google.android.apogee"`, + }), + }}) +}