From 3e39b8698193f72593689235c0358af0c58bf76a Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Thu, 8 Nov 2018 11:32:27 -0800 Subject: [PATCH] Work around relative --sysroot= --- src/messages/initialize.cc | 4 +++- src/project.cc | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/messages/initialize.cc b/src/messages/initialize.cc index 14e4b7f4..bd772773 100644 --- a/src/messages/initialize.cc +++ b/src/messages/initialize.cc @@ -257,7 +257,9 @@ void Initialize(MessageHandler *m, InitializeParam ¶m, ReplyOnce &reply) { LOG_S(INFO) << "initializationOptions: " << output.GetString(); if (g_config->cacheDirectory.size()) { - g_config->cacheDirectory = NormalizePath(g_config->cacheDirectory); + SmallString<256> Path(g_config->cacheDirectory); + sys::fs::make_absolute(Path); + g_config->cacheDirectory = Path.str(); EnsureEndsInSlash(g_config->cacheDirectory); } } diff --git a/src/project.cc b/src/project.cc index d431d6ce..f21d4e2b 100644 --- a/src/project.cc +++ b/src/project.cc @@ -3,6 +3,7 @@ #include "project.hh" +#include "clang_tu.hh" // llvm::vfs #include "filesystem.hh" #include "log.hh" #include "match.hh" @@ -316,6 +317,7 @@ LoadEntriesFromDirectory(ProjectConfig *project, std::vector result; ProjectProcessor proc(project); for (tooling::CompileCommand &Cmd : CDB->getAllCompileCommands()) { + static bool once; Project::Entry entry; entry.root = project->root; DoPathMapping(entry.root); @@ -330,7 +332,18 @@ LoadEntriesFromDirectory(ProjectConfig *project, DoPathMapping(arg); entry.args.push_back(Intern(arg)); } + + // Work around relative --sysroot= as it isn't affected by + // -working-directory=. chdir is thread hostile but this function runs + // before indexers do actual work and it works when there is only one + // workspace folder. + if (!once) { + once = true; + llvm::vfs::getRealFileSystem()->setCurrentWorkingDirectory( + entry.directory); + } proc.Process(entry); + if (Seen.insert(entry.filename).second) result.push_back(entry); }