aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/config/module.cxx
blob: 176eef008ad700ce6f055e9c0d2614c9481d048a (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
// file      : libbuild2/config/module.cxx -*- C++ -*-
// license   : MIT; see accompanying LICENSE file

#include <libbuild2/config/module.hxx>

using namespace std;

namespace build2
{
  namespace config
  {
    bool module::
    save_variable (const variable& var, uint64_t flags)
    {
      const string& n (var.name);

      // First try to find the module with the name that is the longest
      // prefix of this variable name.
      //
      auto& sm (saved_modules);
      auto i (sm.find_sup (n));

      // If no module matched, then create one based on the variable name.
      //
      if (i == sm.end ())
      {
        // Note: with 'config.' prefix.
        //
        i = sm.insert (string (n, 0, n.find ('.', 7))).first;
      }

      // Don't insert duplicates. The config.import.* vars are particularly
      // susceptible to duplication.
      //
      saved_variables& sv (i->second);
      auto j (sv.find (var));

      if (j != sv.end ())
      {
        assert (j->flags == flags);
        return false;
      }

      sv.push_back (saved_variable {var, flags});
      return true;
    }

    bool module::
    save_module (const char* name, int prio)
    {
      return saved_modules.insert (string ("config.") += name, prio).second;
    }

    const string module::name ("config");
    const uint64_t module::version (1);
  }
}