summaryrefslogtreecommitdiff
path: root/lib/Tooling/JSONCompilationDatabase.cpp
diff options
context:
space:
mode:
authorRussell Gallop <russell.gallop@gmail.com>2019-07-12 15:15:56 +0000
committerRussell Gallop <russell.gallop@gmail.com>2019-07-12 15:15:56 +0000
commitfb5e42106a4a6083b0a56b66082c6ee39c6f043b (patch)
treeddd41ffc483fdd6671fe6a383db9bb6ece64da5d /lib/Tooling/JSONCompilationDatabase.cpp
parente4b85c062d1086e9b5e55ce6eaf23031e3f2aad4 (diff)
downloadclang-fb5e42106a4a6083b0a56b66082c6ee39c6f043b.tar.gz
Revert "[JSONCompilationDatabase] Strip distcc/ccache/gomacc wrappers from parsed commands."
New test is failing on Windows bot This reverts commit 9c0391b36a76f8e3949588de3f44b7314c2318bf. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@365906 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Tooling/JSONCompilationDatabase.cpp')
-rw-r--r--lib/Tooling/JSONCompilationDatabase.cpp50
1 files changed, 4 insertions, 46 deletions
diff --git a/lib/Tooling/JSONCompilationDatabase.cpp b/lib/Tooling/JSONCompilationDatabase.cpp
index f19a0f7550..76a82b0fd9 100644
--- a/lib/Tooling/JSONCompilationDatabase.cpp
+++ b/lib/Tooling/JSONCompilationDatabase.cpp
@@ -256,57 +256,15 @@ JSONCompilationDatabase::getAllCompileCommands() const {
return Commands;
}
-static llvm::StringRef stripExecutableExtension(llvm::StringRef Name) {
- Name.consume_back(".exe");
- return Name;
-}
-
-// There are compiler-wrappers (ccache, distcc, gomacc) that take the "real"
-// compiler as an argument, e.g. distcc gcc -O3 foo.c.
-// These end up in compile_commands.json when people set CC="distcc gcc".
-// Clang's driver doesn't understand this, so we need to unwrap.
-static bool unwrapCommand(std::vector<std::string> &Args) {
- if (Args.size() < 2)
- return false;
- StringRef Wrapper =
- stripExecutableExtension(llvm::sys::path::filename(Args.front()));
- if (Wrapper == "distcc" || Wrapper == "gomacc" || Wrapper == "ccache") {
- // Most of these wrappers support being invoked 3 ways:
- // `distcc g++ file.c` This is the mode we're trying to match.
- // We need to drop `distcc`.
- // `distcc file.c` This acts like compiler is cc or similar.
- // Clang's driver can handle this, no change needed.
- // `g++ file.c` g++ is a symlink to distcc.
- // We don't even notice this case, and all is well.
- //
- // We need to distinguish between the first and second case.
- // The wrappers themselves don't take flags, so Args[1] is a compiler flag,
- // an input file, or a compiler. Inputs have extensions, compilers don't.
- bool HasCompiler =
- (Args[1][0] != '-') &&
- !llvm::sys::path::has_extension(stripExecutableExtension(Args[1]));
- if (HasCompiler) {
- Args.erase(Args.begin());
- return true;
- }
- // If !HasCompiler, wrappers act like GCC. Fine: so do we.
- }
- return false;
-}
-
static std::vector<std::string>
nodeToCommandLine(JSONCommandLineSyntax Syntax,
const std::vector<llvm::yaml::ScalarNode *> &Nodes) {
SmallString<1024> Storage;
- std::vector<std::string> Arguments;
if (Nodes.size() == 1)
- Arguments = unescapeCommandLine(Syntax, Nodes[0]->getValue(Storage));
- else
- for (const auto *Node : Nodes)
- Arguments.push_back(Node->getValue(Storage));
- // There may be multiple wrappers: using distcc and ccache together is common.
- while (unwrapCommand(Arguments))
- ;
+ return unescapeCommandLine(Syntax, Nodes[0]->getValue(Storage));
+ std::vector<std::string> Arguments;
+ for (const auto *Node : Nodes)
+ Arguments.push_back(Node->getValue(Storage));
return Arguments;
}