Convert override_apex.package_name with bp2build.

Bug: 216414792
Test: CI and new bazel/bp2build tests
Change-Id: I3974970cdd555b3912798e79e61d61786a4ff677
This commit is contained in:
Jingwen Chen 2022-06-03 09:11:20 +00:00
parent 5d069fb876
commit 9b7ebca187
2 changed files with 59 additions and 0 deletions

View file

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

View file

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