From 930ae81f85e5ee5ac37311f5e9c89000fbcb59a6 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 1 Aug 2019 16:17:09 +0300 Subject: Move bash build system module to separate library --- libbuild2/bash/rule.hxx | 91 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 libbuild2/bash/rule.hxx (limited to 'libbuild2/bash/rule.hxx') diff --git a/libbuild2/bash/rule.hxx b/libbuild2/bash/rule.hxx new file mode 100644 index 0000000..665a6c2 --- /dev/null +++ b/libbuild2/bash/rule.hxx @@ -0,0 +1,91 @@ +// file : libbuild2/bash/rule.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef LIBBUILD2_BASH_RULE_HXX +#define LIBBUILD2_BASH_RULE_HXX + +#include +#include + +#include + +#include + +#include + +namespace build2 +{ + namespace bash + { + // Preprocess a bash script (exe{}) or module (bash{}) .in file that + // imports one or more bash modules. + // + // Note that the default substitution symbol is '@' and the mode is lax + // (think bash arrays). The idea is that '@' is normally used in ways that + // are highly unlikely to be misinterpreted as substitutions. The user, + // however, is still able to override both of these choices with the + // corresponding in.* variables (e.g., to use '`' and strict mode). + // + class LIBBUILD2_BASH_SYMEXPORT in_rule: public in::rule + { + public: + in_rule (): rule ("bash.in 1", "bash.in", '@', false /* strict */) {} + + virtual bool + match (action, target&, const string&) const override; + + virtual recipe + apply (action, target&) const override; + + virtual target_state + perform_update (action, const target&) const override; + + virtual prerequisite_target + search (action, + const target&, + const prerequisite_member&, + include_type) const override; + + virtual optional + substitute (const location&, + action a, + const target&, + const string&, + bool) const override; + + string + substitute_import (const location&, + action a, + const target&, + const string&) const; + }; + + // Installation rule for bash scripts (exe{}) and modules (bash{}). Here + // we do: + // + // 1. Signal to in_rule that this is update for install. + // + // 2. Custom filtering of prerequisites. + // + class LIBBUILD2_BASH_SYMEXPORT install_rule: public install::file_rule + { + public: + install_rule (const in_rule& in): in_ (in) {} + + virtual bool + match (action, target&, const string&) const override; + + virtual recipe + apply (action, target&) const override; + + virtual const target* + filter (action, const target&, const prerequisite&) const override; + + protected: + const in_rule& in_; + }; + } +} + +#endif // LIBBUILD2_BASH_RULE_HXX -- cgit v1.1