forked from conan-io/conan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_mode.py
86 lines (75 loc) · 3.21 KB
/
build_mode.py
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
import fnmatch
from conans.errors import ConanException
class BuildMode(object):
""" build_mode => ["*"] if user wrote "--build"
=> ["hello*", "bye*"] if user wrote "--build hello --build bye"
=> ["hello/0.1@foo/bar"] if user wrote "--build hello/0.1@foo/bar"
=> False if user wrote "never"
=> True if user wrote "missing"
=> "outdated" if user wrote "--build outdated"
"""
def __init__(self, params, output):
self._out = output
self.outdated = False
self.missing = False
self.never = False
self.cascade = False
self.patterns = []
self._unused_patterns = []
self.all = False
if params is None:
return
assert isinstance(params, list)
if len(params) == 0 or "*" in params or "" in params:
self.all = True
else:
for param in params:
if param == "outdated":
self.outdated = True
elif param == "missing":
self.missing = True
elif param == "never":
self.never = True
elif param == "cascade":
self.cascade = True
else:
# Remove the @ at the end, to match for "conan install pkg/0.1@ --build=pkg/0.1@"
clean_pattern = param[:-1] if param.endswith("@") else param
clean_pattern = clean_pattern.replace("@#", "#")
self.patterns.append(clean_pattern)
if self.never and (self.outdated or self.missing or self.patterns or self.cascade):
raise ConanException("--build=never not compatible with other options")
self._unused_patterns = list(self.patterns)
def forced(self, conan_file, ref, with_deps_to_build=False):
if self.never:
return False
if self.all:
return True
if conan_file.build_policy_always:
conan_file.output.info("Building package from source as defined by "
"build_policy='always'")
return True
if self.cascade and with_deps_to_build:
return True
# Patterns to match, if package matches pattern, build is forced
for pattern in self.patterns:
if (fnmatch.fnmatchcase(ref.name, pattern) or
fnmatch.fnmatchcase(repr(ref.copy_clear_rev()), pattern) or
fnmatch.fnmatchcase(repr(ref), pattern)):
try:
self._unused_patterns.remove(pattern)
except ValueError:
pass
return True
return False
def allowed(self, conan_file):
if self.missing or self.outdated:
return True
if conan_file.build_policy_missing:
conan_file.output.info("Building package from source as defined by "
"build_policy='missing'")
return True
return False
def report_matches(self):
for pattern in self._unused_patterns:
self._out.error("No package matching '%s' pattern" % pattern)