25std::unique_ptr<compilation_database>
29 std::string error_message;
30 auto res = clang::tooling::CompilationDatabase::autoDetectFromDirectory(
33 if (!error_message.empty())
36 if (res.get() ==
nullptr)
38 "Autodetection of compilation database from directory '{}' failed",
44 bool is_fixed{res->getAllFiles().empty()};
46 return std::make_unique<compilation_database>(
51 std::unique_ptr<clang::tooling::CompilationDatabase> base,
53 : base_{
std::move(base)}
73 return base().getAllFiles();
76std::vector<clang::tooling::CompileCommand>
79 auto commands =
base().getCompileCommands(FilePath);
86std::vector<clang::tooling::CompileCommand>
89 auto commands =
base().getAllCompileCommands();
97 const std::string &filename)
const
106 const std::vector<std::string> &files)
const
113 for (
const auto &f : files) {
121 std::vector<clang::tooling::CompileCommand> &commands)
const
124 if (
config().query_driver && !
config().query_driver().empty()) {
125 for (
auto &compile_command : commands) {
127 ? compile_command.CommandLine.at(0)
135 std::vector<std::string> system_header_args;
136 for (
const auto &path : extractor.system_include_paths()) {
137 system_header_args.emplace_back(
"-isystem");
138 system_header_args.emplace_back(path);
141 compile_command.CommandLine.insert(
142 compile_command.CommandLine.begin() + 1,
143 system_header_args.begin(), system_header_args.end());
145 if (!extractor.target().empty()) {
146 compile_command.CommandLine.insert(
147 compile_command.CommandLine.begin() + 1,
148 fmt::format(
"--target={}", extractor.target()));
155 for (
auto &compile_command : commands) {
156 compile_command.CommandLine.insert(
158 compile_command.CommandLine.begin() + 1,
166 for (
auto &compile_command : commands) {
169 [&flag](
const auto &arg) { return flag == arg; });
176 const clang::tooling::CompileCommand &command,
177 const std::string &file)
const
179 auto command_filename = std::filesystem::path{command.Filename};
181 if (!command_filename.is_absolute()) {
185 return (command_filename == file) ||
186 (command_filename.lexically_normal().string() == file);