diff options
| author | Colin Cross <ccross@android.com> | 2019-06-03 15:07:03 -0700 |
|---|---|---|
| committer | Colin Cross <ccross@android.com> | 2019-06-05 11:32:50 -0700 |
| commit | ea68aad696009447d2db7be5bcbba60ac6d8f7a0 (patch) | |
| tree | 711f03740dfcbebe46de8d512b09831096965931 /android | |
| parent | 9bd624c76d9152fbf8bc9cd5c4632e6376481f36 (diff) | |
| download | build_soong-ea68aad696009447d2db7be5bcbba60ac6d8f7a0.tar.gz build_soong-ea68aad696009447d2db7be5bcbba60ac6d8f7a0.tar.bz2 build_soong-ea68aad696009447d2db7be5bcbba60ac6d8f7a0.zip | |
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 cefa94bd27f696b975cc7c3dc97ba7ecc91ef0cc)
Diffstat (limited to 'android')
| -rw-r--r-- | android/apex.go | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/android/apex.go b/android/apex.go index bf11ba25..17df7624 100644 --- a/android/apex.go +++ b/android/apex.go @@ -15,6 +15,7 @@ package android import ( + "sort" "sync" "github.com/google/blueprint" @@ -86,7 +87,9 @@ type ApexModuleBase struct { ApexProperties ApexProperties canHaveApexVariants bool - apexVariations []string + + apexVariationsLock sync.Mutex // protects apexVariations during parallel apexDepsMutator + apexVariations []string } func (m *ApexModuleBase) apexModuleBase() *ApexModuleBase { @@ -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...) |
