brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 1 | # Code Reviews |
| 2 | |
| 3 | Code reviews are a central part of developing high-quality code for Chromium. |
| 4 | All changes must be reviewed. |
| 5 | |
Daniel Cheng | 6bffde0 | 2020-06-12 19:10:45 | [diff] [blame^] | 6 | The general patch, upload, and land process is covered in more detail in the |
| 7 | [contributing code](contributing.md) page. |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 8 | |
| 9 | # Code review policies |
| 10 | |
| 11 | Ideally the reviewer is someone who is familiar with the area of code you are |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 12 | touching. Any committer can review code, but an owner must provide a review |
| 13 | for each directory you are touching. If you have doubts, look at the git blame |
| 14 | for the file and the `OWNERS` files (see below). |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 15 | |
Michael Giuffrida | af36705 | 2018-03-22 20:22:34 | [diff] [blame] | 16 | To indicate a positive review, the reviewer provides a "Code-Review +1" in |
| 17 | Gerrit, also known as an LGTM ("Looks Good To Me"). A score of "-1" indicates |
| 18 | the change should not be submitted as-is. |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 19 | |
Michael Giuffrida | af36705 | 2018-03-22 20:22:34 | [diff] [blame] | 20 | If you have multiple reviewers, provide a message indicating what you expect |
| 21 | from each reviewer. Otherwise people might assume their input is not required |
| 22 | or waste time with redundant reviews. |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 23 | |
Annie Sullivan | d04212e7 | 2017-10-19 21:11:32 | [diff] [blame] | 24 | Please also read [Respectful Changes](cl_respect.md) and |
| 25 | [Respectful Code Reviews](cr_respect.md). |
| 26 | |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 27 | #### Expectations for all reviewers |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 28 | |
| 29 | * Aim to provide some kind of actionable response within 24 hours of receipt |
Michael Giuffrida | af36705 | 2018-03-22 20:22:34 | [diff] [blame] | 30 | (not counting weekends and holidays). This doesn't mean you have to do a |
| 31 | complete review, but you should be able to give some initial feedback, |
| 32 | request more time, or suggest another reviewer. |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 33 | |
Michael Giuffrida | af36705 | 2018-03-22 20:22:34 | [diff] [blame] | 34 | * Use the status field in Gerrit settings to indicate if you're away and when |
Mike Frysinger | 7b15bde | 2018-05-15 09:28:05 | [diff] [blame] | 35 | you'll be back. |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 36 | |
| 37 | * Don't generally discourage people from sending you code reviews. This |
Michael Giuffrida | af36705 | 2018-03-22 20:22:34 | [diff] [blame] | 38 | includes using a blanket "slow" in your status field. |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 39 | |
| 40 | ## OWNERS files |
| 41 | |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 42 | In various directories there are files named `OWNERS` that list the email |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 43 | addresses of people qualified to review changes in that directory. You must |
| 44 | get a positive review from an owner of each directory your change touches. |
| 45 | |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 46 | Owners files are recursive, so each file also applies to its subdirectories. |
| 47 | It's generally best to pick more specific owners. People listed in higher-level |
thestig | 9208d8ba | 2017-06-09 22:05:32 | [diff] [blame] | 48 | directories may have less experience with the code in question. For example, |
| 49 | the reviewers in the `//chrome/browser/component_name/OWNERS` file will likely |
| 50 | be more familiar with code in `//chrome/browser/component_name/sub_component` |
| 51 | than reviewers in the higher-level `//chrome/OWNERS` file. |
| 52 | |
| 53 | More detail on the owners file format is provided in the "More information" |
| 54 | section below. |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 55 | |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 56 | *Tip:* The `git cl owners` command can help find owners. |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 57 | |
| 58 | While owners must approve all patches, any committer can contribute to the |
| 59 | review. In some directories the owners can be overloaded or there might be |
| 60 | people not listed as owners who are more familiar with the low-level code in |
| 61 | question. In these cases it's common to request a low-level review from an |
| 62 | appropriate person, and then request a high-level owner review once that's |
| 63 | complete. As always, be clear what you expect of each reviewer to avoid |
| 64 | duplicated work. |
| 65 | |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 66 | Owners do not have to pick other owners for reviews. Since they should already |
| 67 | be familiar with the code in question, a thorough review from any appropriate |
| 68 | committer is sufficient. |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 69 | |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 70 | #### Expectations of owners |
| 71 | |
| 72 | The existing owners of a directory approve additions to the list. It is |
Wei-Yin Chen (陳威尹) | 681bc32 | 2017-07-20 01:55:11 | [diff] [blame] | 73 | preferable to have many directories, each with a smaller number of specific |
Dirk Pranke | 4f9740c | 2018-10-17 03:01:06 | [diff] [blame] | 74 | owners rather than large directories with many owners. Owners should: |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 75 | |
| 76 | * Demonstrate excellent judgment, teamwork and ability to uphold Chrome |
| 77 | development principles. |
| 78 | |
| 79 | * Be already acting as an owner, providing high-quality reviews and design |
Dirk Pranke | 4f9740c | 2018-10-17 03:01:06 | [diff] [blame] | 80 | feedback. |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 81 | |
Dirk Pranke | 4f9740c | 2018-10-17 03:01:06 | [diff] [blame] | 82 | * Be a Chromium project member with full commit access of at least three |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 83 | months tenure. |
| 84 | |
| 85 | * Have submitted a substantial number of non-trivial changes to the affected |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 86 | directory. |
| 87 | |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 88 | * Have committed or reviewed substantial work to the affected directory |
Dirk Pranke | 4f9740c | 2018-10-17 03:01:06 | [diff] [blame] | 89 | within the last ninety days. |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 90 | |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 91 | * Have the bandwidth to contribute to reviews in a timely manner. If the load |
| 92 | is unsustainable, work to expand the number of owners. Don't try to |
| 93 | discourage people from sending reviews, including writing "slow" or |
| 94 | "emeritus" after your name. |
| 95 | |
Dirk Pranke | 4f9740c | 2018-10-17 03:01:06 | [diff] [blame] | 96 | The above are guidelines more than they are hard rules, and exceptions are |
| 97 | okay as long as there is a consensus by the existing owners for them. |
| 98 | For example, seldom-updated directories may have exceptions to the |
| 99 | "substantiality" and "recency" requirements. Directories in `third_party` |
| 100 | should list those most familiar with the library, regardless of how often |
| 101 | the code is updated. |
brettw | 40e953e | 2017-02-08 17:49:28 | [diff] [blame] | 102 | |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 103 | ### OWNERS file details |
| 104 | |
| 105 | Refer to the [source code](https://chromium.googlesource.com/chromium/tools/depot_tools/+/master/owners.py) |
thestig | 9208d8ba | 2017-06-09 22:05:32 | [diff] [blame] | 106 | for all details on the file format. |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 107 | |
| 108 | This example indicates that two people are owners, in addition to any owners |
| 109 | from the parent directory. `git cl owners` will list the comment after an |
| 110 | owner address, so this is a good place to include restrictions or special |
| 111 | instructions. |
| 112 | ``` |
| 113 | # You can include comments like this. |
| 114 | a@chromium.org |
| 115 | b@chromium.org # Only for the frobinator. |
| 116 | ``` |
| 117 | |
| 118 | A `*` indicates that all committers are owners: |
| 119 | ``` |
| 120 | * |
| 121 | ``` |
| 122 | |
brettw | d040b0be | 2017-02-09 19:11:33 | [diff] [blame] | 123 | The text `set noparent` will stop owner propagation from parent directories. |
Jochen Eisinger | ea8f92d8 | 2017-08-02 17:40:14 | [diff] [blame] | 124 | This should be rarely used. If you want to use `set noparent` except for IPC |
| 125 | related files, please first reach out to chrome-eng-review@google.com. |
| 126 | |
Jochen Eisinger | 8f0c8d8 | 2019-10-25 18:28:27 | [diff] [blame] | 127 | You have to use `set noparent` together with a reference to a file that lists |
| 128 | the owners for the given use case. Approved use cases are listed in |
| 129 | `//build/OWNERS.setnoparent`. Owners listed in those files are expected to |
| 130 | execute special governance functions such as eng review or ipc security review. |
| 131 | Every set of owners should implement their own means of auditing membership. The |
| 132 | minimum expectation is that membership in those files is reevaluated on |
| 133 | project, or affiliation changes. |
| 134 | |
| 135 | In this example, only the eng reviewers are owners: |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 136 | ``` |
| 137 | set noparent |
Jochen Eisinger | 8f0c8d8 | 2019-10-25 18:28:27 | [diff] [blame] | 138 | file://ENG_REVIEW_OWNERS |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 139 | ``` |
| 140 | |
| 141 | The `per-file` directive allows owners to be added that apply only to files |
Wei-Yin Chen (陳威尹) | 681bc32 | 2017-07-20 01:55:11 | [diff] [blame] | 142 | matching a pattern. In this example, owners from the parent directory |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 143 | apply, plus one person for some classes of files, and all committers are |
| 144 | owners for the readme: |
| 145 | ``` |
| 146 | per-file foo_bar.cc=a@chromium.org |
| 147 | per-file foo.*=a@chromium.org |
| 148 | |
| 149 | per-file readme.txt=* |
| 150 | ``` |
| 151 | |
George Burgess IV | 1ef0493 | 2018-01-27 07:04:04 | [diff] [blame] | 152 | Note that `per-file` directives cannot directly specify subdirectories, e.g: |
| 153 | ``` |
| 154 | per-file foo/bar.cc=a@chromium.org |
| 155 | ``` |
| 156 | |
| 157 | is not OK; instead, place a `per-file` directive in `foo/OWNERS`. |
| 158 | |
brettw | 2019b9e | 2017-02-09 06:40:20 | [diff] [blame] | 159 | Other `OWNERS` files can be included by reference by listing the path to the |
| 160 | file with `file://...`. This example indicates that only the people listed in |
| 161 | `//ipc/SECURITY_OWNERS` can review the messages files: |
| 162 | ``` |
| 163 | per-file *_messages*.h=set noparent |
| 164 | per-file *_messages*.h=file://ipc/SECURITY_OWNERS |
| 165 | ``` |
Steve Kobes | f885edf | 2018-09-11 13:41:11 | [diff] [blame] | 166 | |
| 167 | ## TBR ("To Be Reviewed") |
| 168 | |
| 169 | "TBR" is our mechanism for post-commit review. It should be used rarely and |
| 170 | only in cases where a normal review is unnecessary, as described under |
| 171 | "When to TBR", below. |
| 172 | |
| 173 | TBR does not mean "no review." A reviewer TBR-ed on a change should still |
| 174 | review the change. If there are comments after landing, the author is obligated |
| 175 | to address them in a followup patch. |
| 176 | |
| 177 | Do not use TBR just because a change is urgent or the reviewer is being slow. |
| 178 | Contact the reviewer directly or find somebody else to review your change. |
| 179 | |
| 180 | ### How to TBR |
| 181 | |
| 182 | To send a change TBR, annotate the description and send email like normal. |
| 183 | Otherwise the reviewer won't know to review the patch. |
| 184 | |
| 185 | * Add the reviewer's email address in the code review tool's reviewer field |
| 186 | like normal. |
| 187 | |
Lei Zhang | 3fd577db | 2020-05-21 21:33:19 | [diff] [blame] | 188 | * Add a line "Tbr: <reviewer's email>" to the bottom of the change list |
| 189 | description. e.g. `Tbr: reviewer1@chromium.org,reviewer2@chromium.org` |
Steve Kobes | f885edf | 2018-09-11 13:41:11 | [diff] [blame] | 190 | |
| 191 | * Type a message so that the owners in the TBR list can understand who is |
| 192 | responsible for reviewing what, as part of their post-commit review |
| 193 | responsibility. e.g. |
| 194 | ``` |
| 195 | TBRing reviewers: |
| 196 | reviewer1: Please review changes to foo/ |
| 197 | reviewer2: Please review changes to bar/ |
| 198 | ``` |
| 199 | |
| 200 | ### When to TBR |
| 201 | |
| 202 | #### Reverts and relands |
| 203 | |
| 204 | The most common use of TBR is to revert patches that broke the build. Clean |
| 205 | reverts of recent patches may be submitted TBR. However, TBR should not be used |
| 206 | if the revert required non-trivial conflict resolution, or if the patch being |
| 207 | reverted is older than a few days. |
| 208 | |
| 209 | A developer relanding a patch can TBR the OWNERS for changes which are identical |
| 210 | to the original (reverted) patch. If the reland patch contains any new changes |
| 211 | (such as bug fixes) on top of the original, those changes should go through the |
| 212 | normal review process. |
| 213 | |
| 214 | When creating a reland patch, you should first upload an up-to-date patchset |
| 215 | with the exact content of the original (reverted) patch, and then upload the |
| 216 | patchset to be relanded. This is important for the reviewers to understand what |
| 217 | the fix for relanding was. |
| 218 | |
| 219 | #### Mechanical changes |
| 220 | |
| 221 | You can use TBR with certain mechanical changes that affect many callers in |
| 222 | different directories. For example, adding a parameter to a common function in |
| 223 | `//base`, with callers in `//chrome/browser/foo`, `//net/bar`, and many other |
| 224 | directories. If the updates to the callers is mechanical, you can: |
| 225 | |
Gabriel Charette | 064574c | 2018-11-17 01:36:32 | [diff] [blame] | 226 | 1. Get a normal owner of the lower-level code you're changing (in this |
| 227 | example, the function in `//base`) to do a proper review of those changes. |
Steve Kobes | f885edf | 2018-09-11 13:41:11 | [diff] [blame] | 228 | |
Gabriel Charette | 064574c | 2018-11-17 01:36:32 | [diff] [blame] | 229 | 2. Get _somebody_ to review the downstream changes made to the callers as a |
| 230 | result of the `//base` change. This is often the same person from the |
| 231 | previous step but could be somebody else. |
Steve Kobes | f885edf | 2018-09-11 13:41:11 | [diff] [blame] | 232 | |
Gabriel Charette | 064574c | 2018-11-17 01:36:32 | [diff] [blame] | 233 | 3. TBR the owner of the lower-level code you're changing (in this example, |
| 234 | `//base`), after they've LGTM'ed the API change, to bypass owners review of |
| 235 | the API consumers incurring trivial side-effects. |
Steve Kobes | f885edf | 2018-09-11 13:41:11 | [diff] [blame] | 236 | |
| 237 | This process ensures that all code is reviewed prior to checkin and that the |
Gabriel Charette | 064574c | 2018-11-17 01:36:32 | [diff] [blame] | 238 | concept of the change is reviewed by a qualified person, without having to ping |
| 239 | many owners with little say in the trivial side-effects they incur. |
| 240 | |
| 241 | **Note:** The above policy is only viable for strictly mechanical changes. For |
| 242 | large-scale scripted changes you should: |
| 243 | |
| 244 | 1. Have an owner of the core change review the script. |
| 245 | |
| 246 | 2. Use `git cl split` to shard the large change into many small CLs with a |
| 247 | clear description of what each reviewer is expected to verify |
| 248 | ([example](https://chromium-review.googlesource.com/1191225)). |
Steve Kobes | f885edf | 2018-09-11 13:41:11 | [diff] [blame] | 249 | |
| 250 | #### Documentation updates |
| 251 | |
| 252 | You can TBR documentation updates. Documentation means markdown files, text |
| 253 | documents, and high-level comments in code. At finer levels of detail, comments |
| 254 | in source files become more like code and should be reviewed normally (not |
| 255 | using TBR). Non-TBR-able stuff includes things like function contracts and most |
| 256 | comments inside functions. |
| 257 | |
| 258 | * Use good judgement. If you're changing something very important, tricky, |
| 259 | or something you may not be very familiar with, ask for the code review |
| 260 | up-front. |
| 261 | |
| 262 | * Don't TBR changes to policy documents like the style guide or this document. |
| 263 | |
| 264 | * Don't mix unrelated documentation updates with code changes. |
| 265 | |
| 266 | * Be sure to actually send out the email for the code review. If you get one, |
| 267 | please actually read the changes. |
| 268 | |