From 977d07a3ae47ef204665d1eda2d642e5064724f3 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 24 Jun 2019 12:01:19 +0200 Subject: Split build system into library and driver --- libbuild2/rule.hxx | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 libbuild2/rule.hxx (limited to 'libbuild2/rule.hxx') diff --git a/libbuild2/rule.hxx b/libbuild2/rule.hxx new file mode 100644 index 0000000..abd754e --- /dev/null +++ b/libbuild2/rule.hxx @@ -0,0 +1,107 @@ +// file : libbuild2/rule.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef LIBBUILD2_RULE_HXX +#define LIBBUILD2_RULE_HXX + +#include +#include + +#include +#include + +#include + +namespace build2 +{ + // Once a rule is registered (for a scope), it is treated as immutable. If + // you need to modify some state (e.g., counters or some such), then make + // sure it is MT-safe. + // + // Note: match() is only called once but may not be followed by apply(). + // + class rule + { + public: + virtual bool + match (action, target&, const string& hint) const = 0; + + virtual recipe + apply (action, target&) const = 0; + }; + + // Fallback rule that only matches if the file exists. It will also match + // an mtime_target provided it has a set timestamp. + // + class LIBBUILD2_SYMEXPORT file_rule: public rule + { + public: + virtual bool + match (action, target&, const string&) const override; + + virtual recipe + apply (action, target&) const override; + + file_rule () {} + static const file_rule instance; + }; + + class LIBBUILD2_SYMEXPORT alias_rule: public rule + { + public: + virtual bool + match (action, target&, const string&) const override; + + virtual recipe + apply (action, target&) const override; + + alias_rule () {} + static const alias_rule instance; + }; + + // Note that this rule ignores the dry_run flag; see mkdir() in filesystem + // for the rationale. + // + class LIBBUILD2_SYMEXPORT fsdir_rule: public rule + { + public: + virtual bool + match (action, target&, const string&) const override; + + virtual recipe + apply (action, target&) const override; + + static target_state + perform_update (action, const target&); + + static target_state + perform_clean (action, const target&); + + // Sometimes, as an optimization, we want to emulate execute_direct() + // of fsdir{} without the overhead of switching to the execute phase. + // + static void + perform_update_direct (action, const target&); + + fsdir_rule () {} + static const fsdir_rule instance; + }; + + // Fallback rule that always matches and does nothing. + // + class LIBBUILD2_SYMEXPORT noop_rule: public rule + { + public: + virtual bool + match (action, target&, const string&) const override; + + virtual recipe + apply (action, target&) const override; + + noop_rule () {} + static const noop_rule instance; + }; +} + +#endif // LIBBUILD2_RULE_HXX -- cgit v1.1