Project

General

Profile

Coding standards » History » Version 10

laforge, 02/21/2016 02:24 PM

1 9 laforge
{{>toc}}
2
3 8 laforge
h1. Osmocom coding standards
4 1
5 10 laforge
h2. Coding Style
6 8 laforge
7
In general, for the C-language projects we maintain in the Osmocom project, we follow the coding style
8
of the Linux kenrel. See https://www.kernel.org/doc/Documentation/CodingStyle for further information.
9
10 1
We will not debate about the coding style and whether some other style is better or worse.  The important factor is not so much _which_ coding style is followed, as long as there is one well-defined coding style and that all developers adhere to it.
11 10 laforge
12
h2. Development Process
13
14
Once again, the Osmocom project follows processes defined for the Linux kernel development whenever applicable.  Of course, as Osmocom is  much smaller project, some simplifications apply.
15
16
For further information on the Linux kernel development process, please see https://www.kernel.org/doc/Documentation/development-process/
17
18
The most important parts are summarized below:
19
20
h2. The lifecycle of a patch
21
22
Patches do not go directly from the developer's keyboard into the mainline project.  There is, instead, a somewhat involved (if somewhat informal) process designed to ensure that each patch is reviewed for quality and that each patch implements a change which is desirable to have in the mainline. This process can happen quickly for minor fixes, or, in the case of large and controversial changes, go on for years.  Much developer frustration
23
comes from a lack of understanding of this process or from attempts to circumvent it.
24
25
In the hopes of reducing that frustration, this document will describe how a patch gets into the kernel.  What follows below is an introduction which describes the process in a somewhat idealized way.  A much more detailed
26
treatment will come in later sections.
27
28
The stages that a patch goes through are, generally:
29
30
* *Design*. This is where the real requirements for the patch - and the way those requirements will be met - are laid out.  Design work is often done without involving the community, but it is better to do this work in the open if at all possible; it can save a lot of time redesigning things later.
31
32
* *Review*.  Patches are posted to the relevant mailing list, and developers on that list reply with any comments they may have.  This process should turn up any major problems with a patch if all goes well. Please note that most maintainers also have day jobs, so merging your patch may not be their highest priority.  If your patch is getting feedback about changes that are needed, you should either make those changes or justify why they should not be made.  If your patch has no review complaints but is not being merged by its appropriate maintainer, you should be persistent in updating the patch to the current master versoin so that it applies cleanly and keep sending it for review and merging.
33
34
* *Merging into the mainline*.  Eventually, a successful patch will be merged into the mainline repository managed by Linus Torvalds.  More comments and/or problems may surface at this time; it is important that the developer be responsive to these and fix any issues which arise.
35
36
* *Long-term maintenance*.  While it is certainly possible for a developer to forget about code after merging it, that sort of behavior tends to leave a poor impression in the development community.  Merging code eliminates some of the maintenance burden, in that others will fix problems caused by API changes.  But the original developer should continue to take responsibility for the code if it is to remain useful in the longer term.
37
38
One of the largest mistakes made by developers (or their employers) is to try to cut the process down to a single *merging into the mainline* step.  This approach invariably leads to frustration for everybody involved.
39
40
41
h3. The importance of submitting your changes to mainline
42
43
Some companies and developers occasionally wonder why they should bother learning how to work with the Osmocom community and get their code into mainline (the "mainline" being the software maintained by the Osmocom team at git.osmocom.org).  In the short term, contributing code can look like an avoidable expense; it seems easier to
44
just keep the code separate and support users directly.  The truth of the matter is that keeping code separate ("out of tree") is a false economy.
45
46
As a way of illustrating the costs of out-of-tree code, here are a few relevant aspects of the kernel development process; most of these will be discussed in greater detail later in this document.  Consider:
47
48
* Code which has been merged into the mainline kernel is available to all users.  There is no need for vendor-specific drivers/builds, downloads, or the hassles of supporting multiple versions of multiple distributions; it all just works, for the developer and for the user.  Incorporation into the mainline solves a large number of distribution and support problems.
49
50
* The internal API of the projects is in constant flux.  The lack of a stable internal interface is a deliberate design decision; it allows fundamental improvements to be made at any time and results in higher-quality code. But one result of that policy is that any out-of-tree code requires constant upkeep if it is to work with new kernels.
51
 
52
Maintaining out-of-tree code requires significant amounts of work just to keep that code working. Code which is in the mainline, instead, does not require this work as the result of a simple rule requiring any developer who makes an API change to also fix any code that breaks as the result of that change.  So code which has been merged into the mainline has significantly lower maintenance costs.
53
54
* Beyond that, code which is in mainline will often be improved by other developers.  Surprising results can come from empowering your user community and customers to improve your product.
55
56
* Code is subjected to review, both before and after merging into the mainline.  No matter how strong the original developer's skills are, this review process invariably finds ways in which the code can be improved.  Often review finds severe bugs and security problems.  This is especially true for code which has been developed in a closed environment; such code benefits strongly from review by outside developers.  Out-of-tree code is lower-quality code.
57
58
* Participation in the development process is your way to influence the direction of the projects development.  Users who complain from the sidelines are heard, but active developers have a stronger voice - and the ability to implement changes which make the kernel work better for their needs.
59
60
* When code is maintained separately, the possibility that a third party will contribute a different implementation of a similar feature always exists.  Should that happen, getting your code merged will become much harder - to the point of impossibility.  Then you will be faced with the unpleasant alternatives of either (1) maintaining a nonstandard features out of tree indefinitely, or (2) abandoning your code and migrating your users over to the in-tree version.
61
62
* Contribution of code is the fundamental action which makes the whole process work.  By contributing your code you can add new functionality to the project and provide capabilities and examples which are of use to other developers.  If you have developed code for a project (or are thinking about doing so), you clearly have an interest in the continued success of this platform; contributing code is one of the best ways to help ensure that success.
63
64
h2. Licensing
65
66
Code is contributed to any Osmocom project under a number of licenses, but all code must be compatible with the respective project license.  This typically is the GNU Affero General Public License, Version 3 (AGPLv3) or Version 2 of the GNU General Public License (GPLv2). Any contributions
67
which are not covered by a compatible license cannot be accepted.
68 8 laforge
69
h2. Submitting Patches
70
71
For submitting patches, the best practises established by the Linux kernel development community should  be followed, whenever applicable.  See https://www.kernel.org/doc/Documentation/SubmittingPatches for further information.
72
73
The generally important topics are:
74
75
h3. Submit patches against a current source tree
76
77
At time of submission, our patches should be based on current @master@ branch of the respective project, or another (more current) feature branch of that repository.
78
79
h3. Use unified diff format
80
81
It's best to let git generate the patches, so you don't have to worry about that.
82
83
h3. Have meaningful descriptions in your patches
84
85
Every commit/patch should have an explanation in the commit message.
86
87
h3. Separate your changes
88
89
Separate each _logical change_ into a separate patch.
90
91
h3. Respond to review comments
92
93
h3. Include PATCH in the subject
94
95
96
h2. Rules of thumb
97
98
Some general rules of thumb:
99
* Consider using tools like @Lindent@ and @checkpatch.pl@ or @universalindentgui@ before submitting code
100
* Run @make@, @make check@ and @make distcheck@ on each of your commits to ensure the build
101
* Use @git send-email@ or @git imap-send@ to send your patches (otherwise your mail client may wrap around lines and corrupt your patch)
Add picture from clipboard (Maximum size: 48.8 MB)