Enable SortIncludes option of clang-format
Categories
(Developer Infrastructure :: Source Code Analysis, task)
Tracking
(Not tracked)
People
(Reporter: sg, Assigned: andi)
References
Details
(Keywords: leave-open)
Attachments
(14 files, 1 obsolete file)
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review |
clang-format provides the ability to sort include directives via the SortIncludes
option. We should check if we can use that to automate adherence to the coding style, at least to some degree. There are various rules that can be configured. If it's not possible to implement the rules written down in the coding style, these could be adapted to match clang-format's abilities.
Reporter | ||
Comment 1•4 years ago
|
||
Other relevant options here are IncludeBlocks
and IncludeCategories
.
It seems that clang-format always sorts ignoring case, so we should probably adapt the coding style draft section accordingly. (The current codebase, here there is a visible sorting, is divided on whether case is ignored or not.)
Reporter | ||
Comment 2•4 years ago
|
||
Sorting includes requires that the headers are self-contained, i.e. they include all other headers they need. I will check to what degree this causes issues.
Conditional includes are however, not affected by this. They are preserved as is, resp. if a conditional block includes multiple includes, these are sorted only within that block.
Reporter | ||
Comment 3•4 years ago
|
||
Reporter | ||
Comment 4•4 years ago
|
||
Depends on D98078
Reporter | ||
Comment 5•4 years ago
|
||
Another issue here are macros defined in system headers, which need to be undefined after they are included somewhere, possibly indirectly. A notorious case is None
, which is defined by some X11 headers, which is undefined through X11UndefineNone.h
. This must be immediately included after including the system header that caused it to be defined. This could be addressed by using a wrapper for that system header that ensures it is undefined appropriately.
Reporter | ||
Comment 6•4 years ago
|
||
check_spidermonkey_style.py
checks some convention for sorting & grouping includes that I don't fully understand. Some things might (probably should) be incorporated into the global rules, e.g. oddly_ordered_inclnames
. Others are entangled with custom header naming conventions for SpiderMonkey.
Maybe this functionality can be retired at some point in favor of using clang-format to handle this? Maybe with a custom rule for js/src
Updated•4 years ago
|
Reporter | ||
Comment 7•4 years ago
|
||
Depends on D98078
Reporter | ||
Comment 8•4 years ago
|
||
Depends on D98220
Updated•4 years ago
|
Reporter | ||
Comment 9•4 years ago
|
||
Depends on D98222
Reporter | ||
Comment 10•4 years ago
|
||
The js code is the only (?) part of the code base that already does automatic sorting/grouping of include directives, using a custom mechanism. There are different options on how to proceed with this when activating SortIncludes
for the codebase.
- Use the existing clang-format configuration for js as well (see https://phabricator.services.mozilla.com/D98312 on how that would currently look)
- Make some extensions to the general clang-format configuration, and use that for js as well (e.g. I think we could add the rules for grouping *-inl headers separately to the general rules, but some other rules are very js-specific, e.g. for grouping js includes separately)
- Make a separate clang-format configuration for js
- Disable
SortIncludes
for js (so for js the situation would stay unchanged after this bug)
(In the first three cases, the existing code for checking and fixing include directive ordering in config/check_spidermonkey_style.py could be removed)
:jandem, WDYT?
Comment 11•4 years ago
|
||
(In reply to Simon Giesecke [:sg] [he/him] from comment #10)
- Disable
SortIncludes
for js (so for js the situation would stay unchanged after this bug)
I'd prefer this option. I think SM engineers are happy with the #include order and grouping enforced by the check_spidermonkey_style.py
script.
Let me drop a link to this bug in our Matrix room to see what others think.
Reporter | ||
Comment 12•4 years ago
|
||
(In reply to Jan de Mooij [:jandem] from comment #11)
(In reply to Simon Giesecke [:sg] [he/him] from comment #10)
- Disable
SortIncludes
for js (so for js the situation would stay unchanged after this bug)I'd prefer this option. I think SM engineers are happy with the #include order and grouping enforced by the
check_spidermonkey_style.py
script.Let me drop a link to this bug in our Matrix room to see what others think.
Thanks! I left a note there as well. I also updated the config and patch for js to follow the existing rules more closely. There are a few things that clang-format can't do as it seems:
- Keep the order of subdirectories and casing as is. clang-format seems to always sort subdirectories after the base directory (so all foo/bar/.h includes after all foo/.h includes), and otherwise always case-insensitive.
- Use the corresponding
*-inl.h
as the main include. It can be configured to do the reverse, i.e. regardfoo.h
as the main include when ordering includes infoo-inl.h
.
Updated•4 years ago
|
Updated•4 years ago
|
Reporter | ||
Comment 13•4 years ago
|
||
Depends on D98312
Reporter | ||
Comment 14•4 years ago
|
||
Depends on D98786
Reporter | ||
Comment 15•4 years ago
|
||
Depends on D98788
Reporter | ||
Comment 16•4 years ago
|
||
Depends on D98789
Reporter | ||
Comment 17•4 years ago
|
||
Depends on D98790
Reporter | ||
Comment 18•4 years ago
|
||
Depends on D98078
Reporter | ||
Comment 19•4 years ago
|
||
Depends on D98884
Reporter | ||
Comment 20•4 years ago
|
||
- Add missing include directives and forward declarations.
- Remove some extra include directives.
- Add missing namespace qualifications.
- Move include directives out of namespace in toolkit/xre/GlobalSemaphore.h
Depends on D98604
Reporter | ||
Comment 21•4 years ago
|
||
Depends on D98894
Reporter | ||
Comment 22•4 years ago
|
||
Unfortunately, mozzconf defines a macro named crc32, which causes a naming
conflict with the struct members in zipstruct.h. This patch renames the
latter to avoid that conflict. Otherwise, there's a brittle dependency on
include order.
Depends on D98895
Updated•4 years ago
|
Reporter | ||
Updated•4 years ago
|
Comment 23•4 years ago
|
||
Reporter | ||
Comment 24•4 years ago
|
||
I have landed the prerequisites that were ready for landing. andi, maybe you can move this forward?
Comment 25•4 years ago
|
||
bugherder |
Assignee | ||
Updated•3 years ago
|
Comment 26•3 years ago
|
||
The leave-open keyword is there and there is no activity for 6 months.
:andi, maybe it's time to close this bug?
For more information, please visit auto_nag documentation.
Assignee | ||
Updated•3 years ago
|
Updated•2 years ago
|
Assignee | ||
Updated•2 years ago
|
Updated•2 years ago
|
Assignee | ||
Comment 27•2 years ago
|
||
This is a major blocker since we don't have support for self contained headers.
Description
•