aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/adhoc-rule-buildscript.hxx
blob: 02939c18f59f0f80253ba0d8f198eebca87f83d8 (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
// file      : libbuild2/adhoc-rule-buildscript.hxx -*- C++ -*-
// license   : MIT; see accompanying LICENSE file

#ifndef LIBBUILD2_ADHOC_RULE_BUILDSCRIPT_HXX
#define LIBBUILD2_ADHOC_RULE_BUILDSCRIPT_HXX

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

#include <libbuild2/rule.hxx>

#include <libbuild2/build/script/script.hxx>

namespace build2
{
  // Ad hoc buildscript rule.
  //
  // Note: not exported and should not be used directly (i.e., registered).
  //
  class adhoc_buildscript_rule: public adhoc_rule,
                                public adhoc_rule_with_deadline
  {
  public:
    virtual bool
    reverse_fallback (action, const target_type&) const override;

    virtual bool
    match (action, target&, const string&, match_extra&) const override;

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

    virtual recipe
    apply (action, target&, match_extra&,
           const optional<timestamp>&) const override;

    target_state
    perform_update_file (action, const target&) const;

    struct match_data;
    struct match_data_byproduct;

    target_state
    perform_update_file_dyndep (action, const target&, match_data&) const;

    target_state
    perform_update_file_dyndep_byproduct (
      action, const target&, match_data_byproduct&) const;

    optional<target_state>
    execute_update_prerequisites (action, const target&, timestamp) const;

    bool
    execute_update_file (const scope&,
                         action a, const file&,
                         build::script::environment&,
                         build::script::default_runner&,
                         bool deferred_failure = false) const;

    static target_state
    perform_clean_file (action, const target&);

    target_state
    default_action (action, const target&, const optional<timestamp>&) const;

    adhoc_buildscript_rule (string n, const location& l, size_t b)
        : adhoc_rule (move (n), l, b) {}

    virtual bool
    recipe_text (const scope&,
                 const target_type&,
                 string&&,
                 attributes&) override;

    virtual void
    dump_attributes (ostream&) const override;

    virtual void
    dump_text (ostream&, string&) const override;

    void
    print_custom_diag (const scope&, names&&, const location&) const;

  public:
    using script_type = build::script::script;

    // The prerequisite_target::include bit that indicates update=unmatch.
    //
    static const uintptr_t include_unmatch = 0x100;

    script_type        script;
    string             checksum; // Script text hash.
    const target_type* ttype;    // First target/pattern type.
  };
}

#endif // LIBBUILD2_ADHOC_RULE_BUILDSCRIPT_HXX