aboutsummaryrefslogtreecommitdiff
path: root/bbot/machine-manifest.hxx
blob: d5009576f82f93eebbbe5b786fd7e9842717f070 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// file      : bbot/machine-manifest.hxx -*- C++ -*-
// license   : MIT; see accompanying LICENSE file

#ifndef BBOT_MACHINE_MANIFEST_HXX
#define BBOT_MACHINE_MANIFEST_HXX

#include <map>

#include <libbutl/manifest-forward.hxx>

#include <libbbot/manifest.hxx> // machine_header

#include <bbot/types.hxx>
#include <bbot/utility.hxx>

#include <bbot/bootstrap-manifest.hxx>

namespace bbot
{
  // Machine type.
  //
  enum class machine_type {kvm, nspawn};

  string
  to_string (machine_type);

  machine_type
  to_machine_type (const string&); // Throws invalid_argument.

  // Machine.
  //
  class machine_manifest: public machine_header_manifest
  {
  public:
    machine_type type;
    optional<string> mac;      // Required in bootstrapped machine manifest.
    optional<strings> options; // Note: could be quoted.
    strings changes;

    strings
    unquoted_options () const; // Return empty if absent.

    machine_manifest (std::string i,
                      std::string n,
                      std::string s,
                      machine_type t,
                      optional<string> m,
                      optional<strings> o,
                      strings c)
        : machine_header_manifest (std::move (i),
                                   std::move (n),
                                   std::move (s),
                                   //
                                   // @@ TMP AUXILIARY
                                   //
                                   nullopt /* role */,
                                   nullopt /* ram_minimum */,
                                   nullopt /* ram_maximum */),
          type (t),
          mac (std::move (m)),
          options (std::move (o)),
          changes (std::move (c)) {}

  public:
    machine_manifest () = default;
    machine_manifest (butl::manifest_parser&, bool ignore_unknown = false);
    machine_manifest (butl::manifest_parser&,
                      butl::manifest_name_value start,
                      bool ignore_unknown = false);

    void
    serialize (butl::manifest_serializer&) const;
  };

  // Toolchain.
  //
  class toolchain_manifest
  {
  public:

    // Toolchain id (SHAXXX).
    //
    string id;

    explicit
    toolchain_manifest (string i): id (i) {}

  public:
    toolchain_manifest () = default;
    toolchain_manifest (butl::manifest_parser&, bool ignore_unknown = false);
    toolchain_manifest (butl::manifest_parser&,
                        butl::manifest_name_value start,
                        bool ignore_unknown = false);

    void
    serialize (butl::manifest_serializer&) const;
  };

  // The manifest stored in <name>-<toolchain>/ consists of the machine
  // manifest (original) and, if this a build machine, toolchain manifest and
  // bootstrap manifest.
  //
  class bootstrapped_machine_manifest
  {
  public:
    machine_manifest   machine;
    toolchain_manifest toolchain;
    bootstrap_manifest bootstrap;

    bootstrapped_machine_manifest (machine_manifest m,
                                   toolchain_manifest t,
                                   bootstrap_manifest b)
        : machine (move (m)), toolchain (move (t)), bootstrap (move (b)) {}

  public:
    bootstrapped_machine_manifest () = default;
    bootstrapped_machine_manifest (butl::manifest_parser&,
                                   bool ignore_unknown = false);

    void
    serialize (butl::manifest_serializer&) const;
  };
}

#endif // BBOT_MACHINE_MANIFEST_HXX