blob: 252182afbd4aa6216c4578e223361872189ae41a [file] [log] [blame] [view]
Armando Montanez7b7a32f2020-03-18 11:02:41 -07001# Contributing
Keir Mierle5d1226f2019-10-31 12:23:43 -07002
3We'd love to accept your patches and contributions to Pigweed. There are just a
Armando Montanez7b7a32f2020-03-18 11:02:41 -07004few small guidelines you need to follow. Before making or sending major changes,
5please reach out on the [mailing list](mailto:pigweed@googlegroups.com) first to
6ensure the changes make sense for upstream. We generally go through a design
7phase before making large changes.
8
Keir Mierle086ef1c2020-03-19 02:03:51 -07009Before participating in our community, please take a moment to review our [code
10of conduct](CODE_OF_CONDUCT.md). We expect everyone who interacts with the
11project to respect these guidelines.
12
Armando Montanez7b7a32f2020-03-18 11:02:41 -070013Pigweed contribution overview:
14 1. One-time contributor setup:
Keir Mierle086ef1c2020-03-19 02:03:51 -070015 * Sign the [Contributor License Agreement](https://cla.developers.google.com/).
David Rogers839a29e2020-03-24 19:29:49 -070016 * 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 Mierle086ef1c2020-03-19 02:03:51 -070019 * Install the [Gerrit commit hook](CONTRIBUTING.md#gerrit-commit-hook) to
David Rogers839a29e2020-03-24 19:29:49 -070020 automatically add a `Change-Id: ...` line to your commit.
Armando Montanez7b7a32f2020-03-18 11:02:41 -070021 * Install the Pigweed presubmit check hook (`pw presubmit --install`).
David Rogers839a29e2020-03-24 19:29:49 -070022 (recommended).
Keir Mierle086ef1c2020-03-19 02:03:51 -070023 2. Ensure all files include a correct [copyright and license header](CONTRIBUTING.md#source-code-headers).
Armando Montanez7b7a32f2020-03-18 11:02:41 -070024 2. Upload the change with `git push origin HEAD:refs/for/master`.
David Rogers839a29e2020-03-24 19:29:49 -070025 3. Address any reviewer feedback by amending the commit (`git commit --amend`).
Armando Montanez7b7a32f2020-03-18 11:02:41 -070026 4. Submit change to CI builders to merge.
Keir Mierle5d1226f2019-10-31 12:23:43 -070027
28## Contributor License Agreement
29
30Contributions to this project must be accompanied by a Contributor License
31Agreement. You (or your employer) retain the copyright to your contribution;
32this simply gives us permission to use and redistribute your contributions as
33part of the project. Head over to <https://cla.developers.google.com/> to see
34your current agreements on file or to sign a new one.
35
36You 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
38again.
39
Armando Montanez7b7a32f2020-03-18 11:02:41 -070040## Gerrit Commit Hook
41
Keir Mierle086ef1c2020-03-19 02:03:51 -070042Gerrit requires all changes to have a `Change-Id` tag at the bottom of each CL.
Armando Montanez7b7a32f2020-03-18 11:02:41 -070043You 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/>
51Download [the Gerrit commit hook](https://gerrit-review.googlesource.com/tools/hooks/commit-msg)
52and then copy it to the `.git\hooks` directory in the Pigweed repository.
53```batch
54copy %HOMEPATH%\Downloads\commit-msg %HOMEPATH%\pigweed\.git\hooks\commit-msg
55```
56
57## Code Reviews
Keir Mierle5d1226f2019-10-31 12:23:43 -070058
59All Pigweed development happens on Gerrit, following the [typical Gerrit
David Rogersc9759af2020-03-26 17:00:31 -070060development 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)
62for more information on using Gerrit.
Keir Mierle5d1226f2019-10-31 12:23:43 -070063
64In the future we may support GitHub pull requests, but until that time we will
65close GitHub pull requests and ask that the changes be uploaded to Gerrit
66instead.
67
68## Community Guidelines
69
70This project follows [Google's Open Source Community
Armando Montanez7b7a32f2020-03-18 11:02:41 -070071Guidelines](https://opensource.google/conduct/) and the [Pigweed Code of
72Conduct](CODE_OF_CONDUCT.md).
Keir Mierle5d1226f2019-10-31 12:23:43 -070073
74## Source Code Headers
75
76Every Pigweed file containing source code must include copyright and license
77information. This includes any JS/CSS files that you might be serving out to
78browsers.
79
80Apache header for C and C++ files:
81
82```javascript
Keir Mierle086ef1c2020-03-19 02:03:51 -070083// Copyright 2020 The Pigweed Authors
Keir Mierle5d1226f2019-10-31 12:23:43 -070084//
85// Licensed under the Apache License, Version 2.0 (the "License"); you may not
Wyatt Hepler1a960942019-11-26 14:13:38 -080086// use this file except in compliance with the License. You may obtain a copy of
87// the License at
Keir Mierle5d1226f2019-10-31 12:23:43 -070088//
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 Hepler1a960942019-11-26 14:13:38 -080094// License for the specific language governing permissions and limitations under
95// the License.
Keir Mierle5d1226f2019-10-31 12:23:43 -070096```
97
98Apache header for Python and GN files:
99
100```python
Keir Mierle086ef1c2020-03-19 02:03:51 -0700101# Copyright 2020 The Pigweed Authors
Keir Mierle5d1226f2019-10-31 12:23:43 -0700102#
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 Montanez7b7a32f2020-03-18 11:02:41 -0700115
116## Continuous Integration
117
118All Pigweed CLs must adhere to Pigweed's style guide and pass a suite of
119automated builds, tests, and style checks to be merged upstream. Much of this
120checking is done using Pigweed's pw_presubmit module by automated builders. To
121speed up the review process, consider adding `pw presubmit` as a git push hook
122using the following command:
123
124**Linux/macOS**<br/>
125```bash
126$ pw presubmit --install
127```
128
129This 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![pigweed presubmit demonstration](docs/images/pw_presubmit_demo.gif)
136
137Running `pw presubmit` manually will default to running the `full` presubmit
138program.
139
140If you ever need to bypass the presubmit hook (due to it being broken, for example) you
141may push using this command:
142
143```bash
144$ git push origin HEAD:refs/for/master --no-verify
145```