forked from OctaForge/OctaBuild
remove rule-, add duprule to duplicate a rule with new deps
This commit is contained in:
parent
3f80d998a2
commit
2ed36fe7c9
31
main.cc
31
main.cc
|
@ -316,8 +316,6 @@ struct ObState {
|
||||||
void rule_add(const char *tgt, const char *dep, ostd::Uint32 *body,
|
void rule_add(const char *tgt, const char *dep, ostd::Uint32 *body,
|
||||||
bool action = false) {
|
bool action = false) {
|
||||||
auto targets = cscript::util::list_explode(tgt);
|
auto targets = cscript::util::list_explode(tgt);
|
||||||
auto deps = dep ? cscript::util::list_explode(dep)
|
|
||||||
: ostd::Vector<ostd::String>();
|
|
||||||
for (auto &target: targets.iter()) {
|
for (auto &target: targets.iter()) {
|
||||||
Rule &r = rules.push();
|
Rule &r = rules.push();
|
||||||
r.target = target;
|
r.target = target;
|
||||||
|
@ -326,10 +324,25 @@ struct ObState {
|
||||||
r.func = body;
|
r.func = body;
|
||||||
cscript::bcode_ref(body);
|
cscript::bcode_ref(body);
|
||||||
}
|
}
|
||||||
for (auto &dep: deps.iter())
|
r.deps = dep ? cscript::util::list_explode(dep)
|
||||||
r.deps.push(dep);
|
: ostd::Vector<ostd::String>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void rule_dup(const char *tgt, const char *ptgt, const char *dep) {
|
||||||
|
Rule *oldr = nullptr;
|
||||||
|
for (auto &rule: rules.iter())
|
||||||
|
if (ptgt == rule.target)
|
||||||
|
oldr = &rule;
|
||||||
|
if (!oldr)
|
||||||
|
return;
|
||||||
|
Rule &r = rules.push();
|
||||||
|
r.target = tgt;
|
||||||
|
r.action = oldr->action;
|
||||||
|
r.func = oldr->func;
|
||||||
|
r.deps = dep ? cscript::util::list_explode(dep)
|
||||||
|
: ostd::Vector<ostd::String>();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static ConstCharRange deffile = "obuild.cfg";
|
static ConstCharRange deffile = "obuild.cfg";
|
||||||
|
@ -420,11 +433,6 @@ int main(int argc, char **argv) {
|
||||||
((ObState &)cs).rule_add(tgt, dep, (*numargs > 2) ? body : nullptr);
|
((ObState &)cs).rule_add(tgt, dep, (*numargs > 2) ? body : nullptr);
|
||||||
});
|
});
|
||||||
|
|
||||||
os.cs.add_command("rule-", "seN", [](CsState &cs, const char *tgt,
|
|
||||||
ostd::Uint32 *body, int *numargs) {
|
|
||||||
((ObState &)cs).rule_add(tgt, nullptr, (*numargs > 1) ? body : nullptr);
|
|
||||||
});
|
|
||||||
|
|
||||||
os.cs.add_command("action", "se", [](CsState &cs, const char *an,
|
os.cs.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);
|
||||||
|
@ -435,6 +443,11 @@ int main(int argc, char **argv) {
|
||||||
((ObState &)cs).rule_add(file, deps, nullptr);
|
((ObState &)cs).rule_add(file, deps, nullptr);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
os.cs.add_command("duprule", "sss", [](CsState &cs, const char *tgt,
|
||||||
|
const char *ptgt, const char *dep) {
|
||||||
|
((ObState &)cs).rule_dup(tgt, ptgt, dep);
|
||||||
|
});
|
||||||
|
|
||||||
os.cs.add_commandn("getenv", "ss", [](CsState &cs, TvalRange args) {
|
os.cs.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("");
|
||||||
|
|
|
@ -19,10 +19,7 @@ rule %_ob.o %.cc [
|
||||||
shell $CXX $OB_CXXFLAGS -c -o $target $source
|
shell $CXX $OB_CXXFLAGS -c -o $target $source
|
||||||
]
|
]
|
||||||
|
|
||||||
rule cubescript_ob.o [@CUBESCRIPT_PATH/cubescript.cc] [
|
duprule cubescript_ob.o %_ob.o [@CUBESCRIPT_PATH/cubescript.cc]
|
||||||
echo " CXX" $target
|
|
||||||
shell $CXX $OB_CXXFLAGS -c -o $target $source
|
|
||||||
]
|
|
||||||
|
|
||||||
action clean [
|
action clean [
|
||||||
echo " CLEAN" $FILES obuild_ob
|
echo " CLEAN" $FILES obuild_ob
|
||||||
|
|
Loading…
Reference in a new issue