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