aboutsummaryrefslogtreecommitdiff
path: root/build2/install/rule.hxx
blob: 32c6889ec3e35030b43e9838ef6fac245610d40b (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// file      : build2/install/rule.hxx -*- C++ -*-
// copyright : Copyright (c) 2014-2018 Code Synthesis Ltd
// license   : MIT; see accompanying LICENSE file

#ifndef BUILD2_INSTALL_RULE_HXX
#define BUILD2_INSTALL_RULE_HXX

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

#include <build2/rule.hxx>
#include <build2/target.hxx>
#include <build2/operation.hxx>
#include <build2/filesystem.hxx>

namespace build2
{
  namespace install
  {
    class alias_rule: public rule
    {
    public:
      virtual bool
      match (action, target&, const string&) const override;

      // Return NULL if this prerequisite should be ignored and pointer to its
      // target otherwise. The default implementation accepts prerequsites
      // from the target's (weak) amalgamation.
      //
      // The prerequisite it passed as an iterator allowing the filter to
      // "see" inside groups.
      //
      using prerequisite_iterator =
        prerequisite_members_range<group_prerequisites>::iterator;

      virtual const target*
      filter (action, const target&, prerequisite_iterator&) const;

      virtual const target*
      filter (action, const target&, const prerequisite&) const;

      virtual recipe
      apply (action, target&) const override;

      alias_rule () {}
      static const alias_rule instance;
    };

    // In addition to the alias rule's semantics, this rule sees through to
    // the group's members.
    //
    // The default group_rule::instance matches any target for which it was
    // registered. It is to be used for non-see-through groups that should
    // exhibit the see-through behavior for install (see lib{} in the bin
    // module for an example).
    //
    // We also register (for all targets) another instance of this rule that
    // only matches see-through groups.
    //
    class group_rule: public alias_rule
    {
    public:
      virtual bool
      match (action, target&, const string&) const override;

      // Return NULL if this group member should be ignored and pointer to its
      // target otherwise. The default implementation accepts all members.
      //
      virtual const target*
      filter (action, const target&, const target& group_member) const;

      using alias_rule::filter; // "Unhide" to make Clang happy.

      virtual recipe
      apply (action, target&) const override;

      group_rule (bool see_through_only): see_through (see_through_only) {}
      static const group_rule instance;

      bool see_through;
    };

    struct install_dir;

    class file_rule: public rule
    {
    public:
      virtual bool
      match (action, target&, const string&) const override;

      // Return NULL if this prerequisite should be ignored and pointer to its
      // target otherwise. The default implementation ignores prerequsites
      // that are outside of this target's project.
      //
      // The prerequisite it passed as an iterator allowing the filter to
      // "see" inside groups.
      //
      using prerequisite_iterator =
        prerequisite_members_range<group_prerequisites>::iterator;

      virtual const target*
      filter (action, const target&, prerequisite_iterator&) const;

      virtual const target*
      filter (action, const target&, const prerequisite&) const;

      virtual recipe
      apply (action, target&) const override;

      static target_state
      perform_update (action, const target&);

      // Extra un/installation hooks. Return true if anything was actually
      // un/installed.
      //
      using install_dir = install::install_dir; // For derived rules.

      virtual bool
      install_extra (const file&, const install_dir&) const;

      virtual bool
      uninstall_extra (const file&, const install_dir&) const;

      // Lower-level pre/post installation hooks that can be used to override
      // the source file path being installed (for example, to implement
      // post-processing, etc).
      //
      // Note that one cannot generally perform post-processing in-place
      // because of permissions.
      //
      virtual auto_rmfile
      install_pre (const file&, const install_dir&) const;

      virtual bool
      install_post (const file&, const install_dir&, auto_rmfile&&) const;

      // Installation/uninstallation "commands".
      //
      // If verbose is false, then only print the command at verbosity level 2
      // or higher.

      // Install a symlink: base/link -> target.
      //
      static void
      install_l (const scope& rs,
                 const install_dir& base,
                 const path& target,
                 const path& link,
                 bool verbose);

      // Uninstall a file or symlink:
      //
      // uninstall <target> <base>/  rm <base>/<target>.leaf (); name empty
      // uninstall <target> <name>   rm <base>/<name>; target can be NULL
      //
      // Return false if nothing has been removed (i.e., the file does not
      // exist).
      //
      static bool
      uninstall_f (const scope& rs,
                   const install_dir& base,
                   const file* target,
                   const path& name,
                   bool verbose);

      target_state
      perform_install (action, const target&) const;

      target_state
      perform_uninstall (action, const target&) const;

      static const file_rule instance;
      file_rule () {}
    };
  }
}

#endif // BUILD2_INSTALL_RULE_HXX