zpeng | 8d6f584a | 2016-12-16 20:50:28 | [diff] [blame] | 1 | # Adding third_party Libraries |
| 2 | |
| 3 | [TOC] |
| 4 | |
| 5 | Using third party code can save time and is consistent with our values - no need |
| 6 | to reinvent the wheel! We put all code that isn't written by Chromium developers |
Dirk Pranke | 568e95c | 2018-11-01 23:41:50 | [diff] [blame] | 7 | into `//third_party` (even if you end up modifying just a few functions). We do |
zpeng | 8d6f584a | 2016-12-16 20:50:28 | [diff] [blame] | 8 | this to make it easy to track license compliance, security patches, and supply |
| 9 | the right credit and attributions. It also makes it a lot easier for other |
| 10 | projects that embed our code to track what is Chromium licensed and what is |
| 11 | covered by other licenses. |
| 12 | |
Dirk Pranke | 568e95c | 2018-11-01 23:41:50 | [diff] [blame] | 13 | ## Put the code in //third_party |
zpeng | 8d6f584a | 2016-12-16 20:50:28 | [diff] [blame] | 14 | |
Dirk Pranke | 568e95c | 2018-11-01 23:41:50 | [diff] [blame] | 15 | By default, all code should be checked into [//third_party](../third_party/), |
| 16 | for the reasons given above. Other locations are only appropriate in a few |
| 17 | situations and need explicit approval; don't assume that because there's some |
| 18 | other directory with third_party in the name it's okay to put new things |
| 19 | there. |
zpeng | 8d6f584a | 2016-12-16 20:50:28 | [diff] [blame] | 20 | |
Tim van der Lippe | 5870ac3 | 2019-10-18 11:46:54 | [diff] [blame] | 21 | ## Before you start |
| 22 | |
| 23 | To make sure the inclusion of a new third_party project makes sense for the |
| 24 | Chromium project, you should first obtain Chrome Eng Review approval. |
| 25 | Googlers should see go/chrome-eng-review and review existing topics in |
| 26 | g/chrome-eng-review. Please include information about the additional checkout |
John Abd-El-Malek | 988e2c0 | 2020-08-18 04:49:24 | [diff] [blame] | 27 | size, build times, and binary size increase of |
| 28 | [official](https://www.chromium.org/developers/gn-build-configuration) builds |
| 29 | on Android and one desktop platform. Please also make sure that the motivation |
Tim van der Lippe | 5870ac3 | 2019-10-18 11:46:54 | [diff] [blame] | 30 | for your project is clear, e.g., a design doc has been circulated. |
| 31 | |
Dirk Pranke | 568e95c | 2018-11-01 23:41:50 | [diff] [blame] | 32 | ## Get the code |
zpeng | 8d6f584a | 2016-12-16 20:50:28 | [diff] [blame] | 33 | |
Dirk Pranke | 568e95c | 2018-11-01 23:41:50 | [diff] [blame] | 34 | There are two common ways to depend on third-party code: you can reference a |
Jason D. Clinton | b21e99b | 2021-09-30 19:19:58 | [diff] [blame^] | 35 | Git repo directly (via entries in the DEPS file) or you can check in a |
| 36 | snapshot. The former is preferable in most cases: |
| 37 | |
| 38 | 1. If you are actively developing in the upstream repo, then having the DEPS |
| 39 | file include the upstream (that's been mirrored to GoB, see below) can be a |
| 40 | way to include those changes into Chromium at a particular revision. The |
| 41 | DEPS file will be updated to a new revision when you are ready to "roll" the |
| 42 | new version into Chromium. This also avoids duplicate copies of the code |
| 43 | showing up in multiple repos leading to contributor confusion. |
| 44 | 1. This interacts favorably with our upstream tracking automation. We |
| 45 | automatically consume the upstream Git hashes and match them against a |
| 46 | database of known upstreams to tracking drift between Chromium and upstream |
| 47 | sources. |
| 48 | 1. This makes adding deps that don't need local changes easier. E.g. some of |
| 49 | our automation automatically converts non-GN build rules into GN build rules |
| 50 | without any additional CLs. |
| 51 | |
| 52 | Checking in a snapshot is useful if this is effectively taking on maintenance |
| 53 | of an unmaintained project (e.g. an ancient library that we're going to GN-ify |
| 54 | that hasn't been updated in years). And, of course, if the code you need isn't |
| 55 | in a Git repo, then you have to snapshot. |
zpeng | 8d6f584a | 2016-12-16 20:50:28 | [diff] [blame] | 56 | |
Tim van der Lippe | 5870ac3 | 2019-10-18 11:46:54 | [diff] [blame] | 57 | ### Node packages |
| 58 | |
| 59 | To include a Node package, add the dependency to the |
| 60 | [Node package.json](../third_party/node/package.json). Make sure to update |
| 61 | the corresponding [`npm_exclude.txt`](../third_party/node/npm_exclude.txt) |
| 62 | and [`npm_include.txt`](../third_party/node/npm_include.txt) to make the code |
| 63 | available during checkout. |
| 64 | |
Dirk Pranke | 568e95c | 2018-11-01 23:41:50 | [diff] [blame] | 65 | ### Pulling the code via DEPS |
| 66 | |
| 67 | If the code is in a Git repo that you want to mirror, please file an [infra git |
| 68 | ticket](https://bugs.chromium.org/p/chromium/issues/entry?template=Infra-Git) |
| 69 | to get the repo mirrored onto chromium.googlesource.com; we don't allow direct |
| 70 | dependencies on non-Google-hosted repositories, so that we can still build |
Jason D. Clinton | b21e99b | 2021-09-30 19:19:58 | [diff] [blame^] | 71 | if an external repository goes down. |
Dirk Pranke | 568e95c | 2018-11-01 23:41:50 | [diff] [blame] | 72 | |
| 73 | Once the mirror is set up, add an entry to [//DEPS](../DEPS) so that gclient |
| 74 | will pull it in. If the code is only needed on some platforms, add a condition |
| 75 | to the deps entry so that developers on other platforms don't pull in things |
| 76 | they don't need. |
| 77 | |
| 78 | As for specifying the path where the library is fetched, a path like |
| 79 | `//third_party/<project_name>/src` is highly recommended so that you can put |
| 80 | the file like OWNERS or README.chromium at `//third_party/<project_name>`. If |
| 81 | you have a wrong path in DEPS and want to change the path of the existing |
| 82 | library in DEPS, please ask the infrastructure team before committing the |
| 83 | change. |
| 84 | |
David Dorwin | 7fde299b | 2020-09-25 02:10:34 | [diff] [blame] | 85 | Lastly, add the new directory to Chromium's `//third_party/.gitignore`, so that |
| 86 | it won't show up as untracked files when you run `git status` on the main |
| 87 | repository. |
Dirk Pranke | 568e95c | 2018-11-01 23:41:50 | [diff] [blame] | 88 | |
| 89 | ### Checking in the code directly |
| 90 | |
| 91 | If you are checking in a snapshot, please describe the source in the |
| 92 | README.chromium file, described below. For security reasons, please retrieve |
| 93 | the code as securely as you can, using HTTPS and GPG signatures if available. |
| 94 | If retrieving a tarball, please do not check the tarball itself into the tree, |
| 95 | but do list the source and the SHA-512 hash (for verification) in the |
| 96 | README.chromium and Change List. The SHA-512 hash can be computed via |
| 97 | `sha512sum` or `openssl dgst -sha512`. If retrieving from a git |
| 98 | repository, please list the revision that the code was pulled from. |
| 99 | |
| 100 | If you are checking the files in directly, you do not need an entry in DEPS |
David Dorwin | 7fde299b | 2020-09-25 02:10:34 | [diff] [blame] | 101 | and do not need to modify `//third_party/.gitignore`. |
Dirk Pranke | 568e95c | 2018-11-01 23:41:50 | [diff] [blame] | 102 | |
| 103 | ### Checking in large files |
| 104 | |
| 105 | _Accessible to Googlers only. Non-Googlers can email one of the people in |
| 106 | third_party/OWNERS for help. |
| 107 | |
| 108 | See [Moving large files to Google Storage](https://goto.google.com/checking-in-large-files) |
| 109 | |
| 110 | ## Document the code's context |
zpeng | 8d6f584a | 2016-12-16 20:50:28 | [diff] [blame] | 111 | |
| 112 | ### Add OWNERS |
| 113 | |
Forrest Fleming | 80f7021 | 2020-07-01 00:13:50 | [diff] [blame] | 114 | Your OWNERS file must either list two Chromium developer accounts as the first |
| 115 | two lines or include a `file:` directive to an OWNERS file within the |
| 116 | `third_party` directory that itself conforms to this criterion. This will ensure |
zpeng | 8d6f584a | 2016-12-16 20:50:28 | [diff] [blame] | 117 | accountability for maintenance of the code over time. While there isn't always |
| 118 | an ideal or obvious set of people that should go in OWNERS, this is critical for |
| 119 | first-line triage of any issues that crop up in the code. |
| 120 | |
| 121 | As an OWNER, you're expected to: |
| 122 | |
| 123 | * Remove the dependency when/if it is no longer needed |
| 124 | * Update the dependency when a security or stability bug is fixed upstream |
| 125 | * Help ensure the Chrome feature that uses the dependency continues to use the |
| 126 | dependency in the best way, as the feature and the dependency change over |
| 127 | time. |
| 128 | |
| 129 | ### Add a README.chromium |
| 130 | |
| 131 | You need a README.chromium file with information about the project from which |
| 132 | you're re-using code. See |
Dirk Pranke | 568e95c | 2018-11-01 23:41:50 | [diff] [blame] | 133 | [//third_party/README.chromium.template](../third_party/README.chromium.template) |
zpeng | 8d6f584a | 2016-12-16 20:50:28 | [diff] [blame] | 134 | for a list of fields to include. A presubmit check will check this has the right |
| 135 | format. |
| 136 | |
Dirk Pranke | 568e95c | 2018-11-01 23:41:50 | [diff] [blame] | 137 | README.chromium files contain a field indicating whether the package is |
| 138 | security-critical or not. A package is security-critical if it is compiled |
| 139 | into the product and does any of the following: |
| 140 | |
| 141 | * Accepts untrustworthy inputs from the internet |
| 142 | * Parses or interprets complex input formats |
| 143 | * Sends data to internet servers |
| 144 | * Collects new data |
| 145 | * Influences or sets security-related policy (including the user experience) |
| 146 | |
Adrian Taylor | 0a06ec3 | 2020-03-03 05:00:07 | [diff] [blame] | 147 | One of the fields is CPEPrefix. This is used by Chromium and Google systems to |
| 148 | spot known upstream security vulnerabilities, and ensure we merge the fixes |
| 149 | into our third-party copy. These systems are not foolproof, so as the OWNER, |
| 150 | it's up to you to keep an eye out rather than solely relying on these |
| 151 | automated systems. But, adding CPEs decreases the chances of us missing |
| 152 | vulnerabilities, so they should always be added if possible. |
| 153 | |
| 154 | The CPE is a common format shared across the industry; you can look up the CPE |
| 155 | for your package [here](https://nvd.nist.gov/products/cpe/search). Please use |
| 156 | CPE format 2.2. When searching for a CPE, you may find that there is not yet |
| 157 | a CPE for the specific upstream version you're using. This is normal, as CPEs |
| 158 | are typically allocated only when a vulnerability is found. You should follow |
| 159 | the version number convention such that, when that does occur in future, we'll |
| 160 | be notified. If no CPE is available, please specify "unknown". |
| 161 | |
Adrian Taylor | 8e0d3fd | 2020-04-17 20:14:25 | [diff] [blame] | 162 | If you're using a patched or modified version which is halfway between two |
| 163 | public versions, please "round downwards" to the lower of the public versions |
| 164 | (it's better for us to be notified of false-positive vulnerabilities than |
| 165 | false-negatives). |
Adrian Taylor | 0a06ec3 | 2020-03-03 05:00:07 | [diff] [blame] | 166 | |
zpeng | 8d6f584a | 2016-12-16 20:50:28 | [diff] [blame] | 167 | ### Add a LICENSE file and run related checks |
| 168 | |
| 169 | You need a LICENSE file. Example: |
Dirk Pranke | 568e95c | 2018-11-01 23:41:50 | [diff] [blame] | 170 | [//third_party/libjpeg/LICENSE](../third_party/libjpeg/LICENSE). |
zpeng | 8d6f584a | 2016-12-16 20:50:28 | [diff] [blame] | 171 | |
Dirk Pranke | 568e95c | 2018-11-01 23:41:50 | [diff] [blame] | 172 | Run `//tools/licenses.py scan`; this will complain about incomplete or missing |
| 173 | data for third_party checkins. We use `licenses.py credits` to generate the |
| 174 | about:credits page in Google Chrome builds. |
zpeng | 8d6f584a | 2016-12-16 20:50:28 | [diff] [blame] | 175 | |
| 176 | If the library will never be shipped as a part of Chrome (e.g. build-time tools, |
| 177 | testing tools), make sure to set "License File" as "NOT_SHIPPED" so that the |
Dirk Pranke | bf4136b | 2018-09-20 22:48:43 | [diff] [blame] | 178 | license is not included in about:credits page ([more on this below](#credits)). |
zpeng | 8d6f584a | 2016-12-16 20:50:28 | [diff] [blame] | 179 | |
Dirk Pranke | 568e95c | 2018-11-01 23:41:50 | [diff] [blame] | 180 | ## Get a review |
zpeng | 8d6f584a | 2016-12-16 20:50:28 | [diff] [blame] | 181 | |
Aaron Gable | fc8cdad | 2018-01-16 21:02:40 | [diff] [blame] | 182 | All third party additions and substantive changes like re-licensing need the |
Dirk Pranke | 568e95c | 2018-11-01 23:41:50 | [diff] [blame] | 183 | following sign-offs. Some of these are accessible to Googlers only. |
| 184 | Non-Googlers can email one of the people in |
| 185 | [//third_party/OWNERS](../third_party/OWNERS) for help. |
zpeng | 8d6f584a | 2016-12-16 20:50:28 | [diff] [blame] | 186 | |
Tim van der Lippe | 8c749839 | 2019-10-28 12:21:04 | [diff] [blame] | 187 | * Make sure you have the approval from Chrome Eng Review as mentioned |
| 188 | [above](#before-you-start). |
Aaron Gable | fc8cdad | 2018-01-16 21:02:40 | [diff] [blame] | 189 | * Get security@chromium.org approval. Email the list with relevant details and |
| 190 | a link to the CL. Third party code is a hot spot for security vulnerabilities. |
| 191 | When adding a new package that could potentially carry security risk, make |
| 192 | sure to highlight risk to security@chromium.org. You may be asked to add |
| 193 | a README.security or, in dangerous cases, README.SECURITY.URGENTLY file. |
Dirk Pranke | 6fb90c0 | 2018-10-17 02:02:20 | [diff] [blame] | 194 | * Add chromium-third-party@google.com as a reviewer on your change. This |
Adam Langley | 88658b3 | 2018-11-20 22:12:47 | [diff] [blame] | 195 | will trigger an automatic round-robin assignment to a reviewer who will check |
| 196 | licensing matters. These reviewers may not be able to +1 a change so look for |
| 197 | verbal approval in the comments. (This list does not receive or deliver |
| 198 | email, so only use it as a reviewer, not for other communication. Internally, |
Dirk Pranke | f743281 | 2020-06-10 22:38:20 | [diff] [blame] | 199 | see [cl/221704656](https://cl/221704656) for details about how |
| 200 | this is configured.). If you have questions about the third-party process, |
| 201 | ask one of the [//third_party/OWNERS](../third_party/OWNERS) instead. |
Adam Langley | 88658b3 | 2018-11-20 22:12:47 | [diff] [blame] | 202 | * Lastly, if all other steps are complete, get a positive code review from a |
| 203 | member of [//third_party/OWNERS](../third_party/OWNERS) to land the change. |
zpeng | 8d6f584a | 2016-12-16 20:50:28 | [diff] [blame] | 204 | |
Dirk Pranke | 6fb90c0 | 2018-10-17 02:02:20 | [diff] [blame] | 205 | Please send separate emails to the eng review and security lists. |
jochen | 893d518 | 2017-01-31 22:01:49 | [diff] [blame] | 206 | |
Dirk Pranke | 568e95c | 2018-11-01 23:41:50 | [diff] [blame] | 207 | Subsequent changes don't normally require third-party-owners or security |
| 208 | approval; you can modify the code as much as you want. When you update code, be |
| 209 | mindful of security-related mailing lists for the project and relevant CVE to |
| 210 | update your package. |
Dirk Pranke | bf4136b | 2018-09-20 22:48:43 | [diff] [blame] | 211 | |
| 212 | ## How we ensure that the right credits are displayed {#credits} |
| 213 | |
| 214 | As we said at the beginning, it is important that Chrome displays the |
| 215 | right credit and attributions for all of the third_party code we use. |
| 216 | |
| 217 | To view this in chrome, you can open chrome://credits. |
| 218 | |
| 219 | That page displays a resource embedded in the browser as part of the |
| 220 | [//components/resources/components_resources.grd](../components/resources/components_resource.grd) |
| 221 | GRIT file; the actual HTML text is generated in the |
| 222 | [//components/resources:about_credits](../components/resources/BUILD.gn) |
| 223 | build target using a template from the output of the |
| 224 | [//tools/licenses.py](../tools/licenses.py) script. Assuming you've followed |
| 225 | the rules above to ensure that you have the proper LICENSE file and it passes |
| 226 | the checks, it'll be included automatically. |