Browse Source

Cleanup of clang resource directory lookup

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

35
src/compile_commands.cpp

@ -83,21 +83,21 @@ 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 {
while(!version.empty() && version.front() != '.' && version.back() != '.') {
auto path = base_path / "clang" / version;
boost::system::error_code ec;
if(boost::filesystem::is_directory(path / "include", ec))
return path.string();
auto pos = version.rfind('.');
if(pos == std::string::npos)
break;
version.erase(pos);
}
return "";
};
static std::string resource_path = []() -> 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;
if(boost::filesystem::is_directory(path / "include", ec))
return path.string();
auto pos = version.rfind('.');
if(pos == std::string::npos)
break;
version.erase(pos);
}
return "";
};
// Try based on clang_getClangVersion first, even though its format is not guaranteed to be stable. // Try based on clang_getClangVersion first, even though its format is not guaranteed to be stable.
auto clang_version = clangmm::to_string(clang_getClangVersion()); auto clang_version = clangmm::to_string(clang_getClangVersion());
std::regex clang_version_regex("([0-9]+\\.[0-9]+\\.[0-9]+)"); std::regex clang_version_regex("([0-9]+\\.[0-9]+\\.[0-9]+)");
@ -105,13 +105,10 @@ std::vector<std::string> CompileCommands::get_arguments(const boost::filesystem:
if(std::regex_search(clang_version, sm, clang_version_regex)) { if(std::regex_search(clang_version, sm, clang_version_regex)) {
auto version = sm[1].str(); auto version = sm[1].str();
auto path = find_resource_path(boost::filesystem::path(LIBCLANG_LIBRARY_DIR), version); auto path = find_resource_path(boost::filesystem::path(LIBCLANG_LIBRARY_DIR), version);
if(path.empty()) { 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>
// 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); path = find_resource_path(boost::filesystem::path(LIBCLANG_LIBRARY_DIR) / ".." / "lib", version);
} if(!path.empty())
if(!path.empty()) {
return path; return path;
}
} }
boost::system::error_code ec; boost::system::error_code ec;

Loading…
Cancel
Save