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

Run codebase through IWYU and add a CI check. ~7-10% improvements to build times. #79631

Merged
merged 15 commits into from
Feb 12, 2025
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
69 changes: 69 additions & 0 deletions .github/workflows/iwyu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: IWYU (include-what-you-use)
on:
push:
branches:
- master
pull_request:
branches:
- master
types: [opened, reopened, synchronize, ready_for_review]
paths:
- 'src/**'
- 'tests/**'
- 'tools/iwyu/**'
- '**/CMakeLists.txt'
- '.github/workflows/iwyu.yml'

# We only care about the latest revision of a PR, so cancel all previous instances.
concurrency:
group: iwyu-${{ github.event.pull_request.number || github.ref_name }}
cancel-in-progress: true
jobs:
run:
runs-on: ubuntu-24.04
env:
COMPILER: clang++-19
steps:
- name: install LLVM 19
if: ${{ needs.skip-duplicates.outputs.should_skip != 'true' && github.event_name != 'pull_request' || github.event.pull_request.draft == false }}
run: |
sudo apt install llvm-19 llvm-19-dev llvm-19-tools clang-19 clang-tidy-19 clang-tools-19 libclang-19-dev
sudo apt install python3-pip ninja-build cmake
- name: checkout IWYU repository
uses: actions/checkout@v4
with:
repository: include-what-you-use/include-what-you-use
path: include-what-you-use-src
ref: clang_19
- name: checkout own repository
uses: actions/checkout@v4
with:
path: Cataclysm-DDA
- name: build IWYU
id: build-iwyu
run: |
cmake -B iwyu-build -DCMAKE_PREFIX_PATH=/usr/lib/llvm-19 include-what-you-use-src
cmake --build iwyu-build --parallel 4
echo "IWYU_SRC_DIR=${PWD}/include-what-you-use-src">> "$GITHUB_OUTPUT"
echo "IWYU_BIN_DIR=${PWD}/iwyu-build/bin">> "$GITHUB_OUTPUT"
- uses: ammaraskar/gcc-problem-matcher@master
- name: create CDDA compilation database
run: |
cmake -B Cataclysm-DDA/build \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCMAKE_CXX_COMPILER=$COMPILER \
-DCMAKE_BUILD_TYPE="Release" \
-DTILES=${TILES:-0} \
-DSOUND=${SOUND:-0} \
-DLOCALIZE=${LOCALIZE:-0} \
Cataclysm-DDA
- name: run the thing
env:
IWYU_SRC_DIR: ${{ steps.build-iwyu.outputs.IWYU_SRC_DIR }}
IWYU_BIN_DIR: ${{ steps.build-iwyu.outputs.IWYU_BIN_DIR }}
run: |
PATH="${PATH}:${IWYU_BIN_DIR}"
cd Cataclysm-DDA
FILES_LIST=$( find src/ tests/ -maxdepth 1 -name '*.cpp' | grep -v -f tools/iwyu/bad_files.txt | sort )
python ${IWYU_SRC_DIR}/iwyu_tool.py ${FILES_LIST} -p build --output-format clang --jobs 4 -- -Xiwyu "--mapping_file=${PWD}/tools/iwyu/cata.imp" -Xiwyu --cxx17ns -Xiwyu --comment_style=long -Xiwyu --max_line_length=1000
4 changes: 0 additions & 4 deletions src/achievement.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "achievement.h"

#include <cstdlib>
#include <set>
#include <string>
#include <tuple>
#include <utility>
Expand All @@ -14,12 +13,9 @@
#include "enums.h"
#include "event.h"
#include "event_statistics.h"
#include "flexbuffer_json-inl.h"
#include "flexbuffer_json.h"
#include "generic_factory.h"
#include "init.h"
#include "json.h"
#include "json_error.h"
#include "past_achievements_info.h"
#include "stats_tracker.h"
#include "string_formatter.h"
Expand Down
9 changes: 2 additions & 7 deletions src/achievement.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,10 @@
class JsonObject;
class JsonOut;
class achievements_tracker;
struct achievement_requirement;
template <typename E> struct enum_traits;

namespace cata
{
class event;
} // namespace cata
class requirement_watcher;
class stats_tracker;
struct achievement_requirement;
template <typename E> struct enum_traits;

enum class achievement_comparison : int {
equal,
Expand Down
1 change: 1 addition & 0 deletions src/active_item_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <algorithm>
#include <numeric>
#include <string>
#include <utility>

#include "item.h"
Expand Down
3 changes: 2 additions & 1 deletion src/active_item_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
#include <vector>

#include "coordinates.h"
#include "item_pocket.h"
#include "point.h"
#include "safe_reference.h"

class item;
class item_pocket;

// A struct used to uniquely identify an item within a submap or vehicle.
struct item_reference {
Expand Down
21 changes: 7 additions & 14 deletions src/activity_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
#include <map>
#include <optional>
#include <set>
#include <sstream>
#include <string>
#include <string_view>
#include <type_traits>
#include <unordered_set>
#include <utility>
#include <vector>
Expand All @@ -27,31 +24,29 @@
#include "avatar.h"
#include "avatar_action.h"
#include "bodypart.h"
#include "cached_options.h"
#include "calendar.h"
#include "cata_assert.h"
#include "cata_utility.h"
#include "character.h"
#include "character_id.h"
#include "clzones.h"
#include "contents_change_handler.h"
#include "coordinates.h"
#include "craft_command.h"
#include "crafting_gui.h"
#include "creature.h"
#include "creature_tracker.h"
#include "debug.h"
#include "enum_conversions.h"
#include "enums.h"
#include "event.h"
#include "event_bus.h"
#include "faction.h"
#include "field_type.h"
#include "fault.h"
#include "field_type.h"
#include "flag.h"
#include "flexbuffer_json-inl.h"
#include "flexbuffer_json.h"
#include "game.h"
#include "game_constants.h"
#include "game_inventory.h"
#include "gates.h"
#include "gun_mode.h"
#include "handle_liquid.h"
Expand All @@ -66,41 +61,39 @@
#include "iuse.h"
#include "iuse_actor.h"
#include "json.h"
#include "json_error.h"
#include "line.h"
#include "magic_enchantment.h"
#include "map.h"
#include "map_iterator.h"
#include "map_scale_constants.h"
#include "map_selector.h"
#include "mapdata.h"
#include "martialarts.h"
#include "memory_fast.h"
#include "messages.h"
#include "monster.h"
#include "morale_types.h"
#include "mtype.h"
#include "npc.h"
#include "options.h"
#include "output.h"
#include "overmap_ui.h"
#include "pickup.h"
#include "pimpl.h"
#include "player_activity.h"
#include "pocket_type.h"
#include "point.h"
#include "ranged.h"
#include "recipe.h"
#include "recipe_dictionary.h"
#include "requirements.h"
#include "ret_val.h"
#include "rng.h"
#include "safe_reference.h"
#include "shearing.h"
#include "skill.h"
#include "sounds.h"
#include "string_formatter.h"
#include "translation.h"
#include "translations.h"
#include "trap.h"
#include "type_id.h"
#include "try_parse_integer.h"
#include "ui.h"
#include "uistate.h"
#include "units.h"
Expand Down
1 change: 1 addition & 0 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "creature_tracker.h"
#include "cuboid_rectangle.h"
#include "debug.h"
#include "effect_on_condition.h"
#include "enums.h"
#include "event.h"
#include "event_bus.h"
Expand Down
1 change: 0 additions & 1 deletion src/activity_handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <map>
#include <optional>
#include <string>
#include <unordered_set>
#include <vector>

#include "coords_fwd.h"
Expand Down
8 changes: 3 additions & 5 deletions src/activity_item_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#include "activity_actor_definitions.h"
#include "activity_type.h"
#include "avatar.h"
#include "calendar.h"
#include "cata_utility.h"
#include "character.h"
#include "clzones.h"
#include "colony.h"
#include "construction.h"
#include "coordinates.h"
#include "craft_command.h"
#include "creature.h"
#include "creature_tracker.h"
Expand All @@ -45,6 +45,7 @@
#include "itype.h"
#include "map.h"
#include "map_iterator.h"
#include "map_scale_constants.h"
#include "map_selector.h"
#include "mapdata.h"
#include "messages.h"
Expand Down Expand Up @@ -183,9 +184,6 @@ struct act_item {
};

// TODO: Deliberately unified with multidrop. Unify further.
using drop_location = std::pair<item_location, int>;
using drop_locations = std::list<std::pair<item_location, int>>;

static bool same_type( const std::list<item> &items )
{
return std::all_of( items.begin(), items.end(), [&items]( const item & it ) {
Expand Down
3 changes: 1 addition & 2 deletions src/activity_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
#include "activity_handlers.h"
#include "assign.h"
#include "debug.h"
#include "flexbuffer_json-inl.h"
#include "enums.h"
#include "flexbuffer_json.h"
#include "generic_factory.h"
#include "json_error.h"
#include "sounds.h"
#include "string_formatter.h"
#include "translations.h"
Expand Down
2 changes: 1 addition & 1 deletion src/activity_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <set>
#include <string>

#include "enums.h"
#include "game_constants.h"
#include "translation.h"
#include "type_id.h"
Expand All @@ -14,6 +13,7 @@ class Character;
class JsonObject;
class activity_type;
class player_activity;
enum class distraction_type : int;
template <typename T> struct enum_traits;

/** @relates string_id */
Expand Down
5 changes: 0 additions & 5 deletions src/addiction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <map>
#include <memory>
#include <optional>
#include <set>
#include <string>
#include <utility>

Expand All @@ -16,11 +15,7 @@
#include "dialogue.h"
#include "effect_on_condition.h"
#include "enums.h"
#include "flexbuffer_json-inl.h"
#include "flexbuffer_json.h"
#include "generic_factory.h"
#include "init.h"
#include "json_error.h"
#include "rng.h"
#include "talker.h"
#include "text_snippets.h"
Expand Down
1 change: 1 addition & 0 deletions src/advanced_inv_area.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <string>
#include <vector>

#include "coordinates.h"
#include "item_location.h"
#include "point.h"
#include "units.h"
Expand Down
2 changes: 1 addition & 1 deletion src/advanced_inv_pagination.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "advanced_inv_pagination.h"

#include <memory>
#include <vector>

#include "advanced_inv_listitem.h"
#include "advanced_inv_pane.h"

class item_category;
Expand Down
2 changes: 0 additions & 2 deletions src/ammo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
#include <utility>

#include "debug.h"
#include "flexbuffer_json-inl.h"
#include "flexbuffer_json.h"
#include "item.h"
#include "json_error.h"
#include "type_id.h"

namespace
Expand Down
4 changes: 0 additions & 4 deletions src/ammo_effect.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
#include "ammo_effect.h"

#include <set>

#include "debug.h"
#include "flexbuffer_json-inl.h"
#include "flexbuffer_json.h"
#include "generic_factory.h"
#include "init.h"

generic_factory<ammo_effect> &get_all_ammo_effects()
{
Expand Down
6 changes: 0 additions & 6 deletions src/anatomy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <unordered_set>

Expand All @@ -12,11 +10,7 @@
#include "creature.h"
#include "debug.h"
#include "flag.h"
#include "flexbuffer_json-inl.h"
#include "flexbuffer_json.h"
#include "generic_factory.h"
#include "init.h"
#include "json_error.h"
#include "messages.h"
#include "output.h"
#include "rng.h"
Expand Down
1 change: 0 additions & 1 deletion src/anatomy.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

class Creature;
class JsonObject;
class anatomy;

/**
* A structure that contains body parts.
Expand Down
Loading
Loading