Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2aa64a61 authored by Jooyung Han's avatar Jooyung Han Committed by Automerger Merge Worker
Browse files

Refactor around apexKeysText singleton am: 2cf35e7b

parents 4215f1fc 2cf35e7b
Loading
Loading
Loading
Loading
+58 −45
Original line number Diff line number Diff line
@@ -102,14 +102,6 @@ func (m *apexKey) GenerateAndroidBuildActions(ctx android.ModuleContext) {
	}
}

// //////////////////////////////////////////////////////////////////////
// apex_keys_text
type apexKeysText struct {
	output android.OutputPath
}

func (s *apexKeysText) GenerateBuildActions(ctx android.SingletonContext) {
	s.output = android.PathForOutput(ctx, "apexkeys.txt")
type apexKeyEntry struct {
	name                 string
	presigned            bool
@@ -120,7 +112,8 @@ func (s *apexKeysText) GenerateBuildActions(ctx android.SingletonContext) {
	partition            string
	signTool             string
}
	toString := func(e apexKeyEntry) string {

func (e apexKeyEntry) String() string {
	signTool := ""
	if e.signTool != "" {
		signTool = fmt.Sprintf(" sign_tool=%q", e.signTool)
@@ -133,11 +126,11 @@ func (s *apexKeysText) GenerateBuildActions(ctx android.SingletonContext) {
	}
}

	apexKeyMap := make(map[string]apexKeyEntry)
	ctx.VisitAllModules(func(module android.Module) {
		if m, ok := module.(*apexBundle); ok && m.Enabled() && m.installable() {
func apexKeyEntryFor(ctx android.SingletonContext, module android.Module) apexKeyEntry {
	switch m := module.(type) {
	case *apexBundle:
		pem, key := m.getCertificateAndPrivateKey(ctx)
			apexKeyMap[m.Name()] = apexKeyEntry{
		return apexKeyEntry{
			name:                 m.Name() + ".apex",
			presigned:            false,
			publicKey:            m.publicKeyFile.String(),
@@ -147,6 +140,35 @@ func (s *apexKeysText) GenerateBuildActions(ctx android.SingletonContext) {
			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
type apexKeysText struct {
	output android.OutputPath
}

func (s *apexKeysText) GenerateBuildActions(ctx android.SingletonContext) {
	s.output = android.PathForOutput(ctx, "apexkeys.txt")

	apexKeyMap := make(map[string]apexKeyEntry)
	ctx.VisitAllModules(func(module android.Module) {
		if m, ok := module.(*apexBundle); ok && m.Enabled() && m.installable() {
			apexKeyMap[m.Name()] = apexKeyEntryFor(ctx, m)
		}
	})

@@ -154,11 +176,7 @@ func (s *apexKeysText) GenerateBuildActions(ctx android.SingletonContext) {
	ctx.VisitAllModules(func(module android.Module) {
		if m, ok := module.(*Prebuilt); ok && m.Enabled() && m.installable() &&
			m.Prebuilt().UsePrebuilt() {
			apexKeyMap[m.BaseModuleName()] = apexKeyEntry{
				name:      m.InstallFilename(),
				presigned: true,
				partition: m.PartitionTag(ctx.DeviceConfig()),
			}
			apexKeyMap[m.BaseModuleName()] = apexKeyEntryFor(ctx, m)
		}
	})

@@ -166,12 +184,7 @@ func (s *apexKeysText) GenerateBuildActions(ctx android.SingletonContext) {
	// so that apex_set are not overridden by prebuilts.
	ctx.VisitAllModules(func(module android.Module) {
		if m, ok := module.(*ApexSet); ok && m.Enabled() {
			entry := apexKeyEntry{
				name:      m.InstallFilename(),
				presigned: true,
				partition: m.PartitionTag(ctx.DeviceConfig()),
			}
			apexKeyMap[m.BaseModuleName()] = entry
			apexKeyMap[m.BaseModuleName()] = apexKeyEntryFor(ctx, m)
		}
	})

@@ -184,7 +197,7 @@ func (s *apexKeysText) GenerateBuildActions(ctx android.SingletonContext) {

	var filecontent strings.Builder
	for _, name := range moduleNames {
		filecontent.WriteString(toString(apexKeyMap[name]))
		filecontent.WriteString(apexKeyMap[name].String())
	}
	android.WriteFileRule(ctx, s.output, filecontent.String())
}