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

Commit ea68aad6 authored by Colin Cross's avatar Colin Cross
Browse files

Fix data race and ordering consistency in apex modules

apexDepsMutator can be called on multiple apex modules in parallel,
and then two goroutines could call BuildForApex on the same module
in parallel, leading to a data race appending to apexVariations.
This also results in random ordering of the entries in
apexVariations.

Hold a mutex around appending to apexVariations, and sort it before
passing it to ctx.CreateVariations.

Fixes: 134425751
Test: m nothing
Change-Id: If5a3b53a778daacb3e26ac05cde872cf8eb980b3
Merged-In: If5a3b53a778daacb3e26ac05cde872cf8eb980b3
(cherry picked from commit cefa94bd)
parent 9bd624c7
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
package android

import (
	"sort"
	"sync"

	"github.com/google/blueprint"
@@ -86,6 +87,8 @@ type ApexModuleBase struct {
	ApexProperties ApexProperties

	canHaveApexVariants bool

	apexVariationsLock sync.Mutex // protects apexVariations during parallel apexDepsMutator
	apexVariations     []string
}

@@ -94,6 +97,8 @@ func (m *ApexModuleBase) apexModuleBase() *ApexModuleBase {
}

func (m *ApexModuleBase) BuildForApex(apexName string) {
	m.apexVariationsLock.Lock()
	defer m.apexVariationsLock.Unlock()
	if !InList(apexName, m.apexVariations) {
		m.apexVariations = append(m.apexVariations, apexName)
	}
@@ -122,6 +127,7 @@ func (m *ApexModuleBase) IsInstallableToApex() bool {

func (m *ApexModuleBase) CreateApexVariations(mctx BottomUpMutatorContext) []blueprint.Module {
	if len(m.apexVariations) > 0 {
		sort.Strings(m.apexVariations)
		variations := []string{""} // Original variation for platform
		variations = append(variations, m.apexVariations...)