aboutsummaryrefslogtreecommitdiff
path: root/build2/test/init.cxx
blob: bd03f0065d583bb8a41bc1ac03e4ff4b2ad93b81 (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
// file      : build2/test/init.cxx -*- C++ -*-
// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
// license   : MIT; see accompanying LICENSE file

#include <build2/test/init>

#include <build2/scope>
#include <build2/target>
#include <build2/rule>
#include <build2/diagnostics>

#include <build2/test/operation>
#include <build2/test/rule>

using namespace std;
using namespace butl;

namespace build2
{
  namespace test
  {
    static rule rule_;

    void
    boot (scope& root, const location&, unique_ptr<module_base>&)
    {
      tracer trace ("test::boot");

      l5 ([&]{trace << "for " << root.out_path ();});

      // Register the test operation.
      //
      root.operations.insert (test_id, test);

      // Enter module variables. Do it during boot in case they get assigned
      // in bootstrap.build.
      //
      {
        auto& v (var_pool);

        // Note: none are overridable.
        //
        v.insert<bool>    ("test");
        v.insert<name>    ("test.input");
        v.insert<name>    ("test.output");
        v.insert<name>    ("test.roundtrip");
        v.insert<strings> ("test.options");
        v.insert<strings> ("test.arguments");
      }
    }

    bool
    init (scope& root,
          scope&,
          const location& l,
          unique_ptr<module_base>&,
          bool first,
          bool,
          const variable_map& config_hints)
    {
      tracer trace ("test::init");

      if (!first)
      {
        warn (l) << "multiple test module initializations";
        return true;
      }

      const dir_path& out_root (root.out_path ());
      l5 ([&]{trace << "for " << out_root;});

      assert (config_hints.empty ()); // We don't known any hints.

      //@@ TODO: Need ability to specify extra diff options (e.g.,
      //   --strip-trailing-cr, now hardcoded).

      // Adjust module priority so that the config.test.* values are saved at
      // the end of config.build.
      //
      // if (s)
      //   config::save_module (r, "test", INT32_MAX);

      // Register rules.
      //
      {
        auto& r (root.rules);

        // Register our test running rule.
        //
        r.insert<target> (perform_test_id, "test", rule_);

        // Register our rule for the dist meta-operation. We need
        // to do this because we have "ad-hoc prerequisites" (test
        // input/output files) that need to be entered into the
        // target list.
        //
        r.insert<target> (dist_id, test_id, "test", rule_);
      }

      return true;
    }
  }
}