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