xref: /openbmc/docs/CONTRIBUTING.md (revision 1dc181c4)
1Contributing to OpenBMC
2=======================
3
4Here's a little guide to working on OpenBMC. This document will always be
5a work-in-progress, feel free to propose changes.
6
7Structure
8---------
9
10OpenBMC has quite a modular structure, consisting of small daemons with a
11limited set of responsibilities. These communicate over D-Bus with other
12components, to implement the complete BMC system.
13
14The BMC's interfaces to the external world are typically through a separate
15daemon, which then translates those requests to D-Bus messages.
16
17These separate projects are then compiled into the final system by the
18overall 'openbmc' build infrastructure.
19
20For future development, keep this design in mind. Components' functionality
21should be logically grouped, and keep related parts together where it
22makes sense.
23
24Starting out
25------------
26
27If you're starting out with OpenBMC, you may want to take a look at the issues
28tagged with 'bitesize'. These are fixes or enhancements that don't require
29extensive knowledge of the OpenBMC codebase, and are easier for a newcomer to
30start working with.
31
32Check out that list here:
33
34 https://github.com/issues?utf8=%E2%9C%93&q=is%3Aopen+is%3Aissue+user%3Aopenbmc+label%3Abitesize
35
36If you need further details on any of these issues, feel free to add comments.
37
38Performing code reviews is another good way to get started.  Go to
39https://gerrit.openbmc-project.xyz and click on the "all" and "open"
40menu items, or if you are interested in a particular repository, for
41example "bmcweb", type "status:open project:openbmc/bmcweb" into the
42search bar and press the "search" button.  Then select a review.
43Remember to be positive and add value with every review comment.
44
45Coding style
46------------
47
48Components of the OpenBMC sources should have a consistent style.  If the source is
49coming from another project, we choose to follow the existing style of the
50upstream project.  Otherwise, conventions are chosen based on the language.
51
52### Python
53
54Python source should all conform to PEP8.  This style is well established
55within the Python community and can be verified with the 'pycodestyle' tool.
56
57https://www.python.org/dev/peps/pep-0008/
58
59### Python Formatting
60
61If a repository has a setup.cfg file present in its root directory,
62then CI will automatically verify the Python code meets the [pycodestyle](http://pycodestyle.pycqa.org/en/latest/intro.html)
63requirements. This enforces PEP 8 standards on all Python code.
64
65OpenBMC standards for Python match with PEP 8 so in general, a blank setup.cfg
66file is all that's needed. If so desired, an enforcement of 80
67(vs. the default 79) chars is fine as well:
68```
69[pycodestyle]
70max-line-length = 80
71```
72By default, pycodestyle does not enforce the following rules: E121, E123, E126,
73E133, E226, E241, E242, E704, W503, and W504. These rules are ignored because
74they are not unanimously accepted and PEP 8 does not enforce them. It is at the
75repository maintainer's discretion as to whether to enforce the aforementioned
76rules. These rules can be enforced by adding the following to the setup.cfg:
77```
78[pycodestyle]
79ignore= NONE
80```
81
82### JavaScript
83
84We follow the
85[Google JavaScript Style Guide](https://google.github.io/styleguide/jsguide.html).
86
87[Example .clang-format](https://www.github.com/openbmc/docs/blob/master/style/javascript/.clang-format)
88
89### HTML/CSS
90
91We follow the
92[Google HTML/CSS Style Guide](https://google.github.io/styleguide/htmlcssguide.html).
93
94### C
95
96For C code, we typically use the Linux coding style, which is documented at:
97
98  http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst
99
100In short:
101
102  - Indent with tabs instead of spaces, set at 8 columns
103
104  - 80-column lines
105
106  - Opening braces on the end of a line, except for functions
107
108This style can mostly be verified with 'astyle' as follows:
109
110    astyle --style=linux --indent=tab=8 --indent=force-tab=8
111
112### C++
113
114See [C++ Style and Conventions](./cpp-style-and-conventions.md).
115
116Planning changes
117----------------
118
119If you are making a nontrivial change, you should plan how to
120introduce it to the OpenBMC development community.
121
122If you are planning a new function, you should get agreement that your
123change will be accepted.  As early as you can, introduce the change
124via the OpenBMC community call, IRC channel, or email list to start
125the discussion.  You may find a better way to do what you need.
126
127Stage your change in small pieces to make them easy to review:
128 - If your change has a specification, sketch out your ideas first
129   and work to get that accepted before completing the details.
130 - Work at most a few days before seeking review.
131 - Commit and review header files before writing code.
132 - Commit and review each implementation module separately.
133
134Make each commit simple to review.
135
136Submitting changes
137------------------
138
139We use git for almost everything. Changes should be sent as patches to their
140relevant source tree - or a git pull request for convenience.
141
142Each commit should be a self-contained logical unit, and smaller patches are
143usually better. However, if there is no clear division, a larger patch is
144okay. During development, it can be useful to consider how your change can be
145submitted as logical units.
146
147Each commit is expected to be tested. The expectation of testing may vary from
148subproject to subproject, but will typically include running all applicable
149automated tests and performing manual testing. Each commit should be tested
150separately, even if they are submitted together (an exception is when commits
151to different projects depend on each other).
152
153Commit messages are important. They should describe why the change is needed,
154and what effects it will have on the system. Do not describe the actual
155code change made by the patch; that's what the patch itself is for.
156
157Use your full name for contributions, and include a "Signed-off-by" line,
158to indicate that you agree to the Developer's Certificate of Origin (see below).
159
160Commit messages should include a "Tested" field describing how you tested the
161code changes in the patch. Example:
162```
163    Tested: I ran unit tests with "make check" (added 2 new tests) and manually
164    tested on Witherspoon that Foo daemon no longer crashes at boot.
165```
166
167Ensure that your patch doesn't change unrelated areas. Be careful of
168accidental whitespace changes - this makes review unnecessarily difficult.
169
170The guidelines in the Linux kernel are very useful:
171
172https://www.kernel.org/doc/html/latest/process/submitting-patches.html
173
174https://www.kernel.org/doc/html/latest/process/submit-checklist.html
175
176Your contribution will generally need to be reviewed before being accepted.
177
178
179Submitting changes via Gerrit server
180------------------------------------
181
182The OpenBMC Gerrit server supports GitHub credentials, its link is:
183
184  https://gerrit.openbmc-project.xyz/#/q/status:open
185
186_One time only_: Execute one of the OpenBMC Contributor License Agreements:
187
188* [Individual CLA](https://github.com/openbmc/openbmc/files/1860742/OpenBMC.ICLA.pdf)
189* [Corporate CLA](https://github.com/openbmc/openbmc/files/1860741/OpenBMC.CCLA.pdf)
190
191If you work for someone, consider asking them to execute the corporate CLA.  This
192allows other contributors that work for your employer to skip the CLA signing process.
193
194After signing a CLA, send it to openbmc@lists.ozlabs.org.
195
196_One time setup_: Login to the WebUI with your GitHub credentials and verify on
197your account Settings that your SSH keys were imported:
198
199  https://gerrit.openbmc-project.xyz/#/settings/
200
201Most repositories are supported by the Gerrit server, the current list can be
202found under Projects -> List:
203
204  https://gerrit.openbmc-project.xyz/#/admin/projects/
205
206If you're going to be working with Gerrit often, it's useful to create an SSH
207host block in ~/.ssh/config. Ex:
208```
209Host openbmc.gerrit
210        Hostname gerrit.openbmc-project.xyz
211        Port 29418
212        User your_github_id
213```
214
215From your OpenBMC git repository, add a remote to the Gerrit server, where
216'openbmc_repo' is the current git repository you're working on, such as
217phosphor-rest-server, and 'openbmc.gerrit' is the name of the Host previously added:
218
219  `git remote add gerrit ssh://openbmc.gerrit/openbmc/openbmc_repo`
220
221Gerrit uses [Change-Ids](https://gerrit-review.googlesource.com/Documentation/user-changeid.html) to identify commits that belong to the same
222review.  Configure your git repository to automatically add a
223Change-Id to your commit messages.  The steps are:
224
225  `gitdir=$(git rev-parse --git-dir)`
226
227  `scp -p -P 29418 openbmc.gerrit:hooks/commit-msg ${gitdir}/hooks`
228
229To submit a change set, commit your changes, and push to the Gerrit server,
230where 'gerrit' is the name of the remote added with the git remote add command:
231
232  `git push gerrit HEAD:refs/for/master`
233
234Gerrit will show you the URL link to your review.  You can also find
235your reviews from the [OpenBMC Gerrit server](https://gerrit.openbmc-project.xyz) search bar
236or menu (All > Open, or My > Changes).
237
238Invite reviewers to review your changes.  Each OpenBMC repository has
239a `MAINTAINERS` file which lists required reviewers who are subject
240matter experts.  Those reviewers may add additional reviewers.  To add
241reviewers from the Gerrit web page, click the "add reviewers" icon by
242the list of reviewers.
243
244You are expected to respond to all comments.  And remember to use the
245"reply" button to publish your replies for others to see.
246
247The review results in the proposed change being accepted, rejected for
248rework, or abandoned.  When you re-work your change, remember to use
249`git commit --amend` so Gerrit handles the update as a new patch of
250the same review.
251
252Each repository is governed by a small group of maintainers who are
253leaders with expertise in their area.  They are responsible for
254reviewing changes and maintaining the quality of the code.  You'll
255need a maintainer to accept your change, and they will look to the
256other reviewers for guidance.  When accepted, your change will merge
257into the OpenBMC project.
258
259
260Avoid references to non-public resources
261----------------------------------------
262
263Code and commit messages should not refer to companies' internal documents
264or systems (including bug trackers). Other developers may not have access to
265these, making future maintenance difficult.
266
267
268Best practices for D-Bus interfaces
269----------------------------------
270
271 * New D-Bus interfaces should be reusable
272
273 * Type signatures should and use the simplest types possible, appropriate
274   for the data passed. For example, don't pass numbers as ASCII strings.
275
276 * D-Bus interfaces are defined in the `phosphor-dbus-interfaces` repository at:
277
278     https://github.com/openbmc/phosphor-dbus-interfaces
279
280See: http://dbus.freedesktop.org/doc/dbus-api-design.html
281
282
283Best practices for C
284--------------------
285
286There are numerous resources available elsewhere, but a few items that are
287relevant to OpenBMC work:
288
289 * You almost never need to use `system(<some shell pipeline>)`. Reading and
290   writing from files should be done with the appropriate system calls.
291
292   Generally, it's much better to use `fork(); execve()` if you do need to
293   spawn a process, especially if you need to provide variable arguments.
294
295 * Use the `stdint` types (eg, `uint32_t`, `int8_t`) for data that needs to be
296   a certain size. Use the `PRIxx` macros for printf, if necessary.
297
298 * Don't assume that `char` is signed or unsigned.
299
300 * Beware of endian considerations when reading to & writing from
301   C types
302
303 * Declare internal-only functions as `static`, declare read-only data
304   as `const` where possible.
305
306 * Ensure that your code compiles without warnings, especially for changes
307   to the kernel.
308
309
310Developer's Certificate of Origin 1.1
311-------------------------------------
312
313    By making a contribution to this project, I certify that:
314
315    (a) The contribution was created in whole or in part by me and I
316        have the right to submit it under the open source license
317        indicated in the file; or
318
319    (b) The contribution is based upon previous work that, to the best
320        of my knowledge, is covered under an appropriate open source
321        license and I have the right under that license to submit that
322        work with modifications, whether created in whole or in part
323        by me, under the same open source license (unless I am
324        permitted to submit under a different license), as indicated
325        in the file; or
326
327    (c) The contribution was provided directly to me by some other
328        person who certified (a), (b) or (c) and I have not modified
329        it.
330
331    (d) I understand and agree that this project and the contribution
332        are public and that a record of the contribution (including all
333        personal information I submit with it, including my sign-off) is
334        maintained indefinitely and may be redistributed consistent with
335        this project or the open source license(s) involved.
336