From 4c66fdf09d9186c6d6a03322947e3104e175c0d2 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 19 Dec 2020 21:42:21 -0800 Subject: [PATCH] Resolve "directory" in compile_commands.json in case CWD is not the project root Also delete an unneeded chdir hack. Close #703 --- src/project.cc | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/project.cc b/src/project.cc index e50190eb..c02bd6b6 100644 --- a/src/project.cc +++ b/src/project.cc @@ -425,14 +425,13 @@ void Project::loadDirectory(const std::string &root, Project::Folder &folder) { } else { LOG_S(INFO) << "loaded " << path.c_str(); for (tooling::CompileCommand &cmd : cdb->getAllCompileCommands()) { - static bool once; Project::Entry entry; entry.root = root; doPathMapping(entry.root); // If workspace folder is real/ but entries use symlink/, convert to // real/. - entry.directory = realPath(cmd.Directory); + entry.directory = realPath(resolveIfRelative(root, cmd.Directory)); entry.directory.push_back('/'); normalizeFolder(entry.directory); entry.directory.pop_back(); @@ -450,18 +449,7 @@ void Project::loadDirectory(const std::string &root, Project::Folder &folder) { entry.args.push_back(intern(args[i])); } entry.compdb_size = entry.args.size(); - - // 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.getSearchDirs(entry); - if (seen.insert(entry.filename).second) folder.entries.push_back(entry); }