#include "setupgen.h"
+#include <algorithm>
#include <msp/core/getopt.h>
#include <msp/core/maputils.h>
+#include <msp/fs/stat.h>
#include <msp/fs/utils.h>
#include <msp/io/console.h>
#include <msp/io/print.h>
SetupGen::SetupGen(int argc, char **argv)
{
+ vector<string> import_dirs;
+
GetOpt getopt;
+ getopt.add_option('I', "importdir", import_dirs, GetOpt::REQUIRED_ARG);
getopt.add_option('o', "output", out_fn, GetOpt::REQUIRED_ARG);
getopt.add_argument("input_file", in_fn, GetOpt::REQUIRED_ARG);
getopt(argc, argv);
+
+ import_path.insert(import_path.end(), import_dirs.begin(), import_dirs.end());
}
int SetupGen::main()
add("component", &Loader::struct_def, Struct::COMPONENT);
add("entity", &Loader::struct_def, Struct::ENTITY);
add("enum", &Loader::enum_def);
+ add("import", &Loader::import);
add("namespace", &Loader::name_space);
}
type.set_enum(*mod.enums.emplace_back(make_unique<Enum>(move(en))));
}
+void SetupGen::Loader::import(const string &n)
+{
+ string fn = n+".mgs";
+ FS::Path full_path;
+ if(!ranges::any_of(obj.import_path, [&full_path, &fn](const FS::Path &p){
+ full_path = p/fn;
+ return FS::exists(full_path);
+ }))
+ throw IO::file_not_found(fn);
+
+ obj.load(full_path);
+ obj.headers.insert(n+".h");
+}
+
void SetupGen::Loader::name_space(const string &ns)
{
mod.name_space = ns;