aboutsummaryrefslogtreecommitdiff
path: root/build/algorithm
blob: 2dc71648c6b72270840d66da11ef8294372751e1 (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
// file      : build/algorithm -*- C++ -*-
// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
// license   : MIT; see accompanying LICENSE file

#ifndef BUILD_ALGORITHM
#define BUILD_ALGORITHM

#include <string>

#include <build/types>
#include <build/target>
#include <build/operation>

namespace build
{
  class scope;
  class prerequisite;
  class prerequisite_key;

  // The default prerequisite search implementation. It first calls the
  // target-type-specific search function. If that doesn't yeld anything,
  // it creates a new target.
  //
  target&
  search (prerequisite&);

  // As above but specify the prerequisite to search as a key.
  //
  target&
  search (const prerequisite_key&);

  // As above but specify the prerequisite to search as individual
  // key components. Useful for searching for target group members
  // where we need to search for a different target type.
  //
  target&
  search (const target_type& type,
          const dir_path& dir,
          const std::string& name,
          const std::string* ext,
          scope* scope);

  // As above but specify the target type as template argument.
  //
  template <typename T>
  T&
  search (const dir_path& dir,
          const std::string& name,
          const std::string* ext,
          scope* scope);

  // Match a rule to the action/target with ambiguity detection.
  //
  void
  match (action, target&);

  // The default prerequisite search and match implementation. It calls
  // search() and then match() for each prerequisite in a loop. If this
  // target is a member of a group, then it first does this to the group's
  // prerequisites.
  //
  void
  search_and_match (action, target&);

  // As above but ignores (does not match) prerequisites that are not
  // in the same or a subdirectory of dir.
  //
  void
  search_and_match (action, target&, const dir_path& dir);

  // Inject dependency on the parent directory's fsdir{}, unless it is
  // the project's out_root (or is outside of any project; say, for
  // example, an install directory).
  //
  void
  inject_parent_fsdir (action, target&);

  // Execute the action on target, assuming a rule has been matched
  // and the recipe for this action has been set. This is the default
  // executor implementation.
  //
  target_state
  execute (action, target&);

  // The default prerequisite execute implementation. It calls execute()
  // on each non-ignored (non-NULL) prerequisite target in a loop. If this
  // target is a member of a group, then it first does this to the group's
  // prerequisites. Returns target_state::changed if any of them were
  // changed and target_state::unchanged otherwise. It treats targets
  // with postponed execution the same as ignored. Note that this
  // function can be used as a recipe.
  //
  target_state
  execute_prerequisites (action, target&);

  // As above but iterates over the prerequisites in reverse.
  //
  target_state
  reverse_execute_prerequisites (action, target&);

  // A version of the above that also determines whether the action
  // needs to be executed on the target based on the passed timestamp.
  //
  bool
  execute_prerequisites (action, target&, const timestamp&);

  // Another version of the above that does two extra things for the
  // caller: it determines whether the action needs to be executed on
  // the target based on the passed timestamp and, if so, finds a
  // prerequisite of the specified type (e.g., a source file). If
  // there are multiple prerequisites of this type, then the last
  // is returned.
  //
  template <typename T>
  T*
  execute_find_prerequisites (action, target&, const timestamp&);

  // Return noop_recipe instead of using this function directly.
  //
  target_state
  noop_action (action, target&);

  // Default action implementation which forwards to the prerequisites.
  // Use default_recipe instead of using this function directly.
  //
  target_state
  default_action (action, target&);

  // Standard perform(clean) action implementation for the file target
  // or derived.
  //
  target_state
  perform_clean (action, target&);
}

#include <build/algorithm.ixx>
#include <build/algorithm.txx>

#endif // BUILD_ALGORITHM