| 233 | ProjectManager *BrowserAction::projectManager = nullptr; |
| 234 | |
| 235 | static bool proceedCommand(std::vector<std::string> command, llvm::StringRef Directory, |
| 236 | llvm::StringRef file, clang::FileManager *FM, DatabaseType WasInDatabase) { |
| 237 | // This code change all the paths to be absolute paths |
| 238 | // FIXME: it is a bit fragile. |
| 239 | bool previousIsDashI = false; |
| 240 | bool previousNeedsMacro = false; |
| 241 | bool hasNoStdInc = false; |
| 242 | for(std::string &A : command) { |
| 243 | if (previousIsDashI && !A.empty() && A[0] != '/') { |
| 244 | A = Directory % "/" % A; |
| 245 | previousIsDashI = false; |
| 246 | continue; |
| 247 | } else if (A == "-I") { |
| 248 | previousIsDashI = true; |
| 249 | continue; |
| 250 | } else if (A == "-nostdinc") { |
| 251 | hasNoStdInc = true; |
| 252 | continue; |
| 253 | } else if (A == "-U" || A == "-D") { |
| 254 | previousNeedsMacro = true; |
| 255 | continue; |
| 256 | } |
| 257 | if (previousNeedsMacro) { |
| 258 | previousNeedsMacro = false; |
| 259 | continue; |
| 260 | } |
| 261 | previousIsDashI = false; |
| 262 | if (A.empty()) continue; |
| 263 | if (llvm::StringRef(A).startswith("-I") && A[2] != '/') { |
| 264 | A = "-I" % Directory % "/" % llvm::StringRef(A).substr(2); |
| 265 | continue; |
| 266 | } |
| 267 | if (A[0] == '-' || A[0] == '/') continue; |
| 268 | std::string PossiblePath = Directory % "/" % A; |
| 269 | if (llvm::sys::fs::exists(PossiblePath)) |
| 270 | A = PossiblePath; |
| 271 | } |
| 272 | |
| 273 | #if CLANG_VERSION_MAJOR == 3 && CLANG_VERSION_MINOR < 6 |
| 274 | auto Ajust = [&](clang::tooling::ArgumentsAdjuster &&aj) { command = aj.Adjust(command); }; |
| 275 | Ajust(clang::tooling::ClangSyntaxOnlyAdjuster()); |
| 276 | Ajust(clang::tooling::ClangStripOutputAdjuster()); |
| 277 | #elif CLANG_VERSION_MAJOR == 3 && CLANG_VERSION_MINOR < 8 |
| 278 | command = clang::tooling::getClangSyntaxOnlyAdjuster()(command); |
| 279 | command = clang::tooling::getClangStripOutputAdjuster()(command); |
| 280 | #else |
| 281 | command = clang::tooling::getClangSyntaxOnlyAdjuster()(command, file); |
| 282 | command = clang::tooling::getClangStripOutputAdjuster()(command, file); |
| 283 | #endif |
| 284 | if (!hasNoStdInc) { |
| 285 | command.push_back("-isystem"); |
| 286 | command.push_back("/builtins"); |
| 287 | } |
| 288 | command.push_back("-Qunused-arguments"); |
| 289 | command.push_back("-Wno-unknown-warning-option"); |
| 290 | clang::tooling::ToolInvocation Inv(command, new BrowserAction(WasInDatabase), FM); |
| 291 | |
| 292 | if (!hasNoStdInc) { |