You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

258 lines
9.0 KiB

  1. # Contributing to mongo-c-driver
  2. Thanks for considering contributing to the mongo-c-driver!
  3. This document intends to be a short guide to helping you contribute to the codebase.
  4. It expects a familiarity with the C programming language and writing portable software.
  5. Whenever in doubt, feel free to ask others that have contributed or look at the existing body of code.
  6. ## Guidelines
  7. The mongo-c-driver has a few guidelines that help direct the process.
  8. ### Portability
  9. mongo-c-driver is portable software. It needs to run on a multitude of
  10. operating systems and architectures.
  11. * Linux (RHEL 5 and newer)
  12. * FreeBSD (10 and newer)
  13. * Windows (Vista and newer)
  14. * macOS (10.8 and newer)
  15. * ARM/SPARC/x86/x86_64
  16. ### Licensing
  17. Some of the mongo-c-driver users embed the library statically in their
  18. products. Therefore, the driver and all contributions must be liberally
  19. licensed. As a policy, we have chosen Apache 2.0 as the license for the
  20. project.
  21. ### Coding Style
  22. We try not to be pedantic with taking contributions that are not properly
  23. formatted, but we will likely perform a followup commit that cleans things up.
  24. The basics are, in vim:
  25. ```
  26. : set ts=3 sw=3 et
  27. ```
  28. 3 space tabs, insert spaces instead of tabs.
  29. For all the gory details, see [.clang-format](.clang-format)
  30. ### Adding a new error code or domain
  31. When adding a new error code or domain, you must do the following. This is most
  32. applicable if you are adding a new symbol with a bson_error_t as a parameter,
  33. and the existing codes or domains are inappropriate.
  34. - Add the domain to `mongoc_error_domain_t` in `src/mongoc/mongoc-error.h`
  35. - Add the code to `mongoc_error_code_t` in `src/mongoc/mongoc-error.h`
  36. - Add documentation for the domain or code to the table in `doc/mongoc_errors.rst`
  37. ### Adding a new symbol
  38. This should be done rarely but there are several things that you need to do
  39. when adding a new symbol.
  40. - Add documentation for the new symbol in `doc/mongoc_your_new_symbol_name.rst`
  41. ### Documentation
  42. We strive to document all symbols. See doc/ for documentation examples. If you
  43. add a new public function, add a new .rst file describing the function so that
  44. we can generate man pages and HTML for it.
  45. For complex internal functions, comment above the function definition with
  46. a block comment like the following:
  47. ```
  48. /*--------------------------------------------------------------------------
  49. *
  50. * mongoc_cmd_parts_append_read_write --
  51. *
  52. * Append user-supplied options to @parts->command_extra, taking the
  53. * selected server's max wire version into account.
  54. *
  55. * Return:
  56. * True if the options were successfully applied. If any options are
  57. * invalid, returns false and fills out @error. In that case @parts is
  58. * invalid and must not be used.
  59. *
  60. * Side effects:
  61. * May partly apply options before returning an error.
  62. *
  63. *--------------------------------------------------------------------------
  64. */
  65. ```
  66. Public functions do not need these comment blocks, since they are documented in
  67. the .rst files.
  68. ### Testing
  69. To run the entire test suite, including authentication tests,
  70. start `mongod` with auth enabled:
  71. ```
  72. $ mongod --auth
  73. ```
  74. In another terminal, use the `mongo` shell to create a user:
  75. ```
  76. $ mongo --eval "db.createUser({user: 'admin', pwd: 'pass', roles: ['root']})" admin
  77. ```
  78. Authentication in MongoDB 3.0 and later uses SCRAM-SHA-1, which in turn
  79. requires a driver built with SSL.
  80. Set the user and password environment variables, then build and run the tests:
  81. ```
  82. $ export MONGOC_TEST_USER=admin
  83. $ export MONGOC_TEST_PASSWORD=pass
  84. $ ./test-libmongoc
  85. ```
  86. Additional environment variables:
  87. * `MONGOC_TEST_HOST`: default `localhost`, the host running MongoDB.
  88. * `MONGOC_TEST_PORT`: default 27017, MongoDB's listening port.
  89. * `MONGOC_TEST_URI`: override both host and port with a full connection string,
  90. like "mongodb://server1,server2".
  91. * `MONGOC_TEST_SERVER_LOG`: set to `stdout` or `stderr` for wire protocol
  92. logging from tests that use `mock_server_t`. Set to `json` to include these
  93. logs in the test framework's JSON output, in a format compatible with
  94. [Evergreen](https://github.com/evergreen-ci/evergreen).
  95. * `MONGOC_TEST_MONITORING_VERBOSE`: set to `on` for verbose output from
  96. Application Performance Monitoring tests.
  97. * `MONGOC_TEST_COMPRESSORS=snappy,zlib`: wire protocol compressors to use
  98. If you start `mongod` with SSL, set these variables to configure how
  99. `test-libmongoc` connects to it:
  100. * `MONGOC_TEST_SSL`: set to `on` to connect to the server with SSL.
  101. * `MONGOC_TEST_SSL_PEM_FILE`: path to a client PEM file.
  102. * `MONGOC_TEST_SSL_PEM_PWD`: the PEM file's password.
  103. * `MONGOC_TEST_SSL_CA_FILE`: path to a certificate authority file.
  104. * `MONGOC_TEST_SSL_CA_DIR`: path to a certificate authority directory.
  105. * `MONGOC_TEST_SSL_CRL_FILE`: path to a certificate revocation list.
  106. * `MONGOC_TEST_SSL_WEAK_CERT_VALIDATION`: set to `on` to relax the client's
  107. validation of the server's certificate.
  108. The SASL / GSSAPI / Kerberos tests are skipped by default. To run them, set up a
  109. separate `mongod` with Kerberos and set its host and Kerberos principal name
  110. as environment variables:
  111. * `MONGOC_TEST_GSSAPI_HOST`
  112. * `MONGOC_TEST_GSSAPI_USER`
  113. URI-escape the username, for example write "user@realm" as "user%40realm".
  114. The user must be authorized to query `kerberos.test`.
  115. MongoDB 3.2 adds support for readConcern, but does not enable support for
  116. read concern majority by default. mongod must be launched using
  117. `--enableMajorityReadConcern`.
  118. The test framework does not (and can't) automatically discover if this option was
  119. provided to MongoDB, so an additional variable must be set to enable these tests:
  120. * `MONGOC_ENABLE_MAJORITY_READ_CONCERN`
  121. Set this environment variable to `on` if MongoDB has enabled majority read concern.
  122. Some tests require Internet access, e.g. to check the error message when failing
  123. to open a MongoDB connection to example.com. Skip them with:
  124. * `MONGOC_TEST_OFFLINE=on`
  125. Some tests require a running MongoDB server. Skip them with:
  126. * `MONGOC_TEST_SKIP_LIVE=on`
  127. For quick checks during development, disable long-running tests:
  128. * `MONGOC_TEST_SKIP_SLOW=on`
  129. Some tests run against a local mock server, these can be skipped with:
  130. * `MONGOC_TEST_SKIP_MOCK=on`
  131. If you have started with MongoDB with `--ipv6`, you can test IPv6 with:
  132. * `MONGOC_CHECK_IPV6=on`
  133. The tests for mongodb+srv:// connection strings require some setup, see the
  134. Initial DNS Seedlist Discovery Spec. By default these connection strings are
  135. NOT tested, enable them with:
  136. * `MONGOC_TEST_DNS=on`
  137. The mock server timeout threshold for future functions can be set with:
  138. * `MONGOC_TEST_FUTURE_TIMEOUT_MS=<int>`
  139. This is useful for debugging, so future calls don't timeout when stepping through code.
  140. All tests should pass before submitting a patch.
  141. ## Configuring the test runner
  142. The test runner can be configured with command-line options. Run `test-libmongoc
  143. --help` for details.
  144. To run just a specific portion of the test suite use the -l option like so:
  145. ```
  146. $ ./test-libmongoc -l "/server_selection/*"
  147. ```
  148. The full list of tests is shown in the help.
  149. ## Creating and checking a distribution tarball
  150. The `make distcheck` command can be used to confirm that any modifications are
  151. able to be packaged into the distribution tarball and that the resulting
  152. distribution tarball can be used to successfully build the project.
  153. A failure of the `make distcheck` target is an indicator of an oversight in the
  154. modification to the project. For example, if a new source file is added to the
  155. project but it is not added to the proper distribution list, it is possible that
  156. the distribution tarball will be created without that file. An attempt to build
  157. the project without the file is likely to fail.
  158. When `make distcheck` is invoked, several things happen. The `dist` target is
  159. executed to create a distribution tarball. Then the tarball is unpacked,
  160. configured (with an invocation of `cmake`), built (by calling `make`), installed
  161. (by calling `make install`), and tested (by calling `make check`). Three
  162. environment variables can be used to modify these steps.
  163. To adjust the options passed to `make` during the build step, set:
  164. * `DISTCHECK_BUILD_OPTS`
  165. If this variable is not set, then `make` is called with a default of "-j 8".
  166. To adjust the options passed to `make install` during the installation step,
  167. set:
  168. * `DISTCHECK_INSTALL_OPTS`
  169. To adjust the options passed to `make check` during the test step, set:
  170. * `DISTCHECK_CHECK_OPTS`
  171. Remember, if you want to modify the top-level `make` invocation, you will need
  172. to pass options on the command line as normal.
  173. For example, the command `make -j 6 distcheck DISTCHECK_BUILD_OPTS="-j 4"` will
  174. call the standard sequence of targets depended upon by `distcheck` with a
  175. parallelism level of 6, while the build step that is later called by the
  176. `distcheck` target will be executed with a parallelism level of 4.