1.. _dev-environment-and-tools:
2
3Development Environment and Tools
4#################################
5
6Code Review
7************
8
9GitHub is intended to provide a framework for reviewing every commit before it
10is accepted into the code base. Changes, in the form of Pull Requests (PR) are
11uploaded to GitHub but don't actually become a part of the project until they've
12been reviewed, passed a series of checks (CI), and are approved by maintainers.
13GitHub is used to support the standard open source practice of submitting
14patches, which are then reviewed by the project members before being applied to
15the code base.
16
17Pull requests should be appropriately :ref:`labeled<gh_labels>`,
18and linked to any relevant :ref:`bug or feature tracking issues<bug_reporting>`
19.
20
21The Zephyr project uses GitHub for code reviews and Git tree management. When
22submitting a change or an enhancement to any Zephyr component, a developer
23should use GitHub. GitHub Actions automatically assigns a responsible reviewer
24on a component basis, as defined in the :zephyr_file:`MAINTAINERS.yml` file
25stored with the code tree in the Zephyr project repository. A limited set of
26release managers are allowed to merge a pull request into the main branch once
27reviews are complete.
28
29.. _review_time:
30
31Give reviewers time to review before code merge
32================================================
33
34The Zephyr project is a global project that is not tied to a certain geography
35or timezone. We have developers and contributors from across the globe. When
36changes are proposed using pull request, we need to allow for a minimal review
37time to give developers and contributors the opportunity to review and comment
38on changes. There are different categories of changes and we know that some
39changes do require reviews by subject matter experts and owners of the subsystem
40being changed. Many changes fall under the "trivial" category that can be
41addressed with general reviews and do not need to be queued for a maintainer or
42code-owner review. Additionally, some changes might require further discussions
43and a decision by the TSC or the Security working group. To summarize the above,
44the diagram below proposes minimal review times for each category:
45
46
47.. figure:: pull_request_classes.png
48    :align: center
49    :alt: Pull request classes
50    :figclass: align-center
51
52    Pull request classes
53
54Workflow
55---------
56
57- An author of a change can suggest in his pull-request which category a change
58  should belong to. A project maintainers or TSC member monitoring the inflow of
59  changes can change the label of a pull request by adding a comment justifying
60  why a change should belong to another category.
61- The project will use the label system to categorize the pull requests.
62- Changes should not be merged before the minimal time has expired.
63
64Categories/Labels
65-----------------
66
67Hotfix
68++++++
69
70Any change that is a fix to an issue that blocks developers from doing their
71daily work, for example CI breakage, Test breakage, Minor documentation fixes
72that impact the user experience.
73
74Such fixes can be merged at any time after they have passed CI checks. Depending
75on the fix, severity, and availability of someone to review them (other than the
76author) they can be merged with justification without review by one of the
77project owners.
78
79Trivial
80+++++++
81
82Trivial changes are those that appear obvious enough and do not require maintainer or code-owner
83involvement. Such changes should not change the logic or the design of a
84subsystem or component. For example a trivial change can be:
85
86- Documentation changes
87- Configuration changes
88- Minor Build System tweaks
89- Minor optimization to code logic without changing the logic
90- Test changes and fixes
91- Sample modifications to support additional configuration or boards etc.
92
93Maintainer
94+++++++++++
95
96Any changes that touch the logic or the original design of a subsystem or
97component will need to be reviewed by the code owner or the designated subsystem
98maintainer. If the code changes is initiated by a contributor or developer other
99than the owner the pull request needs to be assigned to the code owner who will
100have to drive the pull request to a mergeable state by giving feedback to the
101author and asking for more reviews from other developers.
102
103Security
104+++++++++++
105
106Changes that appear to have an impact to the overall security of the system need
107to be reviewed by a security expert from the security working group.
108
109TSC and Working Groups
110++++++++++++++++++++++
111
112Changes that introduce new features or functionality or change the way the
113overall system works need to be reviewed by the TSC or the responsible Working
114Group. For example for :ref:`breaking API changes <breaking_api_changes>`, the
115proposal needs to be presented in the Architecture meeting so that the relevant
116stakeholders are made aware of the change.
117
118A Pull-Request should have an Assignee
119=======================================
120
121- An assignee to a pull request should not be the same as the
122  author of the pull-request
123- An assignee to a pull request is responsible for driving the
124  pull request to a mergeable state
125- An assignee is responsible for dismissing stale reviews and seeking reviews
126  from additional developers and contributors
127- Pull requests should not be merged without an approval by the assignee.
128
129Pull Request should not be merged by author without review
130===========================================================
131
132All pull requests need to be reviewed and should not be merged by the author
133without a review. The following exceptions apply:
134
135- Hot fixes: Fixing CI issues, reverts, and system breakage
136- Release related changes: Changing version file, applying tags and release
137  related activities without any code changes.
138
139Developers and contributors should always seek review, however there are cases
140when reviewers are not available and there is a need to get a code change into
141the tree as soon as possible.
142
143Reviewers shall not 'Request Changes' without comments or justification
144=======================================================================
145
146Any change requests (-1) on a pull request have to be justified. A reviewer
147should avoid blocking a pull-request with no justification. If a reviewer feels
148that a change should not be merged without their review, then: Request change
149of the category: for example:
150
151- Trivial -> Maintainer
152- Assign Pull Request to yourself, this will mean that a pull request should
153  not be merged without your approval.
154
155
156Pull Requests should have at least 2 approvals before they are merged
157======================================================================
158
159A pull-request shall be merged only with two positive reviews (approval). Beside
160the person merging the pull-request (merging != approval), two additional
161approvals are required to be able to merge a pull request. The person merging
162the request can merge without approving or approve and merge to get to the 2
163approvals required.
164
165Reviewers should keep track of pull requests they have provided feedback to
166===========================================================================
167
168If a reviewer has requested changes in a pull request, he or she should monitor
169the state of the pull request and/or respond to mention requests to see if his
170feedback has been addressed. Failing to do so, negative reviews shall be
171dismissed by the assignee or an owner of the repository. Reviews will be
172dismissed following the criteria below:
173
174- The feedback or concerns were visibly addressed by the author
175- The reviewer did not revisit the pull request after 2 week and multiple pings
176  by the author
177- The review is unrelated to the code change or asking for unjustified
178  structural changes such as:
179
180  - Split the PR
181  - Can you fix this unrelated code that happens to appear in the diff
182  - Can you fix unrelated issues
183  - Etc.
184
185Closing Stale Issues and Pull Requests
186=======================================
187
188- The Pull requests and issues sections on Github are NOT discussion forums.
189  They are items that we need to execute and drive to closure.
190  Use the mailing lists for discussions.
191- In case of both issues and pull-requests the original poster needs to respond
192  to questions and provide clarifications regarding the issue or the change.
193  After one week without a response to a request, a second attempt to elicit
194  a response from the contributor will be made. After one more week without a
195  response the item may be closed (draft and DNM tagged pull requests are
196  excluded).
197
198Continuous Integration
199***********************
200
201All changes submitted to GitHub are subject to tests that are run on
202emulated platforms and architectures to identify breakage and regressions that
203can be immediately identified. Testing using Twister additionally performs build tests
204of all boards and platforms. Documentation changes are also verified
205through review and build testing to verify doc generation will be successful.
206
207Any failures found during the CI test run will result in a negative review
208assigned automatically by the CI system.
209Developers are expected to fix issues and rework their patches and submit again.
210
211The CI infrastructure currently runs the following tests:
212
213- Run ``checkpatch`` for code style issues (can vote -1 on errors; see note)
214- Gitlint: Git commit style based on project requirements
215- License Check: Check for conflicting licenses
216- Run ``twister`` script
217
218  - Run kernel tests in QEMU (can vote -1 on errors)
219  - Build various samples for different boards (can vote -1 on errors)
220
221- Verify documentation builds correctly.
222
223.. note::
224
225   ``checkpatch`` is a Perl script that uses regular expressions to
226   extract information that requires a C language parser to process
227   accurately.  As such it sometimes issues false positives.  Known
228   cases include constructs like:
229
230    .. code-block:: c
231
232      static uint8_t __aligned(PAGE_SIZE) page_pool[PAGE_SIZE * POOL_PAGES];
233      IOPCTL_Type *base = config->base;
234
235   Both lines produce a diagnostic regarding spaces around the ``*``
236   operator: the first is misidentified as a pointer type declaration
237   that would be correct as ``PAGE_SIZE *POOL_PAGES`` while the second
238   is misidentified as a multiplication expression that would be correct
239   as ``IOPCTL_Type * base``.
240
241   Maintainers can override the -1 in cases where the CI infrastructure
242   gets the wrong answer.
243
244
245.. _gh_labels:
246
247Labeling issues and pull requests in GitHub
248*******************************************
249
250The project uses GitHub issues and pull requests (PRs) to track and manage
251daily and long-term work and contributions to the Zephyr project. We use
252GitHub **labels** to classify and organize these issues and PRs by area, type,
253priority, and more, making it easier to find and report on relevant items.
254
255All GitHub issues or pull requests must be appropriately labeled.
256Issues and PRs often have multiple labels assigned,
257to help classify them in the different available categories.
258When reviewing a PR, if it has missing or incorrect labels, maintainers shall
259fix it.
260
261This saves us all time when searching, reduces the chances of the PR or issue
262being forgotten, speeds up reviewing, avoids duplicate issue reports, etc.
263
264These are the labels we currently have, grouped by applicability:
265
266Labels applicable to issues only
267================================
268
269.. list-table::
270   :header-rows: 1
271
272   * - Label
273     - Description
274
275   * - :guilabel:`priority: {high|medium|low}`
276     - To classify the impact and importance of a bug or
277       :ref:`feature <feature-tracking>`.
278
279       Note: Issue priorities are generally set or changed during the bug-triage or TSC
280       meetings.
281
282   * - :guilabel:`Regression`
283     - Something, which was working, but does not anymore (bug subtype).
284
285   * - :guilabel:`Enhancement`
286     - Changes/Updates/Additions to existing :ref:`features <feature-tracking>`.
287
288   * - :guilabel:`Feature request`
289     - A request for a new :ref:`feature <feature-tracking>`.
290
291   * - :guilabel:`Feature`
292     - A :ref:`planned feature<feature-tracking>` with a milestone.
293
294   * - :guilabel:`Hardware Support`
295     - Covers porting an existing feature (including Zephyr itself) to new hardware.
296
297   * - :guilabel:`Duplicate`
298     - This issue is a duplicate of another issue (please specify).
299
300   * - :guilabel:`Good first issue`
301     - Good for a first time contributor to take.
302
303   * - :guilabel:`Release Notes`
304     - Issues that need to be mentioned in release notes as known issues with
305       additional information.
306
307Any issue must be classified and labeled as either *Bug*, *Enhancement*, *RFC*,
308*Feature*, *Feature Request* or *Hardware Support*. More information on how
309feature requests are handled and become features can be found in :ref:`Feature
310Tracking<feature-tracking>`.
311
312Labels applicable to pull requests only
313=======================================
314
315The issue or PR describes a change to a stable API.
316
317.. list-table::
318   :header-rows: 1
319
320   * - Label
321     - Description
322
323   * - :guilabel:`Hotfix`
324     - Fix for an issue blocking development.
325
326   * - :guilabel:`Trivial`
327     - Simple changes that can have shorter review time and be reviewed by anyone, i.e. typos,
328       straightforward one-liner bug fixes, etc.
329
330   * - :guilabel:`Maintainer`
331     - Maintainer review required.
332
333   * - :guilabel:`Security Review`
334     - To be reviewed by a security expert.
335
336   * - :guilabel:`DNM`
337     - This PR should not be merged (Do Not Merge). For work in progress, GitHub
338       "draft" PRs are preferred.
339
340   * - :guilabel:`Needs review`
341     - The PR needs attention from the maintainers.
342
343   * - :guilabel:`Backport`
344     - The PR is a backport or should be backported.
345
346   * - :guilabel:`Licensing`
347     - The PR has licensing issues which require a licensing expert to review it.
348
349.. note::
350   For all labels applicable to PRs: Please note that the label, together with
351   PR complexity, affects how long a merge should be held to ensure proper
352   review. See :ref:`review process <review_time>` for details.
353
354
355Labels applicable to both pull requests and issues
356==================================================
357
358.. list-table::
359   :header-rows: 1
360
361   * - Label
362     - Description
363
364   * - :guilabel:`area: {area-name}`
365     - Indicates Zephyr subsystems (e.g, :guilabel:`area: Kernel`, :guilabel:`area: I2C`,
366       :guilabel:`area: Memory Management`), project functions (e.g., :guilabel:`area: Debugging`,
367       :guilabel:`area: Documentation`, :guilabel:`area: Process`), or other categories (e.g.,
368       :guilabel:`area: Coding Style`, :guilabel:`area: MISRA-C`) affected by the bug or the pull request.
369
370       An area maintainer should be able to filter by an area label and find all issues
371       and PRs which relate to that area.
372
373   * - :guilabel:`platform: {platform-name}`
374     - An issue or PR which affects only a particular platform.
375
376   * - :guilabel:`dev-review`
377     - The issue is to be discussed in the following `dev-review`_ if time
378       permits.
379
380       .. _`dev-review`: https://github.com/zephyrproject-rtos/zephyr/wiki/Zephyr-Committee-and-Working-Groups#zephyr-dev-meeting
381
382   * - :guilabel:`TSC`
383     - TSC stands for Technical Steering Committee. The issue is to be discussed in the
384       following `TSC meeting`_ if time permits.
385
386       .. _`TSC meeting`: https://github.com/zephyrproject-rtos/zephyr/wiki/Technical-Steering-Committee-(TSC)
387
388   * - :guilabel:`Breaking API Change`
389     - The issue or PR describes a breaking change to a stable API. See additional information
390       in :ref:`breaking_api_changes`.
391
392   * - :guilabel:`bug`
393     - The issue is a bug, or the PR is fixing a bug.
394
395   * - :guilabel:`Coverity`
396     - A Coverity detected issue or its fix.
397
398   * - :guilabel:`Waiting for response`
399     - The Zephyr developers are waiting for the submitter to respond to a question, or
400       address an issue.
401
402   * - :guilabel:`Blocked`
403     - Blocked by another PR or issue.
404
405   * - :guilabel:`Stale`
406     - An issue or a PR which seems abandoned, and requires attention by the author.
407
408   * - :guilabel:`In progress`
409     - For PRs: is work in progress and should not be merged yet. For issues: Is being
410       worked on.
411
412   * - :guilabel:`RFC`
413     - The author would like input from the community. For a PR it should be considered
414       a draft.
415
416   * - :guilabel:`LTS`
417     - Long term release branch related.
418
419   * - :guilabel:`EXT`
420     - Related to an external component.
421