38 int Run(std::string output, std::vector<std::string> argv)
const override
40 llvm::cl::SetVersionPrinter([](llvm::raw_ostream& ost)
45 std::vector<const char*> buffer(argv.size() + 1);
46 buffer[0] =
"lilac-cxx";
47 for (
int i = 0; i < argv.size(); ++i)
48 buffer[i + 1] = argv[i].c_str();
55 if (
auto ret = ::glob(
"/usr/lib/clang/*/include", GLOB_TILDE,
nullptr, &glob))
59 <<
"glob() failed with return value: " << ret <<
'\n'
60 <<
"is Clang installed with proper directory?";
64 std::vector<std::string> candidates(glob.gl_pathc);
65 for (
auto i = 0; i < glob.gl_pathc; ++i)
67 llvm::outs() <<
"Found candidate Clang installation: " << glob.gl_pathv[i] <<
'\n';
68 candidates[i] = glob.gl_pathv[i];
74 static constexpr long int GetIndex(
const std::string& t)
76 return strtol(t.data() + 15,
nullptr, 10);
79 constexpr bool operator()(
const std::string& lhs,
const std::string& rhs)
const
81 return GetIndex(lhs) > GetIndex(rhs);
84 std::ranges::sort(candidates, comp);
86 llvm::outs() <<
"Selected Clang installation: " << candidates[0] <<
'\n';
89 buffer.push_back(
"--");
90 buffer.push_back(
"-I");
91 buffer.push_back(candidates[0].data());
96 int argc = buffer.size();
98 auto expectedParser = clang::tooling::CommonOptionsParser::create(argc, buffer.data(), llvm::cl::getGeneralCategory());
101 llvm::errs() << expectedParser.takeError();
105 auto& parser = expectedParser.get();
107 clang::tooling::ClangTool tool(parser.getCompilations(), parser.getSourcePathList());
108 if (
const auto ret = tool.run(clang::tooling::newFrontendActionFactory<lilac::cxx::LilacAction>().get()))
113 std::ofstream ofs(output);
114 ofs << static_cast<std::string>(frxml::doc{ root });