summaryrefslogtreecommitdiff
path: root/test/Tooling
diff options
context:
space:
mode:
authorSam McCall <sam.mccall@gmail.com>2017-11-09 10:37:39 +0000
committerSam McCall <sam.mccall@gmail.com>2017-11-09 10:37:39 +0000
commit9336389b0ff98ac05d2fe5781ae4bed492dc891e (patch)
treef3c1d06476e54b9e86c26ff0c3c0794542105d86 /test/Tooling
parentb0146f934b6fe813689ec0058323e52bc12dec23 (diff)
[Tooling] Use FixedCompilationDatabase when `compile_flags.txt` is found.
Summary: This is an alternative to JSONCompilationDatabase for simple projects that don't use a build system such as CMake. (You can also drop one in ~, to make your tools use e.g. C++11 by default) There's no facility for varying flags per-source-file or per-machine. Possibly this could be accommodated backwards-compatibly using cpp, but even if not the simplicity seems worthwhile for the cases that are addressed. Tested with clangd, works great! (requires clangd restart) Reviewers: klimek Subscribers: ilya-biryukov, cfe-commits Differential Revision: https://reviews.llvm.org/D39799 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@317777 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Tooling')
-rw-r--r--test/Tooling/Inputs/fixed-header.h1
-rw-r--r--test/Tooling/fixed-database.cpp18
2 files changed, 19 insertions, 0 deletions
diff --git a/test/Tooling/Inputs/fixed-header.h b/test/Tooling/Inputs/fixed-header.h
new file mode 100644
index 0000000000..4ce318f3a4
--- /dev/null
+++ b/test/Tooling/Inputs/fixed-header.h
@@ -0,0 +1 @@
+#define SECRET_SYMBOL 1
diff --git a/test/Tooling/fixed-database.cpp b/test/Tooling/fixed-database.cpp
new file mode 100644
index 0000000000..e0cdb1e51e
--- /dev/null
+++ b/test/Tooling/fixed-database.cpp
@@ -0,0 +1,18 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t/Src
+// RUN: cp "%s" "%t/Src/test.cpp"
+// RUN: mkdir -p %t/Include
+// RUN: cp "%S/Inputs/fixed-header.h" "%t/Include/"
+// -I flag is relative to %t (where compile_flags is), not Src/.
+// RUN: echo '-IInclude/' >> %t/compile_flags.txt
+// RUN: echo "-Dklazz=class" >> %t/compile_flags.txt
+// RUN: echo '-std=c++11' >> %t/compile_flags.txt
+// RUN: clang-check "%t/Src/test.cpp" 2>&1
+// RUN: not clang-check "%s" 2>&1 | FileCheck "%s" -check-prefix=NODB
+
+// NODB: unknown type name 'klazz'
+klazz F{};
+
+// NODB: 'fixed-header.h' file not found
+#include "fixed-header.h"
+static_assert(SECRET_SYMBOL == 1, "");