remove rule-, add duprule to duplicate a rule with new deps

master
Daniel Kolesa 2015-11-14 01:28:07 +00:00
parent 3f80d998a2
commit 2ed36fe7c9
2 changed files with 23 additions and 13 deletions

31
main.cc
View File

@ -316,8 +316,6 @@ struct ObState {
void rule_add(const char *tgt, const char *dep, ostd::Uint32 *body,
bool action = false) {
auto targets = cscript::util::list_explode(tgt);
auto deps = dep ? cscript::util::list_explode(dep)
: ostd::Vector<ostd::String>();
for (auto &target: targets.iter()) {
Rule &r = rules.push();
r.target = target;
@ -326,10 +324,25 @@ struct ObState {
r.func = body;
cscript::bcode_ref(body);
}
for (auto &dep: deps.iter())
r.deps.push(dep);
r.deps = dep ? cscript::util::list_explode(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";
@ -420,11 +433,6 @@ int main(int argc, char **argv) {
((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,
ostd::Uint32 *body) {
((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);
});
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) {
if (((ObState &)cs).ignore_env) {
cs.result->set_cstr("");

View File

@ -19,10 +19,7 @@ rule %_ob.o %.cc [
shell $CXX $OB_CXXFLAGS -c -o $target $source
]
rule cubescript_ob.o [@CUBESCRIPT_PATH/cubescript.cc] [
echo " CXX" $target
shell $CXX $OB_CXXFLAGS -c -o $target $source
]
duprule cubescript_ob.o %_ob.o [@CUBESCRIPT_PATH/cubescript.cc]
action clean [
echo " CLEAN" $FILES obuild_ob