Attempting to run clang-tidy with the clang-cl driver results in a number of warnings and errors that make the tool unusable. The two main issues, and the solutions implemented here are:
- Command lines are tokenized differently on Windows and non-windows platforms. Using standard tokenization on Windows leads to -- among other things -- all path separators being stripped from paths. Obviously this won't work, so the fix implemented here is to use the correct windows command line tokenizer when clang-tidy is running on Windows.
- The underlying clang driver does not attempt to auto-detect driver mode (CL, GCC, etc) from the program name. It relies only on the existence of a --driver-mode=<mode> option. We already have a function to detect the driver mode based on the program name, so the solution implemented here is to use the program name as a default, which will be overridden by the existence of a --driver-mode option.
With this patch, clang-tidy runs with clang-cl.
D:\src\llvm\tools\lldb>d:\src\llvmbuild\ninja\bin\clang-tidy.exe source\lldb.cpp 1448 warnings generated. warning: argument unused during compilation: '-mincremental-linker-compatible' [clang-diagnostic-unused-command-line-argument] warning: unknown argument ignored in clang-cl: '-resource-dir=d:\src\llvmbuild\ninja\bin\..\lib\clang\4.0.0' [clang-diagnostic-unk nown-argument] D:\src\llvm\tools\lldb\source\lldb.cpp:71:24: warning: invalid case style for variable 'g_version_str' [readability-identifier-nam ing] static std::string g_version_str; ^ D:\src\llvm\tools\lldb\source\lldb.cpp:76:22: warning: invalid case style for variable 'lldb_repo' [readability-identifier-naming] const char * lldb_repo = GetLLDBRepository(); ^ D:\src\llvm\tools\lldb\source\lldb.cpp:83:21: warning: invalid case style for variable 'lldb_rev' [readability-identifier-naming] const char *lldb_rev = GetLLDBRevision(); ^ D:\src\llvm\tools\lldb\source\lldb.cpp:89:21: warning: invalid case style for variable 'clang_rev' [readability-identifier-naming] std::string clang_rev (clang::getClangRevision()); ^ D:\src\llvm\tools\lldb\source\lldb.cpp:95:21: warning: invalid case style for variable 'llvm_rev' [readability-identifier-naming] std::string llvm_rev (clang::getLLVMRevision()); ^ Suppressed 1441 warnings (1441 in non-user code). Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Why not change ToolInvocation::run() to behave more like clang's main? I'd rather not do this twice, mostly for consistency with the regular driver, not because it's inefficient.