blob: a47c1cfef080407419acd86bcd50179da1305e46 [file] [log] [blame]
Bob Badourafaeb6a2021-10-25 16:59:56 -07001// Copyright 2021 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14/*
15
16Package compliance provides an approved means for reading, consuming, and
17analyzing license metadata graphs.
18
19Assuming the license metadata and dependencies are fully and accurately
20recorded in the build system, any discrepancy between the official policy for
21open source license compliance and this code is a bug in this code.
22
23A few principal types to understand are LicenseGraph, LicenseCondition, and
24ResolutionSet.
25
26LicenseGraph
27------------
28
29A LicenseGraph is an immutable graph of the targets and dependencies reachable
30from a specific set of root targets. In general, the root targets will be the
31artifacts in a release or distribution. While conceptually immutable, parts of
32the graph may be loaded or evaluated lazily.
33
34LicenseCondition
35----------------
36
37A LicenseCondition is an immutable tuple pairing a condition name with an
38originating target. e.g. Per current policy, a static library licensed under an
39MIT license would pair a "notice" condition with the static library target, and
40a dynamic license licensed under GPL would pair a "restricted" condition with
41the dynamic library target.
42
43ResolutionSet
44-------------
45
46A ResolutionSet is an immutable set of `AttachesTo`, `ActsOn`, `Resolves`
47tuples describing how license conditions apply to targets.
48
49`AttachesTo` is the trigger for acting. Distribution of the target invokes
50the policy.
51
52`ActsOn` is the target to share, give notice for, hide etc.
53
54`Resolves` is the license condition that the action resolves.
55
56Remember: Each license condition pairs a condition name with an originating
57target so each resolution in a ResolutionSet has two targets it applies to and
58one target from which it originates, all of which may be the same target.
59
60For most condition types, `ActsOn` and `Resolves.Origin` will be the same
61target. For example, a notice condition policy means attribution or notice must
62be given for the target where the condition originates. Likewise, a proprietary
63condition policy means the privacy of the target where the condition originates
64must be respected. i.e. The thing acted on is the origin.
65
66Restricted conditions are different. The infectious nature of restricted often
67means sharing code that is not the target where the restricted condition
68originates. Linking an MIT library to a GPL library implies a policy to share
69the MIT library despite the MIT license having no source sharing requirement.
70
71In this case, one or more resolution tuples will have the MIT license module in
72`ActsOn` and the restricted condition originating at the GPL library module in
73`Resolves`. These tuples will `AttachTo` every target that depends on the GPL
74library because shipping any of those targets trigger the policy to share the
75code.
76*/
77package compliance