r351282 - Revert "[Tooling] Make clang-tool find libc++ dir on mac when running on a file without compilation database."
Vlad Tsyrklevich via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 15 16:37:39 PST 2019
Author: vlad.tsyrklevich
Date: Tue Jan 15 16:37:39 2019
New Revision: 351282
URL: http://llvm.org/viewvc/llvm-project?rev=351282&view=rev
Log:
Revert "[Tooling] Make clang-tool find libc++ dir on mac when running on a file without compilation database."
This reverts commits r351222 and r351229, they were causing ASan/MSan failures
on the sanitizer bots.
Removed:
cfe/trunk/test/Tooling/clang-check-mac-libcxx-fixed-compilation-db.cpp
Modified:
cfe/trunk/lib/Tooling/CompilationDatabase.cpp
cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp
Modified: cfe/trunk/lib/Tooling/CompilationDatabase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/CompilationDatabase.cpp?rev=351282&r1=351281&r2=351282&view=diff
==============================================================================
--- cfe/trunk/lib/Tooling/CompilationDatabase.cpp (original)
+++ cfe/trunk/lib/Tooling/CompilationDatabase.cpp Tue Jan 15 16:37:39 2019
@@ -227,16 +227,6 @@ 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
@@ -276,9 +266,9 @@ static bool stripPositionalArgs(std::vec
Diagnostics));
NewDriver->setCheckInputsExist(false);
- // 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());
+ // 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");
// 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
@@ -376,7 +366,7 @@ FixedCompilationDatabase::loadFromFile(S
FixedCompilationDatabase::
FixedCompilationDatabase(Twine Directory, ArrayRef<std::string> CommandLine) {
- std::vector<std::string> ToolCommandLine(1, GetClangToolCommand());
+ std::vector<std::string> ToolCommandLine(1, "clang-tool");
ToolCommandLine.insert(ToolCommandLine.end(),
CommandLine.begin(), CommandLine.end());
CompileCommands.emplace_back(Directory, StringRef(),
Removed: cfe/trunk/test/Tooling/clang-check-mac-libcxx-fixed-compilation-db.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Tooling/clang-check-mac-libcxx-fixed-compilation-db.cpp?rev=351281&view=auto
==============================================================================
--- cfe/trunk/test/Tooling/clang-check-mac-libcxx-fixed-compilation-db.cpp (original)
+++ cfe/trunk/test/Tooling/clang-check-mac-libcxx-fixed-compilation-db.cpp (removed)
@@ -1,16 +0,0 @@
-// Clang on MacOS can find libc++ living beside the installed compiler.
-// This test makes sure our libTooling-based tools emulate this properly with
-// fixed compilation database.
-//
-// RUN: rm -rf %t
-// RUN: mkdir %t
-//
-// Install the mock libc++ (simulates the libc++ directory structure).
-// RUN: cp -r %S/Inputs/mock-libcxx %t/
-//
-// RUN: cp clang-check %t/mock-libcxx/bin/
-// RUN: cp "%s" "%t/test.cpp"
-// RUN: %t/mock-libcxx/bin/clang-check -p "%t" "%t/test.cpp" -- -stdlib=libc++
-
-#include <mock_vector>
-vector v;
Modified: cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp?rev=351282&r1=351281&r2=351282&view=diff
==============================================================================
--- cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp Tue Jan 15 16:37:39 2019
@@ -14,15 +14,11 @@
#include "clang/Tooling/JSONCompilationDatabase.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/Support/Path.h"
-#include "gmock/gmock.h"
#include "gtest/gtest.h"
namespace clang {
namespace tooling {
-using testing::ElementsAre;
-using testing::EndsWith;
-
static void expectFailure(StringRef JSONDatabase, StringRef Explanation) {
std::string ErrorMessage;
EXPECT_EQ(nullptr,
@@ -471,15 +467,21 @@ TEST(unescapeJsonCommandLine, ParsesSing
}
TEST(FixedCompilationDatabase, ReturnsFixedCommandLine) {
- FixedCompilationDatabase Database(".", /*CommandLine*/ {"one", "two"});
+ std::vector<std::string> CommandLine;
+ CommandLine.push_back("one");
+ CommandLine.push_back("two");
+ FixedCompilationDatabase Database(".", CommandLine);
StringRef FileName("source");
std::vector<CompileCommand> Result =
Database.getCompileCommands(FileName);
ASSERT_EQ(1ul, Result.size());
+ std::vector<std::string> ExpectedCommandLine(1, "clang-tool");
+ ExpectedCommandLine.insert(ExpectedCommandLine.end(),
+ CommandLine.begin(), CommandLine.end());
+ ExpectedCommandLine.push_back("source");
EXPECT_EQ(".", Result[0].Directory);
EXPECT_EQ(FileName, Result[0].Filename);
- EXPECT_THAT(Result[0].CommandLine,
- ElementsAre(EndsWith("clang-tool"), "one", "two", "source"));
+ EXPECT_EQ(ExpectedCommandLine, Result[0].CommandLine);
}
TEST(FixedCompilationDatabase, GetAllFiles) {
@@ -535,8 +537,12 @@ TEST(ParseFixedCompilationDatabase, Retu
Database->getCompileCommands("source");
ASSERT_EQ(1ul, Result.size());
ASSERT_EQ(".", Result[0].Directory);
- ASSERT_THAT(Result[0].CommandLine, ElementsAre(EndsWith("clang-tool"),
- "-DDEF3", "-DDEF4", "source"));
+ std::vector<std::string> CommandLine;
+ CommandLine.push_back("clang-tool");
+ CommandLine.push_back("-DDEF3");
+ CommandLine.push_back("-DDEF4");
+ CommandLine.push_back("source");
+ ASSERT_EQ(CommandLine, Result[0].CommandLine);
EXPECT_EQ(2, Argc);
}
@@ -552,8 +558,10 @@ TEST(ParseFixedCompilationDatabase, Retu
Database->getCompileCommands("source");
ASSERT_EQ(1ul, Result.size());
ASSERT_EQ(".", Result[0].Directory);
- ASSERT_THAT(Result[0].CommandLine,
- ElementsAre(EndsWith("clang-tool"), "source"));
+ std::vector<std::string> CommandLine;
+ CommandLine.push_back("clang-tool");
+ CommandLine.push_back("source");
+ ASSERT_EQ(CommandLine, Result[0].CommandLine);
EXPECT_EQ(2, Argc);
}
@@ -569,8 +577,12 @@ TEST(ParseFixedCompilationDatabase, Hand
Database->getCompileCommands("source");
ASSERT_EQ(1ul, Result.size());
ASSERT_EQ(".", Result[0].Directory);
- ASSERT_THAT(Result[0].CommandLine,
- ElementsAre(EndsWith("clang-tool"), "-c", "-DDEF3", "source"));
+ std::vector<std::string> Expected;
+ Expected.push_back("clang-tool");
+ Expected.push_back("-c");
+ Expected.push_back("-DDEF3");
+ Expected.push_back("source");
+ ASSERT_EQ(Expected, Result[0].CommandLine);
EXPECT_EQ(2, Argc);
}
@@ -587,9 +599,12 @@ TEST(ParseFixedCompilationDatabase, Hand
std::vector<CompileCommand> Result = Database->getCompileCommands("source");
ASSERT_EQ(1ul, Result.size());
ASSERT_EQ(".", Result[0].Directory);
- ASSERT_THAT(
- Result[0].CommandLine,
- ElementsAre(EndsWith("clang-tool"), "-fsyntax-only", "-DDEF3", "source"));
+ std::vector<std::string> Expected;
+ Expected.push_back("clang-tool");
+ Expected.push_back("-fsyntax-only");
+ Expected.push_back("-DDEF3");
+ Expected.push_back("source");
+ ASSERT_EQ(Expected, Result[0].CommandLine);
}
TEST(ParseFixedCompilationDatabase, HandlesArgv0) {
@@ -605,8 +620,9 @@ TEST(ParseFixedCompilationDatabase, Hand
ASSERT_EQ(1ul, Result.size());
ASSERT_EQ(".", Result[0].Directory);
std::vector<std::string> Expected;
- ASSERT_THAT(Result[0].CommandLine,
- ElementsAre(EndsWith("clang-tool"), "source"));
+ Expected.push_back("clang-tool");
+ Expected.push_back("source");
+ ASSERT_EQ(Expected, Result[0].CommandLine);
EXPECT_EQ(2, Argc);
}
More information about the cfe-commits
mailing list