Browse Source

Cleanup of clang resource directory lookup

merge-requests/413/merge
eidheim 2 years ago
parent
commit
91425d9c74
  1. 11
      src/compile_commands.cpp

11
src/compile_commands.cpp

@ -83,7 +83,8 @@ std::vector<std::string> CompileCommands::get_arguments(const boost::filesystem:
}
}
static auto find_resource_path = [](const boost::filesystem::path &base_path, std::string version) -> std::string {
static std::string resource_path = []() -> std::string {
auto find_resource_path = [](const boost::filesystem::path &base_path, std::string version) -> std::string {
while(!version.empty() && version.front() != '.' && version.back() != '.') {
auto path = base_path / "clang" / version;
boost::system::error_code ec;
@ -97,7 +98,6 @@ std::vector<std::string> CompileCommands::get_arguments(const boost::filesystem:
return "";
};
static std::string resource_path = []() -> std::string {
// Try based on clang_getClangVersion first, even though its format is not guaranteed to be stable.
auto clang_version = clangmm::to_string(clang_getClangVersion());
std::regex clang_version_regex("([0-9]+\\.[0-9]+\\.[0-9]+)");
@ -105,14 +105,11 @@ std::vector<std::string> CompileCommands::get_arguments(const boost::filesystem:
if(std::regex_search(clang_version, sm, clang_version_regex)) {
auto version = sm[1].str();
auto path = find_resource_path(boost::filesystem::path(LIBCLANG_LIBRARY_DIR), version);
if(path.empty()) {
// For e.g. Fedora the LibClang is located in /usr/lib64/libclang.so while the resource dir is in /usr/lib/clang/<version>
if(path.empty()) // For e.g. Fedora the LibClang is located in /usr/lib64/libclang.so while the resource dir is in /usr/lib/clang/<version>
path = find_resource_path(boost::filesystem::path(LIBCLANG_LIBRARY_DIR) / ".." / "lib", version);
}
if(!path.empty()) {
if(!path.empty())
return path;
}
}
boost::system::error_code ec;
for(boost::filesystem::directory_iterator it(boost::filesystem::path(LIBCLANG_LIBRARY_DIR) / "clang", ec), end; it != end; ++it) {

Loading…
Cancel
Save