apex_key bp2build: disambiguate module and src deps.

(and remove unused keyName field.)

The private_key and public_key props of an apex_key can point to either
a module or a string. If it's a module, then respect it. If it's a
string, there's additional product variable lookup to find the apex_key
files in product_vars's DefaultAppCertificate parent dir.

This is similar to android_app_certificate.

Test: presubmits
Change-Id: Ib258da14cb0c2df8b5f817fcbc46afebcf225db8
This commit is contained in:
Jingwen Chen
2022-10-05 06:15:15 +00:00
parent 51ad4cbf09
commit 1d873331ad
2 changed files with 50 additions and 13 deletions

View File

@@ -44,8 +44,6 @@ type apexKey struct {
publicKeyFile android.Path publicKeyFile android.Path
privateKeyFile android.Path privateKeyFile android.Path
keyName string
} }
type apexKeyProperties struct { type apexKeyProperties struct {
@@ -102,7 +100,6 @@ func (m *apexKey) GenerateAndroidBuildActions(ctx android.ModuleContext) {
m.publicKeyFile.String(), pubKeyName, m.privateKeyFile, privKeyName) m.publicKeyFile.String(), pubKeyName, m.privateKeyFile, privKeyName)
return return
} }
m.keyName = pubKeyName
} }
// ////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////
@@ -204,7 +201,10 @@ func (s *apexKeysText) MakeVars(ctx android.MakeVarsContext) {
type bazelApexKeyAttributes struct { type bazelApexKeyAttributes struct {
Public_key bazel.LabelAttribute Public_key bazel.LabelAttribute
Public_key_name bazel.LabelAttribute
Private_key bazel.LabelAttribute Private_key bazel.LabelAttribute
Private_key_name bazel.LabelAttribute
} }
// ConvertWithBp2build performs conversion apexKey for bp2build // ConvertWithBp2build performs conversion apexKey for bp2build
@@ -214,18 +214,33 @@ func (m *apexKey) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
func apexKeyBp2BuildInternal(ctx android.TopDownMutatorContext, module *apexKey) { func apexKeyBp2BuildInternal(ctx android.TopDownMutatorContext, module *apexKey) {
var privateKeyLabelAttribute bazel.LabelAttribute var privateKeyLabelAttribute bazel.LabelAttribute
var privateKeyNameAttribute bazel.LabelAttribute
if module.properties.Private_key != nil { if module.properties.Private_key != nil {
privateKeyLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *module.properties.Private_key)) m := String(module.properties.Private_key)
if android.SrcIsModule(m) == "" {
privateKeyNameAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *module.properties.Private_key))
} else {
privateKeyLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *module.properties.Private_key))
}
} }
var publicKeyLabelAttribute bazel.LabelAttribute var publicKeyLabelAttribute bazel.LabelAttribute
var publicKeyNameAttribute bazel.LabelAttribute
if module.properties.Public_key != nil { if module.properties.Public_key != nil {
publicKeyLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *module.properties.Public_key)) m := String(module.properties.Public_key)
if android.SrcIsModule(m) == "" {
publicKeyNameAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *module.properties.Public_key))
} else {
publicKeyLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *module.properties.Public_key))
}
} }
attrs := &bazelApexKeyAttributes{ attrs := &bazelApexKeyAttributes{
Private_key: privateKeyLabelAttribute, Private_key: privateKeyLabelAttribute,
Private_key_name: privateKeyNameAttribute,
Public_key: publicKeyLabelAttribute, Public_key: publicKeyLabelAttribute,
Public_key_name: publicKeyNameAttribute,
} }
props := bazel.BazelTargetModuleProperties{ props := bazel.BazelTargetModuleProperties{

View File

@@ -27,11 +27,12 @@ func runApexKeyTestCase(t *testing.T, tc Bp2buildTestCase) {
} }
func registerApexKeyModuleTypes(ctx android.RegistrationContext) { func registerApexKeyModuleTypes(ctx android.RegistrationContext) {
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
} }
func TestApexKeySimple(t *testing.T) { func TestApexKeySimple_KeysAreSrcFiles(t *testing.T) {
runApexKeyTestCase(t, Bp2buildTestCase{ runApexKeyTestCase(t, Bp2buildTestCase{
Description: "apex key - simple example", Description: "apex key - keys are src files, use key_name attributes",
ModuleTypeUnderTest: "apex_key", ModuleTypeUnderTest: "apex_key",
ModuleTypeUnderTestFactory: apex.ApexKeyFactory, ModuleTypeUnderTestFactory: apex.ApexKeyFactory,
Filesystem: map[string]string{}, Filesystem: map[string]string{},
@@ -43,8 +44,29 @@ apex_key {
} }
`, `,
ExpectedBazelTargets: []string{MakeBazelTargetNoRestrictions("apex_key", "com.android.apogee.key", AttrNameToString{ ExpectedBazelTargets: []string{MakeBazelTargetNoRestrictions("apex_key", "com.android.apogee.key", AttrNameToString{
"private_key": `"com.android.apogee.pem"`, "private_key_name": `"com.android.apogee.pem"`,
"public_key": `"com.android.apogee.avbpubkey"`, "public_key_name": `"com.android.apogee.avbpubkey"`,
}),
}})
}
func TestApexKey_KeysAreModules(t *testing.T) {
runApexKeyTestCase(t, Bp2buildTestCase{
Description: "apex key - keys are modules, use key attributes",
ModuleTypeUnderTest: "apex_key",
ModuleTypeUnderTestFactory: apex.ApexKeyFactory,
Filesystem: map[string]string{},
Blueprint: `
apex_key {
name: "com.android.apogee.key",
public_key: ":com.android.apogee.avbpubkey",
private_key: ":com.android.apogee.pem",
}
` + simpleModuleDoNotConvertBp2build("filegroup", "com.android.apogee.avbpubkey") +
simpleModuleDoNotConvertBp2build("filegroup", "com.android.apogee.pem"),
ExpectedBazelTargets: []string{MakeBazelTargetNoRestrictions("apex_key", "com.android.apogee.key", AttrNameToString{
"private_key": `":com.android.apogee.pem"`,
"public_key": `":com.android.apogee.avbpubkey"`,
}), }),
}}) }})
} }