aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbloodstalker <thabogre@gmail.com>2020-04-30 19:59:28 +0000
committerbloodstalker <thabogre@gmail.com>2020-04-30 19:59:28 +0000
commit0f0799aec14477d27a0cd145b7c5b0e283591b6f (patch)
tree87b276d6d22df27444feac2ad33bf6c3c03e41e9
parentremoved the boost dependency again (diff)
downloadcgrep-0f0799aec14477d27a0cd145b7c5b0e283591b6f.tar.gz
cgrep-0f0799aec14477d27a0cd145b7c5b0e283591b6f.zip
added a note regarding what to do when you get the `stddef.h not found`.
testscript is still WIP.
-rw-r--r--README.md4
-rw-r--r--cgrep.cpp22
-rw-r--r--compile_commands.json8
-rw-r--r--makefile13
-rwxr-xr-xtestscript/main.py10
5 files changed, 42 insertions, 15 deletions
diff --git a/README.md b/README.md
index e251032..51ff3ea 100644
--- a/README.md
+++ b/README.md
@@ -142,6 +142,10 @@ For an up-to-date list, you can run `cgrep --help` or look at the man page.
`cgrep` is a clang tool, so it will accept all valid clang command line options.
## Known Issues
+`cgrep` complains that it cannot find `stddef.h` or some other similar header. If that happens to you , it's because cgrep can't find the clang built-in headers. run `llvm-config --libdir`, then head on to `clang`. Inside that directory you should see one(or maybe more) llvm/clang versions. Pick the one you used to build cgrep against. Inside that directory there will be a directory named `include`. Pass that to cgrep any way you see fit.<br/>
+Alternatively, `$(llvm-config --libdir)/clang/$(llvm-config --version)/include` should give the path cgrep needs to include. If you build your llvm/clang from upstream, this might not work. SVN bulds will have the svn string attached to the version number.<br/>
+You could,for example, use `--extra-arg=-I/usr/lib/llvm-9/lib/clang/9.0.0/include` to call cgrep or you could just alias `cgrep` to `cgrep --extra-arg=-I/usr/lib/llvm-9/lib/clang/9.0.0/include`.<br/>
+
`cgrep`, replaces the clang diagnosticConsumer with a simple one that only tells you there are erros during the compilation. You can get the normal clang output using the `--clangdiag` switch. The decision was made to declutter the output generated by cgrep.
## License
diff --git a/cgrep.cpp b/cgrep.cpp
index 15ee524..c1142f8 100644
--- a/cgrep.cpp
+++ b/cgrep.cpp
@@ -7,7 +7,27 @@
* */
/***********************************************************************************************/
/*included modules*/
-#include "pch.hpp"
+#include "./cfe-extra/cfe_extra.h"
+#include "clang/AST/AST.h"
+#include "clang/AST/ASTConsumer.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Rewrite/Core/Rewriter.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/Support/raw_ostream.h"
+#include <cassert>
+#include <cstdlib>
+#include <dirent.h>
+#include <fstream>
+#include <iostream>
+#include <regex>
+#include <string>
+#include <vector>
/***********************************************************************************************/
/*used namespaces*/
using namespace llvm;
diff --git a/compile_commands.json b/compile_commands.json
index 86af499..598f647 100644
--- a/compile_commands.json
+++ b/compile_commands.json
@@ -1,12 +1,12 @@
[
{
- "command": "c++ -c -fpic -I/home/bloodstalker/extra/llvm-clang-4/llvm/include -I/home/bloodstalker/extra/llvm-clang-4/build/include -std=c++14 -fno-exceptions -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/bloodstalker/extra/llvm-clang-4/llvm/tools/clang/include -I/home/bloodstalker/extra/llvm-clang-4/build/tools/clang/include -std=c++17 -fexceptions -o cfe-extra/cfe_extra.o cfe-extra/cfe_extra.cpp",
+ "command": "c++ -c -fpic -I/home/bloodstalker/extra/llvm-clang-4/llvm/include -I/home/bloodstalker/extra/llvm-clang-4/build/include -std=c++14 -fno-exceptions -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/bloodstalker/extra/llvm-clang-4/llvm/tools/clang/include -I/home/bloodstalker/extra/llvm-clang-4/build/tools/clang/include -std=c++17 -fexceptions -o cgrep.o cgrep.cpp",
"directory": "/home/bloodstalker/extra/cgrep",
- "file": "/home/bloodstalker/extra/cgrep/cfe-extra/cfe_extra.cpp"
+ "file": "/home/bloodstalker/extra/cgrep/cgrep.cpp"
},
{
- "command": "c++ -c -include-pch pch.hpp.gch -fpic -I/home/bloodstalker/extra/llvm-clang-4/llvm/include -I/home/bloodstalker/extra/llvm-clang-4/build/include -std=c++14 -fno-exceptions -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/bloodstalker/extra/llvm-clang-4/llvm/tools/clang/include -I/home/bloodstalker/extra/llvm-clang-4/build/tools/clang/include -std=c++17 -fexceptions -o cgrep.o cgrep.cpp",
+ "command": "c++ -c -fpic -I/home/bloodstalker/extra/llvm-clang-4/llvm/include -I/home/bloodstalker/extra/llvm-clang-4/build/include -std=c++14 -fno-exceptions -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/bloodstalker/extra/llvm-clang-4/llvm/tools/clang/include -I/home/bloodstalker/extra/llvm-clang-4/build/tools/clang/include -std=c++17 -fexceptions -o cfe-extra/cfe_extra.o cfe-extra/cfe_extra.cpp",
"directory": "/home/bloodstalker/extra/cgrep",
- "file": "/home/bloodstalker/extra/cgrep/cgrep.cpp"
+ "file": "/home/bloodstalker/extra/cgrep/cfe-extra/cfe_extra.cpp"
}
] \ No newline at end of file
diff --git a/makefile b/makefile
index cff732a..1bbff7e 100644
--- a/makefile
+++ b/makefile
@@ -11,7 +11,7 @@ endif
CXX=clang++
CXX?=clang++
ifdef OS
- CXX_FLAGS=
+ CXX_FLAGS=-MM
else
CXX_FLAGS=-fpic
endif
@@ -84,7 +84,7 @@ LD_FLAGS+=$(EXTRA_LD_FLAGS)
.PHONY:all clean help ASM SO TAGS
-all: pch.hpp.gch $(TARGET)
+all: $(TARGET)
everything:$(TARGET) A ASM SO $(TARGET)-dbg TAGS $(TARGET)-cov
@@ -98,18 +98,15 @@ depend:.depend
-include ./.depend
-%.o:%.cpp pch.hpp.gch
- $(CXX) -include-pch pch.hpp.gch $(CXX_FLAGS) -c $< -o $@
+%.o:%.cpp
+ $(CXX) $(CXX_FLAGS) -c $< -o $@
%.odbg:%.cpp
$(CXX) $(CXX_FLAGS) -g -c $< -o $@
-%.ocov:%.cpp pch.hpp.gch
+%.ocov:%.cpp
$(CXX) $(CXX_FLAGS) $(COV_CXX) -c $< -o $@
-pch.hpp.gch: pch.hpp
- $(CXX) $(CXX_FLAGS) -c $< -o $@
-
./cfe-extra/cfe_extra.o:./cfe-extra/cfe_extra.cpp
$(CXX) $(CXX_FLAGS) -c $< -o $@
diff --git a/testscript/main.py b/testscript/main.py
index fddc3a3..1015b21 100755
--- a/testscript/main.py
+++ b/testscript/main.py
@@ -5,6 +5,7 @@ import argparse
import subprocess
import os
import sys
+import re
test_files = ["/home/bloodstalker/extra/cgrep/cgrep.cpp"]
@@ -60,14 +61,19 @@ def main():
argparser = Argparser()
cgrep_exe = "cgrep"
os.chdir("../")
- print(os.getcwd())
+ # get LLVM libdir
+ llvm_libdir = call_from_shell_list(["llvm-config", "--libdir"])
+ # get LLVM version. upstream builds can have extra unwanted text attached.
+ llvm_version = re.findall("[0-9]*\.[0-9]*\.[0-9]*", call_from_shell_list(["llvm-config", "--version"]).stdout.decode("utf-8"))
+ # buld the magic sause. we dont wanna get stddef.h not found.
+ clang_builtin_headers = "--extra-arg=-I" + llvm_libdir.stdout.decode("utf-8")[:-1] + "/clang/" + llvm_version[0] + "/include"
for cgrep_test_arg in cgrep_test_args:
arg_list = cgrep_test_arg.split()
arg_list.insert(0, cgrep_exe)
+ arg_list.append(clang_builtin_headers)
arg_list.append(test_files[0])
print(arg_list)
ret = call_from_shell_list(arg_list)
- #print("ret:", ret.returncode)
print("ret:", ret.stdout.decode("utf-8"), end="")
print("ret:", ret.stderr.decode("utf-8"), end="")