1.. _contribute_guidelines:
2
3Contribution Guidelines
4#######################
5
6As an open-source project, we welcome and encourage the community to submit
7patches directly to project ACRN.  In our collaborative open-source
8environment, standards and methods for submitting changes help reduce the
9chaos that can result from an active development community.
10
11This document explains how to participate in project conversations, log
12and track bugs and enhancement requests, and submit patches to the
13project so that your patch will be accepted quickly into the codebase.
14
15Here's a quick summary:
16
17.. include:: ../../../../CONTRIBUTING.rst
18   :start-after: start_include_here
19
20Licensing
21*********
22
23Licensing is very important to open-source projects. It helps ensure that the
24software continues to be available under the terms that the author desired.
25
26Project ACRN uses a BSD-3-Clause license, as found in the
27:acrn_file:`LICENSE <LICENSE>` in the project's GitHub repo.
28
29A license tells you what rights you have as a developer, as provided by
30the copyright holder. It is important that the contributor fully
31understands the licensing rights and agrees to them. Sometimes the
32copyright holder isn't the contributor, such as when the contributor is
33doing work on behalf of a company.
34
35.. _DCO:
36
37Developer Certification of Origin (DCO)
38***************************************
39
40To make a good faith effort to ensure that licensing criteria are met,
41project ACRN requires the Developer Certificate of Origin (DCO) process
42to be followed.
43
44The DCO is an attestation attached to every contribution made by every
45developer. In the commit message of the contribution, (described more
46fully later in this document), the developer simply adds a ``Signed-off-by``
47statement and thereby agrees to the DCO.
48
49When a developer submits a patch, it is a commitment that the contributor has
50the right to submit the patch per the license.  The DCO agreement is shown
51below and at http://developercertificate.org/.
52
53.. code-block:: none
54
55    Developer's Certificate of Origin 1.1
56
57    By making a contribution to this project, I certify that:
58
59    (a) The contribution was created in whole or in part by me and I
60        have the right to submit it under the open source license
61        indicated in the file; or
62
63    (b) The contribution is based upon previous work that, to the
64        best of my knowledge, is covered under an appropriate open
65        source license and I have the right under that license to
66        submit that work with modifications, whether created in whole
67        or in part by me, under the same open source license (unless
68        I am permitted to submit under a different license), as
69        Indicated in the file; or
70
71    (c) The contribution was provided directly to me by some other
72        person who certified (a), (b) or (c) and I have not modified
73        it.
74
75    (d) I understand and agree that this project and the contribution
76        are public and that a record of the contribution (including
77        all personal information I submit with it, including my
78        sign-off) is maintained indefinitely and may be redistributed
79        consistent with this project or the open source license(s)
80        involved.
81
82DCO Sign-Off Methods
83====================
84
85The DCO requires that a sign-off message, in the following format, appears on
86each commit in the pull request::
87
88   Signed-off-by: Acrnus Jones <acrnusj@gmail.com>
89
90You can either manually add the DCO text to your commit body or you can add
91``-s`` or ``--signoff`` to your usual Git commit commands. If you forget to
92add the sign-off, you can also amend a previous commit with the sign-off by
93running ``git commit --amend -s``. If you've pushed your changes to GitHub
94already, you'll need to force push your branch after this with
95``git push -f``.
96
97.. note::
98   The name and email address of the account you use to submit your PR must
99   match the name and email address on the ``Signed-off-by`` line in your
100   commit message.
101
102Prerequisites
103*************
104
105.. _project ACRN website: https://projectacrn.org
106
107As a contributor, you'll want to be familiar with project ACRN, how to
108configure, install, and use it as explained on the
109`project ACRN website`_, and how to set up your development environment
110as introduced in the project ACRN `Getting Started Guide`_.
111
112.. _Getting Started Guide:
113   https://projectacrn.github.io/latest/try.html
114
115You should be familiar with common developer tools and platforms such as Git
116and GitHub.
117
118If you haven't already done so, you'll need to create a (free) GitHub account
119on https://github.com and have Git tools available on your development system.
120
121Repository Layout
122*****************
123
124To clone the ACRN hypervisor repository (including the ``hypervisor``,
125``devicemodel``, and ``doc`` folders), use::
126
127   $ git clone https://github.com/projectacrn/acrn-hypervisor
128
129In addition to the ACRN hypervisor and Device Model itself, you'll also find
130the sources for technical documentation available from the
131`ACRN documentation site`_.  All of these are available for developers to
132contribute to and enhance.
133
134.. _ACRN documentation site:
135   https://projectacrn.github.io/
136
137Submitting Issues
138******************
139
140.. _ACRN-dev mailing list:
141   https://lists.projectacrn.org/g/acrn-dev
142
143.. _ACRN-users mailing list:
144   https://lists.projectacrn.org/g/acrn-users
145
146.. _ACRN hypervisor issues:
147   https://github.com/projectacrn/acrn-hypervisor/issues
148
149Issue tracking for project ACRN bugs or enhancement requests is done using
150GitHub issues in the `ACRN hypervisor issues`_ list. Before submitting a
151bug or enhancement request, first check to see what's already been
152reported, and add to that discussion if you have additional information.
153(Be sure to check both the "open" and "closed" issues.)
154You should also read through discussions in the `ACRN-users mailing list`_
155(and the `ACRN-dev mailing list`_)
156to see what's been reported on or discussed.  You may find others that
157have encountered the issue you're finding, or that have similar ideas
158for changes or additions.
159
160If you don't find an existing issue listed in the `ACRN hypervisor issues`_
161list, then click the "New Issue" button and provide a summary title and a
162more-detailed description of your bug or enhancement request.
163
164When you submit an issue (bug or feature request), the triage team will
165review and comment on the submission, typically within a few business
166days.  Use the `ACRN hypervisor issues`_ list to track the status of your
167submitted issues as well, or to add additional comments.
168
169 .. _Contribution Tools:
170
171Contribution Tools and Git Setup
172********************************
173
174.. _Git send-email documentation:
175   https://git-scm.com/docs/git-send-email
176
177Git-Send-Email
178==============
179
180If you'll be submitting code patches, you may need to install the git-email
181package for easier patch submission.  On Ubuntu, for example, use::
182
183   $ sudo apt install git-email
184
185and then configure Git with your SMTP server information as described in the
186`Git send-email documentation`_.
187
188Signed-Off-By
189=============
190
191The name in the commit message ``Signed-off-by:`` line and your email address
192must match the change authorship information. Make sure that your
193:file:`.gitconfig` is set up correctly by using:
194
195.. code-block:: none
196
197   $ git config --global user.name "David Developer"
198   $ git config --global user.email "david.developer@company.com"
199
200Tracked-On
201==========
202
203All commits must be mapped to a GitHub issue for a feature or bug. Add a
204Tracked-On: #issue-number line to your commit message together with the
205issue number. For example::
206
207   Tracked-On: #1420
208
209Coding Style
210************
211
212Use these coding guidelines to ensure that your development complies with the
213project's style and naming conventions:
214
215.. _Linux kernel coding style:
216   https://kernel.org/doc/html/latest/process/coding-style.html
217
218In general, follow the `Linux kernel coding style`_, with the
219following exceptions:
220
221* Add braces to every ``if`` and ``else`` body, even for single-line code
222  blocks.
223* Use spaces instead of tabs to align comments after declarations, as needed.
224* Use C89-style single-line comments, ``/*  */``. The C99-style single-line
225  comment, ``//``, is not allowed.
226* Use ``/**  */`` for doxygen comments that need to appear in the
227  documentation.
228* The line limit is 120 columns instead of 80 columns. Note that tabs are
229  8-column wide.
230
231You can use *checkpatch* from the Linux kernel to check the compliance. ACRN
232maintains a :acrn_file:`.checkpatch.conf <.checkpatch.conf>` file that
233customizes the script to stop warnings on the exceptions above. Invoke
234*checkpatch* with the root of the ``acrn-hypervisor`` repository as the
235current working directory to make the configurations effective.
236
237.. _Contribution workflow:
238
239Contribution Workflow
240*********************
241
242One general practice we encourage, is to make small, controlled changes. This
243practice simplifies review, makes merging and rebasing easier, and keeps the
244change history clear and clean.
245
246When contributing to project ACRN, it is also important that you provide as
247much information as you can about your change, update appropriate
248documentation, and test your changes thoroughly before submitting.
249
250Documentation changes should also be checked for technical accuracy,
251spelling, grammar, and clarity and that the :ref:`doc_guidelines` are
252being followed. It's also good practice to do a local documentation build to
253verify that the changes don't cause the build to fail. See :ref:`acrn_doc`
254for details.
255
256The general GitHub workflow used by project ACRN developers uses a combination
257of command-line Git commands and browser interaction with GitHub.  As it is
258with Git, there are multiple ways of getting a task done.  We'll describe a
259typical workflow here for the acrn-hypervisor repo, which includes the
260source files for the hypervisor, devicemodel, and documentation.
261
262.. important:: Both code and documentation changes follow the same steps
263   shown here, with one exception: before submitting a GitHub pull request
264   (PR) with your changes, all **code** changes are first sent to the ACRN
265   developer mailing list for discussion and review.  After obtaining the
266   proper **Reviewed-by:** and **Acked-by:** approvals, code patches may
267   then be submitted as a GitHub PR.  Documentation changes should be
268   submitted separately from code changes, and are reviewed via GitHub
269   comments to the PR.
270
271.. _Create a Fork of acrn-hypervisor:
272   https://github.com/projectacrn/acrn-hypervisor#fork-destination-box
273
274#. `Create a Fork of acrn-hypervisor`_
275   to your personal account on GitHub. (Click on the fork button in the top
276   right corner of the project acrn-hypervisor repo page in GitHub.)
277   When you want to submit a pull request with your changes, you'll
278   first submit them to your personal branch, and then to the project's
279   main branch for review and merging by the ACRN maintainers.
280
281#. On your development computer, clone the fork you just made::
282
283     $ git clone https://github.com/<your github id>/acrn-hypervisor
284
285   This would be a good time to let Git know about the upstream repo too::
286
287     $ git remote add upstream https://github.com/projectacrn/acrn-hypervisor.git
288
289   and verify the remote repos::
290
291     $ git remote -v
292
293#. Create a topic branch (off of the main branch) for your work (if you're
294   addressing an issue, we suggest including the issue number in the
295   branch name)::
296
297     $ git checkout master
298     $ git checkout -b fix_comment_typo
299
300   Give your branch a short descriptive name.
301
302#. Make changes, test locally, change, test, test again, ...
303
304#. When things look good, start the pull request process by checking
305   which files have not been staged::
306
307     $ git status
308
309   Then add the changed files::
310
311     $ git add [file(s) that changed]
312
313   (or to have all changed files staged, use)::
314
315     $ git add -A
316
317#. Verify changes to be committed look as you expected::
318
319     $ git diff --cached
320
321#. Commit your changes to your local repo::
322
323     $ git commit -s
324
325   The ``-s`` option automatically adds your ``Signed-off-by:`` to your commit
326   message.  Your commit will be rejected without this line that indicates
327   your agreement with the `DCO`_.  See the `Commit Guidelines`_ section
328   below for specific guidelines for writing your commit messages.
329
330   All commits must be mapped to a GitHub issue for a feature or bug. Add a
331   ``Tracked-On: #issue-number`` line to your commit message together with the
332   issue number. For example::
333
334      Tracked-On: #1420
335
336
337   If only **documentation changes** are made, you can submit your PR
338   without a review on the ACRN developer mailing list, so you can skip
339   directly to step 9.
340
3418. As mentioned earlier, all **code changes** must first be reviewed and
342   approved via the developer mailing list.  You start this review process by
343   sending a patch file for each commit, as created by the
344   ``git format-patch`` command.  For example, if your change is contained in
345   one commit, create a patch file (in ``/tmp``, or some other location) with
346   the command::
347
348      $ git format-patch -o /tmp/ -1
349
350   Then email the generated ``.patch`` file(s) to the ACRN developer
351   mailing list, acrn-dev@lists.projectacrn.org using the ``git send-email``
352   command. (See the `Git send-email documentation`_ for details.
353   For example::
354
355      $ git send-email /tmp/000*.patch --to acrn-dev@lists.projectacrn.org
356
357   You can see examples of change requests and discussions in the
358   `ACRN developer mailing list archive <https://lists.projectacrn.org/g/acrn-dev>`_.
359
360   After all review issues have been resolved, amend your commit with
361   necessary changes, and also update the commit message with approvals given
362   in the mailing list discussion by adding **Reviewed-by:** and **Acked-by:**
363   tags.
364
365   You can then proceed to the next step and submit a Git pull request
366   to the repo.
367
3689. Push your topic branch with your changes to your fork in your personal
369   GitHub account::
370
371     $ git push origin fix_comment_typo
372
373#. In your web browser, go to your personal forked repo and click the
374   Compare & pull request button for the branch you just worked on and want to
375   submit to the upstream ACRN repo.
376
377#. Review the pull request changes, and verify that you are opening a pull
378   request for the appropriate branch. The title and message from your commit
379   message should appear as well.
380
381#. GitHub will assign one or more suggested reviewers (based on the CODEOWNERS
382   file in the repo). If you are a project member, you can select additional
383   reviewers now too. If no reviewers are selected, the ACRN triage team will
384   assign reviewers as appropriate.
385
386#. Click the submit button. Your pull request is sent and awaits review.
387   For code changes, this review should be cursory since any issues were
388   handled via the mailing list review. Email will be sent as review comments
389   are made, or you can check on your pull request at
390   https://github.com/projectacrn/acrn-hypervisor/pulls.
391
392#. While you're waiting for your pull request to be accepted and merged, you
393   can create another branch to work on another issue. (Be sure to make your
394   new branch off of the main branch and not the previous branch)::
395
396     $ git checkout master
397     $ git checkout -b fix_another_issue
398
399   Use the same process described above to work on this new topic branch.
400
401#. If reviewers request changes to your patch, you can interactively rebase
402   one or more commits to fix review issues. In your development repo, make
403   the needed changes on the branch that you initially submitted::
404
405     $ git checkout fix-comment-typo
406
407   Make the requested changes, and then::
408
409     $ git fetch --all
410     $ git rebase --ignore-whitespace upstream/master
411
412   This is an important step to make sure that your changes are properly
413   merged with changes from other developers that may have occurred while you
414   were working on your changes.
415
416   The ``--ignore-whitespace`` option stops ``git apply`` (called by
417   rebase) from changing any whitespace characters (such as spaces, tabs, and
418   newlines). If any merging issues are detected you can address them
419   with::
420
421     $ git rebase -i <offending-commit-id>
422
423   In the interactive rebase editor, replace pick with edit to select a
424   specific commit (if there's more than one in your pull request), or remove
425   the line to delete a commit entirely. Then edit files to fix the issues in
426   the review.
427
428   As before, inspect and test your changes. When ready, continue the
429   patch submission::
430
431      $ git add [file(s)]
432      $ git rebase --continue
433
434   Update commit comment if needed, and then continue::
435
436      $ git push --force origin fix_comment_typo
437
438   By force pushing your update, you ensure that your original pull request
439   will be updated with your changes, so you won't need to resubmit the
440   pull request.
441
442   You can follow the same workflow for contributing to the acrn-devicemodel
443   or acrn-documentation repos.
444
445
446Commit Guidelines
447*****************
448
449Changes are submitted as Git commits. Each commit message must contain:
450
451* A short and descriptive subject line that is fewer than 72 characters,
452  followed by a blank line. The subject line must include a prefix that
453  identifies the subsystem being changed, followed by a colon, and a short
454  title.  For example:  ``doc: update commit guidelines instructions``.
455  (If you're updating an existing file, you can use
456  ``git log <filename>`` to see what developers used as the prefix for
457  previous patches of this file.)
458
459* A change description with your logic or reasoning for the changes, followed
460  by a blank line.
461
462* A Signed-off-by line, ``Signed-off-by: <name> <email>`` typically added
463  automatically by using ``git commit -s``
464
465* For traceability, all changes must include reference to a GitHub
466  issue. Include a line of the form::
467
468      Tracked-On: #issue-number
469
470All changes and topics sent to GitHub must be well-formed, as described above.
471
472Commit Message Body
473===================
474
475When editing the commit message, briefly explain what your change
476does and why it's needed. A change summary of ``"Fixes stuff"`` will be
477rejected.
478
479.. warning::
480   An empty change summary body is not permitted. Even for trivial changes,
481   include a summary body in the commit message.
482
483The description body of the commit message must include:
484
485* **what** the change does,
486* **why** you chose that approach,
487* **what** assumptions were made, and
488* **how** you know it works -- for example, which tests you ran.
489
490For examples of accepted commit messages, you can refer to the acrn-hypervisor
491GitHub
492`changelog <https://github.com/projectacrn/acrn-hypervisor/commits/master>`__.
493
494Other Commit Expectations
495=========================
496
497* Commits must build cleanly when applied on top of each other, thus avoiding
498  breaking bisectability.
499
500* Each commit must address a single identifiable issue and must be
501  logically self-contained. Unrelated changes should be submitted as
502  separate commits.
503
504* You may submit pull-request RFCs (requests for comments) to send work
505  proposals or progress snapshots of your work, or to get early feedback on
506  features or changes that will affect multiple areas in the code base.
507
508Identifying Contribution Origin
509===============================
510
511When adding a new file to the tree, it is important to detail the source of
512origin on the file, provide attributions, and detail the intended usage. In
513cases where the file is an original to acrn-hypervisor, the commit message
514should include the following ("Original" is the assumption if no Origin tag is
515present)::
516
517    Origin: Original
518
519In cases where the file is imported from an external project, the commit
520message must contain details regarding the original project, the location of
521the project, the SHA-id of the origin commit for the file, the intended
522purpose, and whether the file will be maintained by the acrn-hypervisor
523project (whether project ACRN will contain a localized branch or whether it is
524a downstream copy).
525
526For example, a copy of a locally maintained import::
527
528    Origin: Contiki OS
529    License: BSD 3-Clause
530    URL: http://www.contiki-os.org/
531    commit: 853207acfdc6549b10eb3e44504b1a75ae1ad63a
532    Purpose: Introduction of networking stack.
533    Maintained-by: acrn-hypervisor
534
535For example, a copy of an externally maintained import::
536
537    Origin: Tiny Crypt
538    License: BSD 3-Clause
539    URL: https://github.com/01org/tinycrypt
540    commit: 08ded7f21529c39e5133688ffb93a9d0c94e5c6e
541    Purpose: Introduction of TinyCrypt
542    Maintained-by: External
543