From 8413f1a37608e3a27d609663932b11f14f0f28d3 Mon Sep 17 00:00:00 2001 From: PhilipDeegan Date: Mon, 12 Aug 2024 21:37:46 +0200 Subject: [PATCH 1/2] next --- .github/workflows/ubuntu_latest.yml | 4 +- .gitignore | 1 + .sublime-project | 6 ++ .travis.yml | 37 ---------- README.md | 5 +- mod.cpp | 109 ++++++++++++++-------------- 6 files changed, 64 insertions(+), 98 deletions(-) delete mode 100644 .travis.yml diff --git a/.github/workflows/ubuntu_latest.yml b/.github/workflows/ubuntu_latest.yml index 033ad7f..650fafc 100644 --- a/.github/workflows/ubuntu_latest.yml +++ b/.github/workflows/ubuntu_latest.yml @@ -10,12 +10,12 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - run: sudo apt-get install iwyu - run: | curl -Lo mkn https://github.com/mkn/mkn/releases/download/latest/mkn_nix chmod +x mkn - KLOG=3 ./mkn clean build -dtOp iwyu -a "-std=c++17 -fPIC" + KLOG=3 ./mkn clean build -dtOp iwyu -a "-std=c++20 -fPIC" diff --git a/.gitignore b/.gitignore index 34d04f5..ef5af5b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ bin .mkn +.clangd diff --git a/.sublime-project b/.sublime-project index 7ae0fc0..aee86ad 100644 --- a/.sublime-project +++ b/.sublime-project @@ -7,6 +7,12 @@ ], "settings": { + "ClangFormat" : + { + "binary" : "clang-format", + "format_on_save" : true, + "style" : "file" + } } } diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 7616ede..0000000 --- a/.travis.yml +++ /dev/null @@ -1,37 +0,0 @@ -language: generic -branches: - only: - - master -matrix: - include: - - os: linux - dist: bionic - sudo: required - compiler: gcc - addons: - apt: - sources: - - sourceline: 'ppa:ubuntu-toolchain-r/test' - packages: - - g++-8 - - clang++-8 - - iwyu - env: - - MATRIX_EVAL="CC=gcc-8 && CXX=g++-8" - - os: osx - compiler: clang - osx_image: xcode11 - -before_install: - - | - git clone https://github.com/Dekken/maiken --depth 10 -b master maiken - [[ "${TRAVIS_OS_NAME}" == "osx" ]] && make bsd -C maiken CXX="clang++" - [[ "${TRAVIS_OS_NAME}" == "linux" ]] && eval "${MATRIX_EVAL}" - [[ "${TRAVIS_OS_NAME}" == "linux" ]] && make nix -C maiken CXX="$CXX" - mv maiken/mkn . - -script: - - | - export MKN_LIB_LINK_LIB="1" KUL_GIT_CO="--depth 3" KLOG="3" CC CXX - ./mkn build -dtOa "-fPIC -std=c++17" - ./mkn build -p iwyu diff --git a/README.md b/README.md index 8f745d4..6bf9b53 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,6 @@ ** Compile stage plugin to to run include-what-you-use on all applicable files ** -[![Travis](https://travis-ci.org/mkn-mod/cpp.iwyu.svg?branch=master)](https://travis-ci.org/mkn-mod/cpp.iwyu) - ## Prerequisites [maiken](https://github.com/Dekken/maiken) @@ -18,8 +16,7 @@ mod: inc: inc/1 inc/2 # additional include directories paths: search/dir # scan directories ignore: src/python3 # if file found has path that contains string ignore - - + types: cpp hpp cc # file types checked default: {"cpp", "cxx", "cc", "cc", "h", "hpp"} ``` diff --git a/mod.cpp b/mod.cpp index ad7f717..905b65e 100644 --- a/mod.cpp +++ b/mod.cpp @@ -28,40 +28,36 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include // for uint16_t -#include // for string, allocator, operator+, basic_... -#include // for unordered_set -#include // for pair -#include // for vector -#include "mkn/kul/cli.hpp" // for asArgs -#include "mkn/kul/defs.hpp" // for KUL_PUBLISH -#include "mkn/kul/except.hpp" // for Exception, KEXCEPT, KTHROW -#include "mkn/kul/log.hpp" // for KLOG, KLOG_INF, KLOG_DBG -#include "mkn/kul/map.hpp" // for Map -#include "mkn/kul/os.hpp" // for Dir, File, WHICH, Exception, PushDir -#include "mkn/kul/proc.hpp" // for Process, AProcess, ExitException -#include "mkn/kul/string.hpp" // for String -#include "mkn/kul/yaml.hpp" // for NodeValidator, Validator, yaml -#include "maiken/app.hpp" // for Application -#include "maiken/module.hpp" // for Module -#include "maiken/module/init.hpp"// IWYU pragma: keep -#include "maiken/project.hpp" // for Project -#include "maiken/source.hpp" // for Source -#include "yaml-cpp/node/impl.h" // for Node::operator[], Node::Scalar -#include "yaml-cpp/node/node.h" // for Node - -namespace mkn::mod::iwyu { - -class Exception : public mkn::kul::Exception { +#include // for uint16_t +#include // for string, allocator, operator+, basic_... +#include // for unordered_set +#include // for pair +#include // for vector +#include "mkn/kul/cli.hpp" // for asArgs +#include "mkn/kul/defs.hpp" // for KUL_PUBLISH +#include "mkn/kul/except.hpp" // for Exception, KEXCEPT, KTHROW +#include "mkn/kul/log.hpp" // for KLOG, KLOG_INF, KLOG_DBG +#include "mkn/kul/map.hpp" // for Map +#include "mkn/kul/os.hpp" // for Dir, File, WHICH, Exception, PushDir +#include "mkn/kul/proc.hpp" // for Process, AProcess, ExitException +#include "mkn/kul/string.hpp" // for String +#include "mkn/kul/yaml.hpp" // for NodeValidator, Validator, yaml +#include "maiken/app.hpp" // for Application +#include "maiken/module.hpp" // for Module +#include "maiken/module/init.hpp" // IWYU pragma: keep +#include "maiken/project.hpp" // for Project +#include "maiken/source.hpp" // for Source +#include "yaml-cpp/node/impl.h" // for Node::operator[], Node::Scalar +#include "yaml-cpp/node/node.h" // for Node + +namespace mkn::mod::cpp::iwyu { + +class Exception : public kul::Exception { public: - Exception(char const* f, uint16_t const& l, std::string const& s) - : mkn::kul::Exception(f, l, s) {} + Exception(char const* f, uint16_t const& l, std::string const& s) : kul::Exception(f, l, s) {} }; -} - -namespace mkn { -class CPP_IWYU_Module : public maiken::Module { +class Module : public maiken::Module { public: void compile(maiken::Application& a, YAML::Node const& node) KTHROW(std::exception) override { run(a, node); @@ -70,46 +66,48 @@ class CPP_IWYU_Module : public maiken::Module { protected: using App = maiken::Application&; - static std::string find_iwyu(){ + static std::string find_iwyu() { std::vector iwyu{"iwyu", "include-what-you-use"}; - for(auto const& str : iwyu) - if(mkn::kul::env::WHICH(str)) return str; - KEXCEPT(mkn::mod::iwyu::Exception, "Failed to find valid iwyu binary, check PATH"); + for (auto const& str : iwyu) + if (kul::env::WHICH(str)) return str; + KEXCEPT(Exception, "Failed to find valid iwyu binary, check PATH"); } static void VALIDATE_NODE(YAML::Node const& node) { - using namespace mkn::kul::yaml; + using namespace kul::yaml; Validator({NodeValidator("inc"), NodeValidator("args"), NodeValidator("ignore"), - NodeValidator("headers"), - NodeValidator("paths"), NodeValidator("types")}) + NodeValidator("headers"), NodeValidator("paths"), NodeValidator("types")}) .validate(node); } template - void CHECK(std::string const& proc, C_Unit c_unit, mkn::kul::File&& f, YAML::Node const& node) { - if (node["ignore"]) if(f.escm().find(node["ignore"].Scalar()) != std::string::npos) return; + void CHECK(std::string const& proc, C_Unit c_unit, kul::File&& f, YAML::Node const& node) { + if (node["ignore"]) + if (f.escm().find(node["ignore"].Scalar()) != std::string::npos) return; - mkn::kul::Process p(proc); + kul::Process p(proc); auto compileStr = c_unit.compileString().substr(c_unit.compiler.size()); p << compileStr.substr(0, compileStr.rfind(" -o")); if (node["args"]) p << node["args"].Scalar(); - if (node["inc"]) for (const auto& inc : node["inc"].Scalar()) p << std::string{"-I"}+inc; + if (node["inc"]) + for (const auto& inc : node["inc"].Scalar()) p << std::string{"-I"} + inc; if (node["headers"]) p << node["headers"].Scalar(); p << f.escm(); KLOG(DBG) << p; - try{ + try { p.start(); - }catch(mkn::kul::proc::ExitException const& e){} + } catch (kul::proc::ExitException const& e) { + } } void run(App& a, YAML::Node const& node) KTHROW(std::exception) { VALIDATE_NODE(node); - mkn::kul::os::PushDir pushd(a.project().dir()); + kul::os::PushDir pushd(a.project().dir()); std::unordered_set types; if (!node["types"]) { types = {"cpp", "cxx", "cc", "cc", "h", "hpp"}; } else - for (const auto& s : mkn::kul::String::SPLIT(node["types"].Scalar(), ":")) types.insert(s); + for (const auto& s : kul::String::SPLIT(node["types"].Scalar(), ":")) types.insert(s); std::unordered_set files; @@ -119,10 +117,10 @@ class CPP_IWYU_Module : public maiken::Module { for (const auto& p2 : p1.second) for (const auto& p3 : p2.second) files.insert(p3.in()); - if (node["paths"]){ - for (const auto& path : mkn::kul::cli::asArgs(node["paths"].Scalar())) { - mkn::kul::Dir d(path); - if (!d) KEXCEPT(mkn::kul::fs::Exception, "Directory does not exist: ") << d.path(); + if (node["paths"]) { + for (const auto& path : kul::cli::asArgs(node["paths"].Scalar())) { + kul::Dir d(path); + if (!d) KEXCEPT(kul::fs::Exception, "Directory does not exist: ") << d.path(); for (const auto& file : d.files(1)) { const std::string name = file.name(); if (name.find(".") == std::string::npos) continue; @@ -136,14 +134,15 @@ class CPP_IWYU_Module : public maiken::Module { maiken::ThreadingCompiler tc(a); using Pair = std::pair; for (const auto& file : files) - CHECK(proc, tc.compilationUnit(Pair{mkn::kul::File(file).escm()+".cpp", "obj"}), mkn::kul::File(file), node); + CHECK(proc, tc.compilationUnit(Pair{kul::File(file).escm() + ".cpp", "obj"}), kul::File(file), + node); } }; -} // namespace mkn +} // namespace mkn::mod::cpp::iwyu -extern "C" KUL_PUBLISH maiken::Module *maiken_module_construct() { - return new mkn::CPP_IWYU_Module; +extern "C" KUL_PUBLISH maiken::Module* maiken_module_construct() { + return new mkn::mod::cpp::iwyu::Module; } -extern "C" KUL_PUBLISH void maiken_module_destruct(maiken::Module *p) { delete p; } +extern "C" KUL_PUBLISH void maiken_module_destruct(maiken::Module* p) { delete p; } From e292515ee5db048b1fe0df2066422cf842cfeefc Mon Sep 17 00:00:00 2001 From: PhilipDeegan Date: Tue, 17 Sep 2024 22:08:05 +0200 Subject: [PATCH 2/2] incs --- mod.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mod.cpp b/mod.cpp index 905b65e..0c1d7bd 100644 --- a/mod.cpp +++ b/mod.cpp @@ -90,7 +90,8 @@ class Module : public maiken::Module { p << compileStr.substr(0, compileStr.rfind(" -o")); if (node["args"]) p << node["args"].Scalar(); if (node["inc"]) - for (const auto& inc : node["inc"].Scalar()) p << std::string{"-I"} + inc; + for (const auto& inc : mkn::kul::cli::asArgs(node["inc"].Scalar())) + p << std::string{"-I"} + inc; if (node["headers"]) p << node["headers"].Scalar(); p << f.escm(); KLOG(DBG) << p;