Skip to content

Commit 8413f1a

Browse files
committed
next
1 parent 4f570e4 commit 8413f1a

File tree

6 files changed

+64
-98
lines changed

6 files changed

+64
-98
lines changed

.github/workflows/ubuntu_latest.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ jobs:
1010
build:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v2
13+
- uses: actions/checkout@v4
1414

1515
- run: sudo apt-get install iwyu
1616

1717
- run: |
1818
curl -Lo mkn https://github.com/mkn/mkn/releases/download/latest/mkn_nix
1919
chmod +x mkn
20-
KLOG=3 ./mkn clean build -dtOp iwyu -a "-std=c++17 -fPIC"
20+
KLOG=3 ./mkn clean build -dtOp iwyu -a "-std=c++20 -fPIC"
2121

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
bin
22
.mkn
3+
.clangd

.sublime-project

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
],
88
"settings":
99
{
10+
"ClangFormat" :
11+
{
12+
"binary" : "clang-format",
13+
"format_on_save" : true,
14+
"style" : "file"
15+
}
1016
}
1117
}
1218

.travis.yml

Lines changed: 0 additions & 37 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
** Compile stage plugin to to run include-what-you-use on all applicable files **
44

5-
[![Travis](https://travis-ci.org/mkn-mod/cpp.iwyu.svg?branch=master)](https://travis-ci.org/mkn-mod/cpp.iwyu)
6-
75
## Prerequisites
86
[maiken](https://github.com/Dekken/maiken)
97

@@ -18,8 +16,7 @@ mod:
1816
inc: inc/1 inc/2 # additional include directories
1917
paths: search/dir # scan directories
2018
ignore: src/python3 # if file found has path that contains string ignore
21-
22-
19+
types: cpp hpp cc # file types checked default: {"cpp", "cxx", "cc", "cc", "h", "hpp"}
2320

2421
```
2522

mod.cpp

Lines changed: 54 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -28,40 +28,36 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2828
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2929
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030
*/
31-
#include <stdint.h> // for uint16_t
32-
#include <string> // for string, allocator, operator+, basic_...
33-
#include <unordered_set> // for unordered_set
34-
#include <utility> // for pair
35-
#include <vector> // for vector
36-
#include "mkn/kul/cli.hpp" // for asArgs
37-
#include "mkn/kul/defs.hpp" // for KUL_PUBLISH
38-
#include "mkn/kul/except.hpp" // for Exception, KEXCEPT, KTHROW
39-
#include "mkn/kul/log.hpp" // for KLOG, KLOG_INF, KLOG_DBG
40-
#include "mkn/kul/map.hpp" // for Map
41-
#include "mkn/kul/os.hpp" // for Dir, File, WHICH, Exception, PushDir
42-
#include "mkn/kul/proc.hpp" // for Process, AProcess, ExitException
43-
#include "mkn/kul/string.hpp" // for String
44-
#include "mkn/kul/yaml.hpp" // for NodeValidator, Validator, yaml
45-
#include "maiken/app.hpp" // for Application
46-
#include "maiken/module.hpp" // for Module
47-
#include "maiken/module/init.hpp"// IWYU pragma: keep
48-
#include "maiken/project.hpp" // for Project
49-
#include "maiken/source.hpp" // for Source
50-
#include "yaml-cpp/node/impl.h" // for Node::operator[], Node::Scalar
51-
#include "yaml-cpp/node/node.h" // for Node
52-
53-
namespace mkn::mod::iwyu {
54-
55-
class Exception : public mkn::kul::Exception {
31+
#include <stdint.h> // for uint16_t
32+
#include <string> // for string, allocator, operator+, basic_...
33+
#include <unordered_set> // for unordered_set
34+
#include <utility> // for pair
35+
#include <vector> // for vector
36+
#include "mkn/kul/cli.hpp" // for asArgs
37+
#include "mkn/kul/defs.hpp" // for KUL_PUBLISH
38+
#include "mkn/kul/except.hpp" // for Exception, KEXCEPT, KTHROW
39+
#include "mkn/kul/log.hpp" // for KLOG, KLOG_INF, KLOG_DBG
40+
#include "mkn/kul/map.hpp" // for Map
41+
#include "mkn/kul/os.hpp" // for Dir, File, WHICH, Exception, PushDir
42+
#include "mkn/kul/proc.hpp" // for Process, AProcess, ExitException
43+
#include "mkn/kul/string.hpp" // for String
44+
#include "mkn/kul/yaml.hpp" // for NodeValidator, Validator, yaml
45+
#include "maiken/app.hpp" // for Application
46+
#include "maiken/module.hpp" // for Module
47+
#include "maiken/module/init.hpp" // IWYU pragma: keep
48+
#include "maiken/project.hpp" // for Project
49+
#include "maiken/source.hpp" // for Source
50+
#include "yaml-cpp/node/impl.h" // for Node::operator[], Node::Scalar
51+
#include "yaml-cpp/node/node.h" // for Node
52+
53+
namespace mkn::mod::cpp::iwyu {
54+
55+
class Exception : public kul::Exception {
5656
public:
57-
Exception(char const* f, uint16_t const& l, std::string const& s)
58-
: mkn::kul::Exception(f, l, s) {}
57+
Exception(char const* f, uint16_t const& l, std::string const& s) : kul::Exception(f, l, s) {}
5958
};
60-
}
61-
62-
namespace mkn {
6359

64-
class CPP_IWYU_Module : public maiken::Module {
60+
class Module : public maiken::Module {
6561
public:
6662
void compile(maiken::Application& a, YAML::Node const& node) KTHROW(std::exception) override {
6763
run(a, node);
@@ -70,46 +66,48 @@ class CPP_IWYU_Module : public maiken::Module {
7066
protected:
7167
using App = maiken::Application&;
7268

73-
static std::string find_iwyu(){
69+
static std::string find_iwyu() {
7470
std::vector<std::string> iwyu{"iwyu", "include-what-you-use"};
75-
for(auto const& str : iwyu)
76-
if(mkn::kul::env::WHICH(str)) return str;
77-
KEXCEPT(mkn::mod::iwyu::Exception, "Failed to find valid iwyu binary, check PATH");
71+
for (auto const& str : iwyu)
72+
if (kul::env::WHICH(str)) return str;
73+
KEXCEPT(Exception, "Failed to find valid iwyu binary, check PATH");
7874
}
7975

8076
static void VALIDATE_NODE(YAML::Node const& node) {
81-
using namespace mkn::kul::yaml;
77+
using namespace kul::yaml;
8278
Validator({NodeValidator("inc"), NodeValidator("args"), NodeValidator("ignore"),
83-
NodeValidator("headers"),
84-
NodeValidator("paths"), NodeValidator("types")})
79+
NodeValidator("headers"), NodeValidator("paths"), NodeValidator("types")})
8580
.validate(node);
8681
}
8782

8883
template <typename C_Unit>
89-
void CHECK(std::string const& proc, C_Unit c_unit, mkn::kul::File&& f, YAML::Node const& node) {
90-
if (node["ignore"]) if(f.escm().find(node["ignore"].Scalar()) != std::string::npos) return;
84+
void CHECK(std::string const& proc, C_Unit c_unit, kul::File&& f, YAML::Node const& node) {
85+
if (node["ignore"])
86+
if (f.escm().find(node["ignore"].Scalar()) != std::string::npos) return;
9187

92-
mkn::kul::Process p(proc);
88+
kul::Process p(proc);
9389
auto compileStr = c_unit.compileString().substr(c_unit.compiler.size());
9490
p << compileStr.substr(0, compileStr.rfind(" -o"));
9591
if (node["args"]) p << node["args"].Scalar();
96-
if (node["inc"]) for (const auto& inc : node["inc"].Scalar()) p << std::string{"-I"}+inc;
92+
if (node["inc"])
93+
for (const auto& inc : node["inc"].Scalar()) p << std::string{"-I"} + inc;
9794
if (node["headers"]) p << node["headers"].Scalar();
9895
p << f.escm();
9996
KLOG(DBG) << p;
100-
try{
97+
try {
10198
p.start();
102-
}catch(mkn::kul::proc::ExitException const& e){}
99+
} catch (kul::proc::ExitException const& e) {
100+
}
103101
}
104102
void run(App& a, YAML::Node const& node) KTHROW(std::exception) {
105103
VALIDATE_NODE(node);
106-
mkn::kul::os::PushDir pushd(a.project().dir());
104+
kul::os::PushDir pushd(a.project().dir());
107105

108106
std::unordered_set<std::string> types;
109107
if (!node["types"]) {
110108
types = {"cpp", "cxx", "cc", "cc", "h", "hpp"};
111109
} else
112-
for (const auto& s : mkn::kul::String::SPLIT(node["types"].Scalar(), ":")) types.insert(s);
110+
for (const auto& s : kul::String::SPLIT(node["types"].Scalar(), ":")) types.insert(s);
113111

114112
std::unordered_set<std::string> files;
115113

@@ -119,10 +117,10 @@ class CPP_IWYU_Module : public maiken::Module {
119117
for (const auto& p2 : p1.second)
120118
for (const auto& p3 : p2.second) files.insert(p3.in());
121119

122-
if (node["paths"]){
123-
for (const auto& path : mkn::kul::cli::asArgs(node["paths"].Scalar())) {
124-
mkn::kul::Dir d(path);
125-
if (!d) KEXCEPT(mkn::kul::fs::Exception, "Directory does not exist: ") << d.path();
120+
if (node["paths"]) {
121+
for (const auto& path : kul::cli::asArgs(node["paths"].Scalar())) {
122+
kul::Dir d(path);
123+
if (!d) KEXCEPT(kul::fs::Exception, "Directory does not exist: ") << d.path();
126124
for (const auto& file : d.files(1)) {
127125
const std::string name = file.name();
128126
if (name.find(".") == std::string::npos) continue;
@@ -136,14 +134,15 @@ class CPP_IWYU_Module : public maiken::Module {
136134
maiken::ThreadingCompiler tc(a);
137135
using Pair = std::pair<maiken::Source, std::string>;
138136
for (const auto& file : files)
139-
CHECK(proc, tc.compilationUnit(Pair{mkn::kul::File(file).escm()+".cpp", "obj"}), mkn::kul::File(file), node);
137+
CHECK(proc, tc.compilationUnit(Pair{kul::File(file).escm() + ".cpp", "obj"}), kul::File(file),
138+
node);
140139
}
141140
};
142141

143-
} // namespace mkn
142+
} // namespace mkn::mod::cpp::iwyu
144143

145-
extern "C" KUL_PUBLISH maiken::Module *maiken_module_construct() {
146-
return new mkn::CPP_IWYU_Module;
144+
extern "C" KUL_PUBLISH maiken::Module* maiken_module_construct() {
145+
return new mkn::mod::cpp::iwyu::Module;
147146
}
148147

149-
extern "C" KUL_PUBLISH void maiken_module_destruct(maiken::Module *p) { delete p; }
148+
extern "C" KUL_PUBLISH void maiken_module_destruct(maiken::Module* p) { delete p; }

0 commit comments

Comments
 (0)