xref: /aosp_15_r20/build/make/tools/compliance/README.md (revision 9e94795a3d4ef5c1d47486f9a02bb378756cea8a)
1*9e94795aSAndroid Build Coastguard Worker# Compliance
2*9e94795aSAndroid Build Coastguard Worker
3*9e94795aSAndroid Build Coastguard Worker<!-- Much of this content appears too in doc.go
4*9e94795aSAndroid Build Coastguard WorkerWhen changing this file consider whether the change also applies to doc.go -->
5*9e94795aSAndroid Build Coastguard Worker
6*9e94795aSAndroid Build Coastguard WorkerPackage compliance provides an approved means for reading, consuming, and
7*9e94795aSAndroid Build Coastguard Workeranalyzing license metadata graphs.
8*9e94795aSAndroid Build Coastguard Worker
9*9e94795aSAndroid Build Coastguard WorkerAssuming the license metadata and dependencies are fully and accurately
10*9e94795aSAndroid Build Coastguard Workerrecorded in the build system, any discrepancy between the official policy for
11*9e94795aSAndroid Build Coastguard Workeropen source license compliance and this code is **a bug in this code.**
12*9e94795aSAndroid Build Coastguard Worker
13*9e94795aSAndroid Build Coastguard Worker## Naming
14*9e94795aSAndroid Build Coastguard Worker
15*9e94795aSAndroid Build Coastguard WorkerAll of the code that directly reflects a policy decision belongs in a file with
16*9e94795aSAndroid Build Coastguard Workera name begninning `policy_`. Changes to these files need to be authored or
17*9e94795aSAndroid Build Coastguard Workerreviewed by someone in OSPO or whichever successor group governs policy.
18*9e94795aSAndroid Build Coastguard Worker
19*9e94795aSAndroid Build Coastguard WorkerThe files with names not beginning `policy_` describe data types, and general,
20*9e94795aSAndroid Build Coastguard Workerreusable algorithms.
21*9e94795aSAndroid Build Coastguard Worker
22*9e94795aSAndroid Build Coastguard WorkerThe source code for binary tools and utilities appears under the `cmd/`
23*9e94795aSAndroid Build Coastguard Workersubdirectory. Other subdirectories contain reusable components that are not
24*9e94795aSAndroid Build Coastguard Worker`compliance` per se.
25*9e94795aSAndroid Build Coastguard Worker
26*9e94795aSAndroid Build Coastguard Worker## Data Types
27*9e94795aSAndroid Build Coastguard Worker
28*9e94795aSAndroid Build Coastguard WorkerA few principal types to understand are LicenseGraph, LicenseCondition, and
29*9e94795aSAndroid Build Coastguard WorkerResolutionSet.
30*9e94795aSAndroid Build Coastguard Worker
31*9e94795aSAndroid Build Coastguard Worker### LicenseGraph
32*9e94795aSAndroid Build Coastguard Worker
33*9e94795aSAndroid Build Coastguard WorkerA LicenseGraph is an immutable graph of the targets and dependencies reachable
34*9e94795aSAndroid Build Coastguard Workerfrom a specific set of root targets. In general, the root targets will be the
35*9e94795aSAndroid Build Coastguard Workerartifacts in a release or distribution. While conceptually immutable, parts of
36*9e94795aSAndroid Build Coastguard Workerthe graph may be loaded or evaluated lazily.
37*9e94795aSAndroid Build Coastguard Worker
38*9e94795aSAndroid Build Coastguard WorkerConceptually, the graph itself will always be a directed acyclic graph. One
39*9e94795aSAndroid Build Coastguard Workerrepresentation is a set of directed edges. Another is a set of nodes with
40*9e94795aSAndroid Build Coastguard Workerdirected edges to their dependencies.
41*9e94795aSAndroid Build Coastguard Worker
42*9e94795aSAndroid Build Coastguard WorkerThe edges have annotations, which can distinguish between build tools, runtime
43*9e94795aSAndroid Build Coastguard Workerdependencies, and dependencies like 'contains' that make a derivative work.
44*9e94795aSAndroid Build Coastguard Worker
45*9e94795aSAndroid Build Coastguard Worker### LicenseCondition
46*9e94795aSAndroid Build Coastguard Worker
47*9e94795aSAndroid Build Coastguard WorkerA LicenseCondition is an immutable tuple pairing a condition name with an
48*9e94795aSAndroid Build Coastguard Workeroriginating target. e.g. Per current policy, a static library licensed under an
49*9e94795aSAndroid Build Coastguard WorkerMIT license would pair a "notice" condition with the static library target, and
50*9e94795aSAndroid Build Coastguard Workera dynamic license licensed under GPL would pair a "restricted" condition with
51*9e94795aSAndroid Build Coastguard Workerthe dynamic library target.
52*9e94795aSAndroid Build Coastguard Worker
53*9e94795aSAndroid Build Coastguard Worker### ResolutionSet
54*9e94795aSAndroid Build Coastguard Worker
55*9e94795aSAndroid Build Coastguard WorkerA ResolutionSet is an immutable set of `AttachesTo`, `ActsOn`, `Resolves`
56*9e94795aSAndroid Build Coastguard Workertuples describing how license conditions apply to targets.
57*9e94795aSAndroid Build Coastguard Worker
58*9e94795aSAndroid Build Coastguard Worker`AttachesTo` is the trigger for acting. Distribution of the target invokes
59*9e94795aSAndroid Build Coastguard Workerthe policy.
60*9e94795aSAndroid Build Coastguard Worker
61*9e94795aSAndroid Build Coastguard Worker`ActsOn` is the target to share, give notice for, hide etc.
62*9e94795aSAndroid Build Coastguard Worker
63*9e94795aSAndroid Build Coastguard Worker`Resolves` is the set of conditions that the action resolves.
64*9e94795aSAndroid Build Coastguard Worker
65*9e94795aSAndroid Build Coastguard WorkerFor most condition types, `ActsOn` will be the target where the condition
66*9e94795aSAndroid Build Coastguard Workeroriginated. For example, a notice condition policy means attribution or notice
67*9e94795aSAndroid Build Coastguard Workermust be given for the target where the condition originates. Likewise, a
68*9e94795aSAndroid Build Coastguard Workerproprietary condition policy means the privacy of the target where the
69*9e94795aSAndroid Build Coastguard Workercondition originates must be respected. i.e. The thing acted on is the origin.
70*9e94795aSAndroid Build Coastguard Worker
71*9e94795aSAndroid Build Coastguard WorkerRestricted conditions are different. The infectious nature of restricted often
72*9e94795aSAndroid Build Coastguard Workermeans sharing code that is not the target where the restricted condition
73*9e94795aSAndroid Build Coastguard Workeroriginates. Linking an MIT library to a GPL library implies a policy to share
74*9e94795aSAndroid Build Coastguard Workerthe MIT library despite the MIT license having no source sharing requirement.
75*9e94795aSAndroid Build Coastguard Worker
76*9e94795aSAndroid Build Coastguard WorkerIn this case, one or more resolution tuples will have the MIT license module in
77*9e94795aSAndroid Build Coastguard Worker`ActsOn` and the restricted condition originating at the GPL library module in
78*9e94795aSAndroid Build Coastguard Worker`Resolves`. These tuples will `AttachTo` every target that depends on the GPL
79*9e94795aSAndroid Build Coastguard Workerlibrary because shipping any of those targets trigger the policy to share the
80*9e94795aSAndroid Build Coastguard Workercode.
81*9e94795aSAndroid Build Coastguard Worker
82*9e94795aSAndroid Build Coastguard Worker## Processes
83*9e94795aSAndroid Build Coastguard Worker
84*9e94795aSAndroid Build Coastguard Worker### ReadLicenseGraph
85*9e94795aSAndroid Build Coastguard Worker
86*9e94795aSAndroid Build Coastguard WorkerThe principal means to ingest license metadata. Given the distribution targets,
87*9e94795aSAndroid Build Coastguard WorkerReadLicenseGraph populates the LicenseGraph for those root targets.
88*9e94795aSAndroid Build Coastguard Worker
89*9e94795aSAndroid Build Coastguard Worker### NoticeIndex.IndexLicenseTexts
90*9e94795aSAndroid Build Coastguard Worker
91*9e94795aSAndroid Build Coastguard WorkerIndexLicenseTexts reads, deduplicates and caches license texts for notice
92*9e94795aSAndroid Build Coastguard Workerfiles. Also reads and caches project metadata for deriving library names.
93*9e94795aSAndroid Build Coastguard Worker
94*9e94795aSAndroid Build Coastguard WorkerThe algorithm for deriving library names has not been dictated by OSPO policy,
95*9e94795aSAndroid Build Coastguard Workerbut reflects a pragmatic attempt to comply with Android policy regarding
96*9e94795aSAndroid Build Coastguard Workerunreleased product names, proprietary partner names etc.
97*9e94795aSAndroid Build Coastguard Worker
98*9e94795aSAndroid Build Coastguard Worker### projectmetadata.Index.MetadataForProjects
99*9e94795aSAndroid Build Coastguard Worker
100*9e94795aSAndroid Build Coastguard WorkerMetadataForProjects reads, deduplicates and caches project METADATA files used
101*9e94795aSAndroid Build Coastguard Workerfor notice library names, and various properties appearing in SBOMs.
102