|
1 | 1 | # Contributing Guidelines
|
2 | 2 |
|
3 |
| -When contributing code, in addition to following the [C++ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines), please follow the same |
4 |
| -[design guidelines](https://github.com/mongodb/mongo/wiki/Server-Design-Guidelines) |
5 |
| -and [style guidelines](https://github.com/mongodb/mongo/wiki/Style-Guidelines) |
6 |
| -as [mongodb/mongo.](https://github.com/mongodb/mongo) Additions and exceptions are listed |
7 |
| -below. |
| 3 | +Follow the [MongoDB C++ Driver Coding Guidelines](https://github.com/mongodb/mongo-cxx-driver/etc/coding_guidelines.md), ensure files are formatted properly, and follow guidelines for writing PR titles and commit messages. |
8 | 4 |
|
9 |
| -For anything that isn't explicitly covered here, default to the |
10 |
| -[Google C++ Style Guide.](https://google.github.io/styleguide/cppguide.html#Scoping) |
11 |
| -Running [clang-format](https://clang.llvm.org/docs/ClangFormat.html) with our |
12 |
| -configuration file, |
13 |
| -[mongo-cxx-driver/.clang-format](https://github.com/mongodb/mongo-cxx-driver/blob/master/.clang-format), |
14 |
| -will help ensure your code conforms to these standards. |
| 5 | +All contributions must be made via a GitHub pull request (PR). |
15 | 6 |
|
16 |
| -### Commit Messages |
| 7 | +## Commit Messages |
17 | 8 |
|
18 |
| -If a pull-request addresses a JIRA ticket, for a single-commit PR, prefix |
19 |
| -the subject line with the ticket ID. (For a multi-commit PR, we will add |
20 |
| -the ID later when we squash or merge it.) |
| 9 | +Prefix the PR title with the relevant JIRA ticket number when applicable. When multiple JIRA tickets are related, they may be suffixed to the title or mentioned within the commit message instead. |
21 | 10 |
|
22 |
| -> CXX-883 Add commit message conventions to CONTRIBUTING.md |
| 11 | +Examples include: |
23 | 12 |
|
24 |
| -Capitalize subject lines and don't use a trailing period. Keep the subject |
25 |
| -at most 70 characters long. Use active voice! Imagine this preamble to get |
26 |
| -your phrasing right: |
27 |
| - |
28 |
| -> _If applied, this commit will..._ [your subject line] |
29 |
| -
|
30 |
| -See Chris Beams' |
31 |
| -[How to write a git commit message](http://chris.beams.io/posts/git-commit/) |
32 |
| -for more good guidelines to follow. |
33 |
| - |
34 |
| -### Lifecycle Methods |
35 |
| - |
36 |
| -- default-or-argument-bearing 'user' constructors |
37 |
| - |
38 |
| -- declaration-or-deletion-of-move-constructor |
39 |
| -- declaration-or-deletion-of-move-assignment-operator |
40 |
| - |
41 |
| -- declaration-or-deletion-of-copy-constructor |
42 |
| -- declaration-or-deletion-of-copy-assignment-operator |
43 |
| - |
44 |
| -- declaration-of-dtor |
45 |
| - |
46 |
| -### Headers |
47 |
| - |
48 |
| -Public headers must have a ".hpp" suffix. Private headers must have a ".hh" |
49 |
| -suffix. |
50 |
| - |
51 |
| -General structure: |
52 |
| - |
53 |
| -- License |
54 |
| -- Include Guard (`#pragma once`) |
55 |
| -- Header Prelude |
56 |
| -- System Headers `<vector>` (alphabetical order) |
57 |
| -- Driver Headers `<path/to/header.hpp>` (alphabetical order) |
58 |
| -- Open Namespace mongocxx |
59 |
| -- `inline namespace v_noabi {` |
60 |
| -- Code |
61 |
| -- `} // namespace v_noabi` |
62 |
| -- Close Namespace mongocxx |
63 |
| -- Header Postlude |
64 |
| - |
65 |
| -Example: |
66 |
| - |
67 |
| -```{.cpp} |
68 |
| -// Copyright 2009-present MongoDB, Inc. |
69 |
| -// |
70 |
| -// Licensed under the Apache License, Version 2.0 (the "License"); |
71 |
| -// you may not use this file except in compliance with the License. |
72 |
| -// You may obtain a copy of the License at |
73 |
| -// |
74 |
| -// http://www.apache.org/licenses/LICENSE-2.0 |
75 |
| -// |
76 |
| -// Unless required by applicable law or agreed to in writing, software |
77 |
| -// distributed under the License is distributed on an "AS IS" BASIS, |
78 |
| -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
79 |
| -// See the License for the specific language governing permissions and |
80 |
| -// limitations under the License. |
81 |
| -
|
82 |
| -#pragma once |
83 |
| -
|
84 |
| -#include <driver/config/prelude.hpp> |
85 |
| -
|
86 |
| -#include <vector> |
87 |
| -
|
88 |
| -#include <driver/blah.hpp> |
89 |
| -
|
90 |
| -namespace mongocxx { |
91 |
| -inline namespace v_noabi { |
92 |
| -
|
93 |
| -// Declarations |
94 |
| -
|
95 |
| -// Inline Implementations |
96 |
| -
|
97 |
| -} // namespace v_noabi |
98 |
| -} // namespace mongocxx |
99 |
| -
|
100 |
| -#include <driver/config/postlude.hpp> |
101 | 13 | ```
|
102 |
| - |
103 |
| -### Library Root Namespace |
104 |
| - |
105 |
| -The library root namespace declares ABI namespaces (e.g. `mongocxx::v_noabi`, `mongocxx::v1`, etc.), within which symbols are declared according to their compatibility with an ABI version. |
106 |
| - |
107 |
| -The library root namespace also redeclares ABI-specific entities without an ABI namespace qualifier (e.g. `mongocxx::v_noabi::document::view` as `mongocxx::document::view`) to allow users to automatically opt-into the latest supported ABI version of a given entity without requiring changes to source code. The root namespace redeclarations are intended to be the default method for using library entities. A user should only include the ABI namespace in a qualifier if they require compatibility with that specific ABI version. |
108 |
| - |
109 |
| -To avoid being affected by changes to root namespace redeclarations, interfaces declared within an ABI namespace must not be written in terms of a root namespace redeclaration: |
110 |
| - |
111 |
| -```cpp |
112 |
| -namespace mongocxx { |
113 |
| -namespace v_noabi { |
114 |
| -namespace example { |
115 |
| - |
116 |
| -struct type {}; // The type intended to be referenced below. |
117 |
| - |
118 |
| -// Problem: when `mongocxx::example::type` is changed from `v_noabi` to `v1`, |
119 |
| -// this parameter type will also (incorrectly) change from `v_noabi` to `v1`. |
120 |
| -void fn(mongocxx::example::type param); |
121 |
| - |
122 |
| -} // namespace example |
123 |
| -} // namespace v_noabi |
124 |
| -} // namespace mongocxx |
| 14 | +CXX-XXXX Resolve an issue |
125 | 15 | ```
|
126 | 16 |
|
127 |
| -References to ABI-specific entities in ABI namespaces must always be (un)qualified such that it is not affected by changes to root namespace redeclarations: |
128 |
| -
|
129 |
| -```cpp |
130 |
| -namespace mongocxx { |
131 |
| -namespace v_noabi { |
132 |
| -namespace example { |
133 |
| -
|
134 |
| -struct type {}; // The type intended to be referenced below. |
135 |
| -
|
136 |
| -// OK: always resolves to `mongocxx::v_noabi::example::type`. |
137 |
| -void fn(type param); |
138 |
| -
|
139 |
| -// Also OK: unambiguously refers to the ABI-specific type. |
140 |
| -void fn(mongocxx::v_noabi::example::type param); |
141 |
| -
|
142 |
| -} // namespace example |
143 |
| -} // namespace v_noabi |
144 |
| -} // namespace mongocxx |
145 | 17 | ```
|
| 18 | +Fix several related issues (CXX-AAAA, CXX-BBBB) |
146 | 19 |
|
147 |
| -### Class Declarations |
148 |
| - |
149 |
| -Guidelines: |
150 |
| - |
151 |
| -- Blank line at beginning and end of class declaration |
152 |
| -- Public section up top / private at bottom |
153 |
| -- Lifecycle methods first (see rules above) |
154 |
| -- Private Member Ordering |
155 |
| - - Friendships |
156 |
| - - Private Constructors |
157 |
| - - Private Methods |
158 |
| - - Private Variables |
159 |
| - |
160 |
| -Example: |
161 |
| - |
162 |
| -```{.cpp} |
163 |
| -class foo { |
164 |
| -
|
165 |
| - public: |
166 |
| - foo(); |
167 |
| -
|
168 |
| - foo(foo&& other) noexcept; |
169 |
| - foo& operator=(foo&& other) noexcept; |
170 |
| -
|
171 |
| - ~foo(); |
172 |
| -
|
173 |
| - private: |
174 |
| - friend baz; |
175 |
| -
|
176 |
| - class MONGOCXX_PRIVATE impl; |
177 |
| - std::unique_ptr<impl> _impl; |
| 20 | +* Commit A description |
| 21 | +* Commit B description |
| 22 | +* Commit C description |
| 23 | +``` |
178 | 24 |
|
179 |
| -}; |
180 | 25 | ```
|
| 26 | +CXX-XXXX Implement a feature resolving several related issues |
181 | 27 |
|
182 |
| -### Inlines |
| 28 | +* CXX-AAAA Commit A description |
| 29 | +* CXX-BBBB Commit B description |
| 30 | +* Additional commit description |
| 31 | +``` |
183 | 32 |
|
184 |
| -- Define outside of class declaration |
185 |
| -- Specify inline keyword in declaration and definition (for clarity) |
| 33 | +Refer to Chris Beams' guidelines for |
| 34 | +[How to Write a Git Commit Message](http://chris.beams.io/posts/git-commit/). |
186 | 35 |
|
187 |
| -### Relational Operators |
| 36 | +## Formatting |
188 | 37 |
|
189 |
| -- Prefer to use free functions |
| 38 | +Format files with [ClangFormat](https://clang.llvm.org/docs/ClangFormat.html) using the [etc/clang_format.py](https://github.com/mongodb/mongo-cxx-driver/blob/master/etc/clang_format.py) script. |
190 | 39 |
|
191 |
| -### Formatting |
| 40 | +The script must be run in the project root directory to ensure the [.clang-format](https://github.com/mongodb/mongo-cxx-driver/blob/master/.clang-format) configuration file is used properly. |
192 | 41 |
|
193 |
| -The source includes a clang format definitions file (`.clang-format`) to enforce consistent style. Run clang-format (using 3.8) from the root of the repository or use the helper script included in the source: |
| 42 | +```bash |
| 43 | +# Allow the script to download the correct ClangFormat release version. |
| 44 | +python2 ./etc/clang-format.py format |
194 | 45 |
|
195 |
| -``` |
196 |
| -python ./etc/clang-format.py format |
| 46 | +# Provide a path to an existing ClangFormat binary to use instead. |
| 47 | +MONGO_CLANG_FORMAT="path/to/clang-format" python2 ./etc/clang-format.py format |
197 | 48 | ```
|
198 | 49 |
|
199 |
| -Note, this script will automatically download clang-format 3.8 if it cannot detect it on your system. |
| 50 | +> [!NOTE] |
| 51 | +> ClangFormat results may differ across release versions. When using a preinstalled ClangFormat binary, its version must be consistent with the `CLANG_FORMAT_VERSION` variable defined in the `etc/clang_format.py` script. |
0 commit comments