/
conftest.py
293 lines (265 loc) · 9.47 KB
/
conftest.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
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
import os
import platform
import uuid
import pytest
from conans.client.tools import vswhere, which
"""
To override these locations with your own in your dev machine:
1. Create a conftest_user.py just besides this conftest.py file
2. This file is .gitignored, it will not be committed
3. Override the tools_locations, you can completely disabled some tools, tests will be skipped
4. Empty dicts, without specifying the path, means the tool is already in the system
path
tools_locations = {
'svn': {"disabled": True},
'cmake': {
"default": "3.19",
"3.15": {},
"3.16": {"disabled": True},
"3.17": {"disabled": True},
"3.19": {"path": {"Windows": "C:/ws/cmake/cmake-3.19.7-win64-x64/bin"}},
},
'ninja': {
"1.10.2": {}
},
'meson': {"disabled": True},
'bazel': {
"system": {"path": {'Windows': 'C:/ws/bazel/4.2.0'}},
}
}
"""
tools_locations = {
"clang": {"disabled": True},
'visual_studio': {"default": "15",
"15": {},
"16": {"disabled": True},
"17": {"disabled": True}},
'pkg_config': {
"exe": "pkg-config",
"default": "0.28",
"0.28": {
"path": {
# Using chocolatey in Windows -> choco install pkgconfiglite --version 0.28
'Windows': "C:/ProgramData/chocolatey/lib/pkgconfiglite/tools/pkg-config-lite-0.28-1/bin"
}
}},
'autotools': {"exe": "autoconf"},
'cmake': {
"default": "3.15",
"3.15": {
"path": {'Windows': 'C:/cmake/cmake-3.15.7-win64-x64/bin',
'Darwin': '/Users/jenkins/cmake/cmake-3.15.7/bin',
'Linux': '/usr/share/cmake-3.15.7/bin'}
},
"3.16": {
"path": {'Windows': 'C:/cmake/cmake-3.16.9-win64-x64/bin',
'Darwin': '/Users/jenkins/cmake/cmake-3.16.9/bin',
'Linux': '/usr/share/cmake-3.16.9/bin'}
},
"3.17": {
"path": {'Windows': 'C:/cmake/cmake-3.17.5-win64-x64/bin',
'Darwin': '/Users/jenkins/cmake/cmake-3.17.5/bin',
'Linux': '/usr/share/cmake-3.17.5/bin'}
},
"3.19": {
"path": {'Windows': 'C:/cmake/cmake-3.19.7-win64-x64/bin',
'Darwin': '/Users/jenkins/cmake/cmake-3.19.7/bin',
'Linux': '/usr/share/cmake-3.19.7/bin'}
},
"3.23": {
"path": {'Windows': 'C:/cmake/cmake-3.23.1-win64-x64/bin',
'Darwin': '/Users/jenkins/cmake/cmake-3.23.1/bin',
# Not available in Linux
'Linux': None}
}
},
'ninja': {
"default": "1.10.2",
"1.10.2": {
"path": {'Windows': 'C:/Tools/ninja/1.10.2'}
}
},
'mingw32': {
"platform": "Windows",
"default": "system",
"exe": "mingw32-make",
"system": {"path": {'Windows': "C:/msys64/mingw32/bin"}},
},
'ucrt64': {
"disabled": True,
"platform": "Windows",
"default": "system",
"exe": "mingw32-make",
"system": {"path": {'Windows': "C:/msys64/ucrt64/bin"}},
},
'mingw64': {
"platform": "Windows",
"default": "system",
"exe": "mingw32-make",
"system": {"path": {'Windows': "C:/msys64/mingw64/bin"}},
},
'msys2': {
"platform": "Windows",
"default": "system",
"exe": "make",
"system": {"path": {'Windows': "C:/msys64/usr/bin"}},
},
'msys2_clang64': {
"disabled": True,
"platform": "Windows",
"default": "system",
"exe": "mingw32-make",
"system": {"path": {'Windows': "C:/msys64/clang64/bin"}},
},
'msys2_mingw64_clang64': {
"disabled": True,
"platform": "Windows",
"default": "system",
"exe": "mingw32-make",
"system": {"path": {'Windows': "C:/msys64/mingw64/bin"}},
},
'cygwin': {
"platform": "Windows",
"default": "system",
"exe": "make",
"system": {"path": {'Windows': "C:/cygwin64/bin"}},
},
'bazel': {
"default": "system",
"system": {"path": {'Windows': 'C:/bazel/bin',
"Darwin": '/Users/jenkins/bin'}},
},
'premake': {
"exe": "premake5",
"default": "5.0.0",
"5.0.0": {
"path": {'Linux': '/usr/local/bin/premake5'}
}
},
'premake': {},
'xcodegen': {"platform": "Darwin"},
'apt_get': {"exe": "apt-get"},
'brew': {},
'android_ndk': {
"platform": "Darwin",
"exe": "ndk-build",
},
# TODO: Intel oneAPI is not installed in CI yet. Uncomment this line whenever it's done.
# "intel_oneapi": {
# "default": "2021.3",
# "exe": "dpcpp",
# "2021.3": {"path": {"Linux": "/opt/intel/oneapi/compiler/2021.3.0/linux/bin"}}
# }
}
try:
from conans.test.conftest_user import tools_locations as user_tool_locations
def update(d, u):
for k, v in u.items():
if isinstance(v, dict):
d[k] = update(d.get(k, {}), v)
else:
d[k] = v
return d
update(tools_locations, user_tool_locations)
except ImportError as e:
user_tool_locations = None
tools_environments = {
'mingw32': {'Windows': {'MSYSTEM': 'MINGW32'}},
'mingw64': {'Windows': {'MSYSTEM': 'MINGW64'}},
'ucrt64': {'Windows': {'MSYSTEM': 'UCRT64'}},
'msys2_clang64': {"Windows": {"MSYSTEM": "CLANG64"}},
'android_ndk': {'Darwin': {'TEST_CONAN_ANDROID_NDK': '/usr/local/share/android-ndk'}}
}
_cached_tools = {}
def _get_tool(name, version):
# None: not cached yet
# False = tool not available, legally skipped
# True = tool not available, test error
# (path, env) = tool available
cached = _cached_tools.setdefault(name, {}).get(version)
if cached is not None:
return cached
result = _get_individual_tool(name, version)
_cached_tools[name][version] = result
return result
def _get_individual_tool(name, version):
tool = tools_locations.get(name, {})
if tool.get("disabled"):
return False
tool_platform = platform.system()
if tool.get("platform", tool_platform) != tool_platform:
return None, None
version = version or tool.get("default")
tool_version = tool.get(version)
if tool_version is not None:
assert isinstance(tool_version, dict)
if tool_version.get("disabled"):
return False
if name == "visual_studio":
if vswhere(): # TODO: Missing version detection
return None, None
tool_path = tool_version.get("path", {}).get(tool_platform)
# To allow to skip for a platform, we can put the path to None
# "cmake": { "3.23": {
# "path": {'Windows': 'C:/cmake/cmake-3.23.1-win64-x64/bin',
# 'Darwin': '/Users/jenkins/cmake/cmake-3.23.1/bin',
# 'Linux': None}}
# }
if tool_path is None:
return False
else:
if version is not None: # if the version is specified, it should be in the conf
return True
tool_path = None
try:
tool_env = tools_environments[name][tool_platform]
except KeyError:
tool_env = None
cached = tool_path, tool_env
# Check this particular tool is installed
old_environ = None
if tool_path is not None:
old_environ = dict(os.environ)
os.environ["PATH"] = tool_path + os.pathsep + os.environ["PATH"]
exe = tool.get("exe", name)
exe_found = which(exe) # TODO: This which doesn't detect version either
if not exe_found:
cached = True
if old_environ is not None:
os.environ.clear()
os.environ.update(old_environ)
return cached
@pytest.fixture(autouse=True)
def add_tool(request):
tools_paths = []
tools_env_vars = dict()
for mark in request.node.iter_markers():
if mark.name.startswith("tool_"):
tool_name = mark.name[5:]
tool_version = mark.kwargs.get('version')
result = _get_tool(tool_name, tool_version)
if result is True:
version_msg = "Any" if tool_version is None else tool_version
pytest.fail("Required '{}' tool version '{}' is not available".format(tool_name,
version_msg))
if result is False:
version_msg = "Any" if tool_version is None else tool_version
pytest.skip("Required '{}' tool version '{}' is not available".format(tool_name,
version_msg))
tool_path, tool_env = result
if tool_path:
tools_paths.append(tool_path)
if tool_env:
tools_env_vars.update(tool_env)
# Fix random failures CI because of this: https://issues.jenkins.io/browse/JENKINS-9104
if tool_name == "visual_studio":
tools_env_vars['_MSPDBSRV_ENDPOINT_'] = str(uuid.uuid4())
if tools_paths or tools_env_vars:
old_environ = dict(os.environ)
tools_env_vars['PATH'] = os.pathsep.join(tools_paths + [os.environ["PATH"]])
os.environ.update(tools_env_vars)
yield
os.environ.clear()
os.environ.update(old_environ)
else:
yield