blob: 88b9d1d074756722b7161fc616abb8c3d2b1625b [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
60development workflow](http://ceres-solver.org/contributing.html).
61
62In the future we may support GitHub pull requests, but until that time we will
63close GitHub pull requests and ask that the changes be uploaded to Gerrit
64instead.
65
66## Community Guidelines
67
68This project follows [Google's Open Source Community
Armando Montanez7b7a32f2020-03-18 11:02:41 -070069Guidelines](https://opensource.google/conduct/) and the [Pigweed Code of
70Conduct](CODE_OF_CONDUCT.md).
Keir Mierle5d1226f2019-10-31 12:23:43 -070071
72## Source Code Headers
73
74Every Pigweed file containing source code must include copyright and license
75information. This includes any JS/CSS files that you might be serving out to
76browsers.
77
78Apache header for C and C++ files:
79
80```javascript
Keir Mierle086ef1c2020-03-19 02:03:51 -070081// Copyright 2020 The Pigweed Authors
Keir Mierle5d1226f2019-10-31 12:23:43 -070082//
83// Licensed under the Apache License, Version 2.0 (the "License"); you may not
Wyatt Hepler1a960942019-11-26 14:13:38 -080084// use this file except in compliance with the License. You may obtain a copy of
85// the License at
Keir Mierle5d1226f2019-10-31 12:23:43 -070086//
87// https://www.apache.org/licenses/LICENSE-2.0
88//
89// Unless required by applicable law or agreed to in writing, software
90// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
91// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
Wyatt Hepler1a960942019-11-26 14:13:38 -080092// License for the specific language governing permissions and limitations under
93// the License.
Keir Mierle5d1226f2019-10-31 12:23:43 -070094```
95
96Apache header for Python and GN files:
97
98```python
Keir Mierle086ef1c2020-03-19 02:03:51 -070099# Copyright 2020 The Pigweed Authors
Keir Mierle5d1226f2019-10-31 12:23:43 -0700100#
101# Licensed under the Apache License, Version 2.0 (the "License"); you may not
102# use this file except in compliance with the License. You may obtain a copy of
103# the License at
104#
105# https://www.apache.org/licenses/LICENSE-2.0
106#
107# Unless required by applicable law or agreed to in writing, software
108# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
109# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
110# License for the specific language governing permissions and limitations under
111# the License.
112```
Armando Montanez7b7a32f2020-03-18 11:02:41 -0700113
114## Continuous Integration
115
116All Pigweed CLs must adhere to Pigweed's style guide and pass a suite of
117automated builds, tests, and style checks to be merged upstream. Much of this
118checking is done using Pigweed's pw_presubmit module by automated builders. To
119speed up the review process, consider adding `pw presubmit` as a git push hook
120using the following command:
121
122**Linux/macOS**<br/>
123```bash
124$ pw presubmit --install
125```
126
127This will be effectively the same as running the following command before every
128`git push`:
129```bash
130$ pw presubmit --program quick
131```
132
133![pigweed presubmit demonstration](docs/images/pw_presubmit_demo.gif)
134
135Running `pw presubmit` manually will default to running the `full` presubmit
136program.
137
138If you ever need to bypass the presubmit hook (due to it being broken, for example) you
139may push using this command:
140
141```bash
142$ git push origin HEAD:refs/for/master --no-verify
143```