Invalidate module group cache if deps are modified (#334)
* Invalidate module group cache if deps are modified PreSingletons run after the blueprints have been parsed and can run VisitAllModules; however, this seeds the cache of sorted modules which may change after mutators have run. This causes recomputation of the cache if any deps have been modified since the last time it was run. Change-Id: I79fc822dd630f84790f309ba4e6024588a8fe28e
This commit is contained in:
parent
16754d14e2
commit
9ae14f12f9
1 changed files with 5 additions and 1 deletions
|
@ -110,6 +110,8 @@ type Context struct {
|
|||
|
||||
// set lazily by sortedModuleGroups
|
||||
cachedSortedModuleGroups []*moduleGroup
|
||||
// cache deps modified to determine whether cachedSortedModuleGroups needs to be recalculated
|
||||
cachedDepsModified bool
|
||||
|
||||
globs map[string]GlobPath
|
||||
globLock sync.Mutex
|
||||
|
@ -2165,6 +2167,7 @@ func cycleError(cycle []*moduleInfo) (errs []error) {
|
|||
// it encounters dependency cycles. This should called after resolveDependencies,
|
||||
// as well as after any mutator pass has called addDependency
|
||||
func (c *Context) updateDependencies() (errs []error) {
|
||||
c.cachedDepsModified = true
|
||||
visited := make(map[*moduleInfo]bool) // modules that were already checked
|
||||
checking := make(map[*moduleInfo]bool) // modules actively being checked
|
||||
|
||||
|
@ -3015,7 +3018,7 @@ func (c *Context) moduleGroupFromName(name string, namespace Namespace) *moduleG
|
|||
}
|
||||
|
||||
func (c *Context) sortedModuleGroups() []*moduleGroup {
|
||||
if c.cachedSortedModuleGroups == nil {
|
||||
if c.cachedSortedModuleGroups == nil || c.cachedDepsModified {
|
||||
unwrap := func(wrappers []ModuleGroup) []*moduleGroup {
|
||||
result := make([]*moduleGroup, 0, len(wrappers))
|
||||
for _, group := range wrappers {
|
||||
|
@ -3025,6 +3028,7 @@ func (c *Context) sortedModuleGroups() []*moduleGroup {
|
|||
}
|
||||
|
||||
c.cachedSortedModuleGroups = unwrap(c.nameInterface.AllModules())
|
||||
c.cachedDepsModified = false
|
||||
}
|
||||
|
||||
return c.cachedSortedModuleGroups
|
||||
|
|
Loading…
Reference in a new issue