From fd4d6ca859ce71fb0f3d95004da3278d0b120dd1 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 6 Feb 2022 18:02:10 +0000 Subject: Fix IWYU on generated code --- icespider/compile/routeCompiler.cpp | 46 +++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/icespider/compile/routeCompiler.cpp b/icespider/compile/routeCompiler.cpp index 3a25d6e..e2ac9fa 100644 --- a/icespider/compile/routeCompiler.cpp +++ b/icespider/compile/routeCompiler.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -200,9 +201,9 @@ namespace IceSpider { throw std::runtime_error("Failed to open output files"); } AdHoc::ScopeExit outClose(nullptr, nullptr, [&output, &outputh]() { - std::filesystem::remove(output); - std::filesystem::remove(outputh); - }); + std::filesystem::remove(output); + std::filesystem::remove(outputh); + }); processConfiguration(out.get(), outh.get(), output.stem().string(), configuration, units); } @@ -309,28 +310,55 @@ namespace IceSpider { fputs("// This source files was generated by IceSpider.\n", output); fprintbf(output, "// Configuration name: %s\n\n", c->name); + fputs("#pragma once\n", outputh); fputs("// This source files was generated by IceSpider.\n", outputh); fprintbf(outputh, "// Configuration name: %s\n\n", c->name); fputs("// Configuration headers.\n", output); fprintbf(output, "#include \"%s.h\"\n", name); - fputs("// Standard headers.\n", outputh); - fputs("#include \n", outputh); - fputs("#include \n", outputh); - fputs("#include \n", outputh); - + fputs("\n// Interface headers.\n", output); fputs("\n// Interface headers.\n", outputh); for (const auto & s : c->slices) { std::filesystem::path slicePath(s); slicePath.replace_extension(".h"); + fprintbf(output, "#include <%s>\n", slicePath.string()); fprintbf(outputh, "#include <%s>\n", slicePath.string()); } + fputs("\n// Standard headers.\n", outputh); + fputs("namespace IceSpider {\n", outputh); + fputs("\tclass Core; // IWYU pragma: keep\n", outputh); + fputs("\tclass IHttpRequest; // IWYU pragma: keep\n", outputh); + fputs("}\n", outputh); + + fputs("// Standard headers.\n", output); + for (const auto header : { + "core.h", + "irouteHandler.h", + "Ice/Config.h", + "Ice/Exception.h", + "Ice/Proxy.h", + "boost/lexical_cast.hpp", + "future", + "ios", + "memory", + "string", + "string_view", + "factory.h", + "http.h", + "ihttpRequest.h", + "util.h", + }) { + fprintbf(output, "#include <%s>\n", header); + } + if (!c->headers.empty()) { + fputs("\n// Extra headers.\n", output); fputs("\n// Extra headers.\n", outputh); for (const auto & h : c->headers) { - fprintbf(outputh, "#include <%s>\n", h); + fprintbf(output, "#include <%s> // IWYU pragma: keep\n", h); + fprintbf(outputh, "#include <%s> // IWYU pragma: keep\n", h); } } -- cgit v1.2.3