Adds support for auto-detection of compilation databases
from a source file and changes clang-check to make use of this.

This makes clang-check just work on in-tree builds, and allows
easy setup via a symlink per source directory to make clang-check
work without any extra configuration.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159990 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/Tooling/auto-detect-from-source-parent-of-cwd.cpp b/test/Tooling/auto-detect-from-source-parent-of-cwd.cpp
new file mode 100644
index 0000000..7a4f9af
--- /dev/null
+++ b/test/Tooling/auto-detect-from-source-parent-of-cwd.cpp
@@ -0,0 +1,8 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t/abc/def/ijk/qwe
+// RUN: echo "[{\"directory\":\".\",\"command\":\"clang++ -c %t/abc/def/ijk/qwe/test.cpp\",\"file\":\"%t/abc/def/ijk/qwe/test.cpp\"}]" | sed -e 's/\\/\\\\/g' > %t/compile_commands.json
+// RUN: cp "%s" "%t/abc/def/ijk/qwe/test.cpp"
+// RUN: PWD="%t/abc/def" clang-check "ijk/qwe/test.cpp" 2>&1 | FileCheck %s
+
+// CHECK: C++ requires
+invalid;
diff --git a/test/Tooling/auto-detect-from-source-parent.cpp b/test/Tooling/auto-detect-from-source-parent.cpp
new file mode 100644
index 0000000..cb5fd56
--- /dev/null
+++ b/test/Tooling/auto-detect-from-source-parent.cpp
@@ -0,0 +1,8 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t/abc/def/ijk/qwe
+// RUN: echo "[{\"directory\":\".\",\"command\":\"clang++ -c %t/abc/def/ijk/qwe/test.cpp\",\"file\":\"%t/abc/def/ijk/qwe/test.cpp\"}]" | sed -e 's/\\/\\\\/g' > %t/compile_commands.json
+// RUN: cp "%s" "%t/abc/def/ijk/qwe/test.cpp"
+// RUN: clang-check "%t/abc/def/ijk/qwe/test.cpp" 2>&1 | FileCheck %s
+
+// CHECK: C++ requires
+invalid;
diff --git a/test/Tooling/auto-detect-from-source.cpp b/test/Tooling/auto-detect-from-source.cpp
new file mode 100644
index 0000000..40a2a1c
--- /dev/null
+++ b/test/Tooling/auto-detect-from-source.cpp
@@ -0,0 +1,8 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "[{\"directory\":\".\",\"command\":\"clang++ -c %t/test.cpp\",\"file\":\"%t/test.cpp\"}]" | sed -e 's/\\/\\\\/g' > %t/compile_commands.json
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-check "%t/test.cpp" 2>&1 | FileCheck %s
+
+// CHECK: C++ requires
+invalid;
diff --git a/test/Tooling/clang-check-args.cpp b/test/Tooling/clang-check-args.cpp
index ab1585f..9ba5d45 100644
--- a/test/Tooling/clang-check-args.cpp
+++ b/test/Tooling/clang-check-args.cpp
@@ -1,4 +1,4 @@
-// RUN: clang-check . "%s" -- -c 2>&1 | FileCheck %s
+// RUN: clang-check "%s" -- -c 2>&1 | FileCheck %s
 
 // CHECK: C++ requires
 invalid;
diff --git a/test/Tooling/clang-check-builtin-headers.cpp b/test/Tooling/clang-check-builtin-headers.cpp
index fda68cc..504d197 100644
--- a/test/Tooling/clang-check-builtin-headers.cpp
+++ b/test/Tooling/clang-check-builtin-headers.cpp
@@ -3,7 +3,7 @@
 // Add a path that doesn't exist as argv[0] for the compile command line:
 // RUN: echo '[{"directory":".","command":"/random/tool -c %t/test.cpp","file":"%t/test.cpp"}]' | sed -e 's/\\/\//g' > %t/compile_commands.json
 // RUN: cp "%s" "%t/test.cpp"
-// RUN: clang-check "%t" "%t/test.cpp" 2>&1|FileCheck %s
+// RUN: clang-check -p "%t" "%t/test.cpp" 2>&1|FileCheck %s
 // FIXME: Make the above easier.
 
 #include <stddef.h>
diff --git a/test/Tooling/clang-check-chdir.cpp b/test/Tooling/clang-check-chdir.cpp
index d9f1728..29b5abb 100644
--- a/test/Tooling/clang-check-chdir.cpp
+++ b/test/Tooling/clang-check-chdir.cpp
@@ -5,7 +5,7 @@
 // RUN: echo "[{\"directory\":\"%t\",\"command\":\"clang -c test.cpp -I.\",\"file\":\"%t/test.cpp\"}]" | sed -e 's/\\/\//g' > %t/compile_commands.json
 // RUN: cp "%s" "%t/test.cpp"
 // RUN: touch "%t/clang-check-test.h"
-// RUN: clang-check "%t" "%t/test.cpp" 2>&1|FileCheck %s
+// RUN: clang-check -p "%t" "%t/test.cpp" 2>&1|FileCheck %s
 // FIXME: Make the above easier.
 
 #include "clang-check-test.h"
diff --git a/test/Tooling/clang-check-pwd.cpp b/test/Tooling/clang-check-pwd.cpp
index 8dd9e6e..374c579 100644
--- a/test/Tooling/clang-check-pwd.cpp
+++ b/test/Tooling/clang-check-pwd.cpp
@@ -2,7 +2,7 @@
 // RUN: mkdir %t
 // RUN: echo "[{\"directory\":\".\",\"command\":\"clang++ -c %t/test.cpp\",\"file\":\"%t/test.cpp\"}]" | sed -e 's/\\/\\\\/g' > %t/compile_commands.json
 // RUN: cp "%s" "%t/test.cpp"
-// RUN: PWD="%t" clang-check "%t" "test.cpp" 2>&1|FileCheck %s
+// RUN: PWD="%t" clang-check -p "%t" "test.cpp" 2>&1|FileCheck %s
 // FIXME: Make the above easier.
 
 // CHECK: C++ requires
diff --git a/test/Tooling/clang-check.cpp b/test/Tooling/clang-check.cpp
index ff90b88..91ab01b 100644
--- a/test/Tooling/clang-check.cpp
+++ b/test/Tooling/clang-check.cpp
@@ -2,7 +2,7 @@
 // RUN: mkdir %t
 // RUN: echo '[{"directory":".","command":"clang++ -c %t/test.cpp","file":"%t/test.cpp"}]' | sed -e 's/\\/\//g' > %t/compile_commands.json
 // RUN: cp "%s" "%t/test.cpp"
-// RUN: clang-check "%t" "%t/test.cpp" 2>&1|FileCheck %s
+// RUN: clang-check -p "%t" "%t/test.cpp" 2>&1|FileCheck %s
 // FIXME: Make the above easier.
 
 // CHECK: C++ requires
diff --git a/test/Tooling/multi-jobs.cpp b/test/Tooling/multi-jobs.cpp
index 1de5634..a3eb703 100644
--- a/test/Tooling/multi-jobs.cpp
+++ b/test/Tooling/multi-jobs.cpp
@@ -1,4 +1,4 @@
-// RUN: clang-check . "%s" -- -no-integrated-as -c 2>&1 | FileCheck %s
+// RUN: clang-check "%s" -- -no-integrated-as -c 2>&1 | FileCheck %s
 
 // CHECK: C++ requires
 invalid;