From 6845f5a8d8871e8dbc672b6dd11bd47bea02f19a Mon Sep 17 00:00:00 2001 From: q66 Date: Tue, 1 May 2018 20:46:21 +0200 Subject: [PATCH] add a way to conditionally use rules according to predicate --- ostd/build/make.hh | 13 +++++++++++++ src/build_make.cc | 3 +++ 2 files changed, 16 insertions(+) diff --git a/ostd/build/make.hh b/ostd/build/make.hh index 019b838..ea5f567 100644 --- a/ostd/build/make.hh +++ b/ostd/build/make.hh @@ -118,6 +118,18 @@ struct make_rule { return *this; } + make_rule &cond(std::function cond_f) noexcept { + p_cond = std::move(cond_f); + return *this; + } + + bool cond(string_range target) const { + if (!p_cond) { + return true; + } + return p_cond(target); + } + iterator_range depends() const noexcept { return iterator_range( p_deps.data(), p_deps.data() + p_deps.size() @@ -159,6 +171,7 @@ private: make_pattern p_target; std::vector p_deps{}; body_func p_body{}; + std::function p_cond{}; bool p_action = false; }; diff --git a/src/build_make.cc b/src/build_make.cc index 30ee49f..4f652b8 100644 --- a/src/build_make.cc +++ b/src/build_make.cc @@ -176,6 +176,9 @@ void make::find_rules(string_range target, std::vector &rlist) { rule_inst *frule = nullptr; std::size_t pfnl = 0, psubl = 0; for (auto &rule: p_rules) { + if (!rule.cond(target)) { + continue; + } auto &tgt = rule.target(); auto [fnl, subl] = tgt.match(target); if ((fnl + subl) > 0) {