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