Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

codingGuidelines.md: clarify some details about headers #400

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,57 @@ BreakConstructorInitializers: BeforeComma
BreakInheritanceList: BeforeComma
ColumnLimit: '100'
FixNamespaceComments: 'true'
IncludeBlocks: Regroup
IncludeCategories:

# Desired final ordering:
pmolodo marked this conversation as resolved.
Show resolved Hide resolved
# 1. Related header
# 2. All private headers
# 3. All public headers from this repository (maya-usd)
# 4. Pixar + USD headers
# 5. Autodesk + Maya headers
# 6. Other libraries' headers
# 7. C++ standard library headers
# 8. C system headers
# 9. Conditional includes

# 1. Related header
# Handled by the default IncludeIsMainRegex regex, and auto-assigned
# Priority 0

# 3. All public headers from this repository (maya-usd)
- Regex: '^<(mayaUsd|hdMaya|AL|usdMaya)/'
Priority: 3

# 4. Pixar + USD headers
- Regex: '^<pxr/'
Priority: 4

# 5. Autodesk + Maya headers
- Regex: '^<(maya|ufe)/'
Priority: 5

# 7. C++ standard library headers
# angle brackets, no directory, no extension
- Regex: '^<[A-Za-z0-9_-]+>$'
Priority: 7

# 8. C system headers
# angle brackets, no directory, end with ".h"
- Regex: '^<[A-Za-z0-9_-]+\.h>$'
Priority: 8

# 2. All private headers
- Regex: '^"'
Priority: 2

# 6. Other libraries' headers
- Regex: '^<'
Priority: 6

# 9. Conditional includes
# Not reordered by clang-format, we need to manually make sure these come last

MaxEmptyLinesToKeep: '1'
NamespaceIndentation: None
UseTab: Never
Expand Down
39 changes: 24 additions & 15 deletions doc/codingGuidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,44 +148,53 @@ In general, macros should be avoided (see [Modern C++](https://docs.google.com/d
* Comments for users of classes and functions must be written in headers files. Comments in definition files are meant for contributors and maintainers.

### Include directive
For source files (.cpp) with an associated header file (.h) that resides in the same directory, it should be `#include`'d with double quotes and no path. This formatting should be followed regardless of with whether the associated header is public or private. For example:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry, this now reads "regardless of with whether" as opposed to "regardless of whether". :)

```cpp
// In foobar.cpp
#include "foobar.h"
```

All included public header files from outside and inside the project should be `#include`’d using angle brackets. For example:
```cpp
#include <pxr/base/tf/stringUtils.h>
#include <mayaUsd/nodes/stageData.h>
```

Private project’s header files should be `#include`'d using the file name when in the same folder. Private headers may live in sub-directories, but they should never be included using "._" or ".._" as part of a relative paths. For example:
Private project’s header files should be `#include`'d using double quotes, and a relative path. Private headers may live in the same directory or sub-directories, but they should never be included using "._" or ".._" as part of a relative path. For example:
```cpp
#include privateUtils.h"
#include pvt/helperFunctions.h"
#include "privateUtils.h"
#include "pvt/helperFunctions.h"
```

### Include order
Headers should be included in the following order, with each section separated by a blank line and files sorted alphabetically:

1. Related header
2. C system headers
3. C++ standard library headers
4. Other libraries’ headers
2. All private headers
3. All public headers from this repository (maya-usd)
4. Pixar + USD headers
5. Autodesk + Maya headers
6. Pixar + USD headers
7. Your project’s headers
8. Conditional includes
6. Other libraries' headers
7. C++ standard library headers
8. C system headers
9. Conditional includes

```cpp
#include “exportTranslator.h"
#include "exportTranslator.h"

#include "private/util.h"

#include <string>
#include <mayaUsd/fileio/jobs/jobArgs.h>
#include <mayaUsd/fileio/jobs/writeJob.h>
#include <mayaUsd/fileio/shading/shadingModeRegistry.h>
#include <mayaUsd/fileio/utils/writeUtil.h>

#include <maya/MFileObject.h>
#include <maya/MGlobal.h>
#include <maya/MSelectionList.h>
#include <maya/MString.h>

#include <mayaUsd/fileio/jobs/jobArgs.h>
#include <mayaUsd/fileio/jobs/writeJob.h>
#include <mayaUsd/fileio/shading/shadingModeRegistry.h>
#include <mayaUsd/fileio/utils/writeUtil.h>
#include <string>

#if defined(WANT_UFE_BUILD)
#include <ufe/ufe.h>
Expand Down