Debian Codegraph @

doc/dev_guide/development_guide.rst

raw
1 =================
2 Development Guide
3 =================
4
5 We welcome contributions from every human being, corporate entity or club.
6
7 This document describes the rules and recommendations about the development, contribution and review processes.
8
9 If you introduce new features (not flash chips, but stuff like partial
10 programming, support for new external programmers, voltage handling, etc)
11 please **discuss your plans** on the :ref:`mailing list` first. That way, we
12 can avoid duplicated work and know about how flashrom internals need to be
13 adjusted and you avoid frustration if there is some disagreement about the
14 design.
15
16 You can `look at the latest flashrom development efforts in Gerrit <https://review.coreboot.org/q/project:flashrom>`_.
17
18 .. _git repo setup:
19
20 Set up the git repository and dev environment
21 =============================================
22
23 #. Clone git repository
24
25 * If using https: :code:`git clone "https://review.coreboot.org/flashrom"`
26 * If using ssh: :code:`git clone "ssh://<gerrit_username>@review.coreboot.org:29418/flashrom"`
27
28 #. Follow the build guidelines to install dependencies :doc:`building_from_source`
29
30 #. Install Git hooks: :code:`./util/git-hooks/install.sh`
31
32 #. Add upstream as a remote:
33
34 * If using https: :code:`git remote add -f upstream https://review.coreboot.org/flashrom`
35 * If using ssh: :code:`git remote add -f upstream ssh://<gerrit_username>@review.coreboot.org:29418/flashrom`
36
37 #. Check out a new local branch that tracks :code:`upstream/main`: :code:`git checkout -b <branch_name> upstream/main`
38
39 #. Every patch is required to be signed-off (see also :ref:`sign-off`).
40 Set up your ``user.name`` and ``user.email`` in git config, and don't forget
41 to ``-s`` when creating a commit.
42
43 #. See also build guidelines :doc:`building_from_source` and `git docs <https://git-scm.com/doc>`_
44
45 Creating your patch
46 ===================
47
48 In short, commit your changes with a descriptive message and remember to sign off
49 on the commit (``git commit -s``).
50
51 .. _commit-message:
52
53 Commit message
54 --------------
55
56 Commit messages shall have the following format::
57
58 <component>: Short description (up to 72 characters)
59
60 This is a long description. Max width of each line in the description
61 is 72 characters. It is separated from the summary by a blank line. You
62 may skip the long description if the short description is sufficient,
63 for example "flashchips: Add FOO25Q128" to add FOO25Q128 chip support.
64
65 You may have multiple paragraphs in the long description, but please
66 do not write a novel here. For non-trivial changes you must explain
67 what your patch does, why, and how it was tested.
68
69 Finally, follow the sign-off procedure to add your sign-off!
70
71 Signed-off-by: Your Name <your@domain>
72
73 Commit message should include:
74
75 * Commit title
76 * Commit description: explain what the patch is doing, or what it is fixing.
77 * Testing information: how did you test the patch.
78 * Signed-off-by line (see below :ref:`sign-off`)
79 * If applicable, link to the ticket in the bugtracker `<https://ticket.coreboot.org/projects/flashrom>`_
80 * Change-Id for Gerrit. If commit message doesn't have Change-Id, you forgot to install git hooks.
81
82 .. _sign-off:
83
84 Sign-off procedure
85 ^^^^^^^^^^^^^^^^^^
86
87 We employ a similar sign-off procedure as the `Linux kernel developers
88 <http://web.archive.org/web/20070306195036/http://osdlab.org/newsroom/press_releases/2004/2004_05_24_dco.html>`_
89 do. Add a note such as
90
91 :code:`Signed-off-by: Random J Developer <[email protected]>`
92
93 to your email/patch if you agree with the Developer's Certificate of Origin 1.1
94 printed below. Read `this post on the LKML
95 <https://lkml.org/lkml/2004/5/23/10>`_ for rationale (spoiler: SCO).
96
97 You must use your known identity in the ``Signed-off-by`` line and in any
98 copyright notices you add. Anonymous patches lack provenance and cannot be
99 committed!
100
101 Developer's Certificate of Origin 1.1
102 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
103
104 By making a contribution to this project, I certify that:
105
106 (a) The contribution was created in whole or in part by me and I have
107 the right to submit it under the open source license indicated in the file; or
108
109 (b) The contribution is based upon previous work that, to the best of my
110 knowledge, is covered under an appropriate open source license and I have the
111 right under that license to submit that work with modifications, whether created
112 in whole or in part by me, under the same open source license (unless I am
113 permitted to submit under a different license), as indicated in the file; or
114
115 (c) The contribution was provided directly to me by some other person who
116 certified (a), (b) or (c) and I have not modified it; and
117
118 (d) In the case of each of (a), (b), or (c), I understand and agree that
119 this project and the contribution are public and that a record of the contribution
120 (including all personal information I submit with it, including my sign-off) is
121 maintained indefinitely and may be redistributed consistent with this project or the
122 open source license indicated in the file.
123
124 .. note::
125
126 The `Developer's Certificate of Origin 1.1
127 <http://web.archive.org/web/20070306195036/http://osdlab.org/newsroom/press_releases/2004/2004_05_24_dco.html>`_
128 is licensed under the terms of the `Creative Commons Attribution-ShareAlike
129 2.5 License <http://creativecommons.org/licenses/by-sa/2.5/>`_.
130
131 Coding style
132 ------------
133
134 Flashrom generally follows Linux kernel style:
135 https://docs.kernel.org/process/coding-style.html
136
137 The notable exception is line length limit. Our guidelines are:
138
139 * 80-columns soft limit for most code and comments. This is to encourage simple design and concise naming.
140 * 112-columns hard limit. Use this to reduce line breaks in cases where they
141 harm grep-ability or overall readability, such as print statements and
142 function signatures. Don't abuse this for long variable/function names or
143 deep nesting.
144 * Tables are the only exception to the hard limit and may be as long as needed
145 for practical purposes.
146
147 We try to **reuse as much code as possible** and create new files only if
148 absolutely needed, so if you find a function somewhere in the tree which
149 already does what you want, please use it.
150
151 Testing a patch
152 ---------------
153
154 We expect the patch to be appropriately tested by the patch owner.
155 Please add the testing information in commit message, for example that could be some of these:
156 programmer you were using, programmer params, chip, OS, operations you were running
157 (read/write/erase/verify), and anything else that is relevant.
158
159 .. _working-with-gerrit:
160
161 Working with Gerrit
162 ===================
163
164 All of the patches and code reviews need to go via
165 `Gerrit on review.coreboot.org <https://review.coreboot.org/#/q/project:flashrom>`_.
166 While it is technically possible to send a patch to the mailing list, that patch
167 still needs to be pushed to Gerrit by someone. We treat patches on the mailing list as a very
168 exceptional situation. Normal process is to push a patch to Gerrit.
169 Please read below for instructions and check `official Gerrit documentation <https://gerrit-review.googlesource.com/Documentation/>`_.
170
171 Creating an account
172 ---------------------
173
174 #. Go to https://review.coreboot.org/login and sign in using the credentials of
175 your choice.
176 #. Edit your settings by clicking on the gear icon in the upper right corner.
177 #. Set your Gerrit username (this may be the different from the username of an
178 external account you log in with).
179 #. Add an e-mail address so that Gerrit can send notifications to you about
180 your patch.
181 #. Upload an SSH public key, or click the button to generate an HTTPS password.
182 #. After account created, set either "Full name" or "Display name", it is used by Gerrit
183 for code review emails.
184
185 .. _pushing-a-patch:
186
187 Pushing a patch
188 ---------------
189
190 Before pushing a patch, make sure it builds on your environment and all unit tests pass (see :doc:`building_from_source`).
191
192 To push patch to Gerrit, use the follow command: :code:`git push upstream HEAD:refs/for/main`.
193
194 * If using HTTPS you will be prompted for the username and password you
195 set in the Gerrit UI.
196 * If successful, the Gerrit URL for your patch will be shown in the output.
197
198 There is an option to add a topic to the patch. For one-off standalone patches this
199 is not necessary. However if your patch is a part of a larger effort, especially if the
200 work involves multiple contributors, it can be useful to mark that the patch belongs
201 to a certain topic.
202
203 Adding a topic makes it easy to search "all the patches by the topic", even if the patches
204 have been authored by multiple people.
205
206 To add a topic, push with the command: :code:`git push upstream HEAD:refs/for/main%topic=example_topic`.
207 Alternatively, you can add a topic from a Gerrit UI after the patch in pushed
208 (on the top-left section) of patch UI.
209
210 Checking the CI
211 ---------------
212
213 Every patch needs to get a ``Verified +1`` label, typically from Jenkins. Once the patch is pushed
214 to Gerrit, Jenkins is added automatically and runs its build script. The script builds the patch with
215 various config options, and runs unit tests (for more details see source code of ``test_build.sh``).
216 Then, Jenkins gives the patch ``+1`` or ``-1`` vote, indicating success or fail.
217
218 In case of failure, follow Jenkins link (which it adds as a comment to the patch), open Console output,
219 find the error and try to fix it.
220
221 In addition to building and running unit tests, Jenkins also runs a scan-build over the patch. Ideally
222 you should check that your patch does not introduce new warnings. To see scan-build report, follow
223 Jenkins link -> Build artifacts -> scan build link for the given run.
224
225 Adding reviewers to the patch
226 -----------------------------
227
228 After pushing the patch, ideally try to make sure there are some reviewers added to your patch.
229
230 flashrom has MAINTAINERS file with people registered for some areas of the code. People who
231 are in MAINTAINERS file will be automatically added as reviewers if the patch touches that
232 area. However, not all areas are covered in the file, and it is possible that for the patch you
233 sent no one is added automatically.
234
235 If you know someone in the dev community who can help with patch review, add the person(s) you know.
236
237 In general, it's a good idea to add someone who has a knowledge of whatever the patch is doing,
238 even if the person has not been added automatically.
239
240 If you are new, and don't know anyone, and no one has been added automatically: you can add
241 Anastasia Klimchuk (aklm) as a reviewer.
242
243 Going through code reviews
244 --------------------------
245
246 You will likely get some comments on your patch, and you will need to fix the comments.
247 After doing the work locally, amend your commit ``git commit --amend -s`` and push to Gerrit again.
248 Check that Change-Id in commit message stays the same. This way Gerrit knows your change belongs
249 to the same patch, and will upload new change as new patchset for the same patch.
250
251 After uploading the work, go through comments and respond to them. Mark as Done the ones you done
252 and mark them as resolved. If there is something that is impossible to do, or maybe you have more questions,
253 or maybe you are not sure what you are asked about: respond to a comment **without marking it as resolved**.
254
255 It is completely fine to ask a clarifying questions if you don't understand what the comment is asking you to do.
256 If is also fine to explain why a comment can't be done, if you think it can't be done.
257
258 The patch reviews may take some time, but please don't get discouraged.
259 We have quite high standards regarding code quality.
260
261 Initial review should include a broad indication of acceptance or rejection of
262 the idea/rationale/motivation or the implementation
263
264 In general, reviews should focus on the architectural changes and things that
265 affect flashrom as a whole. This includes (but is by no means limited to)
266 changes in APIs and types, safety, portability, extensibility, and
267 maintainability. The purpose of reviews is not to create perfect patches, but
268 to steer development in the right direction and produce consensus within the
269 community. The goal of each patch should be to improve the state of the project
270 - it does not need to fix all problems of the respective field perfectly.
271
272 New contributors may need more detailed advices and should be told about
273 minor issues like formatting problems more precisely. The result of a review
274 should either be an accepted patch or a guideline how the existing code
275 should be changed to be eventually accepted.
276
277 To get an idea whether the patch is ready or not, please check :ref:`merge-checklist`.
278
279 If you sent a patch and later lost interest or no longer have time to follow up on code review,
280 please add a comment saying so. Then, if any of our maintainers are interested in finishing the work,
281 they can take over the patch.
282
283 Downloading patch from Gerrit
284 -----------------------------
285
286 Sometimes you may need to download a patch into your local repository. This can be needed for example:
287
288 * if you want to test someone else's patch,
289 * if multiple developers are collaborating on a patch,
290 * if you are continuing someone else's work, when original author left or unable to continue.
291
292 First prepare local repository: sync to head or to desired tag / commit.
293
294 Open patch in Gerrit, open "three dot" menu on top-right, open Download patch. Copy Cherry-pick command (pick
295 the relevant tab for you: anonymous http / http / ssh) and run the copied command in your local repo.
296
297 Now you have the commit locally and can do the testing or futher developing. To upload your local changes,
298 push patch to Gerrit again (see :ref:`pushing-a-patch`).
299
300 Make sure people involved in the patch agree that you are pushing new version of someone else's patch,
301 so this does not come at a surprise for an original author.
302
303 Merging patches
304 ---------------
305
306 Merging to branches is limited to the "flashrom developers" group on Gerrit (see also :doc:`/about_flashrom/team`).
307
308 The list of requirements for the patch to be ready for merging is below, see :ref:`merge-checklist`.
309 Some of the requirements are enforced by Gerrit, but not all of them. In general, a person who clicks
310 Submit button is responsible to go through Merge checklist. Code reviewers should be aware of the checklist
311 as well.
312
313 Patch owners can use the checklist to detect whether the patch is ready for merging or not.
314
315 .. _merge-checklist:
316
317 Merge checklist
318 ^^^^^^^^^^^^^^^
319
320 #. Every patch has to be reviewed and needs at least one +2 that was not given by the commit's author.
321 Ideally, people who were actively reviewing the patch and adding comments, would be the ones approving it.
322 #. If a patch is authored by more than one person (Co-developed-by), each author may +2 the other author's changes.
323 #. Patch needs to get Verified +1 vote, typically from Jenkins build bot. This means the patch builds successfully
324 and all unit tests pass.
325 #. Commit message should have Signed-off-by line, see :ref:`sign-off` and align with the rest
326 of the rules for :ref:`commit-message`
327 #. All the comments need to be addressed, especially if there was a negative vote in the process of review (-1 or -2).
328 #. flashrom developers are people from literally all around the planet, and various timezones. We usually wait
329 for 3 days (3 * 24hours) after the patch is fully approved just in case of last minute concerns from all timezones.
330 #. In the case of emergency, merging should not take place within less than 24 hours after the review
331 started (i.e. the first message by a reviewer on Gerrit).
332
333 To help search for patches which are potential candidates for merging, you can try using this search in Gerrit::
334
335 status:open project:flashrom -is:wip -label:Verified-1 label:Verified+1 -label:Code-Review<0 age:3d is:mergeable is:submittable -has:unresolved
336
337 Note the search is not a replacement for Merge checklist, but it can help find candidates for merging.
338
339 .. _bugtracker:
340
341 Bugtracker
342 ==========
343
344 We have a bugtracker on `<https://ticket.coreboot.org/projects/flashrom>`_.
345 Anyone can view tickets, but to be able to create/update/assign tickets you need an account.
346
347 Mirrors
348 ========
349
350 The only official repository is https://review.coreboot.org/flashrom ; GitHub and GitLab are just mirrors.
351 **Reviewers do not look at pull requests** on mirrors.
352 Even if pull requests were automatically transferred to Gerrit,
353 requirements such as :ref:`sign-off` still present a problem.
354
355 The quickest and best way to get your patch reviewed and merged is by sending
356 it to review.coreboot.org (see :ref:`working-with-Gerrit`). Conveniently, you can use your GitHub, GitLab or
357 Google account as an OAuth2 `login method <https://review.coreboot.org/login>`_.