blob: d9a7fcef0ea1abe8f35fd551544db430ef8fb30a [file] [log] [blame]
Keir Mierle72cae432021-04-10 02:03:40 -07001.. _docs-contributing:
2
3============
4Contributing
5============
6We'd love to accept your patches and contributions to Pigweed. There are just a
7few small guidelines you need to follow. Before making or sending major
8changes, please reach out on the `mailing list
9<https://groups.google.com/forum/#!forum/pigweed>`_ first to ensure the changes
10make sense for upstream. We generally go through a design phase before making
11large changes.
12
13Before participating in our community, please take a moment to review our
14:ref:`docs-code-of-conduct`. We expect everyone who interacts with the project
15to respect these guidelines.
16
17Pigweed contribution overview
18-----------------------------
19
20#. One-time contributor setup:
21
22 - Sign the `Contributor License Agreement <https://cla.developers.google.com/>`_.
23 - Verify that your Git user email (git config user.email) is either Google
24 Account email or an Alternate email for the Google account used to sign
25 the CLA (Manage Google account → Personal Info → email)
26 - Install the Gerrit commit hook to automatically add a ``Change-Id: ...``
27 line to your commit
28 - Install the Pigweed presubmit check hook with ``pw presubmit --install``
29
30#. Ensure all files include the correct copyright and license headers
31#. Include any necessary changes to the documentation
32#. Run :ref:`module-pw_presubmit` to detect style or compilation issues before
33 uploading
34#. Upload the change with ``git push origin HEAD:refs/for/master``
35#. Address any reviewer feedback by amending the commit (``git commit --amend``)
36#. Submit change to CI builders to merge. If you are not part of Pigweed's
37 core team, you can ask the reviewer to add the `+2 CQ` vote, which will
38 trigger a rebase and submit once the builders pass
39
40.. note::
41
42 If you have any trouble with this flow, reach out in our `chat room
43 <https://discord.gg/M9NSeTA>`_ or on the `mailing list
44 <https://groups.google.com/forum/#!forum/pigweed>`_ for help.
45
46Contributor License Agreement
47-----------------------------
48Contributions to this project must be accompanied by a Contributor License
49Agreement. You (or your employer) retain the copyright to your contribution;
50this simply gives us permission to use and redistribute your contributions as
51part of the project. Head over to <https://cla.developers.google.com/> to see
52your current agreements on file or to sign a new one.
53
54You generally only need to submit a CLA once, so if you've already submitted one
55(even if it was for a different project), you probably don't need to do it
56again.
57
58Gerrit Commit Hook
59------------------
60Gerrit requires all changes to have a ``Change-Id`` tag at the bottom of each
61commit message. You should set this up to be done automatically using the
62instructions below.
63
64**Linux/macOS**
65
66.. code:: bash
67
68 $ 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
69
70**Windows**
71
72Download `the Gerrit commit hook
73<https://gerrit-review.googlesource.com/tools/hooks/commit-msg>`_ and then copy
74it to the ``.git\hooks`` directory in the Pigweed repository.
75
76.. code::
77
78 copy %HOMEPATH%\Downloads\commit-msg %HOMEPATH%\pigweed\.git\hooks\commit-msg
79
80Documentation
81-------------
82
83All Pigweed changes must either
84
85#. Include updates to documentation, or
86#. Include ``No-Docs-Update-Reason: <reason>`` in the commit message or a
87 Gerrit comment on the CL. For example:
88
89 * ``No-Docs-Update-Reason: formatting tweaks``
90 * ``No-Docs-Update-Reason: internal cleanups``
91 * ``No-Docs-Update-Reason: bugfix``
92
93It's acceptable to only document new changes in an otherwise underdocumented
94module, but it's not acceptable to not document new changes because the module
95doesn't have any other documentation.
96
97Code Reviews
98------------
99All Pigweed development happens on Gerrit, following the `typical Gerrit
100development workflow <http://ceres-solver.org/contributing.html>`_. Consult the
101`Gerrit User Guide
102<https://gerrit-documentation.storage.googleapis.com/Documentation/2.12.3/intro-user.html>`_
103for more information on using Gerrit.
104
105In the future we may support GitHub pull requests, but until that time we will
106close GitHub pull requests and ask that the changes be uploaded to Gerrit
107instead.
108
109Community Guidelines
110--------------------
111This project follows `Google's Open Source Community Guidelines
112<https://opensource.google/conduct/>`_ and the :ref:`docs-code-of-conduct`.
113
114Source Code Headers
115-------------------
116Every Pigweed file containing source code must include copyright and license
117information. This includes any JS/CSS files that you might be serving out to
118browsers.
119
120Apache header for C and C++ files:
121
122.. code:: none
123
124 // Copyright 2021 The Pigweed Authors
125 //
126 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
127 // use this file except in compliance with the License. You may obtain a copy of
128 // the License at
129 //
130 // https://www.apache.org/licenses/LICENSE-2.0
131 //
132 // Unless required by applicable law or agreed to in writing, software
133 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
134 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
135 // License for the specific language governing permissions and limitations under
136 // the License.
137
138Apache header for Python and GN files:
139
140.. code:: none
141
142 # Copyright 2020 The Pigweed Authors
143 #
144 # Licensed under the Apache License, Version 2.0 (the "License"); you may not
145 # use this file except in compliance with the License. You may obtain a copy of
146 # the License at
147 #
148 # https://www.apache.org/licenses/LICENSE-2.0
149 #
150 # Unless required by applicable law or agreed to in writing, software
151 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
152 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
153 # License for the specific language governing permissions and limitations under
154 # the License.
155
156Presubmit Checks and Continuous Integration
157-------------------------------------------
158All Pigweed change lists (CLs) must adhere to Pigweed's style guide and pass a
159suite of automated builds, tests, and style checks to be merged upstream. Much
160of this checking is done using Pigweed's ``pw_presubmit`` module by automated
161builders. These builders run before each Pigweed CL is submitted and in our
162continuous integration infrastructure (see `Pigweed's build console
163<https://ci.chromium.org/p/pigweed/g/pigweed/console>`_).
164
165Running Presubmit Checks
166------------------------
167To run automated presubmit checks on a pending CL, click the ``CQ DRY RUN``
168button in the Gerrit UI. The results appear in the Tryjobs section, below the
169source listing. Jobs that passed are green; jobs that failed are red.
170
171If all checks pass, you will see a ``Dry run: This CL passed the CQ dry run.``
172comment on your change. If any checks fail, you will see a ``Dry run: Failed
173builds:`` message. All failures must be addressed before submitting.
174
175In addition to the publicly visible presubmit checks, Pigweed runs internal
176presubmit checks that are only visible within Google. If any these checks fail,
177external developers will see a ``Dry run: Failed builds:`` comment on the CL,
178even if all visible checks passed. Reach out to the Pigweed team for help
179addressing these issues.
180
181Project Presubmit Checks
182------------------------
183In addition to Pigweed's presubmit checks, some projects that use Pigweed run
184their presubmit checks in Pigweed's infrastructure. This supports a development
185flow where projects automatically update their Pigweed submodule if their tests
186pass. If a project cannot build against Pigweed's tip-of-tree, it will stay on
187a fixed Pigweed revision until the issues are fixed. See the `sample project
188<https://pigweed.googlesource.com/pigweed/sample_project/>`_ for an example of
189this.
190
191Pigweed does its best to keep builds passing for dependent projects. In some
192circumstances, the Pigweed maintainers may choose to merge changes that break
193dependent projects. This will only be done if
194
195 * a feature or fix is needed urgently in Pigweed or for a different project,
196 and
197 * the project broken by the change does not imminently need Pigweed updates.
198
199The downstream project will continue to build against their last working
200revision of Pigweed until the incompatibilities are fixed.
201
202In these situations, Pigweed's commit queue submission process will fail for all
203changes. If a change passes all presubmit checks except for known failures, the
204Pigweed team may permit manual submission of the CL. Contact the Pigweed team
205for submission approval.
206
207Running local presubmits
208------------------------
209To speed up the review process, consider adding :ref:`module-pw_presubmit` as a
210git push hook using the following command:
211
212**Linux/macOS**
213
214.. code:: bash
215
216 $ pw presubmit --install
217
218This will be effectively the same as running the following command before every
219``git push``:
220
221.. code:: bash
222
223 $ pw presubmit
224
225
226.. image:: ../pw_presubmit/docs/pw_presubmit_demo.gif
227 :width: 800
228 :alt: pw presubmit demo
229
230If you ever need to bypass the presubmit hook (due to it being broken, for
231example) you may push using this command:
232
233.. code:: bash
234
235 $ git push origin HEAD:refs/for/master --no-verify
236