aboutsummaryrefslogtreecommitdiff
path: root/build/module.cxx
blob: 5f1aeff89cc482a5e0db5111ea2a08d35bd1a39d (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
// 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/variable>
#include <build/diagnostics>

using namespace std;

namespace build
{
  available_module_map builtin_modules;

  bool
  load_module (bool opt,
               const string& name,
               scope& rs,
               scope& bs,
               const location& loc)
  {
    // First see if this modules has already been loaded for this project.
    //
    loaded_module_map& lm (rs.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 ())
      {
        if (!opt)
          fail (loc) << "unknown module " << name;
      }
      else
        i = lm.emplace (name, make_pair (j->second, nullptr)).first;
    }

    bool l (i != lm.end ());
    bool c (l && i->second.first (rs, bs, loc, i->second.second, f, opt));

    const variable& lv (var_pool.find (name + ".loaded",
                                       variable_visibility::project,
                                       bool_type));
    const variable& cv (var_pool.find (name + ".configured",
                                       variable_visibility::project,
                                       bool_type));
    bs.assign (lv) = l;
    bs.assign (cv) = c;

    return l && c;
  }
}