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

#ifndef BUILD2_TEST_SCRIPT_BUILTIN
#define BUILD2_TEST_SCRIPT_BUILTIN

#include <map>

#include <build2/types>
#include <build2/utility>

namespace build2
{
  namespace test
  {
    namespace script
    {
      class scope;

      // Start builtin command. Throw system_error on failure.
      //
      // Note that unlike argc/argv, our args don't include the program name.
      //
      // Also note that the future object being returned doesn't block in dtor
      // until the builtin command terminates.
      //
      using builtin = future<uint8_t> (scope&,
                                       const strings& args,
                                       auto_fd in, auto_fd out, auto_fd err);

      class builtin_map: public std::map<string, builtin*>
      {
      public:
        using base = std::map<string, builtin*>;
        using base::base;

        // Return NULL if not a builtin.
        //
        builtin*
        find (const string& n) const
        {
          auto i (base::find (n));
          return i != end () ? i->second : nullptr;
        }
      };

      extern const builtin_map builtins;
    }
  }
}

#endif // BUILD2_TEST_SCRIPT_BUILTIN