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

#include <build/test/module>

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

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

using namespace std;
using namespace butl;

namespace build
{
  namespace test
  {
    class module: public build::module
    {
    public:
      module (operation_id test_id): rule (test_id) {}

      test::rule rule;
    };

    extern "C" void
    test_init (scope& root,
               scope& base,
               const location& l,
               unique_ptr<build::module>& r,
               bool first)
    {
      tracer trace ("test::init");

      if (&root != &base)
        fail (l) << "test module must be initialized in bootstrap.build";

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

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

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

      unique_ptr<module> m (new module (test_id));

      {
        auto& rs (base.rules);

        // Register the standard alias rule for the test operation.
        //
        rs.insert<alias> (test_id, "alias", alias_rule::instance);

        // Register our test running rule.
        //
        rs.insert<target> (test_id, "test", m->rule);
      }

      r = move (m);
    }
  }
}