[clang-tools-extra] 109bc02 - [clangd] Add --query-driver flag to clangd-indexer
Nathan Ridge via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 24 08:52:09 PDT 2023
Author: Nathan Ridge
Date: 2023-08-24T11:51:59-04:00
New Revision: 109bc024c8d741e57fa6bb5a028d8a4ed4e64a61
URL: https://github.com/llvm/llvm-project/commit/109bc024c8d741e57fa6bb5a028d8a4ed4e64a61
DIFF: https://github.com/llvm/llvm-project/commit/109bc024c8d741e57fa6bb5a028d8a4ed4e64a61.diff
LOG: [clangd] Add --query-driver flag to clangd-indexer
When using `clangd` for cross-compiled projects, it's necessary to use the `--query-driver` flag so that `clangd` can extract the compiler's built-in header paths. However, there's no such flag for `clangd-indexer` so we're unable to build a working static index for these projects.
This patch adds a `--query-driver` flag to `clangd-indexer` for this scenario.
I saw some tests under `clang-tools-extra/clangd/test/` but I think the cross-compilation case is a bit more complex to test. Let me know if you'd like me to look into this further.
Resolves: https://github.com/clangd/clangd/issues/1717
Reviewed By: nridge
Differential Revision: https://reviews.llvm.org/D157990
Added:
Modified:
clang-tools-extra/clangd/indexer/IndexerMain.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/indexer/IndexerMain.cpp b/clang-tools-extra/clangd/indexer/IndexerMain.cpp
index 2717030e979639..bc5d1a74089910 100644
--- a/clang-tools-extra/clangd/indexer/IndexerMain.cpp
+++ b/clang-tools-extra/clangd/indexer/IndexerMain.cpp
@@ -38,6 +38,16 @@ static llvm::cl::opt<IndexFileFormat>
"binary RIFF format")),
llvm::cl::init(IndexFileFormat::RIFF));
+static llvm::cl::list<std::string> QueryDriverGlobs{
+ "query-driver",
+ llvm::cl::desc(
+ "Comma separated list of globs for white-listing gcc-compatible "
+ "drivers that are safe to execute. Drivers matching any of these globs "
+ "will be used to extract system includes. e.g. "
+ "/usr/bin/**/clang-*,/path/to/repo/**/g++-*"),
+ llvm::cl::CommaSeparated,
+};
+
class IndexActionFactory : public tooling::FrontendActionFactory {
public:
IndexActionFactory(IndexFileIn &Result) : Result(Result) {}
@@ -144,12 +154,16 @@ int main(int argc, const char **argv) {
// Collect symbols found in each translation unit, merging as we go.
clang::clangd::IndexFileIn Data;
+ auto Mangler = std::make_shared<clang::clangd::CommandMangler>(
+ clang::clangd::CommandMangler::detect());
+ Mangler->SystemIncludeExtractor = clang::clangd::getSystemIncludeExtractor(
+ static_cast<llvm::ArrayRef<std::string>>(
+ clang::clangd::QueryDriverGlobs));
auto Err = Executor->get()->execute(
std::make_unique<clang::clangd::IndexActionFactory>(Data),
clang::tooling::ArgumentsAdjuster(
- [Mangler = std::make_shared<clang::clangd::CommandMangler>(
- clang::clangd::CommandMangler::detect())](
- const std::vector<std::string> &Args, llvm::StringRef File) {
+ [Mangler = std::move(Mangler)](const std::vector<std::string> &Args,
+ llvm::StringRef File) {
clang::tooling::CompileCommand Cmd;
Cmd.CommandLine = Args;
Mangler->operator()(Cmd, File);
More information about the cfe-commits
mailing list