diff --git a/src/compile_commands.cpp b/src/compile_commands.cpp index e4d773c..3fb4fd9 100644 --- a/src/compile_commands.cpp +++ b/src/compile_commands.cpp @@ -83,21 +83,21 @@ std::vector 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 { + 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. auto clang_version = clangmm::to_string(clang_getClangVersion()); std::regex clang_version_regex("([0-9]+\\.[0-9]+\\.[0-9]+)"); @@ -105,13 +105,10 @@ std::vector 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/ + 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/ 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;