Refactor around apexKeysText singleton
apexkeys.txt should list the installed apexes. But for now it lists all apexes in the source tree. To fix this, each apex(or prebuilt/apexset) will generate its own apexkey info and they'll be merged into a single text only for installed apexes. This change is a preparation before the upcoming change. We'll reuse the apexKeyEntry stuff from the current implementation. Bug: 304914238 Test: m blueprint_tests Change-Id: If9d5d992e5e2b0120e017265d2590b1c55152f52
This commit is contained in:
103
apex/key.go
103
apex/key.go
@@ -102,6 +102,60 @@ func (m *apexKey) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type apexKeyEntry struct {
|
||||||
|
name string
|
||||||
|
presigned bool
|
||||||
|
publicKey string
|
||||||
|
privateKey string
|
||||||
|
containerCertificate string
|
||||||
|
containerPrivateKey string
|
||||||
|
partition string
|
||||||
|
signTool string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e apexKeyEntry) String() string {
|
||||||
|
signTool := ""
|
||||||
|
if e.signTool != "" {
|
||||||
|
signTool = fmt.Sprintf(" sign_tool=%q", e.signTool)
|
||||||
|
}
|
||||||
|
format := "name=%q public_key=%q private_key=%q container_certificate=%q container_private_key=%q partition=%q%s\n"
|
||||||
|
if e.presigned {
|
||||||
|
return fmt.Sprintf(format, e.name, "PRESIGNED", "PRESIGNED", "PRESIGNED", "PRESIGNED", e.partition, signTool)
|
||||||
|
} else {
|
||||||
|
return fmt.Sprintf(format, e.name, e.publicKey, e.privateKey, e.containerCertificate, e.containerPrivateKey, e.partition, signTool)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func apexKeyEntryFor(ctx android.SingletonContext, module android.Module) apexKeyEntry {
|
||||||
|
switch m := module.(type) {
|
||||||
|
case *apexBundle:
|
||||||
|
pem, key := m.getCertificateAndPrivateKey(ctx)
|
||||||
|
return apexKeyEntry{
|
||||||
|
name: m.Name() + ".apex",
|
||||||
|
presigned: false,
|
||||||
|
publicKey: m.publicKeyFile.String(),
|
||||||
|
privateKey: m.privateKeyFile.String(),
|
||||||
|
containerCertificate: pem.String(),
|
||||||
|
containerPrivateKey: key.String(),
|
||||||
|
partition: m.PartitionTag(ctx.DeviceConfig()),
|
||||||
|
signTool: proptools.String(m.properties.Custom_sign_tool),
|
||||||
|
}
|
||||||
|
case *Prebuilt:
|
||||||
|
return apexKeyEntry{
|
||||||
|
name: m.InstallFilename(),
|
||||||
|
presigned: true,
|
||||||
|
partition: m.PartitionTag(ctx.DeviceConfig()),
|
||||||
|
}
|
||||||
|
case *ApexSet:
|
||||||
|
return apexKeyEntry{
|
||||||
|
name: m.InstallFilename(),
|
||||||
|
presigned: true,
|
||||||
|
partition: m.PartitionTag(ctx.DeviceConfig()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panic(fmt.Errorf("unknown type(%t) for apexKeyEntry", module))
|
||||||
|
}
|
||||||
|
|
||||||
// //////////////////////////////////////////////////////////////////////
|
// //////////////////////////////////////////////////////////////////////
|
||||||
// apex_keys_text
|
// apex_keys_text
|
||||||
type apexKeysText struct {
|
type apexKeysText struct {
|
||||||
@@ -110,43 +164,11 @@ type apexKeysText struct {
|
|||||||
|
|
||||||
func (s *apexKeysText) GenerateBuildActions(ctx android.SingletonContext) {
|
func (s *apexKeysText) GenerateBuildActions(ctx android.SingletonContext) {
|
||||||
s.output = android.PathForOutput(ctx, "apexkeys.txt")
|
s.output = android.PathForOutput(ctx, "apexkeys.txt")
|
||||||
type apexKeyEntry struct {
|
|
||||||
name string
|
|
||||||
presigned bool
|
|
||||||
publicKey string
|
|
||||||
privateKey string
|
|
||||||
containerCertificate string
|
|
||||||
containerPrivateKey string
|
|
||||||
partition string
|
|
||||||
signTool string
|
|
||||||
}
|
|
||||||
toString := func(e apexKeyEntry) string {
|
|
||||||
signTool := ""
|
|
||||||
if e.signTool != "" {
|
|
||||||
signTool = fmt.Sprintf(" sign_tool=%q", e.signTool)
|
|
||||||
}
|
|
||||||
format := "name=%q public_key=%q private_key=%q container_certificate=%q container_private_key=%q partition=%q%s\n"
|
|
||||||
if e.presigned {
|
|
||||||
return fmt.Sprintf(format, e.name, "PRESIGNED", "PRESIGNED", "PRESIGNED", "PRESIGNED", e.partition, signTool)
|
|
||||||
} else {
|
|
||||||
return fmt.Sprintf(format, e.name, e.publicKey, e.privateKey, e.containerCertificate, e.containerPrivateKey, e.partition, signTool)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
apexKeyMap := make(map[string]apexKeyEntry)
|
apexKeyMap := make(map[string]apexKeyEntry)
|
||||||
ctx.VisitAllModules(func(module android.Module) {
|
ctx.VisitAllModules(func(module android.Module) {
|
||||||
if m, ok := module.(*apexBundle); ok && m.Enabled() && m.installable() {
|
if m, ok := module.(*apexBundle); ok && m.Enabled() && m.installable() {
|
||||||
pem, key := m.getCertificateAndPrivateKey(ctx)
|
apexKeyMap[m.Name()] = apexKeyEntryFor(ctx, m)
|
||||||
apexKeyMap[m.Name()] = apexKeyEntry{
|
|
||||||
name: m.Name() + ".apex",
|
|
||||||
presigned: false,
|
|
||||||
publicKey: m.publicKeyFile.String(),
|
|
||||||
privateKey: m.privateKeyFile.String(),
|
|
||||||
containerCertificate: pem.String(),
|
|
||||||
containerPrivateKey: key.String(),
|
|
||||||
partition: m.PartitionTag(ctx.DeviceConfig()),
|
|
||||||
signTool: proptools.String(m.properties.Custom_sign_tool),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -154,11 +176,7 @@ func (s *apexKeysText) GenerateBuildActions(ctx android.SingletonContext) {
|
|||||||
ctx.VisitAllModules(func(module android.Module) {
|
ctx.VisitAllModules(func(module android.Module) {
|
||||||
if m, ok := module.(*Prebuilt); ok && m.Enabled() && m.installable() &&
|
if m, ok := module.(*Prebuilt); ok && m.Enabled() && m.installable() &&
|
||||||
m.Prebuilt().UsePrebuilt() {
|
m.Prebuilt().UsePrebuilt() {
|
||||||
apexKeyMap[m.BaseModuleName()] = apexKeyEntry{
|
apexKeyMap[m.BaseModuleName()] = apexKeyEntryFor(ctx, m)
|
||||||
name: m.InstallFilename(),
|
|
||||||
presigned: true,
|
|
||||||
partition: m.PartitionTag(ctx.DeviceConfig()),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -166,12 +184,7 @@ func (s *apexKeysText) GenerateBuildActions(ctx android.SingletonContext) {
|
|||||||
// so that apex_set are not overridden by prebuilts.
|
// so that apex_set are not overridden by prebuilts.
|
||||||
ctx.VisitAllModules(func(module android.Module) {
|
ctx.VisitAllModules(func(module android.Module) {
|
||||||
if m, ok := module.(*ApexSet); ok && m.Enabled() {
|
if m, ok := module.(*ApexSet); ok && m.Enabled() {
|
||||||
entry := apexKeyEntry{
|
apexKeyMap[m.BaseModuleName()] = apexKeyEntryFor(ctx, m)
|
||||||
name: m.InstallFilename(),
|
|
||||||
presigned: true,
|
|
||||||
partition: m.PartitionTag(ctx.DeviceConfig()),
|
|
||||||
}
|
|
||||||
apexKeyMap[m.BaseModuleName()] = entry
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -184,7 +197,7 @@ func (s *apexKeysText) GenerateBuildActions(ctx android.SingletonContext) {
|
|||||||
|
|
||||||
var filecontent strings.Builder
|
var filecontent strings.Builder
|
||||||
for _, name := range moduleNames {
|
for _, name := range moduleNames {
|
||||||
filecontent.WriteString(toString(apexKeyMap[name]))
|
filecontent.WriteString(apexKeyMap[name].String())
|
||||||
}
|
}
|
||||||
android.WriteFileRule(ctx, s.output, filecontent.String())
|
android.WriteFileRule(ctx, s.output, filecontent.String())
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user