aboutsummaryrefslogtreecommitdiff
path: root/libbrep/package.cxx
blob: 7d944220bd9f655767255f90293b6ce376ef44a3 (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
// file      : libbrep/package.cxx -*- C++ -*-
// copyright : Copyright (c) 2014-2018 Code Synthesis Ltd
// 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
  //
  package_name dependency::
  name () const
  {
    return package.object_id ().name;
  }

  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);
  }

  // package
  //
  package::
  package (package_name nm,
           version_type vr,
           priority_type pr,
           string sm,
           license_alternatives_type la,
           strings tg,
           optional<string> ds,
           string ch,
           url_type ur,
           optional<url_type> du,
           optional<url_type> su,
           optional<url_type> pu,
           email_type em,
           optional<email_type> pe,
           optional<email_type> be,
           dependencies_type dp,
           requirements_type rq,
           build_constraints_type bc,
           optional<path> lc,
           optional<string> sh,
           shared_ptr<repository_type> rp)
      : id (move (nm), vr),
        version (move (vr)),
        priority (move (pr)),
        summary (move (sm)),
        license_alternatives (move (la)),
        tags (move (tg)),
        description (move (ds)),
        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)),
        dependencies (move (dp)),
        requirements (move (rq)),
        build_constraints (
          version.compare (wildcard_version, true) != 0
          ? move (bc)
          : build_constraints_type ()),
        internal_repository (move (rp)),
        location (move (lc)),
        sha256sum (move (sh))
  {
    assert (internal_repository->internal);
  }

  package::
  package (package_name nm,
           version_type vr,
           shared_ptr<repository_type> rp)
      : id (move (nm), vr),
        version (move (vr))
  {
    assert (!rp->internal);
    other_repositories.emplace_back (move (rp));
  }

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

    // Derive keywords from the basic package information: name,
    // 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 (id.name.string () + " " + version.string () + " " +
              version.string (true));

    // Add tags to keywords.
    //
    for (const auto& t: tags)
      k += " " + t;

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

        // If license is say LGPLv2 then LGPL is also a 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);
      }
    }

    return {move (k), summary, description ? *description : "", changes};
  }

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

  repository::
  repository (repository_location l)
      : name (l.canonical_name ()),
        location (move (l)),
        priority (0),
        internal (false)
  {
  }
}