diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2020-07-05 17:09:35 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2020-07-05 17:09:35 +0100 |
commit | 25706a611d0bf76781c162652bcc259b2c46a595 (patch) | |
tree | 99dafcba19a9075246f164859102cf632abf52b6 | |
parent | Pass clang-tidy and cppcheck (diff) | |
download | slicer-25706a611d0bf76781c162652bcc259b2c46a595.tar.bz2 slicer-25706a611d0bf76781c162652bcc259b2c46a595.tar.xz slicer-25706a611d0bf76781c162652bcc259b2c46a595.zip |
Add support for a slicer post-processor
Defaults to clang-format -i if clang-format in path
-rw-r--r-- | slicer/tool/slicer.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/slicer/tool/slicer.cpp b/slicer/tool/slicer.cpp index 0145d15..a256bda 100644 --- a/slicer/tool/slicer.cpp +++ b/slicer/tool/slicer.cpp @@ -1,12 +1,35 @@ +#include <boost/algorithm/string/split.hpp> #include <boost/program_options.hpp> +#include <compileTimeFormatter.h> #include <tool/parser.h> +#include <unistd.h> namespace po = boost::program_options; +using namespace AdHoc::literals; + +static std::string +defaultPostProcessor() +{ + constexpr std::array<const std::pair<std::string_view, std::string_view>, 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 argc, char ** argv) { Slicer::Slicer slicer; + std::string post; po::options_description opts("Slicer options"); // clang-format off @@ -15,6 +38,7 @@ main(int argc, char ** argv) ("include,I", po::value(&slicer.includes), "Add include directory to search path") // NOLINTNEXTLINE(clang-analyzer-optin.cplusplus.VirtualCall) ("headerPrefix", po::value(&slicer.headerPrefix)->default_value(slicer.headerPrefix), "Prefix path for Slicer C++ #includes") + ("post,p", po::value(&post)->default_value(defaultPostProcessor()), "Post-process command") ("slice,i", po::value(&slicer.slicePath), "Input ICE Slice file") ("cpp,o", po::value(&slicer.cppPath), "Output C++ file"); // clang-format on @@ -35,5 +59,9 @@ main(int argc, char ** argv) } slicer.Execute(); + if (!post.empty()) { + return system("%? %?"_fmt(post, slicer.cppPath).c_str()); + } + return 0; } |