blob: 145b0140359476964576a38ef6a600744abe6060 [file] [log] [blame] [view]
Daniel Cheng86135f32019-02-27 07:10:381# Contributing to Chromium
2
3This page assumes a working Chromium [checkout and build][checkout-and-build].
4Note that a full Chromium checkout includes external repositories with their
5own workflows for contributing, such as [v8][v8-dev-guide] and
6[Skia][skia-dev-guide]. Similarly, ChromiumOS, which includes Chromium as a
7subrepository, has its own [development workflow][cros-dev-guide].
8
9[TOC]
10
11## Related resources
12
13- [Life of a Chromium Developer][life-of-a-chromium-developer], which is mostly
14 up-to-date.
Toby Huang5105f812019-08-08 23:47:5715- [Tutorial][noms-tutorial] by committer emeritus [email protected].
16- [Commit Checklist][commit-checklist], a useful checklist to go through before
17 submitting each CL on Gerrit.
Daniel Cheng86135f32019-02-27 07:10:3818
19## Communicate
20
21When writing a new feature or fixing an existing bug, get a second opinion
22before going too far. If it's a new feature idea, propose it to the appropriate
23[discussion group][discussion-groups]. If it's in the existing code base, talk
24to some of the folks in the "OWNERS" file (see [code review
25policies][code-reviews] for more) for the code being changed.
26
27- If a change needs further context outside the CL, it should be tracked in the
28 [bug system][crbug]. Bugs are the right place for long histories, discussion
29 and debate, attaching screenshots, and linking to other associated bugs. Bugs
30 are unnecessary for changes isolated enough to need none of these.
31- If there isn't a bug and there should be one, please [file a new
32 bug][crbug-new].
33- Just because there is a bug in the bug system doesn't necessarily mean that a
34 patch will be accepted.
35
John Abd-El-Malek27e1cf02019-12-18 17:35:1836## Design Documents
37Any nontrivial technical effort that will significantly impact Chromium should
38have a design doc ([template][design-doc-template]). Specifically, we require
39design docs in the following cases:
40- When writing code that will have a large impact on Chromium as a whole, e.g.
41 when you are changing code in Chromium's critical path (page loading,
42 rendering).
43- When beginning a large technical undertaking that should be documented for
44 historical reasons (>1 person-month of work can be used as a general guideline).
45
46Send public design docs to
47[[email protected]][chromium-design-docs]. Google internal Chrome
48design docs should follow the process at
49[go/chrome-dd-review-process][chrome-dd-review-process].
50
Daniel Cheng86135f32019-02-27 07:10:3851## Legal stuff
52
53All contributors must complete the contributor license agreement. For
54individual contributors, please complete the [Individual Contributor License
55Agreement][individual-cla] online. Corporate contributors must fill out the
56[Corporate Contributor License Agreement][corporate-cla] and send it to us as
57described on that page.
58
59### First-time contributors
60
61Add your (or your organization's) name and contact info to the AUTHORS file for
62[Chromium][cr-authors] or [Chromium OS][cros-authors]. Please include this as
63part of your first patch and not as a separate standalone patch.
64
65### External contributor checklist for reviewers
66
67Before LGTMing a change from a non-chromium.org address, ensure that the
68contribution can be accepted:
69
70- Definition: The "author" is the email address that owns the code review
71 request on <https://chromium-review.googlesource.com>
72- Ensure the author is already listed in [AUTHORS][cr-authors]. In some cases, the
73 author's company might have a wildcard rule (e.g. \*@google.com).
74- If the author or their company is not listed, the CL should include a new
75 AUTHORS entry.
76 - Ensure the new entry is reviewed by a reviewer who works for Google.
77 - If there is a corporate CLA for the author's company, it must list the
78 person explicitly (or the list of authorized contributors must say
79 something like "All employees"). If the author is not on their company's
80 roster, do not accept the change.
81
82## Initial git setup
83
841. Visit <https://chromium-review.googlesource.com/new-password> and follow the
85 on-screen instructions to get credentials for uploading changes.
862. Tell git about your name, email and some other settings.
87 ```
88 git config --global user.name "My Name"
89 git config --global user.email "[email protected]"
90 git config --global core.autocrlf false
91 git config --global core.filemode false
92 git config --local gerrit.host true
93 # Uncomment this if you want your pull commands to always rebase.
94 # git config --global branch.autosetuprebase always
95 # Uncomment if you want new branches to track the current branch.
96 # git config --global branch.autosetupmerge always
97 ```
Francois Marier197916f2020-01-16 02:23:02983. Visit <https://chromium-review.googlesource.com/settings/> to ensure that
99 your preferred email is set to the same one you use in your git
100 configuration.
Daniel Cheng86135f32019-02-27 07:10:38101
102## Creating a change
103
104First, create a new branch for your change in git. Here, we create a branch
105called `mychange` (use whatever name you want here), with `origin/master` as
106the upstream branch.
107
108```
109git checkout -b mychange -t origin/master
110```
111
112Write and test your change.
113
114- Conform to the [style guide][cr-styleguide].
115- Include tests.
116- Patches should be a reasonable size to review. Review time often increases
Joshua Berenhaus98d2fbc2020-01-07 18:50:42117 exponentially with patch size.
Daniel Cheng86135f32019-02-27 07:10:38118
119Commit your change locally in git:
120
121```
122git commit -a
123```
124
125If you are not familiar with `git`, GitHub's [resources to learn
126git][github-tutorial] is useful for the basics. However, keep in mind that the
127Chromium workflow is not the same as the GitHub pull request workflow.
128
129## Uploading a change for review
130
Toby Huang5105f812019-08-08 23:47:57131Note: go through the [commit checklist][commit-checklist] for Chromium before
132uploading a change for review.
133
Daniel Cheng86135f32019-02-27 07:10:38134Chromium uses a Gerrit instance hosted at
135<https://chromium-review.googlesource.com> for code reviews. In order to upload
136your local change to Gerrit, use `git-cl` from
137[depot\_tools][depot-tools-setup] to create a new Gerrit change, based on the
138diff between the current branch and its upstream branch:
139
140```
141git cl upload
142```
143
144This will open a text editor to create a description for the new change. This
145description will be used as the commit message when the change is landed in the
146Chromium tree. Descriptions should be formatted as follows:
147
148```
149Summary of change (one line)
150
151Longer description of change addressing as appropriate: why the change
152is made, context if it is part of many changes, description of previous
153behavior and newly introduced differences, etc.
154
155Long lines should be wrapped to 72 columns for easier log message
156viewing in terminals.
157
158Bug: 123456
159```
160
161A short subject and a blank line after the subject are crucial: `git` uses this
162as a heuristic for tools like `git log --oneline`. Use the bug number from the
163[issue tracker][crbug] (see more on [CL footer syntax][cl-footer-syntax]). Also
164see [How to Write a Git Commit Message][good-git-commit-message], which has more
165in-depth tips for writing a good commit description.
166
167### Chromium-specific description tips
168
169- Links to previous CLs should be formatted as `https://crrev.com/c/NUMBER`,
170 which forwards to [Gitiles][cr-gitiles], rather than linking to the review at
171 <https://chromium-review.googlesource.com>.
172
173- If there are instructions for testers to verify the change is correct,
174 include them with the `Test:` tag:
175
176 ```
177 Test: Load example.com/page.html and click the foo-button; see
178 crbug.com/123456 for more details.
179 ```
180
181After saving the change description, `git-cl` runs some presubmit scripts to
182check for common errors. If everything passes, `git-cl` will print something
183like this:
184
185```
186remote: SUCCESS
187remote:
188remote: New Changes:
189remote: https://chromium-review.googlesource.com/c/chromium/src/+/1485699 Use base::TimeDelta::FromTimeSpec helper in more places. [WIP]
190```
191
192Additional flags can be used to specify reviewers, bugs fixed by the change, et
193cetera:
194
195```
196git cl upload -r [email protected],[email protected] -b 123456
197```
198
199See `git cl help upload` for a full list of flags.
200
201## Code review
202
203Code reviews are covered in more detail on the [code review
204policies][code-reviews] page.
205
206### Finding a reviewer
207
208Ideally, the reviewer is someone who is familiar with the area of code in
209question. If you're not sure who that should be, check with anyone in the
210nearest ancestor OWNERS file.
211
212- Anybody can review code, but there must be at least one owner for each
213 affected directory.
214- If there are multiple reviewers, make it clear what each reviewer is expected
215 to review. Otherwise, people might assume their input is not required or
216 waste time with redundant reviews.
217- `git cl owners` automatically suggests reviewers based on the OWNERS files.
218
219### Requesting review
220
221Open the change on [the web][crrev]. If you can't find the link, running `git
222cl issue` will display the review URL for the current branch. Alternatively,
223visit <https://chromium-review.googlesource.com> and look in the "Outgoing
224Reviews" section.
225
226Reviewers expect to review code that compiles and passes tests. If you have
227access, now is a good time to run your change through the [automated
228tests](#running-automated-tests).
229
230Click **Add Reviewers** in the left column (if you don't see this link, make
231sure you are logged in). In the **Reviewers** field, enter a comma-separated
232list of the reviewers you picked.
233
234In the same dialog, you can include an optional message to your reviewers. This
235space can be used for specific questions or instructions. Once you're done,
236make sure to click **Send**, which notifies the requested reviewers that they
237should review your change.
238
239**IMPORTANT: UNTIL YOU SEND THE REVIEW REQUEST, NO ONE WILL LOOK AT THE REVIEW**
240
241### Review process
242
243All changes must be reviewed (see [code review policies][code-reviews]).
244
245You should get a response within **one** business day; re-ping your reviewers
246if you do not.
247
248To upload new patch sets that address comments from the reviewers, simply
249commit more changes to your local branch and run `git cl upload` again.
250
251### Approval
252
253When the reviewer is happy with the change, they will set the "Code-Review +1"
254label. Owners of all affected files must approve before a change can be
255committed. See: [code review policies: owners][code-reviews-owners].
256
257## Running automated tests
258
259Before being submitted, a change must pass the commit queue (CQ). The commit
260queue is an automated system which sends a patch to multiple try bots running
261different platforms: each try bot compiles Chromium with the patch and ensures
262the tests still pass on that platform.
263
264To trigger this process, click **CQ Dry Run** in the upper right corner of the
265code review tool. Note that this is equivalent to setting the "Commit-Queue +1"
266label. Anyone can set this label; however, the CQ will not process the patch
267unless the person setting the label has [try job access][try-job-access].
268
269If you don't have try job access and:
270
271- you have an @chromium.org email address, request access for yourself.
272- you have contributed a few patches, ask a reviewer to nominate you for access.
273- neither of the above is true, request that a reviewer run try jobs for you in
274 the code review request message.
275
276The status of the latest try job for a given patchset is visible just below the
277list of changed files. Each bot has its own bubble, using one of the following
278colors to indicate its status:
279
280- Gray: the bot has not started processing the patch yet.
281- Yellow: the run is in progress. Check back later!
282- Purple: the trybot encountered an exception while processing the patch.
283 Usually, this is not the fault of the patch. Try clicking **CQ Dry Run**
284 again.
285- Red: tests failed. Click on the failed bot to see what tests failed and why.
286- Green: the run passed!
287
288## Committing
289
290Changes should generally be committed via the [commit queue][commit-queue].
291This is done by clicking **Submit to CQ** in the upper right corner, or setting
292the "Commit-Queue +2" label on the change. The commit queue will then
293send the patch to the try bots. If all try bots return green, the change will
294automatically be committed. Yay!
295
296Sometimes a test might be flaky. If you have an isolated failure that appears
297unrelated to your change, try sending the change to the commit queue again.
298
299Alternatively, a developer with commit access can [directly
300commit][direct-commit] a change, bypassing the commit queue. This should only
301be used in emergencies because it will bypass all the safety nets.
302
Darin Fisher0e196ee82019-09-06 22:39:12303## Code guidelines
304
305In addition to the adhering to the [styleguide][cr-styleguide], the following
306general rules of thumb can be helpful in navigating how to structure changes:
307
Darin Fisherf061fb12019-11-15 23:46:13308- **Code in the Chromium project should be in service of other code in the
309 Chromium project.** This is important so developers can understand the
310 constraints informing a design decision. Those constraints should be apparent
311 from the scope of code within the boundary of the project and its various
312 repositories. In other words, for each line of code, you should be able to
313 find a product in the Chromium repositories that depends on that line of code
314 or else the line of code should be removed.
Darin Fisher0e196ee82019-09-06 22:39:12315
316- **Code should only be moved to a central location (e.g., //base) when
317 multiple consumers would benefit.** We should resist the temptation to
318 build overly generic common libraries as that can lead to code bloat and
319 unnecessary complexity in common code.
320
321- **The code likely wasn't designed for everything we are trying to do with it
322 now.** Take time to refactor existing code to make sure the new feature or
323 subcomponent you are developing fits properly within the system. Technical
324 debt is easy to accumulate and is everyone's responsibility to avoid.
325
326- **Common code is everyone's responsibility.** Large files that are at the
327 cross-roads of many subsystems, where integration happens, can be some of the
328 most fragile in the system. As a companion to the previous point, be
329 cognizant of how you may be adding more complexity to the commons as you
330 venture to complete your task.
331
332- **Changes should include corresponding tests.** Automated testing is at the
333 heart of how we move forward as a project. All changes should include
334 corresponding tests so we can ensure that there is good coverage for code and
335 that future changes will be less likely to regress functionality. Protect
336 your code with tests!
337
Daniel Cheng86135f32019-02-27 07:10:38338## Tips
339
Dominik Röttschesd113bfa2019-07-10 08:56:24340### Review etiquette
341
Daniel Cheng86135f32019-02-27 07:10:38342During the lifetime of a review, you may want to rebase your change onto a newer
343source revision to minimize merge conflicts. The reviewer-friendly way to do
344this is to first address any unresolved comments and upload those changes as a
345patchset. Then, rebase to the newer revision and upload that as its own
346patchset (with no other changes). This makes it easy for reviewers to see the
347changes made in response to their comments, and then quickly verify the diffs
348from the rebase.
349
350Code authors and reviewers should keep in mind that Chromium is a global
351project: contributors and reviewers are often in time zones far apart. Please
352read these guidelines on [minimizing review lag][review-lag] and take them in
353consideration both when writing reviews and responding to review feedback.
354
Dominik Röttschesd113bfa2019-07-10 08:56:24355### Watchlists
356
357If you would like to be notified about changes to a set of files covering a
358topic or an area of Chromium, you may use the [watchlists][watchlist-doc]
359feature in order to receive email notifications.
360
361
Daniel Cheng86135f32019-02-27 07:10:38362[//]: # (the reference link section should be alphabetically sorted)
363[checkout-and-build]: https://chromium.googlesource.com/chromium/src/+/master/docs/#checking-out-and-building
John Abd-El-Malek27e1cf02019-12-18 17:35:18364[chrome-dd-review-process]: http://go/chrome-dd-review-process
365[chromium-design-docs]: https://groups.google.com/a/chromium.org/forum/#!forum/chromium-design-docs
Daniel Cheng86135f32019-02-27 07:10:38366[cl-footer-syntax]: https://dev.chromium.org/developers/contributing-code/-bug-syntax
367[code-reviews-owners]: code_reviews.md#OWNERS-files
368[code-reviews]: code_reviews.md
Toby Huang5105f812019-08-08 23:47:57369[commit-checklist]: commit_checklist.md
Daniel Cheng86135f32019-02-27 07:10:38370[commit-queue]: infra/cq.md
371[core-principles]: https://www.chromium.org/developers/core-principles
372[corporate-cla]: https://cla.developers.google.com/about/google-corporate?csw=1
373[cr-authors]: https://chromium.googlesource.com/chromium/src/+/HEAD/AUTHORS
374[cr-gitiles]: https://chromium.googlesource.com/chromium/src/+/master/
375[cr-styleguide]: https://chromium.googlesource.com/chromium/src/+/master/styleguide/styleguide.md
376[crbug-new]: https://bugs.chromium.org/p/chromium/issues/entry
377[crbug]: https://bugs.chromium.org/p/chromium/issues/list
378[cros-authors]: https://chromium.googlesource.com/chromium/src/+/master/AUTHORS
379[cros-dev-guide]: https://chromium.googlesource.com/chromiumos/docs/+/master/developer_guide.md
380[crrev]: https://chromium-review.googlesource.com
381[depot-tools-setup]: https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html#_setting_up
John Abd-El-Malek27e1cf02019-12-18 17:35:18382[design-doc-template]: https://docs.google.com/document/d/14YBYKgk-uSfjfwpKFlp_omgUq5hwMVazy_M965s_1KA
Daniel Cheng86135f32019-02-27 07:10:38383[direct-commit]: https://dev.chromium.org/developers/contributing-code/direct-commit
384[discussion-groups]: https://www.chromium.org/developers/discussion-groups
385[github-tutorial]: https://try.github.io
386[good-git-commit-message]: https://chris.beams.io/posts/git-commit/
387[individual-cla]: https://cla.developers.google.com/about/google-individual?csw=1
388[life-of-a-chromium-developer]: https://docs.google.com/a/google.com/present/view?id=0AetfwCoL2lQAZGQ5bXJ0NDVfMGRtdGQ0OWM2
389[noms-tutorial]: https://meowni.ca/posts/chromium-101
390[review-lag]: https://dev.chromium.org/developers/contributing-code/minimizing-review-lag-across-time-zones
391[skia-dev-guide]: https://skia.org/dev/contrib
392[try-job-access]: https://www.chromium.org/getting-involved/become-a-committer#TOC-Try-job-access
393[v8-dev-guide]: https://v8.dev/docs
Dominik Röttschesd113bfa2019-07-10 08:56:24394[watchlist-doc]: infra/watchlists.md