Fix handling of compile_commands.json files with relative include paths (Fixes #189)

This commit is contained in:
Bartek Kryza
2023-10-12 17:08:25 +02:00
parent 8865a42ff0
commit 26abb71b4c
2 changed files with 7 additions and 0 deletions

View File

@@ -80,6 +80,7 @@ Nowadays, this file can be generated rather easily using multiple methods:
* For Boost-based projects
try [commands_to_compilation_database](https://github.com/tee3/commands_to_compilation_database)
* For SCons, invoke `compilation_db` tool (requires SCons > 4.0.0)
* For Bazel, try [bazel-compile-commands-extractor](https://github.com/hedronvision/bazel-compile-commands-extractor)
* For Microsoft Visual Studio projects try [Clang Power Tools](https://www.clangpowertools.com)
### Invocation

View File

@@ -123,6 +123,12 @@ void translation_unit_visitor::set_source_location(
}
}
if (std::filesystem::path file_path{file}; !file_path.is_absolute()) {
file_path =
std::filesystem::canonical(std::filesystem::absolute(file_path));
file = file_path.string();
}
element.set_file(file);
element.set_file_relative(util::path_to_url(
std::filesystem::relative(element.file(), relative_to_path_).string()));