From 7e310953c0ac6d75c5fa32b4544c84e0042c9b5b Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 21 Dec 2020 16:46:16 +0000 Subject: Add C++ post processor Defaults to clang-format -i, same as slicer. --- icespider/compile/main.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/icespider/compile/main.cpp b/icespider/compile/main.cpp index 5796bae..b8eb26e 100644 --- a/icespider/compile/main.cpp +++ b/icespider/compile/main.cpp @@ -1,7 +1,28 @@ #include "routeCompiler.h" +#include #include +#include namespace po = boost::program_options; +using namespace AdHoc::literals; + +static std::string +defaultPostProcessor() +{ + constexpr std::array, 1> pps {{ + {"clang-format", "-i"}, + }}; + const std::string_view path {getenv("PATH")}; + const auto pathBegin = make_split_iterator(path, first_finder(":", boost::is_equal())); + for (const auto & [cmd, opts] : pps) { + for (auto p = pathBegin; p != decltype(pathBegin) {}; ++p) { + if (std::filesystem::exists(std::filesystem::path(p->begin(), p->end()) / cmd)) { + return "%? %?"_fmt(cmd, opts); + } + } + } + return ""; +} int main(int c, char ** v) @@ -9,12 +30,14 @@ main(int c, char ** v) bool showHelp; IceSpider::Compile::RouteCompiler rc; std::filesystem::path input, output; + std::string post; po::options_description opts("IceSpider compile options"); // clang-format off opts.add_options() ("input", po::value(&input), "Input .json file") ("output", po::value(&output), "Output .cpp file") ("include,I", po::value(&rc.searchPath)->composing(), "Search path") + ("post,p", po::value(&post)->default_value(defaultPostProcessor()), "Post-process command") ("help,h", po::value(&showHelp)->default_value(false)->zero_tokens(), "Help") ; // clang-format on @@ -34,5 +57,10 @@ main(int c, char ** v) rc.searchPath.push_back(input.parent_path()); rc.compile(input, output); + if (!post.empty()) { + auto outputh = std::filesystem::path(output).replace_extension(".h"); + return system("%? %? %?"_fmt(post, output, outputh).c_str()); + } + return 0; } -- cgit v1.2.3