Loading tools/compliance/graph.go +4 −6 Original line number Diff line number Diff line Loading @@ -58,13 +58,11 @@ type LicenseGraph struct { /// (guarded by mu) targets map[string]*TargetNode // wgBU becomes non-nil when the bottom-up resolve begins and reaches 0 // (i.e. Wait() proceeds) when the bottom-up resolve completes. (guarded by mu) wgBU *sync.WaitGroup // onceBottomUp makes sure the bottom-up resolve walk only happens one time. onceBottomUp sync.Once // wgTD becomes non-nil when the top-down resolve begins and reaches 0 (i.e. Wait() // proceeds) when the top-down resolve completes. (guarded by mu) wgTD *sync.WaitGroup // onceTopDown makes sure the top-down resolve walk only happens one time. onceTopDown sync.Once // shippedNodes caches the results of a full walk of nodes identifying targets // distributed either directly or as derivative works. (creation guarded by mu) Loading tools/compliance/policy_resolve.go +108 −123 Original line number Diff line number Diff line Loading @@ -49,19 +49,7 @@ func ResolveBottomUpConditions(lg *LicenseGraph) { func TraceBottomUpConditions(lg *LicenseGraph, conditionsFn TraceConditions) { // short-cut if already walked and cached lg.mu.Lock() wg := lg.wgBU if wg != nil { lg.mu.Unlock() wg.Wait() return } wg = &sync.WaitGroup{} wg.Add(1) lg.wgBU = wg lg.mu.Unlock() lg.onceBottomUp.Do(func() { // amap identifes targets previously walked. (guarded by mu) amap := make(map[*TargetNode]struct{}) Loading Loading @@ -125,8 +113,7 @@ func TraceBottomUpConditions(lg *LicenseGraph, conditionsFn TraceConditions) { rnode := lg.targets[rname] _ = walk(rnode, rnode.IsContainer()) } wg.Done() }) } // ResolveTopDownCondtions performs a top-down walk of the LicenseGraph Loading @@ -145,18 +132,9 @@ func ResolveTopDownConditions(lg *LicenseGraph) { func TraceTopDownConditions(lg *LicenseGraph, conditionsFn TraceConditions) { // short-cut if already walked and cached lg.mu.Lock() wg := lg.wgTD if wg != nil { lg.mu.Unlock() wg.Wait() return } wg = &sync.WaitGroup{} lg.onceTopDown.Do(func() { wg := &sync.WaitGroup{} wg.Add(1) lg.wgTD = wg lg.mu.Unlock() // start with the conditions propagated up the graph TraceBottomUpConditions(lg, conditionsFn) Loading @@ -171,42 +149,48 @@ func TraceTopDownConditions(lg *LicenseGraph, conditionsFn TraceConditions) { walk = func(fnode *TargetNode, cs LicenseConditionSet, treatAsAggregate bool) { defer wg.Done() mu.Lock() fnode.resolution |= conditionsFn(fnode) fnode.resolution |= cs fnode.pure = treatAsAggregate amap[fnode] = struct{}{} cs = fnode.resolution mu.Unlock() // for each dependency for _, edge := range fnode.edges { func(edge *TargetEdge) { // dcs holds the dpendency conditions inherited from the target dcs := targetConditionsPropagatingToDep(lg, edge, cs, treatAsAggregate, conditionsFn) dnode := edge.dependency continueWalk := func() bool { mu.Lock() defer mu.Unlock() depcs := dnode.resolution _, alreadyWalked := amap[dnode] if !dcs.IsEmpty() && alreadyWalked { if dcs.Difference(depcs).IsEmpty() { depcs := fnode.resolution _, alreadyWalked := amap[fnode] if alreadyWalked { if cs.IsEmpty() { return false } if cs.Difference(depcs).IsEmpty() { // no new conditions // pure aggregates never need walking a 2nd time with same conditions if treatAsAggregate { return return false } // non-aggregates don't need walking as non-aggregate a 2nd time if !dnode.pure { return if !fnode.pure { return false } // previously walked as pure aggregate; need to re-walk as non-aggregate } } fnode.resolution |= conditionsFn(fnode) fnode.resolution |= cs fnode.pure = treatAsAggregate amap[fnode] = struct{}{} cs = fnode.resolution return true }() if !continueWalk { return } // for each dependency for _, edge := range fnode.edges { // dcs holds the dpendency conditions inherited from the target dcs := targetConditionsPropagatingToDep(lg, edge, cs, treatAsAggregate, conditionsFn) dnode := edge.dependency // add the conditions to the dependency wg.Add(1) go walk(dnode, dcs, treatAsAggregate && dnode.IsContainer()) }(edge) } } Loading @@ -219,4 +203,5 @@ func TraceTopDownConditions(lg *LicenseGraph, conditionsFn TraceConditions) { } wg.Done() wg.Wait() }) } Loading
tools/compliance/graph.go +4 −6 Original line number Diff line number Diff line Loading @@ -58,13 +58,11 @@ type LicenseGraph struct { /// (guarded by mu) targets map[string]*TargetNode // wgBU becomes non-nil when the bottom-up resolve begins and reaches 0 // (i.e. Wait() proceeds) when the bottom-up resolve completes. (guarded by mu) wgBU *sync.WaitGroup // onceBottomUp makes sure the bottom-up resolve walk only happens one time. onceBottomUp sync.Once // wgTD becomes non-nil when the top-down resolve begins and reaches 0 (i.e. Wait() // proceeds) when the top-down resolve completes. (guarded by mu) wgTD *sync.WaitGroup // onceTopDown makes sure the top-down resolve walk only happens one time. onceTopDown sync.Once // shippedNodes caches the results of a full walk of nodes identifying targets // distributed either directly or as derivative works. (creation guarded by mu) Loading
tools/compliance/policy_resolve.go +108 −123 Original line number Diff line number Diff line Loading @@ -49,19 +49,7 @@ func ResolveBottomUpConditions(lg *LicenseGraph) { func TraceBottomUpConditions(lg *LicenseGraph, conditionsFn TraceConditions) { // short-cut if already walked and cached lg.mu.Lock() wg := lg.wgBU if wg != nil { lg.mu.Unlock() wg.Wait() return } wg = &sync.WaitGroup{} wg.Add(1) lg.wgBU = wg lg.mu.Unlock() lg.onceBottomUp.Do(func() { // amap identifes targets previously walked. (guarded by mu) amap := make(map[*TargetNode]struct{}) Loading Loading @@ -125,8 +113,7 @@ func TraceBottomUpConditions(lg *LicenseGraph, conditionsFn TraceConditions) { rnode := lg.targets[rname] _ = walk(rnode, rnode.IsContainer()) } wg.Done() }) } // ResolveTopDownCondtions performs a top-down walk of the LicenseGraph Loading @@ -145,18 +132,9 @@ func ResolveTopDownConditions(lg *LicenseGraph) { func TraceTopDownConditions(lg *LicenseGraph, conditionsFn TraceConditions) { // short-cut if already walked and cached lg.mu.Lock() wg := lg.wgTD if wg != nil { lg.mu.Unlock() wg.Wait() return } wg = &sync.WaitGroup{} lg.onceTopDown.Do(func() { wg := &sync.WaitGroup{} wg.Add(1) lg.wgTD = wg lg.mu.Unlock() // start with the conditions propagated up the graph TraceBottomUpConditions(lg, conditionsFn) Loading @@ -171,42 +149,48 @@ func TraceTopDownConditions(lg *LicenseGraph, conditionsFn TraceConditions) { walk = func(fnode *TargetNode, cs LicenseConditionSet, treatAsAggregate bool) { defer wg.Done() mu.Lock() fnode.resolution |= conditionsFn(fnode) fnode.resolution |= cs fnode.pure = treatAsAggregate amap[fnode] = struct{}{} cs = fnode.resolution mu.Unlock() // for each dependency for _, edge := range fnode.edges { func(edge *TargetEdge) { // dcs holds the dpendency conditions inherited from the target dcs := targetConditionsPropagatingToDep(lg, edge, cs, treatAsAggregate, conditionsFn) dnode := edge.dependency continueWalk := func() bool { mu.Lock() defer mu.Unlock() depcs := dnode.resolution _, alreadyWalked := amap[dnode] if !dcs.IsEmpty() && alreadyWalked { if dcs.Difference(depcs).IsEmpty() { depcs := fnode.resolution _, alreadyWalked := amap[fnode] if alreadyWalked { if cs.IsEmpty() { return false } if cs.Difference(depcs).IsEmpty() { // no new conditions // pure aggregates never need walking a 2nd time with same conditions if treatAsAggregate { return return false } // non-aggregates don't need walking as non-aggregate a 2nd time if !dnode.pure { return if !fnode.pure { return false } // previously walked as pure aggregate; need to re-walk as non-aggregate } } fnode.resolution |= conditionsFn(fnode) fnode.resolution |= cs fnode.pure = treatAsAggregate amap[fnode] = struct{}{} cs = fnode.resolution return true }() if !continueWalk { return } // for each dependency for _, edge := range fnode.edges { // dcs holds the dpendency conditions inherited from the target dcs := targetConditionsPropagatingToDep(lg, edge, cs, treatAsAggregate, conditionsFn) dnode := edge.dependency // add the conditions to the dependency wg.Add(1) go walk(dnode, dcs, treatAsAggregate && dnode.IsContainer()) }(edge) } } Loading @@ -219,4 +203,5 @@ func TraceTopDownConditions(lg *LicenseGraph, conditionsFn TraceConditions) { } wg.Done() wg.Wait() }) }