From c605dab16510471f028dd0cd8c83b470dd55cd46 Mon Sep 17 00:00:00 2001 From: Ole Christian Eidheim Date: Thu, 21 Apr 2016 12:11:48 +0200 Subject: [PATCH] Working directory for libclang set to default build path. Fixes relative include paths in compile_commands.json, see #177 --- src/project_build.cc | 6 ++++++ src/source_clang.cc | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/project_build.cc b/src/project_build.cc index a00729c..586aafd 100644 --- a/src/project_build.cc +++ b/src/project_build.cc @@ -10,6 +10,9 @@ std::unique_ptr Project::get_build(const boost::filesystem::path } boost::filesystem::path Project::Build::get_default_build_path() { + if(project_path.empty()) + return boost::filesystem::path(); + boost::filesystem::path default_build_path=Config::get().project.default_build_path; const std::string path_variable_project_directory_name=""; @@ -30,6 +33,9 @@ boost::filesystem::path Project::Build::get_default_build_path() { } boost::filesystem::path Project::Build::get_debug_build_path() { + if(project_path.empty()) + return boost::filesystem::path(); + boost::filesystem::path debug_build_path=Config::get().project.debug_build_path; const std::string path_variable_project_directory_name=""; diff --git a/src/source_clang.cc b/src/source_clang.cc index c45e879..325ebf2 100644 --- a/src/source_clang.cc +++ b/src/source_clang.cc @@ -178,8 +178,9 @@ void Source::ClangViewParse::soft_reparse() { std::vector Source::ClangViewParse::get_compilation_commands() { auto build=Project::get_build(file_path); + auto default_build_path=build->get_default_build_path(); build->update_default_build(); - clang::CompilationDatabase db(build->get_default_build_path().string()); + clang::CompilationDatabase db(default_build_path.string()); clang::CompileCommands commands(file_path.string(), db); std::vector cmds = commands.get_commands(); std::vector arguments; @@ -209,6 +210,11 @@ std::vector Source::ClangViewParse::get_compilation_commands() { if(file_path.extension()==".h") //TODO: temporary fix for .h-files (parse as c++) arguments.emplace_back("-xc++"); + if(!default_build_path.empty()) { + arguments.emplace_back("-working-directory"); + arguments.emplace_back(default_build_path.string()); + } + return arguments; }