forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request CleverRaven#27683 from jbytheway/iwyu_prep
IWYU support (part 2): Miscellaneous prep work
- Loading branch information
Showing
42 changed files
with
265 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
## Astyle | ||
|
||
Automatic formatting is performed by astyle. If you have make and astyle | ||
installed then this can be done with 'make astyle'. | ||
|
||
On Windows, there is an astyle extension for Visual Studio. | ||
|
||
## include-what-you-use | ||
|
||
[include-what-you-use](https://github.com/include-what-you-use/include-what-you-use) | ||
(IWYU) is a project intended to optimise includes. It will calculate the | ||
required headers and add and remove includes as appropriate. | ||
|
||
Running on this codebase revealed some issues. You will need a version of IWYU | ||
where the following PRs have been merged (which has not yet happened at time of | ||
writing): | ||
|
||
* https://github.com/include-what-you-use/include-what-you-use/pull/637 | ||
* https://github.com/include-what-you-use/include-what-you-use/pull/641 | ||
|
||
Once you have IWYU built, build the codebase using cmake, with | ||
`CMAKE_EXPORT_COMPILE_COMMANDS=ON` on to create a compilation database | ||
(Look for `compile_commands.json` in the build dir to see whether that worked). | ||
|
||
Then run: | ||
|
||
``` | ||
iwyu_tool.py -p $CMAKE_BUILD_DIR/compile_commands.json -- -Xiwyu --mapping_file=$PWD/tools/iwyu/cata.imp | fix_includes.py --nosafe_headers | ||
``` | ||
|
||
We have to use IWYU pragmas in some situations. Some of the reasons are: | ||
|
||
* IWYU has a concept of [associated | ||
headers](https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/IWYUPragmas.md#iwyu-pragma-associated), | ||
where each cpp file can have some number of such headers. The cpp file is | ||
expected to define the things declared in those headers. In Cata, the | ||
mapping between headers and cpp files is not nearly so simple, so there are | ||
files with multiple associated headers, and files with none. Headers that | ||
are not the associated header of any cpp file will not get their includes | ||
updated, which could lead to broken builds, so ideally all headers would be | ||
associated to some cpp file. You can use the following command to get a list | ||
of headers which are not currently associated to any cpp file (requires GNU | ||
sed): | ||
|
||
``` | ||
diff <(ls src/*.h | sed 's!.*/!!') <(for i in src/*.cpp; do echo $i; sed -n '/^#include/{p; :loop n; p; /^$/q; b loop}' $i; done | grep 'e "' | grep -o '"[^"]*"' | sort -u | tr -d '"') | ||
``` | ||
|
||
* Due to a [clang bug](https://bugs.llvm.org/show_bug.cgi?id=20666), uses in | ||
template arguments to explicit instantiations are not counted, which leads to | ||
some need for `IWYU pragma: keep`. | ||
|
||
* Due to | ||
[these](https://github.com/include-what-you-use/include-what-you-use/blob/4909f206b46809775e9b5381f852eda62cbf4bf7/iwyu.cc#L1617) | ||
[missing](https://github.com/include-what-you-use/include-what-you-use/blob/4909f206b46809775e9b5381f852eda62cbf4bf7/iwyu.cc#L1629) | ||
features of IWYU, it does not count uses in template arguments to return | ||
types, which leads to other requirements for `IWYU pragma: keep`. | ||
|
||
* IWYU seems to have particular trouble with types used in maps and | ||
`cata::optional`. Have not looked into this in detail, but again worked | ||
around it with pragmas. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
#ifndef CATA_IO_TAGS_H | ||
#define CATA_IO_TAGS_H | ||
|
||
namespace io | ||
{ | ||
|
||
class JsonArrayInputArchive; | ||
class JsonArrayOutputArchive; | ||
class JsonObjectInputArchive; | ||
class JsonObjectOutputArchive; | ||
|
||
/** | ||
* Tag that indicates the class is stored in a JSON array. | ||
*/ | ||
struct array_archive_tag { | ||
using InputArchive = JsonArrayInputArchive; | ||
using OutputArchive = JsonArrayOutputArchive; | ||
}; | ||
|
||
/** | ||
* Tag that indicates the class is stored in a JSON object. | ||
*/ | ||
struct object_archive_tag { | ||
using InputArchive = JsonObjectInputArchive; | ||
using OutputArchive = JsonObjectOutputArchive; | ||
}; | ||
|
||
} | ||
|
||
#endif // CATA_IO_TAGS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
* | ||
* Further documentation can be found below. | ||
*/ | ||
|
||
class JsonIn; | ||
class JsonOut; | ||
class JsonObject; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.