Share certificate bp2build between android_app and apex.

The certificate module is handled the same in Soong between android apps
and apexes, so share the bp2build code as well.

There are a few changes in this CL:

- If override_apex.certificate is unset, the generated apex also unsets
  it. This prevents the generated apex from using the base apex's
  certificate, which is most likely incorrect (e.g. google variant using
  the cert for the aosp variant). Instead, rely on the default
  certificate handling in the macro.
- If the certificate prop is a string, then it gets generated into
  certificate_name in order to disambiguate. This behavior is identical
  to android_app.

Test: added various unit tests.

Bug: 249089160
Fixes: 249089160
Change-Id: I99e18964ff546429a985d0f64dc21e2c69d35d9d
This commit is contained in:
Jingwen Chen
2022-09-29 16:56:02 +00:00
parent 44022c867d
commit bea58093b4
3 changed files with 221 additions and 22 deletions

View File

@@ -120,7 +120,7 @@ apex {
file_contexts: ":com.android.apogee-file_contexts",
min_sdk_version: "29",
key: "com.android.apogee.key",
certificate: "com.android.apogee.certificate",
certificate: ":com.android.apogee.certificate",
updatable: false,
installable: false,
compressible: false,
@@ -582,7 +582,7 @@ apex {
file_contexts: ":com.android.apogee-file_contexts",
min_sdk_version: "29",
key: "com.android.apogee.key",
certificate: "com.android.apogee.certificate",
certificate: ":com.android.apogee.certificate",
updatable: false,
installable: false,
compressible: false,
@@ -618,7 +618,7 @@ override_apex {
name: "com.google.android.apogee",
base: ":com.android.apogee",
key: "com.google.android.apogee.key",
certificate: "com.google.android.apogee.certificate",
certificate: ":com.google.android.apogee.certificate",
prebuilts: [],
compressible: true,
}
@@ -1016,3 +1016,193 @@ override_apex {
}),
}})
}
func TestBp2BuildOverrideApex_CertificateNil(t *testing.T) {
runOverrideApexTestCase(t, Bp2buildTestCase{
Description: "override_apex - don't set default certificate",
ModuleTypeUnderTest: "override_apex",
ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
Filesystem: map[string]string{},
Blueprint: `
android_app_certificate {
name: "com.android.apogee.certificate",
certificate: "com.android.apogee",
bazel_module: { bp2build_available: false },
}
filegroup {
name: "com.android.apogee-file_contexts",
srcs: [
"com.android.apogee-file_contexts",
],
bazel_module: { bp2build_available: false },
}
apex {
name: "com.android.apogee",
manifest: "apogee_manifest.json",
file_contexts: ":com.android.apogee-file_contexts",
certificate: ":com.android.apogee.certificate",
bazel_module: { bp2build_available: false },
}
override_apex {
name: "com.google.android.apogee",
base: ":com.android.apogee",
// certificate is deliberately omitted, and not converted to bazel,
// because the overridden apex shouldn't be using the base apex's cert.
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
"file_contexts": `":com.android.apogee-file_contexts"`,
"manifest": `"apogee_manifest.json"`,
}),
}})
}
func TestApexCertificateIsModule(t *testing.T) {
runApexTestCase(t, Bp2buildTestCase{
Description: "apex - certificate is module",
ModuleTypeUnderTest: "apex",
ModuleTypeUnderTestFactory: apex.BundleFactory,
Filesystem: map[string]string{},
Blueprint: `
android_app_certificate {
name: "com.android.apogee.certificate",
certificate: "com.android.apogee",
bazel_module: { bp2build_available: false },
}
apex {
name: "com.android.apogee",
manifest: "apogee_manifest.json",
file_contexts: ":com.android.apogee-file_contexts",
certificate: ":com.android.apogee.certificate",
}
` + simpleModuleDoNotConvertBp2build("filegroup", "com.android.apogee-file_contexts"),
ExpectedBazelTargets: []string{
MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
"certificate": `":com.android.apogee.certificate"`,
"file_contexts": `":com.android.apogee-file_contexts"`,
"manifest": `"apogee_manifest.json"`,
}),
}})
}
func TestApexCertificateIsSrc(t *testing.T) {
runApexTestCase(t, Bp2buildTestCase{
Description: "apex - certificate is src",
ModuleTypeUnderTest: "apex",
ModuleTypeUnderTestFactory: apex.BundleFactory,
Filesystem: map[string]string{},
Blueprint: `
apex {
name: "com.android.apogee",
manifest: "apogee_manifest.json",
file_contexts: ":com.android.apogee-file_contexts",
certificate: "com.android.apogee.certificate",
}
` + simpleModuleDoNotConvertBp2build("filegroup", "com.android.apogee-file_contexts"),
ExpectedBazelTargets: []string{
MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
"certificate_name": `"com.android.apogee.certificate"`,
"file_contexts": `":com.android.apogee-file_contexts"`,
"manifest": `"apogee_manifest.json"`,
}),
}})
}
func TestBp2BuildOverrideApex_CertificateIsModule(t *testing.T) {
runOverrideApexTestCase(t, Bp2buildTestCase{
Description: "override_apex - certificate is module",
ModuleTypeUnderTest: "override_apex",
ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
Filesystem: map[string]string{},
Blueprint: `
android_app_certificate {
name: "com.android.apogee.certificate",
certificate: "com.android.apogee",
bazel_module: { bp2build_available: false },
}
filegroup {
name: "com.android.apogee-file_contexts",
srcs: [
"com.android.apogee-file_contexts",
],
bazel_module: { bp2build_available: false },
}
apex {
name: "com.android.apogee",
manifest: "apogee_manifest.json",
file_contexts: ":com.android.apogee-file_contexts",
certificate: ":com.android.apogee.certificate",
bazel_module: { bp2build_available: false },
}
android_app_certificate {
name: "com.google.android.apogee.certificate",
certificate: "com.google.android.apogee",
bazel_module: { bp2build_available: false },
}
override_apex {
name: "com.google.android.apogee",
base: ":com.android.apogee",
certificate: ":com.google.android.apogee.certificate",
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
"file_contexts": `":com.android.apogee-file_contexts"`,
"certificate": `":com.google.android.apogee.certificate"`,
"manifest": `"apogee_manifest.json"`,
}),
}})
}
func TestBp2BuildOverrideApex_CertificateIsSrc(t *testing.T) {
runOverrideApexTestCase(t, Bp2buildTestCase{
Description: "override_apex - certificate is src",
ModuleTypeUnderTest: "override_apex",
ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
Filesystem: map[string]string{},
Blueprint: `
android_app_certificate {
name: "com.android.apogee.certificate",
certificate: "com.android.apogee",
bazel_module: { bp2build_available: false },
}
filegroup {
name: "com.android.apogee-file_contexts",
srcs: [
"com.android.apogee-file_contexts",
],
bazel_module: { bp2build_available: false },
}
apex {
name: "com.android.apogee",
manifest: "apogee_manifest.json",
file_contexts: ":com.android.apogee-file_contexts",
certificate: ":com.android.apogee.certificate",
bazel_module: { bp2build_available: false },
}
override_apex {
name: "com.google.android.apogee",
base: ":com.android.apogee",
certificate: "com.google.android.apogee.certificate",
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
"file_contexts": `":com.android.apogee-file_contexts"`,
"certificate_name": `"com.google.android.apogee.certificate"`,
"manifest": `"apogee_manifest.json"`,
}),
}})
}