diff options
author | Zachary Turner <zturner@google.com> | 2016-08-17 20:04:35 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2016-08-17 20:04:35 +0000 |
commit | a0d032eacf3c40bdfef53b6d160dc895fa5df131 (patch) | |
tree | 8991148db8c0e1b96af16659440d08d19aefb60e /clang/lib/Tooling/JSONCompilationDatabase.cpp | |
parent | 2931d171428d56cd4d3b7139bc2e677ea42de680 (diff) | |
download | llvm-a0d032eacf3c40bdfef53b6d160dc895fa5df131.zip llvm-a0d032eacf3c40bdfef53b6d160dc895fa5df131.tar.gz llvm-a0d032eacf3c40bdfef53b6d160dc895fa5df131.tar.bz2 |
[Tooling] Parse compilation database command lines on Windows.
When a compilation database is used on Windows, the command lines cannot
be parsed using the standard GNU style syntax. LLVM provides functions for
parsing Windows style command lines, so use them where appropriate.
After this patch, clang-tidy runs correctly on Windows.
Reviewed by: alexfh
Differential Revision: https://reviews.llvm.org/D23455
llvm-svn: 278964
Diffstat (limited to 'clang/lib/Tooling/JSONCompilationDatabase.cpp')
-rw-r--r-- | clang/lib/Tooling/JSONCompilationDatabase.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/clang/lib/Tooling/JSONCompilationDatabase.cpp b/clang/lib/Tooling/JSONCompilationDatabase.cpp index 299fbdc..5f192f7 100644 --- a/clang/lib/Tooling/JSONCompilationDatabase.cpp +++ b/clang/lib/Tooling/JSONCompilationDatabase.cpp @@ -16,7 +16,10 @@ #include "clang/Tooling/CompilationDatabasePluginRegistry.h" #include "clang/Tooling/Tooling.h" #include "llvm/ADT/SmallString.h" +#include "llvm/Support/Allocator.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/Path.h" +#include "llvm/Support/StringSaver.h" #include <system_error> namespace clang { @@ -113,6 +116,21 @@ class CommandLineArgumentParser { std::vector<std::string> unescapeCommandLine( StringRef EscapedCommandLine) { + llvm::Triple Triple(llvm::sys::getProcessTriple()); + if (Triple.getOS() == llvm::Triple::OSType::Win32) { + // Assume Windows command line parsing on Win32 unless the triple explicitly + // tells us otherwise. + if (!Triple.hasEnvironment() || + Triple.getEnvironment() == llvm::Triple::EnvironmentType::MSVC) { + llvm::BumpPtrAllocator Alloc; + llvm::StringSaver Saver(Alloc); + llvm::SmallVector<const char *, 64> T; + llvm::cl::TokenizeWindowsCommandLine(EscapedCommandLine, Saver, T); + std::vector<std::string> Result(T.begin(), T.end()); + return Result; + } + } + CommandLineArgumentParser parser(EscapedCommandLine); return parser.parse(); } |