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