1*cfb92d14SAndroid Build Coastguard Worker# Contributing to OpenThread 2*cfb92d14SAndroid Build Coastguard Worker 3*cfb92d14SAndroid Build Coastguard WorkerWe would love for you to contribute to OpenThread and help make it even better than it is today! As a contributor, here are the guidelines we would like you to follow. 4*cfb92d14SAndroid Build Coastguard Worker 5*cfb92d14SAndroid Build Coastguard Worker- [1 Code of Conduct](#code-of-conduct) 6*cfb92d14SAndroid Build Coastguard Worker- [2 Bugs](#bugs) 7*cfb92d14SAndroid Build Coastguard Worker- [3 New Features](#new-features) 8*cfb92d14SAndroid Build Coastguard Worker- [4 Contributing Code](#contributing-code) 9*cfb92d14SAndroid Build Coastguard Worker - [4.1 Initial Setup](#initial-setup) 10*cfb92d14SAndroid Build Coastguard Worker - [4.2 Contributor License Agreement (CLA)](#contributor-license-agreement--cla-) 11*cfb92d14SAndroid Build Coastguard Worker - [4.3 Submitting a Pull Request](#submitting-a-pull-request) 12*cfb92d14SAndroid Build Coastguard Worker- [5 Contributing Documentation](#contributing-documentation) 13*cfb92d14SAndroid Build Coastguard Worker 14*cfb92d14SAndroid Build Coastguard Worker## Code of Conduct 15*cfb92d14SAndroid Build Coastguard Worker 16*cfb92d14SAndroid Build Coastguard WorkerHelp us keep OpenThread open and inclusive. Please read and follow our [Code of Conduct](CODE_OF_CONDUCT.md). 17*cfb92d14SAndroid Build Coastguard Worker 18*cfb92d14SAndroid Build Coastguard Worker## Bugs 19*cfb92d14SAndroid Build Coastguard Worker 20*cfb92d14SAndroid Build Coastguard WorkerIf you find a bug in the source code, you can help us by [submitting a GitHub Issue](https://github.com/openthread/openthread/issues/new). The best bug reports provide a detailed description of the issue and step-by-step instructions for predictably reproducing the issue. Even better, you can [submit a Pull Request](#submitting-a-pull-request) with a fix. 21*cfb92d14SAndroid Build Coastguard Worker 22*cfb92d14SAndroid Build Coastguard Worker## New Features 23*cfb92d14SAndroid Build Coastguard Worker 24*cfb92d14SAndroid Build Coastguard WorkerYou can request a new feature by [submitting a GitHub Issue](https://github.com/openthread/openthread/issues/new). 25*cfb92d14SAndroid Build Coastguard Worker 26*cfb92d14SAndroid Build Coastguard WorkerIf you would like to implement a new feature, please consider the scope of the new feature: 27*cfb92d14SAndroid Build Coastguard Worker 28*cfb92d14SAndroid Build Coastguard Worker- _Large feature_: first [submit a GitHub Issue](https://github.com/openthread/openthread/issues/new) and communicate your proposal so that the community can review and provide feedback. Getting early feedback will help ensure your implementation work is accepted by the community. This will also allow us to better coordinate our efforts and minimize duplicated effort. 29*cfb92d14SAndroid Build Coastguard Worker 30*cfb92d14SAndroid Build Coastguard Worker- _Small feature_: can be implemented and directly [submitted as a Pull Request](#submitting-a-pull-request). 31*cfb92d14SAndroid Build Coastguard Worker 32*cfb92d14SAndroid Build Coastguard Worker## Contributing Code 33*cfb92d14SAndroid Build Coastguard Worker 34*cfb92d14SAndroid Build Coastguard WorkerThe OpenThread Project follows the "Fork-and-Pull" model for accepting contributions. 35*cfb92d14SAndroid Build Coastguard Worker 36*cfb92d14SAndroid Build Coastguard Worker### Initial Setup 37*cfb92d14SAndroid Build Coastguard Worker 38*cfb92d14SAndroid Build Coastguard WorkerSetup your GitHub fork and continuous-integration services: 39*cfb92d14SAndroid Build Coastguard Worker 40*cfb92d14SAndroid Build Coastguard Worker1. Fork the [OpenThread repository](https://github.com/openthread/openthread) by clicking "Fork" on the web UI. 41*cfb92d14SAndroid Build Coastguard Worker 42*cfb92d14SAndroid Build Coastguard WorkerSetup your local development environment: 43*cfb92d14SAndroid Build Coastguard Worker 44*cfb92d14SAndroid Build Coastguard Worker```bash 45*cfb92d14SAndroid Build Coastguard Worker# Clone your fork 46*cfb92d14SAndroid Build Coastguard Workergit clone [email protected]:<username>/openthread.git 47*cfb92d14SAndroid Build Coastguard Worker 48*cfb92d14SAndroid Build Coastguard Worker# Configure upstream alias 49*cfb92d14SAndroid Build Coastguard Workergit remote add upstream [email protected]:openthread/openthread.git 50*cfb92d14SAndroid Build Coastguard Worker``` 51*cfb92d14SAndroid Build Coastguard Worker 52*cfb92d14SAndroid Build Coastguard Worker### Contributor License Agreement (CLA) 53*cfb92d14SAndroid Build Coastguard Worker 54*cfb92d14SAndroid Build Coastguard WorkerContributions to this project must be accompanied by a Contributor License Agreement. You (or your employer) retain the copyright to your contribution; this simply gives us permission to use and redistribute your contributions as part of the project. Head over to <https://cla.developers.google.com/> to see your current agreements on file or to sign a new one. 55*cfb92d14SAndroid Build Coastguard Worker 56*cfb92d14SAndroid Build Coastguard WorkerYou generally only need to submit a CLA once, so if you've already submitted one (even if it was for a different project), you probably don't need to do it again. 57*cfb92d14SAndroid Build Coastguard Worker 58*cfb92d14SAndroid Build Coastguard Worker### Submitting a Pull Request 59*cfb92d14SAndroid Build Coastguard Worker 60*cfb92d14SAndroid Build Coastguard Worker#### Branch 61*cfb92d14SAndroid Build Coastguard Worker 62*cfb92d14SAndroid Build Coastguard WorkerFor each new feature, create a working branch: 63*cfb92d14SAndroid Build Coastguard Worker 64*cfb92d14SAndroid Build Coastguard Worker```bash 65*cfb92d14SAndroid Build Coastguard Worker# Create a working branch for your new feature 66*cfb92d14SAndroid Build Coastguard Workergit branch --track <branch-name> origin/main 67*cfb92d14SAndroid Build Coastguard Worker 68*cfb92d14SAndroid Build Coastguard Worker# Checkout the branch 69*cfb92d14SAndroid Build Coastguard Workergit checkout <branch-name> 70*cfb92d14SAndroid Build Coastguard Worker``` 71*cfb92d14SAndroid Build Coastguard Worker 72*cfb92d14SAndroid Build Coastguard Worker#### Create Commits 73*cfb92d14SAndroid Build Coastguard Worker 74*cfb92d14SAndroid Build Coastguard Worker```bash 75*cfb92d14SAndroid Build Coastguard Worker# Add each modified file you'd like to include in the commit 76*cfb92d14SAndroid Build Coastguard Workergit add <file1> <file2> 77*cfb92d14SAndroid Build Coastguard Worker 78*cfb92d14SAndroid Build Coastguard Worker# Create a commit 79*cfb92d14SAndroid Build Coastguard Workergit commit 80*cfb92d14SAndroid Build Coastguard Worker``` 81*cfb92d14SAndroid Build Coastguard Worker 82*cfb92d14SAndroid Build Coastguard WorkerThis will open up a text editor where you can craft your commit message. 83*cfb92d14SAndroid Build Coastguard Worker 84*cfb92d14SAndroid Build Coastguard Worker#### Upstream Sync and Clean Up 85*cfb92d14SAndroid Build Coastguard Worker 86*cfb92d14SAndroid Build Coastguard WorkerPrior to submitting your pull request, you might want to do a few things to clean up your branch and make it as simple as possible for the original repo's maintainer to test, accept, and merge your work. 87*cfb92d14SAndroid Build Coastguard Worker 88*cfb92d14SAndroid Build Coastguard WorkerIf any commits have been made to the upstream main branch, you should rebase your development branch so that merging it will be a simple fast-forward that won't require any conflict resolution work. 89*cfb92d14SAndroid Build Coastguard Worker 90*cfb92d14SAndroid Build Coastguard Worker```bash 91*cfb92d14SAndroid Build Coastguard Worker# Fetch upstream main and merge with your repo's main branch 92*cfb92d14SAndroid Build Coastguard Workergit checkout main 93*cfb92d14SAndroid Build Coastguard Workergit pull upstream main 94*cfb92d14SAndroid Build Coastguard Worker 95*cfb92d14SAndroid Build Coastguard Worker# If there were any new commits, rebase your development branch 96*cfb92d14SAndroid Build Coastguard Workergit checkout <branch-name> 97*cfb92d14SAndroid Build Coastguard Workergit rebase main 98*cfb92d14SAndroid Build Coastguard Worker``` 99*cfb92d14SAndroid Build Coastguard Worker 100*cfb92d14SAndroid Build Coastguard WorkerNow, it may be desirable to squash some of your smaller commits down into a small number of larger more cohesive commits. You can do this with an interactive rebase: 101*cfb92d14SAndroid Build Coastguard Worker 102*cfb92d14SAndroid Build Coastguard Worker```bash 103*cfb92d14SAndroid Build Coastguard Worker# Rebase all commits on your development branch 104*cfb92d14SAndroid Build Coastguard Workergit checkout 105*cfb92d14SAndroid Build Coastguard Workergit rebase -i main 106*cfb92d14SAndroid Build Coastguard Worker``` 107*cfb92d14SAndroid Build Coastguard Worker 108*cfb92d14SAndroid Build Coastguard WorkerThis will open up a text editor where you can specify which commits to squash. 109*cfb92d14SAndroid Build Coastguard Worker 110*cfb92d14SAndroid Build Coastguard Worker#### Coding Conventions and Style 111*cfb92d14SAndroid Build Coastguard Worker 112*cfb92d14SAndroid Build Coastguard WorkerOpenThread uses and enforces the [OpenThread Coding Conventions and Style](STYLE_GUIDE.md) on all code, except for code located in [third_party](third_party). Use `script/make-pretty` and `script/make-pretty check` to automatically reformat code and check for code-style compliance, respectively. OpenThread currently requires [clang-format v14.0.0](https://releases.llvm.org/download.html#14.0.0) for C/C++ and [yapf v0.31.0](https://github.com/google/yapf) for Python. 113*cfb92d14SAndroid Build Coastguard Worker 114*cfb92d14SAndroid Build Coastguard WorkerAs part of the cleanup process, you should also run `script/make-pretty check` to ensure that your code passes the baseline code style checks. 115*cfb92d14SAndroid Build Coastguard Worker 116*cfb92d14SAndroid Build Coastguard Worker#### Push and Test 117*cfb92d14SAndroid Build Coastguard Worker 118*cfb92d14SAndroid Build Coastguard Worker```bash 119*cfb92d14SAndroid Build Coastguard Worker# Checkout your branch 120*cfb92d14SAndroid Build Coastguard Workergit checkout <branch-name> 121*cfb92d14SAndroid Build Coastguard Worker 122*cfb92d14SAndroid Build Coastguard Worker# Push to your GitHub fork: 123*cfb92d14SAndroid Build Coastguard Workergit push origin <branch-name> 124*cfb92d14SAndroid Build Coastguard Worker``` 125*cfb92d14SAndroid Build Coastguard Worker 126*cfb92d14SAndroid Build Coastguard WorkerThis will trigger continuous-integration checks using GitHub Actions. You can view the status and logs via the "Actions" tab in your fork. 127*cfb92d14SAndroid Build Coastguard Worker 128*cfb92d14SAndroid Build Coastguard Worker#### Submit Pull Request 129*cfb92d14SAndroid Build Coastguard Worker 130*cfb92d14SAndroid Build Coastguard WorkerOnce you've validated that all continuous-integration checks have passed, go to the page for your fork on GitHub, select your development branch, and click the pull request button. If you need to make any adjustments to your pull request, just push the updates to GitHub. Your pull request will automatically track the changes on your development branch and update. 131*cfb92d14SAndroid Build Coastguard Worker 132*cfb92d14SAndroid Build Coastguard Worker#### Checks fail 133*cfb92d14SAndroid Build Coastguard Worker 134*cfb92d14SAndroid Build Coastguard WorkerOnce you've submitted a pull request, all continuous-integration checks are triggered again. If some of these checks fail, it could be either problems with the pull request or an intermittent failure of some test cases. For more information on the failure, check the output and download artifacts. (After all jobs in one group are completed, an `Artifacts` button appears beside the `Re-run` jobs button.) If the failure is intermittent, the check will usually pass after rerunning once or twice. 135*cfb92d14SAndroid Build Coastguard Worker 136*cfb92d14SAndroid Build Coastguard WorkerWe want to eliminate intermittent failures as well, so when you experience such a failure, please log an issue and attach any relevant artifacts. If the artifacts are too big, provide the link of the failed run (do not rerun checks again, or it will be overwritten). Alternatively, upload the artifacts to a file-sharing service like Google Drive and share a link to it. 137*cfb92d14SAndroid Build Coastguard Worker 138*cfb92d14SAndroid Build Coastguard Worker##### Analyze core dumps in failed checks 139*cfb92d14SAndroid Build Coastguard Worker 140*cfb92d14SAndroid Build Coastguard WorkerFor some checks, core dumps for crashed programs are uploaded as artifacts in a failed check. Besides core dumps, binaries and shared libraries are also uploaded so that we can analyze the dumps locally. To analyze the dumps, download the artifact `core-xxx` and unzip it. The package is in the following format: 141*cfb92d14SAndroid Build Coastguard Worker 142*cfb92d14SAndroid Build Coastguard Worker``` 143*cfb92d14SAndroid Build Coastguard Worker|-- build 144*cfb92d14SAndroid Build Coastguard Worker| `-- cmake 145*cfb92d14SAndroid Build Coastguard Worker| `-- openthread-simulation-1.2 146*cfb92d14SAndroid Build Coastguard Worker| `-- examples 147*cfb92d14SAndroid Build Coastguard Worker| `-- apps 148*cfb92d14SAndroid Build Coastguard Worker| `-- cli 149*cfb92d14SAndroid Build Coastguard Worker| |-- ot-cli-ftd 150*cfb92d14SAndroid Build Coastguard Worker| `-- ot-cli-mtd 151*cfb92d14SAndroid Build Coastguard Worker|-- ot-core-dump 152*cfb92d14SAndroid Build Coastguard Worker| `-- corefile-ot-cli-ftd-11323-1606274703 153*cfb92d14SAndroid Build Coastguard Worker`-- so-lib 154*cfb92d14SAndroid Build Coastguard Worker |-- ld-linux-x86-64.so.2 155*cfb92d14SAndroid Build Coastguard Worker |-- libc.so.6 156*cfb92d14SAndroid Build Coastguard Worker `-- libgcc_s.so.1 157*cfb92d14SAndroid Build Coastguard Worker``` 158*cfb92d14SAndroid Build Coastguard Worker 159*cfb92d14SAndroid Build Coastguard WorkerOnce unzipped: 160*cfb92d14SAndroid Build Coastguard Worker 161*cfb92d14SAndroid Build Coastguard Worker1. `cd` to the unzipped directory 162*cfb92d14SAndroid Build Coastguard Worker2. Run `gdb build/cmake/openthread-simulation-1.2/examples/apps/cli/ot-cli-ftd ./ot-core-dump/corefile-ot-cli-ftd-XXX`. 163*cfb92d14SAndroid Build Coastguard Worker3. Set the absolute path of `so-lib`. In gdb, run `set solib-absolute-prefix /ABSOLUTE/PATH/TO/so-lib/`, then run `set solib-search-path /ABSOLUTE/PATH/TO/so-lib/`. 164*cfb92d14SAndroid Build Coastguard Worker4. In gdb, run `backtrace` or `bt`. Then you should see the stack of the crashed program. Find and fix the problem! 165*cfb92d14SAndroid Build Coastguard Worker 166*cfb92d14SAndroid Build Coastguard Worker## Contributing Documentation 167*cfb92d14SAndroid Build Coastguard Worker 168*cfb92d14SAndroid Build Coastguard WorkerDocumentation undergoes the same review process as code and contributions may be mirrored on our [openthread.io](https://openthread.io) website. 169*cfb92d14SAndroid Build Coastguard Worker 170*cfb92d14SAndroid Build Coastguard Worker### Codelabs and Guides 171*cfb92d14SAndroid Build Coastguard Worker 172*cfb92d14SAndroid Build Coastguard WorkerTo review and contribute to OpenThread Codelabs and Guides, refer to the following GitHub repositories: 173*cfb92d14SAndroid Build Coastguard Worker 174*cfb92d14SAndroid Build Coastguard Worker- [Codelabs](https://github.com/openthread/ot-docs/tree/main/site/en/codelabs) 175*cfb92d14SAndroid Build Coastguard Worker- [Guides](https://github.com/openthread/ot-docs/tree/main/site/en/guides) 176*cfb92d14SAndroid Build Coastguard Worker 177*cfb92d14SAndroid Build Coastguard WorkerFor information on how to author and format documentation for contribution, refer to the [Documentation Style Guide](https://github.com/openthread/ot-docs/blob/main/STYLE_GUIDE.md). 178*cfb92d14SAndroid Build Coastguard Worker 179*cfb92d14SAndroid Build Coastguard Worker### API Reference topics 180*cfb92d14SAndroid Build Coastguard Worker 181*cfb92d14SAndroid Build Coastguard WorkerAPI Reference topics use [Doxygen comment blocks](https://www.doxygen.nl/manual/docblocks.html) to render the HTML output on [https://openthread.io/reference](https://openthread.io/reference). OpenThread scripts support the following Doxygen [special commands](https://www.doxygen.nl/manual/commands.html): 182*cfb92d14SAndroid Build Coastguard Worker 183*cfb92d14SAndroid Build Coastguard Worker- @file 184*cfb92d14SAndroid Build Coastguard Worker- @brief 185*cfb92d14SAndroid Build Coastguard Worker- @param 186*cfb92d14SAndroid Build Coastguard Worker- @returns 187*cfb92d14SAndroid Build Coastguard Worker 188*cfb92d14SAndroid Build Coastguard WorkerYou can find most of these comments in the [OpenThread header files](https://github.com/openthread/openthread/tree/main/include/openthread). To review an example, refer to [`border_agent.h`](https://github.com/openthread/openthread/tree/main/include/openthread/border_agent.h). The Doxygen comments in `border_agent.h` output the [Border Agent](https://openthread.io/reference/group/api-border-agent) reference topic on openthread.io. For more information, refer to [Comments](https://github.com/openthread/openthread/blob/main/STYLE_GUIDE.md#comments) in the OpenThread Coding Conventions and Style guide. 189