Imported Upstream version 3.2.6
[platform/upstream/ccache.git] / HACKING.txt
1 Hacking ccache
2 ==============
3
4 Code formatting
5 ---------------
6
7 * Use tabs for indenting and spaces for aligning C code.
8 * Use 4 spaces for indenting other code (and spaces for aligning).
9 * Put the opening curly brace on a new line when defining a function, otherwise
10   at the end of the same line.
11 * Put no space between function name and the following parenthesis.
12 * Put one space between if/switch/for/while/do and opening curly brace.
13 * Always use curly braces around if/for/while/do bodies, even if they only
14   contain one statement.
15 * If possible, keep lines at most 80 character wide for a 2 character tab
16   width.
17 * Use only lowercase names for functions and variables.
18 * Use only uppercase names for enum items and (with some exceptions) macros.
19 * Don't use typedefs for structs and enums.
20
21 Tip: Install the tool uncrustify <http://uncrustify.sourceforge.net> and then
22 run "make uncrustify" to fix up source code formatting.
23
24 Idioms
25 ------
26
27 * Use NULL to initialize null pointers.
28 * Don't use NULL when comparing pointers.
29 * Use format(), x_malloc() and friends instead of checking for memory
30   allocation failure explicitly.
31 * Use str_eq() instead of strcmp() when testing for string (in)equality.
32 * Consider using str_startswith() instead of strncmp().
33 * Use bool, true and false for boolean values.
34 * Use tmp_unlink() or x_unlink() instead of unlink().
35 * Use x_rename() instead of rename().
36
37 Other
38 -----
39
40 * Strive to minimize use of global variables.
41 * Write test cases for new code.
42
43 Commit messages
44 ---------------
45
46 * Write a short description on the first line. If wanted, leave the second line
47   empty and write a longer description on line three and below.
48 * Start the short description with a capital letter. Optional: prefix the short
49   description with a context followed by a colon.
50 * The short description should be in "command form" (see examples below).
51 * Don't put a final period after the short description.
52 * Keep lines in the message at most 75 characters wide.
53
54 Example 1:
55
56     Hash a delimiter string between parts to separate them
57
58     Previously, "gcc -I-O2 -c file.c" and "gcc -I -O2 -c file.c" would hash to
59     the same sum.
60
61 Example 2:
62
63     win32: Add a space between filename and error string in x_fmmap()