MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ main()

int main ( int argc,
const char ** argv )

Definition at line 132 of file MayaFluxReflect.cpp.

133{
134 llvm::cl::OptionCategory category("mayaflux-reflect options");
135 llvm::cl::list<std::string> roots("root",
136 llvm::cl::desc("Directory searched recursively for MF_DESCRIBE, or a single header "
137 "(default without headers: src/MayaFlux when it exists, else src)"),
138 llvm::cl::value_desc("path"), llvm::cl::cat(category));
139 llvm::cl::list<std::string> headers(llvm::cl::Positional,
140 llvm::cl::desc("<header>..."), llvm::cl::cat(category));
141 llvm::cl::opt<std::string> build_path("p",
142 llvm::cl::desc("Directory holding compile_commands.json"),
143 llvm::cl::value_desc("dir"), llvm::cl::init("build"), llvm::cl::cat(category));
144 llvm::cl::opt<std::string> translation_unit("translation-unit",
145 llvm::cl::desc("Source file whose compile command is borrowed for the scan"),
146 llvm::cl::value_desc("file"), llvm::cl::cat(category));
147 llvm::cl::opt<std::string> resource_dir("resource-dir",
148 llvm::cl::desc("Clang resource directory holding the builtin headers"),
149 llvm::cl::value_desc("dir"), llvm::cl::init(MAYAFLUX_REFLECT_RESOURCE_DIR),
150 llvm::cl::cat(category));
151 llvm::cl::list<std::string> extra_args("extra-arg",
152 llvm::cl::desc("Extra Clang argument added to the scan"),
153 llvm::cl::value_desc("argument"), llvm::cl::cat(category));
154
155 llvm::cl::opt<bool> no_insert_include("no-insert-include",
156 llvm::cl::desc("Report a missing sidecar include instead of inserting it"),
157 llvm::cl::cat(category));
158
159 llvm::cl::opt<bool> check("check",
160 llvm::cl::desc("Write nothing; exit 1 when a sidecar, its include or a marker is out of date"),
161 llvm::cl::cat(category));
162
163 llvm::cl::opt<bool> build("build",
164 llvm::cl::desc("Build step: describe the one header given, inserting its sidecar include when missing, "
165 "and write nothing else in the source tree. Needs --translation-unit or --compile-arg"),
166 llvm::cl::cat(category));
167 llvm::cl::list<std::string> compile_args("compile-arg",
168 llvm::cl::desc("With --build: one argument of the whole compile command, used instead of the database"),
169 llvm::cl::value_desc("argument"), llvm::cl::cat(category));
170 llvm::cl::opt<std::string> depfile("depfile",
171 llvm::cl::desc("With --build: write a depfile of the files the scan read"),
172 llvm::cl::value_desc("file"), llvm::cl::cat(category));
173 llvm::cl::opt<std::string> depfile_target("depfile-target",
174 llvm::cl::desc("With --build: the target named in the depfile (default: the sidecar path)"),
175 llvm::cl::value_desc("path"), llvm::cl::cat(category));
176
177 llvm::cl::HideUnrelatedOptions(category);
178 llvm::cl::ParseCommandLineOptions(argc, argv,
179 "Writes a Name.describe.hpp sidecar beside each header that holds MF_DESCRIBE requests.\n");
180
181 Config config;
182 config.roots.assign(roots.begin(), roots.end());
183 config.headers.assign(headers.begin(), headers.end());
184 config.build_path = build_path.getValue();
185 config.translation_unit = translation_unit.getValue();
186 config.resource_dir = resource_dir.getValue();
187 config.extra_args.assign(extra_args.begin(), extra_args.end());
188 config.insert_includes = !no_insert_include;
189 config.check = check;
190
191 if (build) {
192 if (config.headers.size() != 1 || !config.roots.empty() || config.check) {
193 return fail("--build takes exactly one header, and neither --root nor --check");
194 }
195 ReflectBuildOptions options;
196 options.header = config.headers.front();
197 options.build_path = config.build_path;
198 options.translation_unit = config.translation_unit;
199 options.resource_dir = config.resource_dir;
200 options.extra_args = config.extra_args;
201 options.compile_args.assign(compile_args.begin(), compile_args.end());
202 options.depfile = depfile.getValue();
203 options.depfile_target = depfile_target.getValue();
204 options.insert_includes = config.insert_includes;
205 return run_reflect_build(options);
206 }
207
208 if (config.roots.empty() && config.headers.empty()) {
209 config.roots.emplace_back(std::filesystem::is_directory("src/MayaFlux") ? "src/MayaFlux" : "src");
210 }
211
212 for (auto& root : config.roots) {
213 std::error_code code;
214 const auto canonical = std::filesystem::canonical(root, code);
215 if (code) {
216 return fail("cannot read root " + root.string());
217 }
218 root = canonical;
219 }
220 return generate(config);
221}
#define MAYAFLUX_REFLECT_RESOURCE_DIR
int run_reflect_build(const ReflectBuildOptions &options)
Writes the sidecar of one header, for a build step.
What mayaflux_reflect --build needs to describe one header.

References MayaFlux::Reflect::Tool::ReflectBuildOptions::build_path, MayaFlux::Reflect::Tool::ReflectBuildOptions::compile_args, MayaFlux::Reflect::Tool::ReflectBuildOptions::depfile, MayaFlux::Reflect::Tool::ReflectBuildOptions::depfile_target, MayaFlux::Reflect::Tool::ReflectBuildOptions::extra_args, MayaFlux::Reflect::Tool::ReflectBuildOptions::header, MayaFlux::Reflect::Tool::ReflectBuildOptions::insert_includes, MAYAFLUX_REFLECT_RESOURCE_DIR, MayaFlux::Reflect::Tool::ReflectBuildOptions::resource_dir, MayaFlux::Reflect::Tool::run_reflect_build(), and MayaFlux::Reflect::Tool::ReflectBuildOptions::translation_unit.

Here is the call graph for this function: