r278964 - [Tooling] Parse compilation database command lines on Windows.
Zachary Turner via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 17 13:04:36 PDT 2016
Author: zturner
Date: Wed Aug 17 15:04:35 2016
New Revision: 278964
URL: http://llvm.org/viewvc/llvm-project?rev=278964&view=rev
Log:
[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
Modified:
cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp
Modified: cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp?rev=278964&r1=278963&r2=278964&view=diff
==============================================================================
--- cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp (original)
+++ cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp Wed Aug 17 15:04:35 2016
@@ -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();
}
More information about the cfe-commits
mailing list