aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2021-12-09 00:18:38 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-12-09 00:18:38 +0000
commitccfd736edabeed3097a50b6db60757fc08615e0b (patch)
tree6d65e598a52c71808c4940bde3ea0c405fb468e0
parent1fb8dbd1c8603715b93f898991a0f061a186c77b (diff)
parent159ae38aaad25f21b22f862a0cd1b2e16dbf3bf9 (diff)
downloadbuild-ccfd736edabeed3097a50b6db60757fc08615e0b.tar.gz
Merge "license metadata remove path on top-down walk" am: 159ae38aaa
Original change: https://android-review.googlesource.com/c/platform/build/+/1915582 Change-Id: I5d4af25da66c92813a13c0653c710d5adbc21109
-rw-r--r--tools/compliance/cmd/dumpresolutions_test.go90
-rw-r--r--tools/compliance/policy/resolve.go151
-rw-r--r--tools/compliance/policy/resolve_test.go9
-rw-r--r--tools/compliance/policy/resolvenotices_test.go1
-rw-r--r--tools/compliance/policy/resolveshare_test.go2
-rw-r--r--tools/compliance/policy/walk_test.go2
6 files changed, 177 insertions, 78 deletions
diff --git a/tools/compliance/cmd/dumpresolutions_test.go b/tools/compliance/cmd/dumpresolutions_test.go
index 1328a364c1..cab1cc8f05 100644
--- a/tools/compliance/cmd/dumpresolutions_test.go
+++ b/tools/compliance/cmd/dumpresolutions_test.go
@@ -577,7 +577,9 @@ func Test_plaintext(t *testing.T) {
"testdata/restricted/highest.apex.meta_lic testdata/restricted/lib/libd.so.meta_lic testdata/restricted/lib/libb.so.meta_lic restricted",
"testdata/restricted/lib/liba.so.meta_lic testdata/restricted/lib/liba.so.meta_lic testdata/restricted/lib/liba.so.meta_lic restricted",
"testdata/restricted/lib/libb.so.meta_lic testdata/restricted/lib/libb.so.meta_lic testdata/restricted/lib/libb.so.meta_lic restricted",
+ "testdata/restricted/lib/libc.a.meta_lic testdata/restricted/lib/libc.a.meta_lic testdata/restricted/lib/liba.so.meta_lic restricted",
"testdata/restricted/lib/libc.a.meta_lic testdata/restricted/lib/libc.a.meta_lic testdata/restricted/lib/libc.a.meta_lic reciprocal",
+ "testdata/restricted/lib/libd.so.meta_lic testdata/restricted/lib/libd.so.meta_lic testdata/restricted/lib/libb.so.meta_lic restricted",
"testdata/restricted/lib/libd.so.meta_lic testdata/restricted/lib/libd.so.meta_lic testdata/restricted/lib/libd.so.meta_lic notice",
},
},
@@ -610,7 +612,9 @@ func Test_plaintext(t *testing.T) {
"highest.apex.meta_lic lib/libd.so.meta_lic lib/libb.so.meta_lic restricted",
"lib/liba.so.meta_lic lib/liba.so.meta_lic lib/liba.so.meta_lic restricted",
"lib/libb.so.meta_lic lib/libb.so.meta_lic lib/libb.so.meta_lic restricted",
+ "lib/libc.a.meta_lic lib/libc.a.meta_lic lib/liba.so.meta_lic restricted",
"lib/libc.a.meta_lic lib/libc.a.meta_lic lib/libc.a.meta_lic reciprocal",
+ "lib/libd.so.meta_lic lib/libd.so.meta_lic lib/libb.so.meta_lic restricted",
"lib/libd.so.meta_lic lib/libd.so.meta_lic lib/libd.so.meta_lic notice",
},
},
@@ -723,7 +727,9 @@ func Test_plaintext(t *testing.T) {
"highest.apex.meta_lic:notice lib/libd.so.meta_lic:notice lib/libb.so.meta_lic:restricted restricted",
"lib/liba.so.meta_lic:restricted lib/liba.so.meta_lic:restricted lib/liba.so.meta_lic:restricted restricted",
"lib/libb.so.meta_lic:restricted lib/libb.so.meta_lic:restricted lib/libb.so.meta_lic:restricted restricted",
+ "lib/libc.a.meta_lic:reciprocal lib/libc.a.meta_lic:reciprocal lib/liba.so.meta_lic:restricted restricted",
"lib/libc.a.meta_lic:reciprocal lib/libc.a.meta_lic:reciprocal lib/libc.a.meta_lic:reciprocal reciprocal",
+ "lib/libd.so.meta_lic:notice lib/libd.so.meta_lic:notice lib/libb.so.meta_lic:restricted restricted",
"lib/libd.so.meta_lic:notice lib/libd.so.meta_lic:notice lib/libd.so.meta_lic:notice notice",
},
},
@@ -755,7 +761,9 @@ func Test_plaintext(t *testing.T) {
"testdata/restricted/container.zip.meta_lic testdata/restricted/lib/libd.so.meta_lic testdata/restricted/lib/libb.so.meta_lic restricted",
"testdata/restricted/lib/liba.so.meta_lic testdata/restricted/lib/liba.so.meta_lic testdata/restricted/lib/liba.so.meta_lic restricted",
"testdata/restricted/lib/libb.so.meta_lic testdata/restricted/lib/libb.so.meta_lic testdata/restricted/lib/libb.so.meta_lic restricted",
+ "testdata/restricted/lib/libc.a.meta_lic testdata/restricted/lib/libc.a.meta_lic testdata/restricted/lib/liba.so.meta_lic restricted",
"testdata/restricted/lib/libc.a.meta_lic testdata/restricted/lib/libc.a.meta_lic testdata/restricted/lib/libc.a.meta_lic reciprocal",
+ "testdata/restricted/lib/libd.so.meta_lic testdata/restricted/lib/libd.so.meta_lic testdata/restricted/lib/libb.so.meta_lic restricted",
"testdata/restricted/lib/libd.so.meta_lic testdata/restricted/lib/libd.so.meta_lic testdata/restricted/lib/libd.so.meta_lic notice",
},
},
@@ -772,6 +780,7 @@ func Test_plaintext(t *testing.T) {
"testdata/restricted/application.meta_lic testdata/restricted/lib/libb.so.meta_lic testdata/restricted/lib/libb.so.meta_lic restricted",
"testdata/restricted/bin/bin3.meta_lic testdata/restricted/bin/bin3.meta_lic testdata/restricted/bin/bin3.meta_lic restricted",
"testdata/restricted/lib/liba.so.meta_lic testdata/restricted/lib/liba.so.meta_lic testdata/restricted/lib/liba.so.meta_lic restricted",
+ "testdata/restricted/lib/liba.so.meta_lic testdata/restricted/lib/liba.so.meta_lic testdata/restricted/lib/libb.so.meta_lic restricted",
"testdata/restricted/lib/libb.so.meta_lic testdata/restricted/lib/libb.so.meta_lic testdata/restricted/lib/libb.so.meta_lic restricted",
},
},
@@ -786,6 +795,7 @@ func Test_plaintext(t *testing.T) {
"testdata/restricted/bin/bin1.meta_lic testdata/restricted/lib/libc.a.meta_lic testdata/restricted/lib/liba.so.meta_lic restricted",
"testdata/restricted/bin/bin1.meta_lic testdata/restricted/lib/libc.a.meta_lic testdata/restricted/lib/libc.a.meta_lic reciprocal",
"testdata/restricted/lib/liba.so.meta_lic testdata/restricted/lib/liba.so.meta_lic testdata/restricted/lib/liba.so.meta_lic restricted",
+ "testdata/restricted/lib/libc.a.meta_lic testdata/restricted/lib/libc.a.meta_lic testdata/restricted/lib/liba.so.meta_lic restricted",
"testdata/restricted/lib/libc.a.meta_lic testdata/restricted/lib/libc.a.meta_lic testdata/restricted/lib/libc.a.meta_lic reciprocal",
},
},
@@ -821,6 +831,7 @@ func Test_plaintext(t *testing.T) {
"testdata/proprietary/lib/liba.so.meta_lic testdata/proprietary/lib/liba.so.meta_lic testdata/proprietary/lib/liba.so.meta_lic by_exception_only:proprietary",
"testdata/proprietary/lib/libb.so.meta_lic testdata/proprietary/lib/libb.so.meta_lic testdata/proprietary/lib/libb.so.meta_lic restricted",
"testdata/proprietary/lib/libc.a.meta_lic testdata/proprietary/lib/libc.a.meta_lic testdata/proprietary/lib/libc.a.meta_lic by_exception_only:proprietary",
+ "testdata/proprietary/lib/libd.so.meta_lic testdata/proprietary/lib/libd.so.meta_lic testdata/proprietary/lib/libb.so.meta_lic restricted",
"testdata/proprietary/lib/libd.so.meta_lic testdata/proprietary/lib/libd.so.meta_lic testdata/proprietary/lib/libd.so.meta_lic notice",
},
},
@@ -849,6 +860,7 @@ func Test_plaintext(t *testing.T) {
"lib/liba.so.meta_lic lib/liba.so.meta_lic lib/liba.so.meta_lic by_exception_only:proprietary",
"lib/libb.so.meta_lic lib/libb.so.meta_lic lib/libb.so.meta_lic restricted",
"lib/libc.a.meta_lic lib/libc.a.meta_lic lib/libc.a.meta_lic by_exception_only:proprietary",
+ "lib/libd.so.meta_lic lib/libd.so.meta_lic lib/libb.so.meta_lic restricted",
"lib/libd.so.meta_lic lib/libd.so.meta_lic lib/libd.so.meta_lic notice",
},
},
@@ -950,6 +962,7 @@ func Test_plaintext(t *testing.T) {
"lib/liba.so.meta_lic:by_exception_only:proprietary lib/liba.so.meta_lic:by_exception_only:proprietary lib/liba.so.meta_lic:by_exception_only:proprietary by_exception_only:proprietary",
"lib/libb.so.meta_lic:restricted lib/libb.so.meta_lic:restricted lib/libb.so.meta_lic:restricted restricted",
"lib/libc.a.meta_lic:by_exception_only:proprietary lib/libc.a.meta_lic:by_exception_only:proprietary lib/libc.a.meta_lic:by_exception_only:proprietary by_exception_only:proprietary",
+ "lib/libd.so.meta_lic:notice lib/libd.so.meta_lic:notice lib/libb.so.meta_lic:restricted restricted",
"lib/libd.so.meta_lic:notice lib/libd.so.meta_lic:notice lib/libd.so.meta_lic:notice notice",
},
},
@@ -977,6 +990,7 @@ func Test_plaintext(t *testing.T) {
"testdata/proprietary/lib/liba.so.meta_lic testdata/proprietary/lib/liba.so.meta_lic testdata/proprietary/lib/liba.so.meta_lic by_exception_only:proprietary",
"testdata/proprietary/lib/libb.so.meta_lic testdata/proprietary/lib/libb.so.meta_lic testdata/proprietary/lib/libb.so.meta_lic restricted",
"testdata/proprietary/lib/libc.a.meta_lic testdata/proprietary/lib/libc.a.meta_lic testdata/proprietary/lib/libc.a.meta_lic by_exception_only:proprietary",
+ "testdata/proprietary/lib/libd.so.meta_lic testdata/proprietary/lib/libd.so.meta_lic testdata/proprietary/lib/libb.so.meta_lic restricted",
"testdata/proprietary/lib/libd.so.meta_lic testdata/proprietary/lib/libd.so.meta_lic testdata/proprietary/lib/libd.so.meta_lic notice",
},
},
@@ -992,6 +1006,7 @@ func Test_plaintext(t *testing.T) {
"testdata/proprietary/application.meta_lic testdata/proprietary/lib/libb.so.meta_lic testdata/proprietary/lib/libb.so.meta_lic restricted",
"testdata/proprietary/bin/bin3.meta_lic testdata/proprietary/bin/bin3.meta_lic testdata/proprietary/bin/bin3.meta_lic restricted",
"testdata/proprietary/lib/liba.so.meta_lic testdata/proprietary/lib/liba.so.meta_lic testdata/proprietary/lib/liba.so.meta_lic by_exception_only:proprietary",
+ "testdata/proprietary/lib/liba.so.meta_lic testdata/proprietary/lib/liba.so.meta_lic testdata/proprietary/lib/libb.so.meta_lic restricted",
"testdata/proprietary/lib/libb.so.meta_lic testdata/proprietary/lib/libb.so.meta_lic testdata/proprietary/lib/libb.so.meta_lic restricted",
},
},
@@ -2886,11 +2901,21 @@ func Test_graphviz(t *testing.T) {
matchResolution(
"testdata/restricted/lib/libc.a.meta_lic",
"testdata/restricted/lib/libc.a.meta_lic",
+ "testdata/restricted/lib/liba.so.meta_lic",
+ "restricted"),
+ matchResolution(
+ "testdata/restricted/lib/libc.a.meta_lic",
+ "testdata/restricted/lib/libc.a.meta_lic",
"testdata/restricted/lib/libc.a.meta_lic",
"reciprocal"),
matchResolution(
"testdata/restricted/lib/libd.so.meta_lic",
"testdata/restricted/lib/libd.so.meta_lic",
+ "testdata/restricted/lib/libb.so.meta_lic",
+ "restricted"),
+ matchResolution(
+ "testdata/restricted/lib/libd.so.meta_lic",
+ "testdata/restricted/lib/libd.so.meta_lic",
"testdata/restricted/lib/libd.so.meta_lic",
"notice"),
},
@@ -3026,11 +3051,21 @@ func Test_graphviz(t *testing.T) {
matchResolution(
"lib/libc.a.meta_lic",
"lib/libc.a.meta_lic",
+ "lib/liba.so.meta_lic",
+ "restricted"),
+ matchResolution(
+ "lib/libc.a.meta_lic",
+ "lib/libc.a.meta_lic",
"lib/libc.a.meta_lic",
"reciprocal"),
matchResolution(
"lib/libd.so.meta_lic",
"lib/libd.so.meta_lic",
+ "lib/libb.so.meta_lic",
+ "restricted"),
+ matchResolution(
+ "lib/libd.so.meta_lic",
+ "lib/libd.so.meta_lic",
"lib/libd.so.meta_lic",
"notice"),
},
@@ -3409,11 +3444,21 @@ func Test_graphviz(t *testing.T) {
matchResolution(
"lib/libc.a.meta_lic",
"lib/libc.a.meta_lic",
+ "lib/liba.so.meta_lic",
+ "restricted"),
+ matchResolution(
+ "lib/libc.a.meta_lic",
+ "lib/libc.a.meta_lic",
"lib/libc.a.meta_lic",
"reciprocal"),
matchResolution(
"lib/libd.so.meta_lic",
"lib/libd.so.meta_lic",
+ "lib/libb.so.meta_lic",
+ "restricted"),
+ matchResolution(
+ "lib/libd.so.meta_lic",
+ "lib/libd.so.meta_lic",
"lib/libd.so.meta_lic",
"notice"),
},
@@ -3548,11 +3593,21 @@ func Test_graphviz(t *testing.T) {
matchResolution(
"testdata/restricted/lib/libc.a.meta_lic",
"testdata/restricted/lib/libc.a.meta_lic",
+ "testdata/restricted/lib/liba.so.meta_lic",
+ "restricted"),
+ matchResolution(
+ "testdata/restricted/lib/libc.a.meta_lic",
+ "testdata/restricted/lib/libc.a.meta_lic",
"testdata/restricted/lib/libc.a.meta_lic",
"reciprocal"),
matchResolution(
"testdata/restricted/lib/libd.so.meta_lic",
"testdata/restricted/lib/libd.so.meta_lic",
+ "testdata/restricted/lib/libb.so.meta_lic",
+ "restricted"),
+ matchResolution(
+ "testdata/restricted/lib/libd.so.meta_lic",
+ "testdata/restricted/lib/libd.so.meta_lic",
"testdata/restricted/lib/libd.so.meta_lic",
"notice"),
},
@@ -3607,6 +3662,11 @@ func Test_graphviz(t *testing.T) {
"testdata/restricted/lib/liba.so.meta_lic",
"restricted"),
matchResolution(
+ "testdata/restricted/lib/liba.so.meta_lic",
+ "testdata/restricted/lib/liba.so.meta_lic",
+ "testdata/restricted/lib/libb.so.meta_lic",
+ "restricted"),
+ matchResolution(
"testdata/restricted/lib/libb.so.meta_lic",
"testdata/restricted/lib/libb.so.meta_lic",
"testdata/restricted/lib/libb.so.meta_lic",
@@ -3654,6 +3714,11 @@ func Test_graphviz(t *testing.T) {
matchResolution(
"testdata/restricted/lib/libc.a.meta_lic",
"testdata/restricted/lib/libc.a.meta_lic",
+ "testdata/restricted/lib/liba.so.meta_lic",
+ "restricted"),
+ matchResolution(
+ "testdata/restricted/lib/libc.a.meta_lic",
+ "testdata/restricted/lib/libc.a.meta_lic",
"testdata/restricted/lib/libc.a.meta_lic",
"reciprocal"),
},
@@ -3789,6 +3854,11 @@ func Test_graphviz(t *testing.T) {
matchResolution(
"testdata/proprietary/lib/libd.so.meta_lic",
"testdata/proprietary/lib/libd.so.meta_lic",
+ "testdata/proprietary/lib/libb.so.meta_lic",
+ "restricted"),
+ matchResolution(
+ "testdata/proprietary/lib/libd.so.meta_lic",
+ "testdata/proprietary/lib/libd.so.meta_lic",
"testdata/proprietary/lib/libd.so.meta_lic",
"notice"),
},
@@ -3912,6 +3982,11 @@ func Test_graphviz(t *testing.T) {
matchResolution(
"lib/libd.so.meta_lic",
"lib/libd.so.meta_lic",
+ "lib/libb.so.meta_lic",
+ "restricted"),
+ matchResolution(
+ "lib/libd.so.meta_lic",
+ "lib/libd.so.meta_lic",
"lib/libd.so.meta_lic",
"notice"),
},
@@ -4240,6 +4315,11 @@ func Test_graphviz(t *testing.T) {
matchResolution(
"lib/libd.so.meta_lic",
"lib/libd.so.meta_lic",
+ "lib/libb.so.meta_lic",
+ "restricted"),
+ matchResolution(
+ "lib/libd.so.meta_lic",
+ "lib/libd.so.meta_lic",
"lib/libd.so.meta_lic",
"notice"),
},
@@ -4362,6 +4442,11 @@ func Test_graphviz(t *testing.T) {
matchResolution(
"testdata/proprietary/lib/libd.so.meta_lic",
"testdata/proprietary/lib/libd.so.meta_lic",
+ "testdata/proprietary/lib/libb.so.meta_lic",
+ "restricted"),
+ matchResolution(
+ "testdata/proprietary/lib/libd.so.meta_lic",
+ "testdata/proprietary/lib/libd.so.meta_lic",
"testdata/proprietary/lib/libd.so.meta_lic",
"notice"),
},
@@ -4413,6 +4498,11 @@ func Test_graphviz(t *testing.T) {
"by_exception_only",
"proprietary"),
matchResolution(
+ "testdata/proprietary/lib/liba.so.meta_lic",
+ "testdata/proprietary/lib/liba.so.meta_lic",
+ "testdata/proprietary/lib/libb.so.meta_lic",
+ "restricted"),
+ matchResolution(
"testdata/proprietary/lib/libb.so.meta_lic",
"testdata/proprietary/lib/libb.so.meta_lic",
"testdata/proprietary/lib/libb.so.meta_lic",
diff --git a/tools/compliance/policy/resolve.go b/tools/compliance/policy/resolve.go
index c051ed8bb2..58547f84d5 100644
--- a/tools/compliance/policy/resolve.go
+++ b/tools/compliance/policy/resolve.go
@@ -41,59 +41,7 @@ func ResolveBottomUpConditions(lg *LicenseGraph) *ResolutionSet {
// must be indexed for fast lookup
lg.indexForward()
- rs = newResolutionSet()
-
- // cmap contains an entry for every target that was previously walked as a pure aggregate only.
- cmap := make(map[string]bool)
-
- var walk func(f string, treatAsAggregate bool) actionSet
-
- walk = func(f string, treatAsAggregate bool) actionSet {
- target := lg.targets[f]
- result := make(actionSet)
- result[target] = newLicenseConditionSet()
- result[target].add(target, target.proto.LicenseConditions...)
- if preresolved, ok := rs.resolutions[target]; ok {
- if treatAsAggregate {
- result.addSet(preresolved)
- return result
- }
- if _, asAggregate := cmap[f]; !asAggregate {
- result.addSet(preresolved)
- return result
- }
- // previously walked in a pure aggregate context,
- // needs to walk again in non-aggregate context
- delete(cmap, f)
- }
- if treatAsAggregate {
- cmap[f] = true
- }
-
- // add all the conditions from all the dependencies
- for _, edge := range lg.index[f] {
- // walk dependency to get its conditions
- as := walk(edge.dependency, treatAsAggregate && lg.targets[edge.dependency].IsContainer())
-
- // turn those into the conditions that apply to the target
- as = depActionsApplicableToTarget(TargetEdge{lg, edge}, as, treatAsAggregate)
-
- // add them to the result
- result.addSet(as)
- }
-
- // record these conditions as applicable to the target
- rs.addConditions(target, result)
- rs.addSelf(target, result.byName(ImpliesRestricted))
-
- // return this up the tree
- return result
- }
-
- // walk each of the roots
- for _, r := range lg.rootFiles {
- _ = walk(r, lg.targets[r].IsContainer())
- }
+ rs = resolveBottomUp(lg, make(map[*TargetNode]actionSet) /* empty map; no prior resolves */)
// if not yet cached, save the result
lg.mu.Lock()
@@ -137,31 +85,13 @@ func ResolveTopDownConditions(lg *LicenseGraph) *ResolutionSet {
// cmap contains the set of targets walked as pure aggregates. i.e. containers
cmap := make(map[*TargetNode]bool)
- path := make([]*dependencyEdge, 0, 32)
-
var walk func(fnode *TargetNode, cs *LicenseConditionSet, treatAsAggregate bool)
walk = func(fnode *TargetNode, cs *LicenseConditionSet, treatAsAggregate bool) {
- if !cs.IsEmpty() {
- parentsAllAggregate := true
- for _, e := range path {
- target := lg.targets[e.target]
- if _, ok := rmap[target]; !ok {
- rmap[target] = make(actionSet)
- }
- rmap[target].add(fnode, cs)
- if !target.IsContainer() {
- parentsAllAggregate = false
- break
- }
- }
- if parentsAllAggregate {
- if _, ok := rmap[fnode]; !ok {
- rmap[fnode] = make(actionSet)
- }
- rmap[fnode].add(fnode, cs)
- }
+ if _, ok := rmap[fnode]; !ok {
+ rmap[fnode] = make(actionSet)
}
+ rmap[fnode].add(fnode, cs)
if treatAsAggregate {
cmap[fnode] = true
}
@@ -197,10 +127,8 @@ func ResolveTopDownConditions(lg *LicenseGraph) *ResolutionSet {
delete(cmap, dnode)
}
}
- path = append(path, edge)
// add the conditions to the dependency
walk(dnode, dcs, treatAsAggregate && lg.targets[edge.dependency].IsContainer())
- path = path[:len(path)-1]
}
}
@@ -216,7 +144,6 @@ func ResolveTopDownConditions(lg *LicenseGraph) *ResolutionSet {
continue
}
- path = path[:0]
// add the conditions to the root and its transitive closure
walk(rnode, newLicenseConditionSet(), lg.targets[r].IsContainer())
}
@@ -230,7 +157,8 @@ func ResolveTopDownConditions(lg *LicenseGraph) *ResolutionSet {
}
}
- rs = &ResolutionSet{rmap}
+ // propagate any new conditions back up the graph
+ rs = resolveBottomUp(lg, rmap)
// if not yet cached, save the result
lg.mu.Lock()
@@ -244,3 +172,70 @@ func ResolveTopDownConditions(lg *LicenseGraph) *ResolutionSet {
return rs
}
+
+// resolveBottomUp implements a bottom-up resolve propagating conditions both
+// from the graph, and from a `priors` map of resolutions.
+func resolveBottomUp(lg *LicenseGraph, priors map[*TargetNode]actionSet) *ResolutionSet {
+ rs := newResolutionSet()
+
+ // cmap contains an entry for every target that was previously walked as a pure aggregate only.
+ cmap := make(map[string]bool)
+
+ var walk func(f string, treatAsAggregate bool) actionSet
+
+ walk = func(f string, treatAsAggregate bool) actionSet {
+ target := lg.targets[f]
+ result := make(actionSet)
+ result[target] = newLicenseConditionSet()
+ result[target].add(target, target.proto.LicenseConditions...)
+ if pas, ok := priors[target]; ok {
+ result.addSet(pas)
+ }
+ if preresolved, ok := rs.resolutions[target]; ok {
+ if treatAsAggregate {
+ result.addSet(preresolved)
+ return result
+ }
+ if _, asAggregate := cmap[f]; !asAggregate {
+ result.addSet(preresolved)
+ return result
+ }
+ // previously walked in a pure aggregate context,
+ // needs to walk again in non-aggregate context
+ delete(cmap, f)
+ }
+ if treatAsAggregate {
+ cmap[f] = true
+ }
+
+ // add all the conditions from all the dependencies
+ for _, edge := range lg.index[f] {
+ // walk dependency to get its conditions
+ as := walk(edge.dependency, treatAsAggregate && lg.targets[edge.dependency].IsContainer())
+
+ // turn those into the conditions that apply to the target
+ as = depActionsApplicableToTarget(TargetEdge{lg, edge}, as, treatAsAggregate)
+
+ // add them to the result
+ result.addSet(as)
+ }
+
+ // record these conditions as applicable to the target
+ rs.addConditions(target, result)
+ if len(priors) == 0 {
+ // on the first bottom-up resolve, parents have their own sharing and notice needs
+ // on the later resolve, if priors is empty, there will be nothing new to add
+ rs.addSelf(target, result.byName(ImpliesRestricted))
+ }
+
+ // return this up the tree
+ return result
+ }
+
+ // walk each of the roots
+ for _, r := range lg.rootFiles {
+ _ = walk(r, lg.targets[r].IsContainer())
+ }
+
+ return rs
+}
diff --git a/tools/compliance/policy/resolve_test.go b/tools/compliance/policy/resolve_test.go
index aa5bb2a3c7..4c99d3546f 100644
--- a/tools/compliance/policy/resolve_test.go
+++ b/tools/compliance/policy/resolve_test.go
@@ -434,6 +434,7 @@ func TestResolveTopDownConditions(t *testing.T) {
{"apacheBin.meta_lic", "mitLib.meta_lic", "gplLib.meta_lic", "restricted"},
{"apacheBin.meta_lic", "mitLib.meta_lic", "mitLib.meta_lic", "notice"},
{"gplLib.meta_lic", "gplLib.meta_lic", "gplLib.meta_lic", "restricted"},
+ {"mitLib.meta_lic", "mitLib.meta_lic", "gplLib.meta_lic", "restricted"},
{"mitLib.meta_lic", "mitLib.meta_lic", "mitLib.meta_lic", "notice"},
},
},
@@ -480,6 +481,7 @@ func TestResolveTopDownConditions(t *testing.T) {
{"mitBin.meta_lic", "mitBin.meta_lic", "mitBin.meta_lic", "notice"},
{"mitBin.meta_lic", "mitLib.meta_lic", "mitLib.meta_lic", "notice"},
{"mitLib.meta_lic", "mitLib.meta_lic", "mitLib.meta_lic", "notice"},
+ {"mplLib.meta_lic", "mplLib.meta_lic", "gplLib.meta_lic", "restricted"},
{"mplLib.meta_lic", "mplLib.meta_lic", "mplLib.meta_lic", "reciprocal"},
},
},
@@ -512,6 +514,7 @@ func TestResolveTopDownConditions(t *testing.T) {
{"apacheBin.meta_lic", "gplLib.meta_lic", "gplLib.meta_lic", "restricted"},
{"apacheBin.meta_lic", "mitLib.meta_lic", "gplLib.meta_lic", "restricted"},
{"gplLib.meta_lic", "gplLib.meta_lic", "gplLib.meta_lic", "restricted"},
+ {"mitLib.meta_lic", "mitLib.meta_lic", "gplLib.meta_lic", "restricted"},
{"mitLib.meta_lic", "mitLib.meta_lic", "mitLib.meta_lic", "notice"},
},
},
@@ -540,6 +543,7 @@ func TestResolveTopDownConditions(t *testing.T) {
{"gplLib.meta_lic", "gplLib.meta_lic", "gplLib.meta_lic", "restricted"},
{"mitBin.meta_lic", "mitBin.meta_lic", "mitBin.meta_lic", "notice"},
{"mitLib.meta_lic", "mitLib.meta_lic", "mitLib.meta_lic", "notice"},
+ {"mplLib.meta_lic", "mplLib.meta_lic", "gplLib.meta_lic", "restricted"},
{"mplLib.meta_lic", "mplLib.meta_lic", "mplLib.meta_lic", "reciprocal"},
},
},
@@ -573,6 +577,7 @@ func TestResolveTopDownConditions(t *testing.T) {
{"apacheBin.meta_lic", "mitLib.meta_lic", "mitLib.meta_lic", "notice"},
{"apacheBin.meta_lic", "mitLib.meta_lic", "lgplLib.meta_lic", "restricted"},
{"lgplLib.meta_lic", "lgplLib.meta_lic", "lgplLib.meta_lic", "restricted"},
+ {"mitLib.meta_lic", "mitLib.meta_lic", "lgplLib.meta_lic", "restricted"},
{"mitLib.meta_lic", "mitLib.meta_lic", "mitLib.meta_lic", "notice"},
},
},
@@ -612,6 +617,7 @@ func TestResolveTopDownConditions(t *testing.T) {
{"apacheBin.meta_lic", "mitLib.meta_lic", "mitLib.meta_lic", "notice"},
{"apacheBin.meta_lic", "mitLib.meta_lic", "lgplLib.meta_lic", "restricted"},
{"lgplLib.meta_lic", "lgplLib.meta_lic", "lgplLib.meta_lic", "restricted"},
+ {"mitLib.meta_lic", "mitLib.meta_lic", "lgplLib.meta_lic", "restricted"},
{"mitLib.meta_lic", "mitLib.meta_lic", "mitLib.meta_lic", "notice"},
},
},
@@ -687,6 +693,7 @@ func TestResolveTopDownConditions(t *testing.T) {
{"apacheBin.meta_lic", "mitLib.meta_lic", "mitLib.meta_lic", "notice"},
{"apacheBin.meta_lic", "mitLib.meta_lic", "gplWithClasspathException.meta_lic", "restricted"},
{"gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "restricted"},
+ {"mitLib.meta_lic", "mitLib.meta_lic", "gplWithClasspathException.meta_lic", "restricted"},
{"mitLib.meta_lic", "mitLib.meta_lic", "mitLib.meta_lic", "notice"},
},
},
@@ -704,6 +711,7 @@ func TestResolveTopDownConditions(t *testing.T) {
{"dependentModule.meta_lic", "mitLib.meta_lic", "mitLib.meta_lic", "notice"},
{"dependentModule.meta_lic", "mitLib.meta_lic", "gplWithClasspathException.meta_lic", "restricted"},
{"gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "restricted"},
+ {"mitLib.meta_lic", "mitLib.meta_lic", "gplWithClasspathException.meta_lic", "restricted"},
{"mitLib.meta_lic", "mitLib.meta_lic", "mitLib.meta_lic", "notice"},
},
},
@@ -735,6 +743,7 @@ func TestResolveTopDownConditions(t *testing.T) {
{"dependentModule.meta_lic", "mitLib.meta_lic", "mitLib.meta_lic", "notice"},
{"dependentModule.meta_lic", "mitLib.meta_lic", "gplWithClasspathException.meta_lic", "restricted"},
{"gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "restricted"},
+ {"mitLib.meta_lic", "mitLib.meta_lic", "gplWithClasspathException.meta_lic", "restricted"},
{"mitLib.meta_lic", "mitLib.meta_lic", "mitLib.meta_lic", "notice"},
},
},
diff --git a/tools/compliance/policy/resolvenotices_test.go b/tools/compliance/policy/resolvenotices_test.go
index b428d5b549..275c0a5fe2 100644
--- a/tools/compliance/policy/resolvenotices_test.go
+++ b/tools/compliance/policy/resolvenotices_test.go
@@ -153,6 +153,7 @@ func TestResolveNotices(t *testing.T) {
{"apacheBin.meta_lic", "apacheBin.meta_lic", "apacheBin.meta_lic", "notice"},
{"apacheBin.meta_lic", "apacheBin.meta_lic", "gplLib.meta_lic", "restricted"},
{"apacheBin.meta_lic", "mitLib.meta_lic", "gplLib.meta_lic", "restricted"},
+ {"mitLib.meta_lic", "mitLib.meta_lic", "gplLib.meta_lic", "restricted"},
{"mitLib.meta_lic", "mitLib.meta_lic", "mitLib.meta_lic", "notice"},
},
},
diff --git a/tools/compliance/policy/resolveshare_test.go b/tools/compliance/policy/resolveshare_test.go
index 7371ccf94b..ad3630db06 100644
--- a/tools/compliance/policy/resolveshare_test.go
+++ b/tools/compliance/policy/resolveshare_test.go
@@ -176,6 +176,7 @@ func TestResolveSourceSharing(t *testing.T) {
expectedResolutions: []res{
{"gplBin.meta_lic", "gplBin.meta_lic", "gplBin.meta_lic", "restricted"},
{"gplBin.meta_lic", "apacheLib.meta_lic", "gplBin.meta_lic", "restricted"},
+ {"apacheLib.meta_lic", "apacheLib.meta_lic", "gplBin.meta_lic", "restricted"},
},
},
{
@@ -218,6 +219,7 @@ func TestResolveSourceSharing(t *testing.T) {
expectedResolutions: []res{
{"gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "restricted"},
{"gplWithClasspathException.meta_lic", "dependentModule.meta_lic", "gplWithClasspathException.meta_lic", "restricted"},
+ {"dependentModule.meta_lic", "dependentModule.meta_lic", "gplWithClasspathException.meta_lic", "restricted"},
},
},
{
diff --git a/tools/compliance/policy/walk_test.go b/tools/compliance/policy/walk_test.go
index 2eef702ef6..07710aa90d 100644
--- a/tools/compliance/policy/walk_test.go
+++ b/tools/compliance/policy/walk_test.go
@@ -336,6 +336,7 @@ func TestWalkResolutionsForCondition(t *testing.T) {
expectedResolutions: []res{
{"gplBin.meta_lic", "gplBin.meta_lic", "gplBin.meta_lic", "restricted"},
{"gplBin.meta_lic", "apacheLib.meta_lic", "gplBin.meta_lic", "restricted"},
+ {"apacheLib.meta_lic", "apacheLib.meta_lic", "gplBin.meta_lic", "restricted"},
},
},
{
@@ -428,6 +429,7 @@ func TestWalkResolutionsForCondition(t *testing.T) {
expectedResolutions: []res{
{"gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "restricted"},
{"gplWithClasspathException.meta_lic", "dependentModule.meta_lic", "gplWithClasspathException.meta_lic", "restricted"},
+ {"dependentModule.meta_lic", "dependentModule.meta_lic", "gplWithClasspathException.meta_lic", "restricted"},
},
},
{