aboutsummaryrefslogtreecommitdiff
path: root/libbrep/package.cxx
blob: 4eb6fe82289df71f6cfad70c18887c31f48dc52b (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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
// file      : libbrep/package.cxx -*- C++ -*-
// license   : MIT; see accompanying LICENSE file

#include <libbrep/package.hxx>

#include <odb/database.hxx>

#include <libbrep/package-odb.hxx>

using namespace std;
using namespace odb::core;

namespace brep
{
  // dependency
  //
  ostream&
  operator<< (ostream& o, const dependency& d)
  {
    o << d.name;

    if (d.constraint)
      o << ' ' << *d.constraint;

    return o;
  }

  bool
  operator== (const dependency& x, const dependency& y)
  {
    return x.name == y.name && x.constraint == y.constraint;
  }

  bool
  operator!= (const dependency& x, const dependency& y)
  {
    return !(x == y);
  }

  // tenant
  //
  tenant::
  tenant (string i,
          bool p,
          optional<string> r,
          optional<tenant_service> s)
      : id (move (i)),
        private_ (p),
        interactive (move (r)),
        creation_timestamp (timestamp::clock::now ()),
        service (move (s))
  {
  }

  // package
  //
  package::
  package (package_name nm,
           version_type vr,
           optional<string> uv,
           package_name pn,
           priority_type pr,
           string sm,
           license_alternatives_type la,
           small_vector<string, 5> tp,
           small_vector<string, 5> kw,
           optional<typed_text> ds,
           optional<typed_text> pds,
           optional<typed_text> ch,
           optional<manifest_url> ur,
           optional<manifest_url> du,
           optional<manifest_url> su,
           optional<manifest_url> pu,
           optional<email_type> em,
           optional<email_type> pe,
           optional<email_type> be,
           optional<email_type> bwe,
           optional<email_type> bee,
           dependencies_type dp,
           requirements_type rq,
           small_vector<test_dependency, 1> ts,
           build_class_exprs bs,
           build_constraints_type bc,
           build_auxiliaries_type ac,
           package_build_bot_keys bk,
           package_build_configs bcs,
           optional<path> lc,
           optional<string> fr,
           optional<string> sh,
           shared_ptr<repository_type> rp)
      : id (rp->tenant, move (nm), vr),
        tenant (id.tenant),
        name (id.name),
        version (move (vr)),
        upstream_version (move (uv)),
        project (move (pn)),
        priority (move (pr)),
        summary (move (sm)),
        license_alternatives (move (la)),
        topics (move (tp)),
        keywords (move (kw)),
        description (move (ds)),
        package_description (move (pds)),
        changes (move (ch)),
        url (move (ur)),
        doc_url (move (du)),
        src_url (move (su)),
        package_url (move (pu)),
        email (move (em)),
        package_email (move (pe)),
        build_email (move (be)),
        build_warning_email (move (bwe)),
        build_error_email (move (bee)),
        dependencies (move (dp)),
        requirements (move (rq)),
        tests (move (ts)),
        builds (move (bs)),
        build_constraints (move (bc)),
        build_auxiliaries (move (ac)),
        build_bot_keys (move (bk)),
        build_configs (move (bcs)),
        internal_repository (move (rp)),
        location (move (lc)),
        fragment (move (fr)),
        sha256sum (move (sh))
  {
    // The default configuration is always added by the package manifest
    // parser (see libbpkg/manifest.cxx for details).
    //
    assert (find ("default", build_configs) != nullptr);

    if (stub ())
      unbuildable_reason = brep::unbuildable_reason::stub;
    else if (!internal_repository->buildable)
      unbuildable_reason = brep::unbuildable_reason::unbuildable;

    buildable = !unbuildable_reason;

    // If the package is buildable deduce the custom_bot flag.
    //
    if (buildable)
    {
      for (const package_build_config& bc: build_configs)
      {
        bool custom (!bc.effective_bot_keys (build_bot_keys).empty ());

        if (!custom_bot)
        {
          custom_bot = custom;
        }
        //
        // If both the custom and default bots are used by the package, then
        // reset the custom_bot flag to nullopt and bail out from the build
        // package configurations loop.
        //
        else if (*custom_bot != custom)
        {
          custom_bot = nullopt;
          break;
        }
      }
    }

    assert (internal_repository->internal);
  }

  package::
  package (package_name nm,
           version_type vr,
           build_class_exprs bs,
           build_constraints_type bc,
           build_auxiliaries_type ac,
           package_build_configs bcs,
           shared_ptr<repository_type> rp)
      : id (rp->tenant, move (nm), vr),
        tenant (id.tenant),
        name (id.name),
        version (move (vr)),
        builds (move (bs)),
        build_constraints (move (bc)),
        build_auxiliaries (move (ac)),
        build_configs (move (bcs)),
        buildable (false),
        unbuildable_reason (stub ()
                            ? brep::unbuildable_reason::stub
                            : brep::unbuildable_reason::external)
  {
    // The default configuration is always added by the package manifest
    // parser (see libbpkg/manifest.cxx for details).
    //
    assert (find ("default", build_configs) != nullptr);

    assert (!rp->internal);
    other_repositories.emplace_back (move (rp));
  }

  weighted_text package::
  search_text () const
  {
    if (!internal ())
      return weighted_text ();

    // Derive search keywords from the basic package information: project,
    // name, and version.
    //
    //@@ What about 'stable' from cppget.org/stable? Add path of
    //   the repository to keywords? Or is it too "polluting" and
    //   we will handle it in some other way (e.g., by allowing
    //   the user to specify repo location in the drop-down box)?
    //   Probably drop-box would be better as also tells what are
    //   the available internal repositories.
    //
    string k (project.string () + ' ' + name.string () + ' ' +
              version.string () + ' ' + version.string (true));

    if (upstream_version)
      k += ' ' + *upstream_version;

    // Add licenses to search keywords.
    //
    for (const auto& la: license_alternatives)
    {
      for (const auto& l: la)
      {
        k += ' ' + l;

        // If license is say LGPLv2 then LGPL is also a search keyword.
        //
        size_t n (l.size ());
        if (n > 2 && l[n - 2] == 'v' && l[n - 1] >= '0' && l[n - 1] <= '9')
          k += ' ' + string (l, 0, n - 2);
      }
    }

    // Derive second-strongest search keywords from the package summary.
    //
    string k2 (summary);

    // Add topics to the second-strongest search keywords.
    //
    for (const auto& t: topics)
      k2 += ' ' + t;

    // Add keywords to the second-strongest search keywords.
    //
    for (const auto& k: keywords)
      k2 += ' ' + k;

    string d (description ? description->text : "");

    if (package_description)
    {
      if (description)
        d += ' ';

      d += package_description->text;
    }

    return {move (k), move (k2), move (d), changes ? changes->text : ""};
  }

  // repository
  //
  repository::
  repository (string t,
              repository_location l,
              string d,
              repository_location h,
              optional<certificate_type> c,
              bool b,
              uint16_t r)
      : id (move (t), l.canonical_name ()),
        tenant (id.tenant),
        canonical_name (id.canonical_name),
        location (move (l)),
        display_name (move (d)),
        priority (r),
        cache_location (move (h)),
        certificate (move (c)),
        internal (true),
        buildable (b)
  {
  }

  repository::
  repository (string t, repository_location l)
      : id (move (t), l.canonical_name ()),
        tenant (id.tenant),
        canonical_name (id.canonical_name),
        location (move (l)),
        priority (0),
        internal (false),
        buildable (false)
  {
  }
}