Skip to content

Commit 4c66fdf

Browse files
committed
Resolve "directory" in compile_commands.json in case CWD is not the project root
Also delete an unneeded chdir hack. Close #703
1 parent feb153a commit 4c66fdf

File tree

1 file changed

+1
-13
lines changed

1 file changed

+1
-13
lines changed

src/project.cc

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -425,14 +425,13 @@ void Project::loadDirectory(const std::string &root, Project::Folder &folder) {
425425
} else {
426426
LOG_S(INFO) << "loaded " << path.c_str();
427427
for (tooling::CompileCommand &cmd : cdb->getAllCompileCommands()) {
428-
static bool once;
429428
Project::Entry entry;
430429
entry.root = root;
431430
doPathMapping(entry.root);
432431

433432
// If workspace folder is real/ but entries use symlink/, convert to
434433
// real/.
435-
entry.directory = realPath(cmd.Directory);
434+
entry.directory = realPath(resolveIfRelative(root, cmd.Directory));
436435
entry.directory.push_back('/');
437436
normalizeFolder(entry.directory);
438437
entry.directory.pop_back();
@@ -450,18 +449,7 @@ void Project::loadDirectory(const std::string &root, Project::Folder &folder) {
450449
entry.args.push_back(intern(args[i]));
451450
}
452451
entry.compdb_size = entry.args.size();
453-
454-
// Work around relative --sysroot= as it isn't affected by
455-
// -working-directory=. chdir is thread hostile but this function runs
456-
// before indexers do actual work and it works when there is only one
457-
// workspace folder.
458-
if (!once) {
459-
once = true;
460-
llvm::vfs::getRealFileSystem()->setCurrentWorkingDirectory(
461-
entry.directory);
462-
}
463452
proc.getSearchDirs(entry);
464-
465453
if (seen.insert(entry.filename).second)
466454
folder.entries.push_back(entry);
467455
}

0 commit comments

Comments
 (0)