[clang-tools-extra] r350515 - [clangd] Fix a regression issue caused by r348365.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 7 04:35:02 PST 2019
Author: hokein
Date: Mon Jan 7 04:35:02 2019
New Revision: 350515
URL: http://llvm.org/viewvc/llvm-project?rev=350515&view=rev
Log:
[clangd] Fix a regression issue caused by r348365.
Summary:
With r348365, we now detect libc++ dir using the actual compiler path
(from the compilation command), rather than the resource-dir.
This new behavior will cause clangd couldn't find libc++ dir (even the libc++ is
built from the source) when using a fallback compilation command (`clang xxx`)
The fix is to use `<clangd_install_dir>/clang` as the actual compiler path.
Reviewers: ilya-biryukov
Reviewed By: ilya-biryukov
Subscribers: ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D56380
Modified:
clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp
clang-tools-extra/trunk/unittests/clangd/GlobalCompilationDatabaseTests.cpp
Modified: clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp?rev=350515&r1=350514&r2=350515&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp (original)
+++ clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp Mon Jan 7 04:35:02 2019
@@ -17,9 +17,19 @@ using namespace llvm;
namespace clang {
namespace clangd {
+static std::string getFallbackClangPath() {
+ static int Dummy;
+ std::string ClangdExecutable =
+ llvm::sys::fs::getMainExecutable("clangd", (void *)&Dummy);
+ SmallString<128> ClangPath;
+ ClangPath = llvm::sys::path::parent_path(ClangdExecutable);
+ llvm::sys::path::append(ClangPath, "clang");
+ return ClangPath.str();
+}
+
tooling::CompileCommand
GlobalCompilationDatabase::getFallbackCommand(PathRef File) const {
- std::vector<std::string> Argv = {"clang"};
+ std::vector<std::string> Argv = {getFallbackClangPath()};
// Clang treats .h files as C by default, resulting in unhelpful diagnostics.
// Parsing as Objective C++ is friendly to more cases.
if (sys::path::extension(File) == ".h")
Modified: clang-tools-extra/trunk/unittests/clangd/GlobalCompilationDatabaseTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/GlobalCompilationDatabaseTests.cpp?rev=350515&r1=350514&r2=350515&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clangd/GlobalCompilationDatabaseTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/GlobalCompilationDatabaseTests.cpp Mon Jan 7 04:35:02 2019
@@ -19,18 +19,21 @@ namespace clang {
namespace clangd {
namespace {
using ::testing::ElementsAre;
+using ::testing::EndsWith;
TEST(GlobalCompilationDatabaseTest, FallbackCommand) {
DirectoryBasedGlobalCompilationDatabase DB(None);
auto Cmd = DB.getFallbackCommand(testPath("foo/bar.cc"));
EXPECT_EQ(Cmd.Directory, testPath("foo"));
- EXPECT_THAT(Cmd.CommandLine, ElementsAre("clang", testPath("foo/bar.cc")));
+ EXPECT_THAT(Cmd.CommandLine, ElementsAre(
+ EndsWith("clang"), testPath("foo/bar.cc")));
EXPECT_EQ(Cmd.Output, "");
// .h files have unknown language, so they are parsed liberally as obj-c++.
Cmd = DB.getFallbackCommand(testPath("foo/bar.h"));
- EXPECT_THAT(Cmd.CommandLine, ElementsAre("clang", "-xobjective-c++-header",
- testPath("foo/bar.h")));
+ EXPECT_THAT(Cmd.CommandLine,
+ ElementsAre(EndsWith("clang"), "-xobjective-c++-header",
+ testPath("foo/bar.h")));
}
static tooling::CompileCommand cmd(StringRef File, StringRef Arg) {
@@ -88,7 +91,7 @@ TEST_F(OverlayCDBTest, NoBase) {
EXPECT_EQ(CDB.getCompileCommand(testPath("bar.cc")), Override);
EXPECT_THAT(CDB.getFallbackCommand(testPath("foo.cc")).CommandLine,
- ElementsAre("clang", testPath("foo.cc"), "-DA=6"));
+ ElementsAre(EndsWith("clang"), testPath("foo.cc"), "-DA=6"));
}
TEST_F(OverlayCDBTest, Watch) {
More information about the cfe-commits
mailing list