aboutsummaryrefslogtreecommitdiff
path: root/bbot/manifest
blob: c95e83cef62d860b24b4d239db5f8e91c1e07358 (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// file      : bbot/manifest -*- C++ -*-
// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
// license   : MIT; see accompanying LICENSE file

#ifndef BBOT_MANIFEST
#define BBOT_MANIFEST

#include <string>
#include <vector>
#include <iosfwd>

#include <butl/optional>
#include <butl/small-vector>
#include <butl/target-triplet>
#include <butl/manifest-forward>

#include <bpkg/manifest> // version, repository_location

#include <bbot/export>

#include <bbot/variable>

namespace bbot
{
  enum class machine_type {kvm, nspawn};

  class LIBBBOT_EXPORT machine_manifest
  {
  public:
    std::string id;
    std::string name;

    // Absent if inside task_request_manifest.
    //
    butl::optional<machine_type> type;

    std::string summary;

  public:
    machine_manifest () = default; // VC export.
    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;

  private:
    machine_manifest (butl::manifest_parser&,
                      butl::manifest_name_value start,
                      bool in_list,
                      bool ignore_unknown);
  };

  class LIBBBOT_EXPORT task_request_manifest
  {
  public:
    std::string agent;

    // Agent's public key SHA256 fingerprint.
    //
    // @@ How the fingerpring for openssl public key will be produced? Seems
    //    there is no "standard" for it. Possibly we will use the following
    //    command result (plain SHA256).
    //
    //    $ cat key.pub | openssl sha256
    //
    std::string fingerprint;

    std::vector<machine_manifest> machines;

  public:
    task_request_manifest () = default; // VC export.
    task_request_manifest (butl::manifest_parser&,
                           bool ignore_unknown = false);

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

  class LIBBBOT_EXPORT task_manifest
  {
  public:
    // Package to build.
    //
    std::string name;
    bpkg::version version;
    bpkg::repository_location repository; // Remote or absolute.

    // Build machine to use for building the package.
    //
    std::string machine;

    // Default for the machine if absent.
    //
    butl::optional<butl::target_triplet> target;

    // Build system configuration variables (in addition to build environment
    // configuration variables).
    //
    variables config;

  public:
    task_manifest () = default; // VC export.
    task_manifest (butl::manifest_parser&, bool ignore_unknown = false);
    task_manifest (butl::manifest_parser&,
                   butl::manifest_name_value start,
                   bool ignore_unknown = false);

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

  class LIBBBOT_EXPORT task_response_manifest
  {
  public:
    // If empty then no task available.
    //
    std::string session;

    // Challenge and task are absent if session is empty.
    //
    butl::optional<std::string> challenge;
    butl::optional<task_manifest> task;

  public:
    task_response_manifest () = default; // VC export.
    task_response_manifest (butl::manifest_parser&,
                            bool ignore_unknown = false);

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

  // Build task or operation result status.
  //
  enum class result_status: std::uint8_t
  {
    // The order of the enumerators is arranged so that their integral values
    // indicate whether one "overrides" the other in the "merge" operator|
    // (see below).
    //
    success,
    warning,
    error,
    abort,
    abnormal
  };

  std::ostream&
  operator<< (std::ostream&, result_status);

  inline result_status&
  operator |= (result_status& l, result_status r)
  {
    if (static_cast<std::uint8_t> (r) > static_cast<std::uint8_t> (l))
      l = r;
    return l;
  }

  struct operation_result
  {
    std::string operation; // "configure", "update", "test", etc.
    result_status status;
    std::string log;
  };

  using operation_results = butl::small_vector<operation_result, 3>;

  class LIBBBOT_EXPORT result_manifest
  {
  public:
    // Built package.
    //
    std::string name;
    bpkg::version version;

    result_status status;

    // Ordered (ascending) by operation value. May not contain all the
    // operations if the task failed in the middle, but should have no gaps
    // (operation can not start unless all previous ones succeeded).
    //
    operation_results results;

    result_manifest () = default; // VC export.
    result_manifest (butl::manifest_parser&, bool ignore_unknown = false);
    result_manifest (butl::manifest_parser&,
                     butl::manifest_name_value start,
                     bool ignore_unknown = false);

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

  class LIBBBOT_EXPORT result_request_manifest
  {
  public:
    std::string session;   // The task response session.
    std::string challenge; // The answer to challenge in the task response.

    result_manifest result;

  public:
    result_request_manifest () = default; // VC export.
    result_request_manifest (butl::manifest_parser&,
                             bool ignore_unknown = false);

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

#endif // BBOT_MANIFEST