|
| 1 | +# Contributing to mongo-c-driver |
| 2 | + |
| 3 | +Thanks for considering contributing to the mongo-c-driver! |
| 4 | + |
| 5 | +This document intends to be a short guide to helping you contribute to the codebase. |
| 6 | +It expects a familiarity with the C programming language and writing portable software. |
| 7 | +Whenever in doubt, feel free to ask others that have contributed or look at the existing body of code. |
| 8 | + |
| 9 | + |
| 10 | +## Guidelines |
| 11 | + |
| 12 | +The mongo-c-driver has a few guidelines that help direct the process. |
| 13 | + |
| 14 | + |
| 15 | +### Portability |
| 16 | + |
| 17 | +mongo-c-driver is portable software. It needs to run on a multitude of |
| 18 | +operating systems and architectures. |
| 19 | + |
| 20 | + * Linux (RHEL 5 and newer) |
| 21 | + * FreeBSD (10 and newer) |
| 22 | + * Windows (Vista a newer) |
| 23 | + * Solaris x86_64/SPARC (11 and newer) |
| 24 | + * SmartOS (Solaris based) |
| 25 | + * Possibly more if users show an interest. |
| 26 | + * ARM/SPARC/x86/x86_64 |
| 27 | + |
| 28 | + |
| 29 | +### Licensing |
| 30 | + |
| 31 | +Some of the mongo-c-driver users embed the library statically in their |
| 32 | +products. Therefore, the driver needs to be liberally licensed (as opposed to |
| 33 | +the authors usual preference of LGPL-2+). Therefore, all contributions must |
| 34 | +also be under this license. As a policy, we have chosen Apache 2.0 as the |
| 35 | +license for the project. |
| 36 | + |
| 37 | + |
| 38 | +### Coding Style |
| 39 | + |
| 40 | +We try not to be pedantic with taking contributions that are not properly |
| 41 | +formatted, but we will likely perform a followup commit that cleans things up. |
| 42 | +The basics are, in vim: |
| 43 | + |
| 44 | + : set ts=3 sw=3 et |
| 45 | + |
| 46 | +3 space tabs, insert spaces instead of tabs. |
| 47 | + |
| 48 | +Place a space between the function name and the parameter as such: |
| 49 | + |
| 50 | + static void |
| 51 | + my_func (Param *p) |
| 52 | + |
| 53 | + my_func (p); |
| 54 | + |
| 55 | +Not all of the code does this today, but it should be cleaned up at some point. |
| 56 | + |
| 57 | +Just look at the code around for more pedantic styling choices. |
| 58 | + |
| 59 | + |
| 60 | +### Enum, Struct, Variable Naming |
| 61 | + |
| 62 | +The naming conventions for mongo-c-driver should feel very object oriented. |
| 63 | +In fact, mongo-c-driver is OOP. Those that have used the GLib library will |
| 64 | +feel right at home, as the author has spent many years contributing to that |
| 65 | +project as well. |
| 66 | + |
| 67 | +Structs are suffixed in `_t`, and underscores. |
| 68 | + |
| 69 | +```c |
| 70 | +typedef struct _my_struct_t my_struct_t; |
| 71 | + |
| 72 | +struct _my_struct_t |
| 73 | +{ |
| 74 | + int foo; |
| 75 | +}; |
| 76 | +``` |
| 77 | + |
| 78 | +Function names should be prefixed by the type name, without the `_t`. |
| 79 | + |
| 80 | +```c |
| 81 | +int my_struct_get_foo (my_struct_t *my); |
| 82 | +``` |
| 83 | +
|
| 84 | +Enums are also named with the `_t` suffix. |
| 85 | +
|
| 86 | +
|
| 87 | +```c |
| 88 | +typedef enum |
| 89 | +{ |
| 90 | + MY_FLAGS_A = 1, |
| 91 | + MY_FLAGS_B = 1 << 1, |
| 92 | + MY_FLAGS_C = 1 << 2, |
| 93 | +} my_flags_t; |
| 94 | +``` |
| 95 | + |
| 96 | + |
| 97 | +### Documentation |
| 98 | + |
| 99 | +We strive to document all symbols. See doc/ for documentation examples. If you |
| 100 | +add a new function, add a new .txt file describing the function so that we can |
| 101 | +generate man pages and HTML for it. |
| 102 | + |
| 103 | + |
| 104 | +### Testing |
| 105 | + |
| 106 | +You should always run `make test` before submitting a patch. Just make sure you |
| 107 | +have a locally running `mongod` instance available on 127.0.0.1:27017. All |
| 108 | +tests should pass. Alternatively, you can specify MONGOC_TEST_HOST environment |
| 109 | +variable to specify a non-localhost hostname or ip address. |
| 110 | + |
| 111 | +All tests should pass before submitting a patch. |
| 112 | + |
0 commit comments