diff --git a/.github/workflows/iwyu.yml b/.github/workflows/iwyu.yml new file mode 100644 index 000000000..f52ac353e --- /dev/null +++ b/.github/workflows/iwyu.yml @@ -0,0 +1,63 @@ +# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions +# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners +name: include-what-you-use + +on: workflow_dispatch + +jobs: + build: + + runs-on: ubuntu-20.04 + + container: + image: "kalilinux/kali-rolling" + + steps: + - uses: actions/checkout@v2 + + # TODO: the necessary packages are excessive - mostly because of Qt - use a pre-built image + - name: Install missing software + run: | + apt-get update + apt-get install -y cmake g++ make libz3-dev libpcre3-dev + apt-get install -y qtbase5-dev qttools5-dev libqt5charts5-dev + apt-get install -y wget iwyu + + - name: Prepare CMake + run: | + mkdir cmake.output + cd cmake.output + cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DUSE_Z3=On -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=On -DBUILD_TESTS=On -DBUILD_GUI=On -DWITH_QCHART=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCPPCHK_GLIBCXX_DEBUG=Off -DUSE_MATCHCOMPILER=Off .. + cd .. + + - name: Prepare CMake dependencies + run: | + # make sure the precompiled headers exist + #make -C cmake.output lib/CMakeFiles/lib_objs.dir/cmake_pch.hxx.cxx + #make -C cmake.output test/CMakeFiles/testrunner.dir/cmake_pch.hxx.cxx + # make sure the auto-generated GUI sources exist + make -C cmake.output autogen + # make sure the auto-generated GUI dependencies exist + make -C cmake.output gui-build-deps + + - name: Build Qt mappings + run: | + wget https://raw.githubusercontent.com/include-what-you-use/include-what-you-use/master/mapgen/iwyu-mapgen-qt.py + python3 iwyu-mapgen-qt.py /usr/include/x86_64-linux-gnu/qt5/ > qt5.imp + + # TODO: the mapping file causes a massive slowdown so we cannot use it at the moment. + # add "-Xiwyu --mapping_file=qt5.imp" at the end of the whole command if we can use them. + - name: iwyu_tool + run: | + # do not fail for now so the output is being saved + iwyu_tool -p cmake.output -j $(nproc) -- -w > iwyu.log || true + + - uses: actions/upload-artifact@v2 + with: + name: Qt Mappings + path: ./qt5.imp + + - uses: actions/upload-artifact@v2 + with: + name: Logs + path: ./*.log diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index 6e79362d0..4d59d81f0 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -62,8 +62,7 @@ # include #endif #ifdef __linux__ -#include -#include +#include #endif #endif diff --git a/cli/main.cpp b/cli/main.cpp index f8a89420b..82597a30b 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -59,15 +59,15 @@ */ -#include "errortypes.h" #include "cppcheckexecutor.h" +#ifdef NDEBUG +#include "errortypes.h" + #include #include -#include - -#ifdef NDEBUG #include +#include #endif #ifdef _WIN32 diff --git a/cli/threadexecutor.cpp b/cli/threadexecutor.cpp index 90fd43aac..e22344c1d 100644 --- a/cli/threadexecutor.cpp +++ b/cli/threadexecutor.cpp @@ -38,6 +38,7 @@ #ifdef __SVR4 // Solaris #include #endif + #ifdef THREADING_MODEL_FORK #if defined(__linux__) #include @@ -45,8 +46,10 @@ #include #include #include +#include #include #endif + #ifdef THREADING_MODEL_WIN #include #include diff --git a/externals/simplecpp/simplecpp.cpp b/externals/simplecpp/simplecpp.cpp index 852a5b892..68ff803da 100644 --- a/externals/simplecpp/simplecpp.cpp +++ b/externals/simplecpp/simplecpp.cpp @@ -27,12 +27,13 @@ #include #include #include -#include +#include // IWYU pragma: keep #include #include -#include +#include // IWYU pragma: keep #include #include +#include #include #ifdef SIMPLECPP_WINDOWS diff --git a/lib/analyzerinfo.cpp b/lib/analyzerinfo.cpp index dd068ba55..e0f043f18 100644 --- a/lib/analyzerinfo.cpp +++ b/lib/analyzerinfo.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include // IWYU pragma: keep AnalyzerInformation::~AnalyzerInformation() { diff --git a/lib/checkother.cpp b/lib/checkother.cpp index b3da83ec7..e1b966203 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -40,7 +40,6 @@ #include #include #include -#include #include #include diff --git a/lib/color.cpp b/lib/color.cpp index 378daa143..9a62f415a 100644 --- a/lib/color.cpp +++ b/lib/color.cpp @@ -22,7 +22,7 @@ #include #endif #include -#include +#include // IWYU pragma: keep #ifdef _WIN32 std::ostream& operator<<(std::ostream& os, const Color& /*c*/) diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index c7aef5a52..2cf52fab2 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -24,6 +24,7 @@ #include "path.h" #include "token.h" #include "tokenlist.h" +#include "utils.h" #include #include diff --git a/lib/importproject.cpp b/lib/importproject.cpp index c5ea4e600..a2577b95b 100644 --- a/lib/importproject.cpp +++ b/lib/importproject.cpp @@ -29,7 +29,7 @@ #include #include #include -#include +#include // IWYU pragma: keep #include #include diff --git a/lib/pathanalysis.cpp b/lib/pathanalysis.cpp index 1b9e7a300..a102da1de 100644 --- a/lib/pathanalysis.cpp +++ b/lib/pathanalysis.cpp @@ -27,6 +27,7 @@ #include #include #include +#include const Scope* PathAnalysis::findOuterScope(const Scope * scope) { diff --git a/lib/programmemory.cpp b/lib/programmemory.cpp index 96326f57d..7e8c937c9 100644 --- a/lib/programmemory.cpp +++ b/lib/programmemory.cpp @@ -35,7 +35,6 @@ #include #include #include -#include #include #include diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 0b08eaff1..0adf7a145 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -33,7 +33,6 @@ #include #include #include -#include #include static Token *skipRequires(Token *tok) diff --git a/test/testrunner.cpp b/test/testrunner.cpp index 7e85bd3ff..a76e3b60b 100644 --- a/test/testrunner.cpp +++ b/test/testrunner.cpp @@ -16,17 +16,18 @@ * along with this program. If not, see . */ -#include "errortypes.h" #include "options.h" #include "preprocessor.h" #include "testsuite.h" #include -#include -#include #ifdef NDEBUG +#include "errortypes.h" // for InternalError + +#include #include +#include #endif int main(int argc, char *argv[])