Skip to content

Commit

Permalink
Resolve "directory" in compile_commands.json in case CWD is not the p…
Browse files Browse the repository at this point in the history
…roject root

Also delete an unneeded chdir hack.

Close #703
  • Loading branch information
MaskRay committed Dec 20, 2020
1 parent feb153a commit 4c66fdf
Showing 1 changed file with 1 addition and 13 deletions.
14 changes: 1 addition & 13 deletions src/project.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
Expand Down

0 comments on commit 4c66fdf

Please sign in to comment.