aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/recipe.hxx
blob: 4c903b51b397744bb4ab1348b15ca99e0ac3e12d (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
// file      : libbuild2/recipe.hxx -*- C++ -*-
// license   : MIT; see accompanying LICENSE file

#ifndef LIBBUILD2_RECIPE_HXX
#define LIBBUILD2_RECIPE_HXX

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

#include <libbuild2/action.hxx>
#include <libbuild2/target-state.hxx>

#include <libbuild2/export.hxx>

namespace build2
{
  // The returned target state is normally changed or unchanged. If there is
  // an error, then the recipe should throw failed rather than returning (this
  // is the only exception that a recipe can throw).
  //
  // The return value of the recipe is used to update the target state. If it
  // is target_state::group then the target's state is the group's state.
  //
  // The recipe may also return postponed in which case the target state is
  // assumed to be unchanged (normally this means a prerequisite was postponed
  // and while the prerequisite will be re-examined via another dependency,
  // this target is done).
  //
  // Note that max size for the "small capture optimization" in std::function
  // ranges (in pointer sizes) from 0 (GCC prior to 5) to 2 (GCC 5) to 6 (VC
  // 14.2). With the size ranging (in bytes for 64-bit target) from 32 (GCC)
  // to 64 (VC).
  //
  using recipe_function = target_state (action, const target&);
  using recipe = function<recipe_function>;

  // Commonly-used recipes.
  //
  // The default recipe executes the action on all the prerequisites in a
  // loop, skipping ignored. Specifically, for actions with the "first"
  // execution mode, it calls execute_prerequisites() while for those with
  // "last" -- reverse_execute_prerequisites() (see <libbuild2/operation.hxx>,
  // <libbuild2/algorithm.hxx> for details). The group recipe calls the
  // group's recipe.
  //
  LIBBUILD2_SYMEXPORT extern const recipe empty_recipe;
  LIBBUILD2_SYMEXPORT extern const recipe noop_recipe;
  LIBBUILD2_SYMEXPORT extern const recipe default_recipe;
  LIBBUILD2_SYMEXPORT extern const recipe group_recipe;

  // Ad hoc recipe.
  //
  struct adhoc_recipe
  {
    using action_type = build2::action;
    using location_type = build2::location;

    action_type      action;
    string           script;
    optional<string> diag;   // Command name for low-verbosity diagnostics.

    // Diagnostics-related information.
    //
    path_name_value file;    // Buildfile of recipe.
    location_type location;  // Buildfile location of recipe.
    size_t braces;           // Number of braces in multi-brace tokens.

    adhoc_recipe (action_type a,
                  string s,
                  optional<string> d,
                  const location_type& l, size_t b)
        : action (a),
          script (move (s)),
          diag (move (d)),
          file (l.file), location (file, l.line, l.column), braces (b) {}
  };
}

#endif // LIBBUILD2_RECIPE_HXX