aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/bash/rule.hxx
blob: 81c460415c9384e715858734ed5cec5b2e6973d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// file      : libbuild2/bash/rule.hxx -*- C++ -*-
// license   : MIT; see accompanying LICENSE file

#ifndef LIBBUILD2_BASH_RULE_HXX
#define LIBBUILD2_BASH_RULE_HXX

#include <libbuild2/types.hxx>
#include <libbuild2/utility.hxx>

#include <libbuild2/install/rule.hxx>

#include <libbuild2/in/rule.hxx>

#include <libbuild2/bash/export.hxx>

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<string>
      substitute (const location&,
                  action a,
                  const target&,
                  const string&,
                  bool,
                  const optional<string>&) 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