aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Tooling/CompilationDatabase.cpp
diff options
context:
space:
mode:
authorHaojian Wu <hokein@google.com>2019-01-15 19:05:50 +0000
committerHaojian Wu <hokein@google.com>2019-01-15 19:05:50 +0000
commitd271d918f0d29a600219e2c3bf2e44f9e5736f84 (patch)
tree529f0c3dce88ca6fb7738da7ee82a1ad16c0e33d /clang/lib/Tooling/CompilationDatabase.cpp
parentdc375486b0e8573e3bb2916325673d1ee5114738 (diff)
downloadllvm-d271d918f0d29a600219e2c3bf2e44f9e5736f84.zip
llvm-d271d918f0d29a600219e2c3bf2e44f9e5736f84.tar.gz
llvm-d271d918f0d29a600219e2c3bf2e44f9e5736f84.tar.bz2
[Tooling] Make clang-tool find libc++ dir on mac when running on a file without compilation database.
Summary: This is a regression of r348365. When clang-tools run on a file without a complation database (`clang-check /tmp/t.cc`), we will use fixed compilation database as a fallback. However the actual compiler path in the fallback complation command is just `clang-tool` which is insufficient to detect the libc++ dir. Reviewers: ilya-biryukov, EricWF Reviewed By: ilya-biryukov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D56680 llvm-svn: 351222
Diffstat (limited to 'clang/lib/Tooling/CompilationDatabase.cpp')
-rw-r--r--clang/lib/Tooling/CompilationDatabase.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/clang/lib/Tooling/CompilationDatabase.cpp b/clang/lib/Tooling/CompilationDatabase.cpp
index 246d3c0..032250b 100644
--- a/clang/lib/Tooling/CompilationDatabase.cpp
+++ b/clang/lib/Tooling/CompilationDatabase.cpp
@@ -227,6 +227,16 @@ struct FilterUnusedFlags {
}
};
+std::string GetClangToolCommand() {
+ static int Dummy;
+ std::string ClangExecutable =
+ llvm::sys::fs::getMainExecutable("clang", (void *)&Dummy);
+ SmallString<128> ClangToolPath;
+ ClangToolPath = llvm::sys::path::parent_path(ClangExecutable);
+ llvm::sys::path::append(ClangToolPath, "clang-tool");
+ return ClangToolPath.str();
+}
+
} // namespace
/// Strips any positional args and possible argv[0] from a command-line
@@ -266,9 +276,9 @@ static bool stripPositionalArgs(std::vector<const char *> Args,
Diagnostics));
NewDriver->setCheckInputsExist(false);
- // This becomes the new argv[0]. The value is actually not important as it
- // isn't used for invoking Tools.
- Args.insert(Args.begin(), "clang-tool");
+ // This becomes the new argv[0]. The value is used to detect libc++ include
+ // dirs on Mac, it isn't used for other platforms.
+ Args.insert(Args.begin(), GetClangToolCommand().c_str());
// By adding -c, we force the driver to treat compilation as the last phase.
// It will then issue warnings via Diagnostics about un-used options that
@@ -366,7 +376,7 @@ FixedCompilationDatabase::loadFromFile(StringRef Path, std::string &ErrorMsg) {
FixedCompilationDatabase::
FixedCompilationDatabase(Twine Directory, ArrayRef<std::string> CommandLine) {
- std::vector<std::string> ToolCommandLine(1, "clang-tool");
+ std::vector<std::string> ToolCommandLine(1, GetClangToolCommand());
ToolCommandLine.insert(ToolCommandLine.end(),
CommandLine.begin(), CommandLine.end());
CompileCommands.emplace_back(Directory, StringRef(),