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

#include <build/module>

#include <utility> // make_pair()

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

using namespace std;

namespace build
{
  available_module_map builtin_modules;

  void
  load_module (const string& name, scope& root, scope& base, const location& l)
  {
    // First see if this modules has already been loaded for this
    // project.
    //
    loaded_module_map& lm (root.modules);
    auto i (lm.find (name));
    bool f (i == lm.end ());

    if (f)
    {
      // Otherwise search for this module.
      //
      auto j (builtin_modules.find (name));

      if (j == builtin_modules.end ())
        fail (l) << "unknown module " << name;

      i = lm.emplace (name, make_pair (j->second, nullptr)).first;
    }

    i->second.first (root, base, l, i->second.second, f);
  }
}