blob: 69d0eeab34747b9d8c181bbc2a26e98800eaaba0 (
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
|
// file : bpkg/satisfaction.cxx -*- C++ -*-
// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
// license : MIT; see accompanying LICENSE file
#include <bpkg/satisfaction>
#include <bpkg/package-odb>
#include <bpkg/diagnostics>
using namespace std;
using namespace butl;
namespace bpkg
{
bool
satisfies (const version& v, const dependency_constraint& c)
{
assert (!c.empty ());
bool s (true);
if (c.min_version)
s = c.min_open ? v > *c.min_version : v >= *c.min_version;
if (s && c.max_version)
s = c.max_open ? v < *c.max_version : v <= *c.max_version;
return s;
}
bool
satisfies (const dependency_constraint& l, const dependency_constraint& r)
{
assert (!l.empty () && !r.empty ());
bool s (false);
if (l.min_version)
{
if (r.min_version)
{
if (l.min_open)
// Doesn't matter if r is min_open or not.
//
s = *l.min_version >= *r.min_version;
else
s = r.min_open
? *l.min_version > *r.min_version
: *l.min_version >= *r.min_version;
}
else
s = true; // Doesn't matter what l.min_version is.
}
else
s = !r.min_version;
if (s)
{
if (l.max_version)
{
if (r.max_version)
{
if (l.max_open)
// Doesn't matter if r is max_open or not.
//
s = *l.max_version <= *r.max_version;
else
s = r.max_open
? *l.max_version < *r.max_version
: *l.max_version <= *r.max_version;
}
else
{
// Doesn't matter what l.max_version is, so leave s to be true.
}
}
else
s = !r.max_version;
}
return s;
}
}
|