Armando Montanez | 7b7a32f | 2020-03-18 11:02:41 -0700 | [diff] [blame] | 1 | # Contributing |
Keir Mierle | 5d1226f | 2019-10-31 12:23:43 -0700 | [diff] [blame] | 2 | |
| 3 | We'd love to accept your patches and contributions to Pigweed. There are just a |
Armando Montanez | 7b7a32f | 2020-03-18 11:02:41 -0700 | [diff] [blame] | 4 | few small guidelines you need to follow. Before making or sending major changes, |
| 5 | please reach out on the [mailing list](mailto:pigweed@googlegroups.com) first to |
| 6 | ensure the changes make sense for upstream. We generally go through a design |
| 7 | phase before making large changes. |
| 8 | |
Keir Mierle | 086ef1c | 2020-03-19 02:03:51 -0700 | [diff] [blame] | 9 | Before participating in our community, please take a moment to review our [code |
| 10 | of conduct](CODE_OF_CONDUCT.md). We expect everyone who interacts with the |
| 11 | project to respect these guidelines. |
| 12 | |
Armando Montanez | 7b7a32f | 2020-03-18 11:02:41 -0700 | [diff] [blame] | 13 | Pigweed contribution overview: |
| 14 | 1. One-time contributor setup: |
Keir Mierle | 086ef1c | 2020-03-19 02:03:51 -0700 | [diff] [blame] | 15 | * Sign the [Contributor License Agreement](https://cla.developers.google.com/). |
David Rogers | 839a29e | 2020-03-24 19:29:49 -0700 | [diff] [blame] | 16 | * Verify that Git user email (git config user.email) is either Google Account |
| 17 | email or an Alternate email for the Google account used to sign the CLA (Manage |
| 18 | Google account->Personal Info->email). |
Keir Mierle | 086ef1c | 2020-03-19 02:03:51 -0700 | [diff] [blame] | 19 | * Install the [Gerrit commit hook](CONTRIBUTING.md#gerrit-commit-hook) to |
David Rogers | 839a29e | 2020-03-24 19:29:49 -0700 | [diff] [blame] | 20 | automatically add a `Change-Id: ...` line to your commit. |
Armando Montanez | 7b7a32f | 2020-03-18 11:02:41 -0700 | [diff] [blame] | 21 | * Install the Pigweed presubmit check hook (`pw presubmit --install`). |
David Rogers | 839a29e | 2020-03-24 19:29:49 -0700 | [diff] [blame] | 22 | (recommended). |
Keir Mierle | 086ef1c | 2020-03-19 02:03:51 -0700 | [diff] [blame] | 23 | 2. Ensure all files include a correct [copyright and license header](CONTRIBUTING.md#source-code-headers). |
Armando Montanez | 7b7a32f | 2020-03-18 11:02:41 -0700 | [diff] [blame] | 24 | 2. Upload the change with `git push origin HEAD:refs/for/master`. |
David Rogers | 839a29e | 2020-03-24 19:29:49 -0700 | [diff] [blame] | 25 | 3. Address any reviewer feedback by amending the commit (`git commit --amend`). |
Armando Montanez | 7b7a32f | 2020-03-18 11:02:41 -0700 | [diff] [blame] | 26 | 4. Submit change to CI builders to merge. |
Keir Mierle | 5d1226f | 2019-10-31 12:23:43 -0700 | [diff] [blame] | 27 | |
| 28 | ## Contributor License Agreement |
| 29 | |
| 30 | Contributions to this project must be accompanied by a Contributor License |
| 31 | Agreement. You (or your employer) retain the copyright to your contribution; |
| 32 | this simply gives us permission to use and redistribute your contributions as |
| 33 | part of the project. Head over to <https://cla.developers.google.com/> to see |
| 34 | your current agreements on file or to sign a new one. |
| 35 | |
| 36 | You generally only need to submit a CLA once, so if you've already submitted one |
| 37 | (even if it was for a different project), you probably don't need to do it |
| 38 | again. |
| 39 | |
Armando Montanez | 7b7a32f | 2020-03-18 11:02:41 -0700 | [diff] [blame] | 40 | ## Gerrit Commit Hook |
| 41 | |
Keir Mierle | 086ef1c | 2020-03-19 02:03:51 -0700 | [diff] [blame] | 42 | Gerrit requires all changes to have a `Change-Id` tag at the bottom of each CL. |
Armando Montanez | 7b7a32f | 2020-03-18 11:02:41 -0700 | [diff] [blame] | 43 | You should set this up to be done automatically using the instructions below. |
| 44 | |
| 45 | **Linux/macOS**<br/> |
| 46 | ```bash |
| 47 | $ f=`git rev-parse --git-dir`/hooks/commit-msg ; mkdir -p $(dirname $f) ; curl -Lo $f https://gerrit-review.googlesource.com/tools/hooks/commit-msg ; chmod +x $f |
| 48 | ``` |
| 49 | |
| 50 | **Windows**<br/> |
| 51 | Download [the Gerrit commit hook](https://gerrit-review.googlesource.com/tools/hooks/commit-msg) |
| 52 | and then copy it to the `.git\hooks` directory in the Pigweed repository. |
| 53 | ```batch |
| 54 | copy %HOMEPATH%\Downloads\commit-msg %HOMEPATH%\pigweed\.git\hooks\commit-msg |
| 55 | ``` |
| 56 | |
| 57 | ## Code Reviews |
Keir Mierle | 5d1226f | 2019-10-31 12:23:43 -0700 | [diff] [blame] | 58 | |
| 59 | All Pigweed development happens on Gerrit, following the [typical Gerrit |
David Rogers | c9759af | 2020-03-26 17:00:31 -0700 | [diff] [blame] | 60 | development workflow](http://ceres-solver.org/contributing.html). Consult |
| 61 | [Gerrit User Guide](https://gerrit-documentation.storage.googleapis.com/Documentation/2.12.3/intro-user.html) |
| 62 | for more information on using Gerrit. |
Keir Mierle | 5d1226f | 2019-10-31 12:23:43 -0700 | [diff] [blame] | 63 | |
| 64 | In the future we may support GitHub pull requests, but until that time we will |
| 65 | close GitHub pull requests and ask that the changes be uploaded to Gerrit |
| 66 | instead. |
| 67 | |
| 68 | ## Community Guidelines |
| 69 | |
| 70 | This project follows [Google's Open Source Community |
Armando Montanez | 7b7a32f | 2020-03-18 11:02:41 -0700 | [diff] [blame] | 71 | Guidelines](https://opensource.google/conduct/) and the [Pigweed Code of |
| 72 | Conduct](CODE_OF_CONDUCT.md). |
Keir Mierle | 5d1226f | 2019-10-31 12:23:43 -0700 | [diff] [blame] | 73 | |
| 74 | ## Source Code Headers |
| 75 | |
| 76 | Every Pigweed file containing source code must include copyright and license |
| 77 | information. This includes any JS/CSS files that you might be serving out to |
| 78 | browsers. |
| 79 | |
| 80 | Apache header for C and C++ files: |
| 81 | |
| 82 | ```javascript |
Keir Mierle | 086ef1c | 2020-03-19 02:03:51 -0700 | [diff] [blame] | 83 | // Copyright 2020 The Pigweed Authors |
Keir Mierle | 5d1226f | 2019-10-31 12:23:43 -0700 | [diff] [blame] | 84 | // |
| 85 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not |
Wyatt Hepler | 1a96094 | 2019-11-26 14:13:38 -0800 | [diff] [blame] | 86 | // use this file except in compliance with the License. You may obtain a copy of |
| 87 | // the License at |
Keir Mierle | 5d1226f | 2019-10-31 12:23:43 -0700 | [diff] [blame] | 88 | // |
| 89 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 90 | // |
| 91 | // Unless required by applicable law or agreed to in writing, software |
| 92 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 93 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
Wyatt Hepler | 1a96094 | 2019-11-26 14:13:38 -0800 | [diff] [blame] | 94 | // License for the specific language governing permissions and limitations under |
| 95 | // the License. |
Keir Mierle | 5d1226f | 2019-10-31 12:23:43 -0700 | [diff] [blame] | 96 | ``` |
| 97 | |
| 98 | Apache header for Python and GN files: |
| 99 | |
| 100 | ```python |
Keir Mierle | 086ef1c | 2020-03-19 02:03:51 -0700 | [diff] [blame] | 101 | # Copyright 2020 The Pigweed Authors |
Keir Mierle | 5d1226f | 2019-10-31 12:23:43 -0700 | [diff] [blame] | 102 | # |
| 103 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 104 | # use this file except in compliance with the License. You may obtain a copy of |
| 105 | # the License at |
| 106 | # |
| 107 | # https://www.apache.org/licenses/LICENSE-2.0 |
| 108 | # |
| 109 | # Unless required by applicable law or agreed to in writing, software |
| 110 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 111 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 112 | # License for the specific language governing permissions and limitations under |
| 113 | # the License. |
| 114 | ``` |
Armando Montanez | 7b7a32f | 2020-03-18 11:02:41 -0700 | [diff] [blame] | 115 | |
| 116 | ## Continuous Integration |
| 117 | |
| 118 | All Pigweed CLs must adhere to Pigweed's style guide and pass a suite of |
| 119 | automated builds, tests, and style checks to be merged upstream. Much of this |
| 120 | checking is done using Pigweed's pw_presubmit module by automated builders. To |
| 121 | speed up the review process, consider adding `pw presubmit` as a git push hook |
| 122 | using the following command: |
| 123 | |
| 124 | **Linux/macOS**<br/> |
| 125 | ```bash |
| 126 | $ pw presubmit --install |
| 127 | ``` |
| 128 | |
| 129 | This will be effectively the same as running the following command before every |
| 130 | `git push`: |
| 131 | ```bash |
| 132 | $ pw presubmit --program quick |
| 133 | ``` |
| 134 | |
| 135 |  |
| 136 | |
| 137 | Running `pw presubmit` manually will default to running the `full` presubmit |
| 138 | program. |
| 139 | |
| 140 | If you ever need to bypass the presubmit hook (due to it being broken, for example) you |
| 141 | may push using this command: |
| 142 | |
| 143 | ```bash |
| 144 | $ git push origin HEAD:refs/for/master --no-verify |
| 145 | ``` |