13 int fail(
const std::string& message)
15 std::cerr << message <<
'\n';
24 const std::filesystem::path source_root = std::filesystem::canonical(options.
root /
"src", code);
26 return fail(
"cannot read " + (options.
root /
"src").string());
29 return fail(
"--build needs --translation-unit with a compile database, or --compile-arg");
33 if (resource_dir.empty()) {
34 return fail(
"no Clang resource directory: pass --resource-dir, or put clang on PATH");
51 const auto canonical = std::filesystem::canonical(entry.header, code);
53 return fail(
"cannot read header " + entry.header.string());
61 std::vector<std::filesystem::path> dependencies;
62 if (!
scan_for_build(input, [&collector](clang::ast_matchers::MatchFinder& finder) { collector.
attach(finder); },
63 dependencies, error)) {
66 if (!collector.
errors().empty()) {
67 for (
const auto& message : collector.
errors()) {
68 std::cerr << message <<
'\n';
72 if (
const auto missing = collector.
missing(); !missing.empty()) {
73 for (
const auto& name : missing) {
74 std::cerr << name <<
": expected one complete class definition, found none\n";
80 const std::vector<std::pair<std::string, const std::string*>> outputs {
81 {
"CreatorIncludes.hpp", &files.
includes },
82 {
"CreatorClasses.hpp", &files.
classes },
87 std::filesystem::create_directories(options.
output, code);
89 return fail(
"cannot create " + options.
output.string());
91 for (
const auto& [name, text] : outputs) {
98 const std::filesystem::path output_root = std::filesystem::weakly_canonical(options.
output, code);
99 std::erase_if(dependencies, [&output_root](
const std::filesystem::path& path) {
100 const auto relative = path.lexically_relative(output_root);
101 return !relative.empty() && *relative.begin() !=
"..";
103 const auto registry = std::filesystem::weakly_canonical(options.
registry, code);
104 dependencies.push_back(registry);
105 std::ranges::sort(dependencies);
106 dependencies.erase(std::ranges::unique(dependencies).begin(), dependencies.end());
109 ? (options.
output / outputs.front().first).generic_string()
116 std::cout <<
"Generated methods for " << collector.
classes().size() <<
" classes\n";
One class of the Creator registry: the method name, its qualified type and its header.