blob: 12429c55f512ad54c4fdb634b16f3a71aca293a8 [file] [log] [blame]
David B. Kinder2d4728d2017-07-27 17:04:04 -07001Contribution Guidelines
2#######################
3
4As an open-source project, we welcome and encourage the community to submit
5patches directly to the project. In our collaborative open source environment,
6standards and methods for submitting changes help reduce the chaos that can result
7from an active development community.
8
9This document explains how to participate in project conversations, log bugs
10and enhancement requests, and submit patches to the project so your patch will
11be accepted quickly in the codebase.
12
13
14Licensing
15*********
16
17Licensing is very important to open source projects. It helps ensure the
18software continues to be available under the terms that the author desired.
19
20.. _Apache 2.0 license:
21 https://github.com/zephyrproject-rtos/zephyr/blob/master/LICENSE
22
23.. _GitHub repo: https://github.com/zephyrproject-rtos/zephyr
24
David B. Kinder10b24a82017-09-19 17:23:35 -070025Zephyr uses the `Apache 2.0 license`_ (as found in the LICENSE file in
26the project's `GitHub repo`_) to strike a balance between open
27contribution and allowing you to use the software however you would like
28to. The Apache 2.0 license is a permisive open source license that
29allows you to freely use, modify, distribute and sell your own products
30that include Apache 2.0 licensed software. (For more information about
31this, check out articles such as `Why choose Apache 2.0 licensing`_ and
32`Top 10 Apache License Questions Answered`_).
David B. Kinder2d4728d2017-07-27 17:04:04 -070033
David B. Kinder10b24a82017-09-19 17:23:35 -070034.. _Why choose Apache 2.0 licensing:
David B. Kinderfafff0f2017-11-03 15:12:06 -070035 https://www.zephyrproject.org/about/#faq
David B. Kinder2d4728d2017-07-27 17:04:04 -070036
David B. Kinder10b24a82017-09-19 17:23:35 -070037.. _Top 10 Apache License Questions Answered:
38 https://www.whitesourcesoftware.com/whitesource-blog/top-10-apache-license-questions-answered/
39
40A license tells you what rights you have as a developer, as provided by the
David B. Kinder2d4728d2017-07-27 17:04:04 -070041copyright holder. It is important that the contributor fully understands the
42licensing rights and agrees to them. Sometimes the copyright holder isn't the
43contributor, such as when the contributor is doing work on behalf of a
44company.
45
David B. Kinder10b24a82017-09-19 17:23:35 -070046Components using other Licenses
47===============================
48
49There are some imported or reused components of the Zephyr project that
50use other licensing, as described in `Zephyr Licensing`_.
51
52.. _Zephyr Licensing:
53 https://www.zephyrproject.org/doc/LICENSING.html
54
55Importing code into the Zephyr OS from other projects that use a license
56other than the Apache 2.0 license needs to be fully understood in
57context and approved by the Zephyr governing board.
58
Christoph Sax885f0b42017-11-04 16:15:07 +010059By carefully reviewing potential contributions and also enforcing a
60:ref:`DCO` for contributed code, we can ensure that
David B. Kinder10b24a82017-09-19 17:23:35 -070061the Zephyr community can develop products with the Zephyr Project
62without concerns over patent or copyright issues.
63
64See `Contributing non-Apache 2.0 components`_ for more information about
65this contributing and review process for imported components.
66
67.. _Contributing non-Apache 2.0 components:
68 https://www.zephyrproject.org/doc/contribute/contribute_non-apache.html
69
David B. Kinder2d4728d2017-07-27 17:04:04 -070070.. _DCO:
71
72Developer Certification of Origin (DCO)
73***************************************
74
75To make a good faith effort to ensure licensing criteria are met, the Zephyr
76project requires the Developer Certificate of Origin (DCO) process to be
77followed.
78
79The DCO is an attestation attached to every contribution made by every
80developer. In the commit message of the contribution, (described more fully
81later in this document), the developer simply adds a ``Signed-off-by``
82statement and thereby agrees to the DCO.
83
84When a developer submits a patch, it is a commitment that the contributor has
85the right to submit the patch per the license. The DCO agreement is shown
86below and at http://developercertificate.org/.
87
88
89.. code-block:: none
90
91 Developer's Certificate of Origin 1.1
92
93 By making a contribution to this project, I certify that:
94
95 (a) The contribution was created in whole or in part by me and I
96 have the right to submit it under the open source license
97 indicated in the file; or
98
99 (b) The contribution is based upon previous work that, to the
100 best of my knowledge, is covered under an appropriate open
101 source license and I have the right under that license to
102 submit that work with modifications, whether created in whole
103 or in part by me, under the same open source license (unless
104 I am permitted to submit under a different license), as
105 Indicated in the file; or
106
107 (c) The contribution was provided directly to me by some other
108 person who certified (a), (b) or (c) and I have not modified
109 it.
110
111 (d) I understand and agree that this project and the contribution
112 are public and that a record of the contribution (including
113 all personal information I submit with it, including my
114 sign-off) is maintained indefinitely and may be redistributed
115 consistent with this project or the open source license(s)
116 involved.
117
118DCO Sign-Off Methods
119====================
120
121The DCO requires a sign-off message in the following format appear on each
122commit in the pull request::
123
124 Signed-off-by: Zephyrus Zephyr <zephyrus@zephyrproject.org>
125
126The DCO text can either be manually added to your commit body, or you can add
127either ``-s`` or ``--signoff`` to your usual Git commit commands. If you forget
128to add the sign-off you can also amend a previous commit with the sign-off by
129running ``git commit --amend -s``. If you've pushed your changes to GitHub
130already you'll need to force push your branch after this with ``git push -f``.
131
132
133Prerequisites
134*************
135
136.. _Zephyr Project website: https://zephyrproject.org
137
138As a contributor, you'll want to be familiar with the Zephyr project, how to
139configure, install, and use it as explained in the `Zephyr Project website`_
140and how to set up your development environment as introduced in the Zephyr
141`Getting Started Guide`_.
142
143.. _Getting Started Guide:
144 https://www.zephyrproject.org/doc/getting_started/getting_started.html
145
146The examples below use a Linux host environment for Zephyr development.
Anas Nashif602a1432017-10-31 08:35:24 -0400147You should be familiar with common developer tools such as Git and CMake, and
David B. Kinder2d4728d2017-07-27 17:04:04 -0700148platforms such as GitHub.
149
150If you haven't already done so, you'll need to create a (free) GitHub account
151on http://github.com and have Git tools available on your development system.
152
153Repository layout
154*****************
155
156To clone the main Zephyr Project repository use::
157
158 $ git clone https://github.com/zephyrproject-rtos/zephyr
159
160The Zephyr project directory structure is described in `Source Tree Structure`_
161documentation. In addition to the Zephyr kernel itself, you'll also find the
162sources for technical documentation, sample code, supported board
163configurations, and a collection of subsystem tests. All of these are
164available for developers to contribute to and enhance.
165
166.. _Source Tree Structure:
167 https://www.zephyrproject.org/doc/kernel/overview/source_tree.html
168
169Pull Requests and Issues
170************************
171
Anas Nashif37b9ee02017-10-02 22:33:16 -0400172.. _Zephyr Project Issues: https://github.com/zephyrproject-rtos/zephyr/issues
David B. Kinder2d4728d2017-07-27 17:04:04 -0700173
174.. _open pull requests: https://github.com/zephyrproject-rtos/zephyr/pulls
175
176.. _Zephyr-devel mailing list:
177 https://lists.zephyrproject.org/mailman/listinfo/zephyr-devel
178
Anas Nashif37b9ee02017-10-02 22:33:16 -0400179Before starting on a patch, first check in our issues `Zephyr Project Issues`_
David B. Kinder2d4728d2017-07-27 17:04:04 -0700180system to see what's been reported on the issue you'd like to address. Have a
181conversation on the `Zephyr-devel mailing list`_ (or the #zephyrproject IRC
182channel on freenode.net) to see what others think of your issue (and proposed
183solution). You may find others that have encountered the issue you're
184finding, or that have similar ideas for changes or additions. Send a message
185to the `Zephyr-devel mailing list`_ to introduce and discuss your idea with
186the development community.
187
Marti Bolivar1948f8b2017-11-13 09:51:14 -0500188Please note that it's common practice on IRC to be away from the
189channel, but still have a client logged in to receive traffic. If you
190ask a question to a particular person and they don't answer, **try
191to stay signed in to the channel** if you can, so they have time to
192respond to you. This is especially important given the many different
193timezones Zephyr developers live in. If you don't get a timely
194response on IRC, try sending a message to the mailing list instead.
195
David B. Kinder2d4728d2017-07-27 17:04:04 -0700196It's always a good practice to search for existing or related issues before
197submitting your own. When you submit an issue (bug or feature request), the
198triage team will review and comment on the submission, typically within a few
199business days.
200
201You can find all `open pull requests`_ on GitHub and open `Zephyr Project
Anas Nashif37b9ee02017-10-02 22:33:16 -0400202Issues`_ in Github issues.
David B. Kinder2d4728d2017-07-27 17:04:04 -0700203
204Development Tools and Git Setup
205*******************************
206
207Signed-off-by
208=============
209
210The name in the commit message ``Signed-off-by:`` line and your email must
211match the change authorship information. Make sure your *.git/config* is set
212up correctly::
213
214 $ git config --global user.name "David Developer"
215 $ git config --global user.email "david.developer@company.com"
216
217gitlint
218=========
219
220When you submit a pull request to the project, a series of checks are
221performed to verify your commit messages meet the requirements. The same step
222done during the CI process can be performed locally using the the *gitlint*
223command.
224
225Install gitlint and run it locally in your tree and branch where your patches
226have been committed::
227
228 $ sudo pip3 install gitlint
229 $ gitlint
230
231Note, gitlint only checks HEAD (the most recent commit), so you should run it
232after each commit, or use the ``--commits`` option to specify a commit range
233covering all the development patches to be submitted.
234
235sanitycheck
236===========
237
238To verify that your changes did not break any tests or samples, please run the
239``sanitycheck`` script locally before submitting your pull request to GitHub. To
240run the same tests the CI system runs, follow these steps from within your
241local Zephyr source working directory::
242
243 $ source zephyr-env.sh
Sebastian Bøe7cc20712017-11-09 12:32:56 +0100244 $ ./scripts/sanitycheck
David B. Kinder2d4728d2017-07-27 17:04:04 -0700245
246The above will execute the basic sanitycheck script, which will run various
247kernel tests using the QEMU emulator. It will also do some build tests on
248various samples with advanced features that can't run in QEMU.
249
Anas Nashif602a1432017-10-31 08:35:24 -0400250We highly recommend you run these tests locally to avoid any CI
Sebastian Bøe7cc20712017-11-09 12:32:56 +0100251failures.
David B. Kinder2d4728d2017-07-27 17:04:04 -0700252
253
254Coding Style
255************
256
257Use these coding guidelines to ensure that your development complies with the
258project's style and naming conventions.
259
260.. _Linux kernel coding style:
261 https://kernel.org/doc/html/latest/process/coding-style.html
262
263
264In general, follow the `Linux kernel coding style`_, with the
265following exceptions:
266
267* Add braces to every ``if`` and ``else`` body, even for single-line code
268 blocks. Use the ``--ignore BRACES`` flag to make *checkpatch* stop
269 complaining.
270* Use spaces instead of tabs to align comments after declarations, as needed.
271* Use C89-style single line comments, ``/* */``. The C99-style single line
272 comment, ``//``, is not allowed.
273* Use ``/** */`` for doxygen comments that need to appear in the documentation.
274
275The Linux kernel GPL-licensed tool ``checkpatch`` is used to check coding
276style conformity. Checkpatch is available in the scripts directory. To invoke
277it when committing code, edit your *.git/hooks/pre-commit* file to contain:
278
Anas Nashif454d0af2017-08-01 15:03:17 -0400279.. code-block:: bash
David B. Kinder2d4728d2017-07-27 17:04:04 -0700280
281 #!/bin/sh
282 set -e exec
283 exec git diff --cached | ${ZEPHYR_BASE}/scripts/checkpatch.pl - || true
284
David B. Kinder10b24a82017-09-19 17:23:35 -0700285.. _Contribution workflow:
286
David B. Kinder2d4728d2017-07-27 17:04:04 -0700287Contribution Workflow
288*********************
289
290One general practice we encourage, is to make small,
291controlled changes. This practice simplifies review, makes merging and
292rebasing easier, and keeps the change history clear and clean.
293
294When contributing to the Zephyr Project, it is also important you provide as much
295information as you can about your change, update appropriate documentation,
296and test your changes thoroughly before submitting.
297
298The general GitHub workflow used by Zephyr developers uses a combination of
299command line Git commands and browser interaction with GitHub. As it is with
300Git, there are multiple ways of getting a task done. We'll describe a typical
301workflow here:
302
303.. _Create a Fork of Zephyr:
304 https://github.com/zephyrproject-rtos/zephyr#fork-destination-box
305
306#. `Create a Fork of Zephyr`_
307 to your personal account on GitHub. (Click on the fork button in the top
308 right corner of the Zephyr project repo page in GitHub.)
309
310#. On your development computer, clone the fork you just made::
311
312 $ git clone https://github.com/<your github id>/zephyr
313
314 This would be a good time to let Git know about the upstream repo too::
315
316 $ git remote add upstream https://github.com/zephyrproject-rtos/zephyr.git
317
318 and verify the remote repos::
319
320 $ git remote -v
321
322#. Create a topic branch (off of master) for your work (if you're addressing
Anas Nashif37b9ee02017-10-02 22:33:16 -0400323 an issue, we suggest including the issue number in the branch name)::
David B. Kinder2d4728d2017-07-27 17:04:04 -0700324
325 $ git checkout master
326 $ git checkout -b fix_comment_typo
327
328 Some Zephyr subsystems do development work on a separate branch from
329 master so you may need to indicate this in your checkout::
330
331 $ git checkout -b fix_out_of_date_patch origin/net
332
333#. Make changes, test locally, change, test, test again, ... (Check out the
334 prior chapter on `sanitycheck`_ as well).
335
336#. When things look good, start the pull request process by adding your changed
337 files::
338
339 $ git add [file(s) that changed, add -p if you want to be more specific]
340
341 You can see files that are not yet staged using::
342
343 $ git status
344
345#. Verify changes to be committed look as you expected::
346
347 $ git diff --cached
348
349#. Commit your changes to your local repo::
350
351 $ git commit -s
352
353 The ``-s`` option automatically adds your ``Signed-off-by:`` to your commit
354 message. Your commit will be rejected without this line that indicates your
355 agreement with the `DCO`_. See the `Commit Guidelines`_ section for
356 specific guidelines for writing your commit messages.
357
358#. Push your topic branch with your changes to your fork in your personal
359 GitHub account::
360
361 $ git push origin fix_comment_typo
362
363#. In your web browser, go to your forked repo and click on the
364 ``Compare & pull request`` button for the branch you just worked on and
365 you want to open a pull request with.
366
367#. Review the pull request changes, and verify that you are opening a
368 pull request for the appropriate branch. The title and message from your
369 commit message should appear as well.
370
371#. If you're working on a subsystem branch that's not ``master``,
372 you may need to change the intended branch for the pull request
373 here, for example, by changing the base branch from ``master`` to ``net``.
374
375#. GitHub will assign one or more suggested reviewers (based on the
376 CODEOWNERS file in the repo). If you are a project member, you can
377 select additional reviewers now too.
378
379#. Click on the submit button and your pull request is sent and awaits
380 review. Email will be sent as review comments are made, or you can check
381 on your pull request at https://github.com/zephyrproject-rtos/zephyr/pulls.
382
383#. While you're waiting for your pull request to be accepted and merged, you
384 can create another branch to work on another issue. (Be sure to make your
385 new branch off of master and not the previous branch.)::
386
387 $ git checkout master
388 $ git checkout -b fix_another_issue
389
390 and use the same process described above to work on this new topic branch.
391
392#. If reviewers do request changes to your patch, you can interactively rebase
393 commit(s) to fix review issues. In your development repo::
394
395 $ git fetch --all
396 $ git rebase --ignore-whitespace upstream/master
397
398 The ``--ignore-whitespace`` option stops ``git apply`` (called by rebase)
399 from changing any whitespace. Continuing::
400
401 $ git rebase -i <offending-commit-id>^
402
403 In the interactive rebase editor, replace ``pick`` with ``edit`` to select
404 a specific commit (if there's more than one in your pull request), or
405 remove the line to delete a commit entirely. Then edit files to fix the
406 issues in the review.
407
408 As before, inspect and test your changes. When ready, continue the
409 patch submission::
410
411 $ git add [file(s)]
412 $ git rebase --continue
413
414 Update commit comment if needed, and continue::
415
416 $ git push --force origin fix_comment_typo
417
418 By force pushing your update, your original pull request will be updated
419 with your changes so you won't need to resubmit the pull request.
420
421
422Commit Guidelines
423*****************
424
425Changes are submitted as Git commits. Each commit message must contain:
426
427* A short and descriptive subject line that is less than 72 characters,
428 followed by a blank line. The subject line must include a prefix that
429 identifies the subsystem being changed, followed by a colon, and a short
430 title, for example: ``doc: update wiki references to new site``.
431 (If you're updating an existing file, you can use
432 ``git log <filename>`` to see what developers used as the prefix for
433 previous patches of this file.)
434
435* A change description with your logic or reasoning for the changes, followed
436 by a blank line.
437
438* A Signed-off-by line, ``Signed-off-by: <name> <email>`` typically added
439 automatically by using ``git commit -s``
440
Anas Nashif37b9ee02017-10-02 22:33:16 -0400441* If the change addresses an issue, include a line of the form::
David B. Kinder2d4728d2017-07-27 17:04:04 -0700442
Anas Nashif37b9ee02017-10-02 22:33:16 -0400443 Fixes #<issue number>.
David B. Kinder2d4728d2017-07-27 17:04:04 -0700444
445
446All changes and topics sent to GitHub must be well-formed, as described above.
447
448Commit Message Body
449===================
450
451When editing the commit message, please briefly explain what your change
452does and why it's needed. A change summary of ``"Fixes stuff"`` will be rejected. An
453empty change summary is only acceptable for trivial changes fully described by
454the commit title (e.g., ``doc: fix misspellings in CONTRIBUTING doc``)
455
456The description body of the commit message must include:
457
458* **what** the change does,
459* **why** you chose that approach,
460* **what** assumptions were made, and
461* **how** you know it works -- for example, which tests you ran.
462
463For examples of accepted commit messages, you can refer to the Zephyr GitHub
464`changelog <https://github.com/zephyrproject-rtos/zephyr/commits/master>`__.
465
466Other Commit Expectations
467=========================
468
469* Commits must build cleanly when applied on top of each other, thus avoiding
470 breaking bisectability.
471
472* Commits must pass the *scripts/checkpatch.pl* requirements.
473
474* Each commit must address a single identifiable issue and must be
475 logically self-contained. Unrelated changes should be submitted as
476 separate commits.
477
478* You may submit pull request RFCs (requests for comments) to send work
479 proposals, progress snapshots of your work, or to get early feedback on
480 features or changes that will affect multiple areas in the code base.
481
482Identifying Contribution Origin
483===============================
484
485When adding a new file to the tree, it is important to detail the source of
486origin on the file, provide attributions, and detail the intended usage. In
487cases where the file is an original to Zephyr, the commit message should
488include the following ("Original" is the assumption if no Origin tag is
489present)::
490
491 Origin: Original
492
493In cases where the file is imported from an external project, the commit
494message shall contain details regarding the original project, the location of
495the project, the SHA-id of the origin commit for the file, the intended
496purpose, and if the file will be maintained by the Zephyr project,
497(whether or not the Zephyr project will contain a localized branch or if
498it is a downstream copy).
499
500For example, a copy of a locally maintained import::
501
502 Origin: Contiki OS
Anas Nashif788ca642017-08-03 09:30:38 -0400503 License: BSD 3-Clause
David B. Kinder2d4728d2017-07-27 17:04:04 -0700504 URL: http://www.contiki-os.org/
505 commit: 853207acfdc6549b10eb3e44504b1a75ae1ad63a
506 Purpose: Introduction of networking stack.
507 Maintained-by: Zephyr
508
509For example, a copy of an externally maintained import::
510
511 Origin: Tiny Crypt
Anas Nashif788ca642017-08-03 09:30:38 -0400512 License: BSD 3-Clause
David B. Kinder2d4728d2017-07-27 17:04:04 -0700513 URL: https://github.com/01org/tinycrypt
514 commit: 08ded7f21529c39e5133688ffb93a9d0c94e5c6e
515 Purpose: Introduction of TinyCrypt
516 Maintained-by: External