xref: /aosp_15_r20/external/pdfium/CONTRIBUTING.md (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1*3ac0a46fSAndroid Build Coastguard Worker# CONTRIBUTING
2*3ac0a46fSAndroid Build Coastguard WorkerIn general, we follow the
3*3ac0a46fSAndroid Build Coastguard Worker[Chromium Contributing](https://chromium.googlesource.com/chromium/src/+/main/docs/contributing.md)
4*3ac0a46fSAndroid Build Coastguard Workerguidelines in PDFium. The code review process, and the build tools are all very
5*3ac0a46fSAndroid Build Coastguard Workersimilar to Chromium. The PDFium
6*3ac0a46fSAndroid Build Coastguard Worker[README](https://pdfium.googlesource.com/pdfium/+/refs/heads/main/README.md)
7*3ac0a46fSAndroid Build Coastguard Workeroutlines specific build and test information for PDFium.
8*3ac0a46fSAndroid Build Coastguard Worker
9*3ac0a46fSAndroid Build Coastguard WorkerThis document focuses on how the PDFium project operates and how we’d like it
10*3ac0a46fSAndroid Build Coastguard Workerto operate in the future. This is a living document, please file bugs if you
11*3ac0a46fSAndroid Build Coastguard Workerthink there are changes/updates which could be put in place to make it easier
12*3ac0a46fSAndroid Build Coastguard Workerto contribute to PDFium.
13*3ac0a46fSAndroid Build Coastguard Worker
14*3ac0a46fSAndroid Build Coastguard Worker## Communication
15*3ac0a46fSAndroid Build Coastguard WorkerWhen writing a new feature or fixing an existing bug, get a second opinion
16*3ac0a46fSAndroid Build Coastguard Workerbefore investing effort in coding. Coordinating up front makes it much easier
17*3ac0a46fSAndroid Build Coastguard Workerto avoid frustration later on.
18*3ac0a46fSAndroid Build Coastguard Worker
19*3ac0a46fSAndroid Build Coastguard WorkerIf it‘s a new feature, or updating existing code, first propose it to the
20*3ac0a46fSAndroid Build Coastguard Worker[mailing list](https://groups.google.com/forum/#!forum/pdfium).
21*3ac0a46fSAndroid Build Coastguard Worker
22*3ac0a46fSAndroid Build Coastguard Worker * If a change needs further context outside the CL, it should be tracked in
23*3ac0a46fSAndroid Build Coastguard Worker   the [bug system](https://bugs.chromium.org/p/pdfium). Bugs are the right
24*3ac0a46fSAndroid Build Coastguard Worker   place for long histories, discussion and debate, attaching screenshots, and
25*3ac0a46fSAndroid Build Coastguard Worker   linking to other associated bugs. Bugs are unnecessary for changes isolated
26*3ac0a46fSAndroid Build Coastguard Worker   enough to not need any of these.
27*3ac0a46fSAndroid Build Coastguard Worker * If the work being implemented is especially complex or large a design
28*3ac0a46fSAndroid Build Coastguard Worker   document may be warranted. The document should be linked to the filled bug
29*3ac0a46fSAndroid Build Coastguard Worker   and be set to publicly viewable.
30*3ac0a46fSAndroid Build Coastguard Worker * If there isn't a bug and there should be one, please file a new bug.
31*3ac0a46fSAndroid Build Coastguard Worker * Just because there is a bug in the bug system doesn't necessarily mean that
32*3ac0a46fSAndroid Build Coastguard Worker   a patch will be accepted.
33*3ac0a46fSAndroid Build Coastguard Worker
34*3ac0a46fSAndroid Build Coastguard Worker## Public APIs
35*3ac0a46fSAndroid Build Coastguard WorkerThe public API of PDFium has grown over time. There are multiple mechanisms in
36*3ac0a46fSAndroid Build Coastguard Workerplace to support this growth from the stability requirements to the versioning
37*3ac0a46fSAndroid Build Coastguard Workerfields. Along with those there are several other factors to be considered when
38*3ac0a46fSAndroid Build Coastguard Workeradding public APIs.
39*3ac0a46fSAndroid Build Coastguard Worker
40*3ac0a46fSAndroid Build Coastguard Worker * _Consistency_. We try to keep the APIs consistent with each other, this
41*3ac0a46fSAndroid Build Coastguard Worker   includes things like naming, parameter ordering and how parameters are
42*3ac0a46fSAndroid Build Coastguard Worker   handled.
43*3ac0a46fSAndroid Build Coastguard Worker * _Generality_. PDFium is used in several places outside the browser. This
44*3ac0a46fSAndroid Build Coastguard Worker   could be server side, or in user applications. APIs should be designed to
45*3ac0a46fSAndroid Build Coastguard Worker   work in the general case, or such that they can be expanded to the general
46*3ac0a46fSAndroid Build Coastguard Worker   case if possible.
47*3ac0a46fSAndroid Build Coastguard Worker * _Documentation_. All public APIs should be documented to include information
48*3ac0a46fSAndroid Build Coastguard Worker   on ownership of passed parameters, valid values being provided, error
49*3ac0a46fSAndroid Build Coastguard Worker   conditions and return values.
50*3ac0a46fSAndroid Build Coastguard Worker * _Differentiate error conditions_. If at all possible, it should be possible
51*3ac0a46fSAndroid Build Coastguard Worker   to tell the difference between a valid failure and an error.
52*3ac0a46fSAndroid Build Coastguard Worker * _Avoid global state_. APIs should receive the objects to be operated on
53*3ac0a46fSAndroid Build Coastguard Worker   instead of assuming they exist in a global context.
54*3ac0a46fSAndroid Build Coastguard Worker
55*3ac0a46fSAndroid Build Coastguard Worker### Stability
56*3ac0a46fSAndroid Build Coastguard WorkerThere are a lot of consumers of PDFium outside of Chromium. These include
57*3ac0a46fSAndroid Build Coastguard WorkerLibreOffice, Android and offline conversion tooling. As such, a lot of care is
58*3ac0a46fSAndroid Build Coastguard Workertaken around the code in the
59*3ac0a46fSAndroid Build Coastguard Worker[public](https://pdfium.googlesource.com/pdfium/+/refs/heads/main/public/)
60*3ac0a46fSAndroid Build Coastguard Workerfolder. When planning on changing the public API, the change should be preceded
61*3ac0a46fSAndroid Build Coastguard Workerby a bug being created and an email to the mailing list to gather feedback from
62*3ac0a46fSAndroid Build Coastguard Workerother PDFium embedders.
63*3ac0a46fSAndroid Build Coastguard Worker
64*3ac0a46fSAndroid Build Coastguard WorkerThe only stability guarantees that PDFium provides are around the APIs in the
65*3ac0a46fSAndroid Build Coastguard Workerpublic folder. Any other interface in the system can be changed without notice.
66*3ac0a46fSAndroid Build Coastguard WorkerIf there are features needed which are not exposed through the public headers
67*3ac0a46fSAndroid Build Coastguard Workeryou'll need to file a bug to get it added to the public APIs.
68*3ac0a46fSAndroid Build Coastguard Worker
69*3ac0a46fSAndroid Build Coastguard Worker#### Experimental
70*3ac0a46fSAndroid Build Coastguard WorkerAll APIs start as Experimental. The experimental status is a documentation tag
71*3ac0a46fSAndroid Build Coastguard Workerwhich is added to the API, the first line of the API documentation should be
72*3ac0a46fSAndroid Build Coastguard Worker`// Experimental API.`
73*3ac0a46fSAndroid Build Coastguard Worker
74*3ac0a46fSAndroid Build Coastguard WorkerExperimental APIs may be changed or removed entirely without formal notice to
75*3ac0a46fSAndroid Build Coastguard Workerthe community.
76*3ac0a46fSAndroid Build Coastguard Worker
77*3ac0a46fSAndroid Build Coastguard Worker#### Stable
78*3ac0a46fSAndroid Build Coastguard WorkerAPIs eventually graduate to stable. This is done by removing the
79*3ac0a46fSAndroid Build Coastguard Worker`// Experimental API.` marker in the documentation. We endeavor to not change
80*3ac0a46fSAndroid Build Coastguard Workerstable APIs without notice to the community.
81*3ac0a46fSAndroid Build Coastguard Worker
82*3ac0a46fSAndroid Build Coastguard WorkerNOTE, the process of migrating from experimental to stable isn’t well defined
83*3ac0a46fSAndroid Build Coastguard Workerat this point. We have experimental APIs which have been that way for multiple
84*3ac0a46fSAndroid Build Coastguard Workeryears. We should work to better define how this transition happens.
85*3ac0a46fSAndroid Build Coastguard Worker
86*3ac0a46fSAndroid Build Coastguard Worker#### Deprecated
87*3ac0a46fSAndroid Build Coastguard WorkerIf the API is retired, it is marked as deprecated and will eventually be removed.
88*3ac0a46fSAndroid Build Coastguard WorkerAPI deprecation should, ideally, come with a better replacement API and have a
89*3ac0a46fSAndroid Build Coastguard Worker6-12 months deprecation period.  The pending removal should be recorded in the
90*3ac0a46fSAndroid Build Coastguard Workerdocumentation comment for the API and should also be recorded in the README with
91*3ac0a46fSAndroid Build Coastguard Workerthe target removal timeframe. All deprecations should have an associated bug
92*3ac0a46fSAndroid Build Coastguard Workerattached to them.
93*3ac0a46fSAndroid Build Coastguard Worker
94*3ac0a46fSAndroid Build Coastguard Worker### Versioning
95*3ac0a46fSAndroid Build Coastguard WorkerIn order to allow the public API to expand there are `version` fields in some
96*3ac0a46fSAndroid Build Coastguard Workerstructures. When the versioned structures are expanded those version fields
97*3ac0a46fSAndroid Build Coastguard Workerneed to be incremented to cover the new additions. The code then needs to guard
98*3ac0a46fSAndroid Build Coastguard Workeragainst the structure being received having the required version number in
99*3ac0a46fSAndroid Build Coastguard Workerorder to validate the new additions are available.
100*3ac0a46fSAndroid Build Coastguard Worker
101*3ac0a46fSAndroid Build Coastguard Worker## Trybot Access
102*3ac0a46fSAndroid Build Coastguard WorkerChanges must pass the try bots before they are merged into the repo. For your
103*3ac0a46fSAndroid Build Coastguard Workerfirst few CLs the try bots will need to be triggered by a committer. After
104*3ac0a46fSAndroid Build Coastguard Workeryou've submitted 2-3 CLs you can request try bot access by emailing one of the
105*3ac0a46fSAndroid Build Coastguard WorkerOWNERS and requesting try bot access. This will allow you to trigger the bots
106*3ac0a46fSAndroid Build Coastguard Workeron your own changes without needing a committer.
107*3ac0a46fSAndroid Build Coastguard Worker
108*3ac0a46fSAndroid Build Coastguard Worker## Committers
109*3ac0a46fSAndroid Build Coastguard WorkerAll changes committed to PDFium must be reviewed by a committer. Committers
110*3ac0a46fSAndroid Build Coastguard Workerhave done significant work in the PDFium code base and have a good overall
111*3ac0a46fSAndroid Build Coastguard Workerunderstanding of the system.
112*3ac0a46fSAndroid Build Coastguard Worker
113*3ac0a46fSAndroid Build Coastguard WorkerContributors can become committers as they exhibit a strong understanding
114*3ac0a46fSAndroid Build Coastguard Workerof the code base. There is a general requirement for ~10 non-trivial CLs to be
115*3ac0a46fSAndroid Build Coastguard Workerwritten by the contributor before being considered for committership. The
116*3ac0a46fSAndroid Build Coastguard Workercontributor is then nominated by an existing committer and if the nomination is
117*3ac0a46fSAndroid Build Coastguard Workeraccepted by two other committers they receive committer status.
118*3ac0a46fSAndroid Build Coastguard Worker
119*3ac0a46fSAndroid Build Coastguard Worker## OWNERS
120*3ac0a46fSAndroid Build Coastguard WorkerThe OWNERS files list long time committers to the project and have a broad
121*3ac0a46fSAndroid Build Coastguard Workerunderstanding of the code base and how the various pieces interact. In the
122*3ac0a46fSAndroid Build Coastguard Workerevent of a code review stalling with a committer, the OWNERS are the first line
123*3ac0a46fSAndroid Build Coastguard Workerof escalation. The OWNERS files inherit up the tree, so an OWNER in a top-level
124*3ac0a46fSAndroid Build Coastguard Workerfolder has OWNERS in the folders subdirectories.
125*3ac0a46fSAndroid Build Coastguard Worker
126*3ac0a46fSAndroid Build Coastguard WorkerThere are a limited number of OWNERS files in PDFium at this time due to the
127*3ac0a46fSAndroid Build Coastguard Workerinherent interconnectedness of the code. We are hoping to expand the number of
128*3ac0a46fSAndroid Build Coastguard WorkerOWNERS files to make them more targeted as the code quality progresses.
129*3ac0a46fSAndroid Build Coastguard Worker
130*3ac0a46fSAndroid Build Coastguard WorkerCommitters can be added to OWNERS files when they exhibit a strong
131*3ac0a46fSAndroid Build Coastguard Workerunderstanding of the PDFium code base. This typically involves a combination of
132*3ac0a46fSAndroid Build Coastguard Workersignificant CLs, code review on other contributor CLs, and working with the
133*3ac0a46fSAndroid Build Coastguard Workerother OWNERs to work through design and development considerations for the code.
134*3ac0a46fSAndroid Build Coastguard WorkerAn OWNER must be committed to upholding the principles for the long term health
135*3ac0a46fSAndroid Build Coastguard Workerof the project, take on a responsibility for reviewing future work, and
136*3ac0a46fSAndroid Build Coastguard Workermentor new contributors. Once you are a committer, you should feel free to reach
137*3ac0a46fSAndroid Build Coastguard Workerout to the OWNERS who have reviewed your patches to ask what else they’d like to
138*3ac0a46fSAndroid Build Coastguard Workersee from you to be comfortable nominating you as an OWNER. Once nominated,
139*3ac0a46fSAndroid Build Coastguard WorkerOWNERS are added or removed by rough consensus of the existing OWNERS.
140*3ac0a46fSAndroid Build Coastguard Worker
141*3ac0a46fSAndroid Build Coastguard Worker## Escalations
142*3ac0a46fSAndroid Build Coastguard WorkerThere are times when reviews stall due to differences between reviewers,
143*3ac0a46fSAndroid Build Coastguard Workerdevelopers and OWNERS. If this happens, please escalate the situation to one of
144*3ac0a46fSAndroid Build Coastguard Workerthe people in the top-level OWNERS file (or another of the owners if already
145*3ac0a46fSAndroid Build Coastguard Workerdiscussing with a top-level owner). If the disagreement has moved up through
146*3ac0a46fSAndroid Build Coastguard Workerall the OWNERS files in the PDFium repo, the escalation should then proceed to
147*3ac0a46fSAndroid Build Coastguard Workerthe Chromium
148*3ac0a46fSAndroid Build Coastguard Worker[ATL_OWNERS](https://chromium.googlesource.com/chromium/src/+/refs/heads/main/ATL_OWNERS)
149*3ac0a46fSAndroid Build Coastguard Workeras the final deciders.
150*3ac0a46fSAndroid Build Coastguard Worker
151*3ac0a46fSAndroid Build Coastguard WorkerThe
152*3ac0a46fSAndroid Build Coastguard Worker[Standard of Code Review](https://google.github.io/eng-practices/review/reviewer/standard.html)
153*3ac0a46fSAndroid Build Coastguard Workerdocument has some good guidance on resolving conflicts during code review.
154*3ac0a46fSAndroid Build Coastguard Worker
155*3ac0a46fSAndroid Build Coastguard Worker## CLA
156*3ac0a46fSAndroid Build Coastguard WorkerAll contributors must complete the Google contributor license agreement. For
157*3ac0a46fSAndroid Build Coastguard Workerindividual contributors, please complete the
158*3ac0a46fSAndroid Build Coastguard Worker[Individual Contributor License Agreement](https://cla.developers.google.com/about/google-individual?csw=1)
159*3ac0a46fSAndroid Build Coastguard Workeronline. Corporate contributors must fill out the
160*3ac0a46fSAndroid Build Coastguard Worker[Corporate Contributor License Agreement](https://cla.developers.google.com/about/google-corporate?csw=1)
161*3ac0a46fSAndroid Build Coastguard Workerand send it to us as described on that page.
162*3ac0a46fSAndroid Build Coastguard Worker
163*3ac0a46fSAndroid Build Coastguard WorkerYour first CL should add yourself to the
164*3ac0a46fSAndroid Build Coastguard Worker[AUTHORS](https://pdfium.googlesource.com/pdfium/+/refs/heads/main/AUTHORS)
165*3ac0a46fSAndroid Build Coastguard Workerfile (unless you’re covered by one of the blanket entries).
166*3ac0a46fSAndroid Build Coastguard Worker
167*3ac0a46fSAndroid Build Coastguard Worker### External contributor checklist for reviewers
168*3ac0a46fSAndroid Build Coastguard WorkerBefore LGTMing a change, ensure that the contribution can be accepted:
169*3ac0a46fSAndroid Build Coastguard Worker * Definition: The "author" is the email address that owns the code review
170*3ac0a46fSAndroid Build Coastguard Worker   request on
171*3ac0a46fSAndroid Build Coastguard Worker   [https://pdfium-review.googlesource.com](https://pdfium-review.googlesource.com/)
172*3ac0a46fSAndroid Build Coastguard Worker * Ensure the author is already listed in
173*3ac0a46fSAndroid Build Coastguard Worker   [AUTHORS](https://pdfium.googlesource.com/pdfium/+/refs/heads/main/AUTHORS).
174*3ac0a46fSAndroid Build Coastguard Worker   In some cases, the author's company might have a wildcard rule
175*3ac0a46fSAndroid Build Coastguard Worker   (e.g. \*@google.com).
176*3ac0a46fSAndroid Build Coastguard Worker * If the author or their company is not listed, the CL should include a new
177*3ac0a46fSAndroid Build Coastguard Worker   AUTHORS entry.
178*3ac0a46fSAndroid Build Coastguard Worker   * Ensure the new entry is reviewed by a reviewer who works for Google.
179*3ac0a46fSAndroid Build Coastguard Worker   * Contributor License Agreement can be verified by Googlers at
180*3ac0a46fSAndroid Build Coastguard Worker     [http://go/cla](http://go/cla)
181*3ac0a46fSAndroid Build Coastguard Worker   * If there is a corporate CLA for the author‘s company, it must list the
182*3ac0a46fSAndroid Build Coastguard Worker     person explicitly (or the list of authorized contributors must say
183*3ac0a46fSAndroid Build Coastguard Worker     something like "All employees"). If the author is not on their company’s
184*3ac0a46fSAndroid Build Coastguard Worker     roster, do not accept the change.
185*3ac0a46fSAndroid Build Coastguard Worker
186*3ac0a46fSAndroid Build Coastguard Worker## Legacy Code
187*3ac0a46fSAndroid Build Coastguard WorkerThe PDFium code base has been around in one form or another for a long time. As
188*3ac0a46fSAndroid Build Coastguard Workersuch, there is a lot of legacy hidden in the existing code. There are surprising
189*3ac0a46fSAndroid Build Coastguard Workerinteractions and untested corners of the code. We are actively working on
190*3ac0a46fSAndroid Build Coastguard Workerincreasing code coverage on the existing code, and especially welcome additions
191*3ac0a46fSAndroid Build Coastguard Workerwhich move the coverage upwards. All new code should come with tests (either
192*3ac0a46fSAndroid Build Coastguard Workerunit tests or integration tests depending on the feature).
193*3ac0a46fSAndroid Build Coastguard Worker
194*3ac0a46fSAndroid Build Coastguard WorkerAs part of this legacy nature, there is a good chance the code you’re working
195*3ac0a46fSAndroid Build Coastguard Workerwith wasn’t designed to do what you need it to do. There are often refactorings
196*3ac0a46fSAndroid Build Coastguard Workerand bug fixes that end up happening along with feature development. Those
197*3ac0a46fSAndroid Build Coastguard Workerfixes/refactorings should be pulled out to their own changes with the
198*3ac0a46fSAndroid Build Coastguard Workerappropriate tests. This will make reviews a lot easier as, currently, it can be
199*3ac0a46fSAndroid Build Coastguard Workerhard to tell if there are far reaching effects of a given change.
200*3ac0a46fSAndroid Build Coastguard Worker
201*3ac0a46fSAndroid Build Coastguard WorkerThere is a lot of existing technical debt that is being paid down in PDFium,
202*3ac0a46fSAndroid Build Coastguard Workeranything we can do here to make future development easier is a great benefit to
203*3ac0a46fSAndroid Build Coastguard Workerthe project. This debt means means code reviews can take a bit longer if
204*3ac0a46fSAndroid Build Coastguard Workerresearch is needed to determine how a feature change will interact with the
205*3ac0a46fSAndroid Build Coastguard Workerrest of the system.
206