more cleanups

master
Daniel Kolesa 2015-08-22 00:31:33 -07:00
parent 4cab581d58
commit 8e6b107b48
1 changed files with 16 additions and 12 deletions

28
main.cc
View File

@ -6,6 +6,7 @@
#include <cubescript.hh> #include <cubescript.hh>
/* represents a rule definition, possibly with a function */
struct Rule { struct Rule {
ostd::String target; ostd::String target;
ostd::Vector<ostd::String> deps; ostd::Vector<ostd::String> deps;
@ -20,23 +21,20 @@ struct Rule {
ostd::Vector<Rule> rules; ostd::Vector<Rule> rules;
struct SubRule { /* check funcs */
ostd::ConstCharRange sub;
Rule *rule;
};
static time_t ob_get_file_ts(const char *fname) {
struct stat st;
if (stat(fname, &st) < 0) return 0;
return st.st_mtime;
}
static bool ob_check_ts(ostd::ConstCharRange tname, static bool ob_check_ts(ostd::ConstCharRange tname,
const ostd::Vector<ostd::String> &deps) { const ostd::Vector<ostd::String> &deps) {
time_t tts = ob_get_file_ts(tname.data()); auto get_ts = [](ostd::ConstCharRange fname) -> time_t {
struct stat st;
if (stat(ostd::String(fname).data(), &st) < 0)
return 0;
return st.st_mtime;
};
time_t tts = get_ts(tname.data());
if (!tts) return true; if (!tts) return true;
for (auto &dep: deps.iter()) { for (auto &dep: deps.iter()) {
time_t sts = ob_get_file_ts(dep.data()); time_t sts = get_ts(dep.data());
if (sts && tts < sts) return true; if (sts && tts < sts) return true;
} }
return false; return false;
@ -56,6 +54,7 @@ static bool ob_check_exec(ostd::ConstCharRange tname,
return ob_check_ts(tname, deps); return ob_check_ts(tname, deps);
} }
/* this lets us properly match % patterns in target names */
static ostd::ConstCharRange ob_compare_subst(ostd::ConstCharRange expanded, static ostd::ConstCharRange ob_compare_subst(ostd::ConstCharRange expanded,
ostd::ConstCharRange toexpand) { ostd::ConstCharRange toexpand) {
auto rep = ostd::find(toexpand, '%'); auto rep = ostd::find(toexpand, '%');
@ -90,6 +89,11 @@ struct ObState {
cscript::CsState cs; cscript::CsState cs;
ostd::ConstCharRange progname; ostd::ConstCharRange progname;
struct SubRule {
ostd::ConstCharRange sub;
Rule *rule;
};
template<typename ...A> template<typename ...A>
int error(int retcode, ostd::ConstCharRange fmt, A &&...args) { int error(int retcode, ostd::ConstCharRange fmt, A &&...args) {
ostd::err.write(progname, ": "); ostd::err.write(progname, ": ");