|
| 1 | +## Development Model |
| 2 | + |
| 3 | +Development generally follows the following ideas: |
| 4 | + |
| 5 | + * New features are merged into to the `development` branch using |
| 6 | + Pull Requests (PRs). |
| 7 | + |
| 8 | + * Bug fixes, questions and contributions of new features are welcome! |
| 9 | + |
| 10 | + * Bugs should be reported through GitHub Issues. |
| 11 | + * We suggest asking questions through GitHub Discussions. |
| 12 | + * All contributions should be done via pull requests. |
| 13 | + A pull request should be generated from your fork of |
| 14 | + IAMReX and target the `development` branch. See below for |
| 15 | + details on how this process works. |
| 16 | + |
| 17 | + In general we squash commits upon merge to have a clean history. |
| 18 | + *Please ensure that your PR title and description are descriptive, |
| 19 | + since these will be used for a squashed commit message.* |
| 20 | + |
| 21 | + Please note the following: |
| 22 | + If you choose to make contributions to the code |
| 23 | + then you hereby grant a non-exclusive, royalty-free perpetual license |
| 24 | + to install, use, modify, prepare derivative works, |
| 25 | + incorporate into other computer software, |
| 26 | + distribute, and sublicense such enhancements or derivative works |
| 27 | + thereof, in binary and source code form. |
| 28 | + |
| 29 | + |
| 30 | +## Git workflow |
| 31 | + |
| 32 | +IAMReX uses [git](https://git-scm.com) for version control. If you |
| 33 | +are new to git, you can follow one of these tutorials: |
| 34 | +- [Learn git with bitbucket](https://www.atlassian.com/git/tutorials/learn-git-with-bitbucket-cloud) |
| 35 | +- [git - the simple guide](http://rogerdudler.github.io/git-guide/) |
| 36 | + |
| 37 | +### Make your own fork and create a branch on it |
| 38 | + |
| 39 | +The basic workflow is: |
| 40 | +- Fork the main repo (or update it if you already created it). |
| 41 | +- Implement your changes and push them on a new branch `<branch_name>` on |
| 42 | +your fork. |
| 43 | +- Create a Pull Request from branch `<branch_name>` on your fork to branch |
| 44 | +`development` on the main IAMReX repository. |
| 45 | + |
| 46 | +First, let us setup your local git repo. To make your own fork of the main |
| 47 | +repository, press the fork button on the [IAMReX Github page](https://github.com/ruohai0925/IAMReX). |
| 48 | + |
| 49 | + |
| 50 | +Then, clone IAMReX on your local computer. If you plan on doing a lot of IAMReX development, |
| 51 | +we recommend configuring your clone to use ssh access so you won't have to enter your Github |
| 52 | +password every time, which you can do using these commands: |
| 53 | + |
| 54 | +``` |
| 55 | +git clone https://github.com/ruohai0925/IAMReX.git |
| 56 | +cd IAMReX |
| 57 | +
|
| 58 | +# Add your own fork. |
| 59 | +# Here <Jane> is the name you give to your fork. It does not need to be your github name. |
| 60 | +# <myGithubUsername> is your GitHub name. |
| 61 | +git remote add <Jane> git@github.com:<myGithubUsername>/IAMReX.git |
| 62 | +git fetch <Jane> |
| 63 | +
|
| 64 | +# Don't push to the main repo. Instead pushes go to your fork. |
| 65 | +git remote set-url --push origin git@github.com:<myGithubUsername>/IAMReX.git |
| 66 | +``` |
| 67 | + |
| 68 | +For instructions on setting up SSH access to your Github account on a new |
| 69 | +machine, see |
| 70 | +[here.](https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh) |
| 71 | + |
| 72 | +If you instead prefer to use HTTPS authentication, configure your local clone as follows: |
| 73 | + |
| 74 | +``` |
| 75 | +git clone https://github.com/ruohai0925/IAMReX.git |
| 76 | +cd IAMReX |
| 77 | +
|
| 78 | +# Add your own fork. |
| 79 | +# Here <Jane> is the name you give to your fork. It does not need to be your github name. |
| 80 | +# <myGithubUsername> is your GitHub name. |
| 81 | +git remote add <Jane> https://github.com/<myGithubUsername>/IAMReX.git |
| 82 | +git fetch <Jane> |
| 83 | +
|
| 84 | +# Don't push to the main repo. Instead pushes go to your fork. |
| 85 | +git remote set-url --push origin https://github.com/<myGithubUsername>/IAMReX.git |
| 86 | +``` |
| 87 | + |
| 88 | +Now you are free to play with your fork (for additional information, you can visit the |
| 89 | +[Github fork help page](https://help.github.com/en/articles/fork-a-repo)). |
| 90 | + |
| 91 | +> Note: you do not have to re-do the setup above every time. |
| 92 | +
|
| 93 | +Make sure you are on the `development` branch with |
| 94 | +``` |
| 95 | +git checkout development |
| 96 | +git pull |
| 97 | +``` |
| 98 | +in the IAMReX directory. |
| 99 | + |
| 100 | +Create a branch `<branch_name>` (the branch name should reflect the piece |
| 101 | +of code you want to add, like `high_order_interpolation`) with |
| 102 | +``` |
| 103 | +git checkout -b <branch_name> |
| 104 | +``` |
| 105 | +and do the coding you want. |
| 106 | +Add the files you work on to the git staging area with |
| 107 | +``` |
| 108 | +git add <file_I_created> <and_file_I_modified> |
| 109 | +``` |
| 110 | +### Commit & push your changes |
| 111 | + |
| 112 | +Periodically commit your changes with |
| 113 | +``` |
| 114 | +git commit -m "This is a 50-char description to explain my work" |
| 115 | +``` |
| 116 | + |
| 117 | +The commit message (between quotation marks) is super important in order to |
| 118 | +follow the developments and identify bugs. |
| 119 | + |
| 120 | +For the moment, commits are on your local repo only. You can push them to |
| 121 | +your fork with |
| 122 | +``` |
| 123 | +git push -u <Jane> <branch_name> |
| 124 | +``` |
| 125 | + |
| 126 | +If you want to synchronize your branch with the `development` branch (this is useful |
| 127 | +when `development` is being modified while you are working on |
| 128 | +`<branch_name>`), you can use |
| 129 | +``` |
| 130 | +# merge IAMReX main repo's development into current branch |
| 131 | +git pull origin development |
| 132 | +``` |
| 133 | +and fix any conflicts that may occur. |
| 134 | + |
| 135 | +Do not merge your branch for PR into your local `development` branch, |
| 136 | +because it will make your local `development` branch diverge from the |
| 137 | +matching branch in the main repository after your PR is merged. |
| 138 | + |
| 139 | +### Submit a Pull Request |
| 140 | + |
| 141 | +A Pull Request is the way to efficiently visualize the changes you made |
| 142 | +and to propose your new feature/improvement/fix to the IAMReX project. |
| 143 | +Right after you push changes, a banner should appear on the Github page of |
| 144 | +your fork, with your `<branch_name>`. |
| 145 | +- Click on the `compare & pull request` button to prepare your PR. |
| 146 | +- It is time to communicate your changes: write a title and a description for |
| 147 | +your PR. People who review your PR are happy to know |
| 148 | + * what feature/fix you propose, and why |
| 149 | + * how you made it (created a new class than inherits from...) |
| 150 | + * and anything relevant to your PR (performance tests, images, *etc.*) |
| 151 | +- Press `Create pull request`. Now you can navigate through your PR, which |
| 152 | +highlights the changes you made. |
| 153 | + |
| 154 | +Please DO NOT write large Pull Requests, as they are very difficult and |
| 155 | +time-consuming to review. As much as possible, split them into small, |
| 156 | +targeted PRs. |
| 157 | +For example, if find typos in the documentation open a pull request that only fixes typos. |
| 158 | +If you want to fix a bug, make a small pull request that only fixes a bug. |
| 159 | +If you want to implement a large feature, write helper functionality first, test it and submit those as a first pull request. |
| 160 | +If you want to implement a feature and are not too sure how to split it, |
| 161 | +just open a discussion about your plans and ping other IAMReX developers on it to chime in. |
| 162 | + |
| 163 | +Even before your work is ready to merge, it can be convenient to create a PR |
| 164 | +(so you can use Github tools to visualize your changes). In this case, please |
| 165 | +make a "draft" PR using the drop-down menu next to the "Create pull request" button. |
| 166 | + |
| 167 | +Once your pull request is made, we will review and potentially merge it. |
| 168 | +We recommend always creating a new branch for each pull request, as per the above instructions. |
| 169 | +Once your pull request is merged, you can delete your local PR branch with |
| 170 | +``` |
| 171 | +git branch -D <branch_name> |
| 172 | +``` |
| 173 | + |
| 174 | +and you can delete the remote one on your fork with |
| 175 | +``` |
| 176 | +git push <Jane> --delete <branch_name> |
| 177 | +``` |
| 178 | + |
| 179 | +Generally speaking, you want to follow the following rules. |
| 180 | + |
| 181 | + * Do not merge your branch for PR into your local `development` branch that tracks IAMReX |
| 182 | + `development` branch. Otherwise your local `development` branch will diverge from IAMReX |
| 183 | + `development` branch. |
| 184 | + |
| 185 | + * Do not commit in your `development` branch that tracks IAMReX `development` branch. |
| 186 | + |
| 187 | + * Always create a new branch based off the latest `development` branch for |
| 188 | + each pull request, unless you are going to use git to fix it later. |
| 189 | + |
| 190 | +If you have accidentally committed in `development` branch, you can fix it as follows, |
| 191 | +``` |
| 192 | +git checkout -b new_branch # save your changes in a branch |
| 193 | +git checkout development |
| 194 | +git fetch origin |
| 195 | +git reset --hard origin/development |
| 196 | +``` |
| 197 | +After this, the local `development` should be in sync with IAMReX `development` and your recent |
| 198 | +commits have been saved in `new_branch` branch. |
| 199 | + |
| 200 | +## IAMReX Coding Style Guide |
| 201 | + |
| 202 | +### Code Guidelines |
| 203 | + |
| 204 | +IAMReX developers should adhere to the following coding guidelines: |
| 205 | + * Indentations should use 4 spaces, not tabs. |
| 206 | + * Use curly braces for single statement blocks. For example: |
| 207 | +```cpp |
| 208 | + for (int n=0; n<10; ++n) { |
| 209 | + Print() << "Like this!"; |
| 210 | + } |
| 211 | +``` |
| 212 | + or |
| 213 | +```cpp |
| 214 | + for (int n=0; n<10; ++n) { Print() << "Like this!"; } |
| 215 | +``` |
| 216 | + but not |
| 217 | +```cpp |
| 218 | + |
| 219 | + for (int n=0; n<10; ++n) Print() << "Not like this."; |
| 220 | +``` |
| 221 | + or |
| 222 | +```cpp |
| 223 | + for (int n=0; n<10; ++n) |
| 224 | + Print() << "Not like this."; |
| 225 | +``` |
| 226 | + * When declaring and defining a function, add a space after the function name and before the |
| 227 | +parenthesis of the parameter list (but not when simply calling the function). For example: |
| 228 | +```cpp |
| 229 | + void CorrectFunctionDec (int input) |
| 230 | +``` |
| 231 | + Not |
| 232 | +```cpp |
| 233 | + void IncorrectFunctionDec(int input) |
| 234 | +``` |
| 235 | + This makes it easy to find where functions are defined with grep. |
| 236 | + * Member variables should be prefixed with `m_`. For example: |
| 237 | +```cpp |
| 238 | + amrex::Real m_variable; |
| 239 | +``` |
| 240 | +These guidelines should be adhered to in new contributions to IAMReX, but |
| 241 | +please refrain from making stylistic changes to unrelated sections of code in your PRs. |
| 242 | + |
| 243 | +### API Documentation Using Doxygen |
| 244 | + |
| 245 | +The Doxygen documentation is designed for advanced user-developers. It aims |
| 246 | +to maximize the efficiency of a search-and-find style of locating information. |
| 247 | +Doxygen style comment blocks should proceed the namespace, class, function, etc. |
| 248 | +to be documented where appropriate. For example: |
| 249 | +```cpp |
| 250 | + /** |
| 251 | + * \brief A one line description. |
| 252 | + * |
| 253 | + * \param[in] variable A short description of the variable. |
| 254 | + * \param[inout] data The value of data is read and changed. |
| 255 | + * |
| 256 | + * A longer description can be included here. |
| 257 | + */ |
| 258 | + |
| 259 | + void MyFunction (int variable, MultiFab& data){ |
| 260 | + ... |
| 261 | +``` |
| 262 | +Additional information regarding Doxygen comment formatting can be found |
| 263 | +in the [Doxygen Manual](https://www.doxygen.nl/manual/). |
| 264 | +
|
| 265 | +### Describe |
| 266 | +
|
| 267 | +The current CONTRIBUTING.md file is modified based on the [CONTRIBUTING.md](https://github.com/AMReX-Codes/amrex/blob/development/CONTRIBUTING.md). in the amrex project. |
0 commit comments