xref: /openbmc/docs/CONTRIBUTING.md (revision 5cc3a78a)
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
260References to non-public resources
261----------------------------------------
262
263Code and commit messages shall not refer to companies' internal documents
264or systems (including bug trackers). Other developers may not have access to
265these, making future maintenance difficult.
266
267Code contributed to OpenBMC must build from the publicly available sources,
268with no dependencies on non-public resources (URLs, repositories, etc).
269
270Best practices for D-Bus interfaces
271----------------------------------
272
273 * New D-Bus interfaces should be reusable
274
275 * Type signatures should and use the simplest types possible, appropriate
276   for the data passed. For example, don't pass numbers as ASCII strings.
277
278 * D-Bus interfaces are defined in the `phosphor-dbus-interfaces` repository at:
279
280     https://github.com/openbmc/phosphor-dbus-interfaces
281
282See: http://dbus.freedesktop.org/doc/dbus-api-design.html
283
284
285Best practices for C
286--------------------
287
288There are numerous resources available elsewhere, but a few items that are
289relevant to OpenBMC work:
290
291 * You almost never need to use `system(<some shell pipeline>)`. Reading and
292   writing from files should be done with the appropriate system calls.
293
294   Generally, it's much better to use `fork(); execve()` if you do need to
295   spawn a process, especially if you need to provide variable arguments.
296
297 * Use the `stdint` types (eg, `uint32_t`, `int8_t`) for data that needs to be
298   a certain size. Use the `PRIxx` macros for printf, if necessary.
299
300 * Don't assume that `char` is signed or unsigned.
301
302 * Beware of endian considerations when reading to & writing from
303   C types
304
305 * Declare internal-only functions as `static`, declare read-only data
306   as `const` where possible.
307
308 * Ensure that your code compiles without warnings, especially for changes
309   to the kernel.
310
311
312Developer's Certificate of Origin 1.1
313-------------------------------------
314
315    By making a contribution to this project, I certify that:
316
317    (a) The contribution was created in whole or in part by me and I
318        have the right to submit it under the open source license
319        indicated in the file; or
320
321    (b) The contribution is based upon previous work that, to the best
322        of my knowledge, is covered under an appropriate open source
323        license and I have the right under that license to submit that
324        work with modifications, whether created in whole or in part
325        by me, under the same open source license (unless I am
326        permitted to submit under a different license), as indicated
327        in the file; or
328
329    (c) The contribution was provided directly to me by some other
330        person who certified (a), (b) or (c) and I have not modified
331        it.
332
333    (d) I understand and agree that this project and the contribution
334        are public and that a record of the contribution (including all
335        personal information I submit with it, including my sign-off) is
336        maintained indefinitely and may be redistributed consistent with
337        this project or the open source license(s) involved.
338