in glean/lang/clang/index.cpp [355:415]
bool index(const SourceFile& source) {
auto pcdb = cdb.load(source);
ClangCfg cfg{
ClangDB::Env{
locatorOf(source),
platformOf(source),
config.root,
config.target_subdir,
config.path_prefix,
batch,
},
config.diagnostics.get()
};
FrontendActionFactory factory(&cfg);
clang::tooling::ClangTool tool(*pcdb, source.file);
if (!FLAGS_clang_arguments.empty()) {
clang::tooling::CommandLineArguments args;
folly::split(" ", FLAGS_clang_arguments, args, true);
if (!args.empty()) {
tool.appendArgumentsAdjuster(
clang::tooling::getInsertArgumentAdjuster(
args, clang::tooling::ArgumentInsertPosition::END));
}
}
tool.appendArgumentsAdjuster([](const auto& args, auto) {
clang::tooling::CommandLineArguments stripped;
stripped.reserve(args.size());
for (size_t i = 0; i < args.size(); ++i) {
if (FLAGS_clang_no_pch && args[i] == "-include-pch") {
++i; // skip next argument
} else if (FLAGS_clang_no_pch
&& args[i] == "-include"
&& i+1 < args.size()
&& boost::ends_with(args[i+1],".pch")) {
// headers included from the command line cause problems
// because they won't be visible to tools exploring the
// include graph via the cxx.Trace predicate. When used to
// include a .pch file these are typically a compile-time
// optimisation only, so we strip them out when
// --clang_no_pch is on.
++i;
} else if (!FLAGS_clang_resource_dir.empty()
&& args[i] == "-resource-dir") {
++i; // replace -resource-dir flag
stripped.push_back("-resource-dir");
stripped.push_back(FLAGS_clang_resource_dir);
} else if (boost::starts_with(args[i], "--cc=")) {
// skip this flag - llvm complains about it
} else if (FLAGS_clang_no_modules &&
(args[i] == "-fmodules"
|| args[i] == "-fcxx-modules"
|| boost::starts_with(args[i], "-fmodule-name="))) {
// skip these
} else {
stripped.push_back(args[i]);
}
}
return stripped;
});
return tool.run(&factory) == 0;
}