forked from OctaForge/OctaBuild
abuse inheritance a little
This commit is contained in:
parent
a83cf836cd
commit
ea8c0ff002
47
main.cc
47
main.cc
|
@ -228,8 +228,7 @@ static ThreadPool tpool;
|
||||||
|
|
||||||
static ConstCharRange deffile = "obuild.cfg";
|
static ConstCharRange deffile = "obuild.cfg";
|
||||||
|
|
||||||
struct ObState {
|
struct ObState: CsState {
|
||||||
CsState cs;
|
|
||||||
ConstCharRange progname;
|
ConstCharRange progname;
|
||||||
int jobs = 1;
|
int jobs = 1;
|
||||||
bool ignore_env = false;
|
bool ignore_env = false;
|
||||||
|
@ -348,18 +347,18 @@ struct ObState {
|
||||||
if ((!ret && (act || ob_check_exec(tname, subdeps))) && func) {
|
if ((!ret && (act || ob_check_exec(tname, subdeps))) && func) {
|
||||||
StackedValue targetv, sourcev, sourcesv;
|
StackedValue targetv, sourcev, sourcesv;
|
||||||
|
|
||||||
targetv.id = cs.new_ident("target");
|
targetv.id = this->new_ident("target");
|
||||||
if (!cscript::check_alias(targetv.id))
|
if (!cscript::check_alias(targetv.id))
|
||||||
return 1;
|
return 1;
|
||||||
targetv.set_cstr(tname);
|
targetv.set_cstr(tname);
|
||||||
targetv.push();
|
targetv.push();
|
||||||
|
|
||||||
if (subdeps.size() > 0) {
|
if (subdeps.size() > 0) {
|
||||||
sourcev.id = cs.new_ident("source");
|
sourcev.id = this->new_ident("source");
|
||||||
if (!cscript::check_alias(sourcev.id))
|
if (!cscript::check_alias(sourcev.id))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
sourcesv.id = cs.new_ident("sources");
|
sourcesv.id = this->new_ident("sources");
|
||||||
if (!cscript::check_alias(sourcesv.id))
|
if (!cscript::check_alias(sourcesv.id))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
@ -372,13 +371,13 @@ struct ObState {
|
||||||
sourcesv.push();
|
sourcesv.push();
|
||||||
}
|
}
|
||||||
|
|
||||||
return cs.run_int(func);
|
return this->run_int(func);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int exec_action(Rule *rule) {
|
int exec_action(Rule *rule) {
|
||||||
return cs.run_int(rule->func);
|
return this->run_int(rule->func);
|
||||||
}
|
}
|
||||||
|
|
||||||
int find_rules(ConstCharRange target, Vector<SubRule> &rlist) {
|
int find_rules(ConstCharRange target, Vector<SubRule> &rlist) {
|
||||||
|
@ -477,23 +476,23 @@ struct ObState {
|
||||||
}
|
}
|
||||||
|
|
||||||
void register_rulecmds() {
|
void register_rulecmds() {
|
||||||
cs.add_command("rule", "sseN", [](CsState &cs, const char *tgt,
|
this->add_command("rule", "sseN", [](CsState &cs, const char *tgt,
|
||||||
const char *dep, ostd::Uint32 *body,
|
const char *dep, ostd::Uint32 *body,
|
||||||
int *numargs) {
|
int *numargs) {
|
||||||
((ObState &)cs).rule_add(tgt, dep, (*numargs > 2) ? body : nullptr);
|
((ObState &)cs).rule_add(tgt, dep, (*numargs > 2) ? body : nullptr);
|
||||||
});
|
});
|
||||||
|
|
||||||
cs.add_command("action", "se", [](CsState &cs, const char *an,
|
this->add_command("action", "se", [](CsState &cs, const char *an,
|
||||||
ostd::Uint32 *body) {
|
ostd::Uint32 *body) {
|
||||||
((ObState &)cs).rule_add(an, nullptr, body, true);
|
((ObState &)cs).rule_add(an, nullptr, body, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
cs.add_command("depend", "ss", [](CsState &cs, const char *file,
|
this->add_command("depend", "ss", [](CsState &cs, const char *file,
|
||||||
const char *deps) {
|
const char *deps) {
|
||||||
((ObState &)cs).rule_add(file, deps, nullptr);
|
((ObState &)cs).rule_add(file, deps, nullptr);
|
||||||
});
|
});
|
||||||
|
|
||||||
cs.add_command("duprule", "sssN", [](CsState &cs, const char *tgt,
|
this->add_command("duprule", "sssN", [](CsState &cs, const char *tgt,
|
||||||
const char *ptgt, const char *dep,
|
const char *ptgt, const char *dep,
|
||||||
int *numargs) {
|
int *numargs) {
|
||||||
((ObState &)cs).rule_dup(tgt, ptgt, dep, *numargs <= 2);
|
((ObState &)cs).rule_dup(tgt, ptgt, dep, *numargs <= 2);
|
||||||
|
@ -520,15 +519,15 @@ int main(int argc, char **argv) {
|
||||||
ConstCharRange lslash = ostd::find_last(pn, '/');
|
ConstCharRange lslash = ostd::find_last(pn, '/');
|
||||||
os.progname = lslash.empty() ? pn : (lslash + 1);
|
os.progname = lslash.empty() ? pn : (lslash + 1);
|
||||||
|
|
||||||
cscript::init_lib_base(os.cs);
|
cscript::init_lib_base(os);
|
||||||
cscript::init_lib_io(os.cs);
|
cscript::init_lib_io(os);
|
||||||
cscript::init_lib_math(os.cs);
|
cscript::init_lib_math(os);
|
||||||
cscript::init_lib_string(os.cs);
|
cscript::init_lib_string(os);
|
||||||
cscript::init_lib_list(os.cs);
|
cscript::init_lib_list(os);
|
||||||
|
|
||||||
int ncpus = ostd::cpu_count_get();
|
int ncpus = ostd::cpu_count_get();
|
||||||
os.cs.add_ident(cscript::ID_VAR, "numcpus", 4096, 1, &ncpus);
|
os.add_ident(cscript::ID_VAR, "numcpus", 4096, 1, &ncpus);
|
||||||
os.cs.add_ident(cscript::ID_VAR, "numjobs", 4096, 1, &os.jobs);
|
os.add_ident(cscript::ID_VAR, "numjobs", 4096, 1, &os.jobs);
|
||||||
|
|
||||||
ConstCharRange fcont;
|
ConstCharRange fcont;
|
||||||
|
|
||||||
|
@ -571,7 +570,7 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
os.register_rulecmds();
|
os.register_rulecmds();
|
||||||
|
|
||||||
os.cs.add_command("shell", "C", [](CsState &cs, ConstCharRange s) {
|
os.add_command("shell", "C", [](CsState &cs, ConstCharRange s) {
|
||||||
auto cnt = ((ObState &)cs).counters.back();
|
auto cnt = ((ObState &)cs).counters.back();
|
||||||
cnt->incr();
|
cnt->incr();
|
||||||
String ds = s;
|
String ds = s;
|
||||||
|
@ -585,7 +584,7 @@ int main(int argc, char **argv) {
|
||||||
cs.result->set_int(0);
|
cs.result->set_int(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
os.cs.add_commandn("getenv", "ss", [](CsState &cs, TvalRange args) {
|
os.add_commandn("getenv", "ss", [](CsState &cs, TvalRange args) {
|
||||||
if (((ObState &)cs).ignore_env) {
|
if (((ObState &)cs).ignore_env) {
|
||||||
cs.result->set_cstr("");
|
cs.result->set_cstr("");
|
||||||
return;
|
return;
|
||||||
|
@ -601,7 +600,7 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
os.cs.add_command("extreplace", "sss", [](cscript::CsState &cs,
|
os.add_command("extreplace", "sss", [](cscript::CsState &cs,
|
||||||
const char *lst,
|
const char *lst,
|
||||||
const char *oldext,
|
const char *oldext,
|
||||||
const char *newext) {
|
const char *newext) {
|
||||||
|
@ -623,13 +622,13 @@ int main(int argc, char **argv) {
|
||||||
cs.result->set_str_dup(ret);
|
cs.result->set_str_dup(ret);
|
||||||
});
|
});
|
||||||
|
|
||||||
os.cs.add_command("invoke", "s", [](CsState &cs, const char *name) {
|
os.add_command("invoke", "s", [](CsState &cs, const char *name) {
|
||||||
cs.result->set_int(((ObState &)cs).exec_main(name));
|
cs.result->set_int(((ObState &)cs).exec_main(name));
|
||||||
});
|
});
|
||||||
|
|
||||||
cs_register_globs(os.cs);
|
cs_register_globs(os);
|
||||||
|
|
||||||
if ((!fcont.empty() && !os.cs.run_bool(fcont)) || !os.cs.run_file(deffile))
|
if ((!fcont.empty() && !os.run_bool(fcont)) || !os.run_file(deffile))
|
||||||
return os.error(1, "failed creating rules");
|
return os.error(1, "failed creating rules");
|
||||||
|
|
||||||
if (os.rules.empty())
|
if (os.rules.empty())
|
||||||
|
|
Loading…
Reference in a new issue