// file : build2/rule -*- C++ -*- // copyright : Copyright (c) 2014-2016 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file #ifndef BUILD2_RULE #define BUILD2_RULE #include #include #include #include namespace build2 { class match_result { public: bool result; action recipe_action = action (); // Used as recipe's action if set. explicit operator bool () const {return result;} // Note that the from-bool constructor is intentionally implicit so that // we can return true/false from match(). // match_result (bool r): result (r) {} match_result (bool r, action a): result (r), recipe_action (a) {} }; class rule { public: virtual match_result match (action, target&, const string& hint) const = 0; virtual recipe apply (action, target&) const = 0; }; // Fallback rule that on update verifies that the file exists and is // not older than any of its prerequisites. // class file_rule: public rule { public: virtual match_result match (action, target&, const string& hint) const override; virtual recipe apply (action, target&) const override; static target_state perform_update (action, target&); static file_rule instance; }; class alias_rule: public rule { public: virtual match_result match (action, target&, const string& hint) const override; virtual recipe apply (action, target&) const override; static alias_rule instance; }; class fsdir_rule: public rule { public: virtual match_result match (action, target&, const string& hint) const override; virtual recipe apply (action, target&) const override; static target_state perform_update (action, target&); static target_state perform_clean (action, target&); static fsdir_rule instance; }; // Fallback rule that always matches and does nothing. // class fallback_rule: public build2::rule { public: virtual match_result match (action, target&, const string&) const override {return true;} virtual recipe apply (action, target&) const override {return noop_recipe;} static fallback_rule instance; }; } #endif // BUILD2_RULE