forked from conan-io/conan
/
conftest.py
173 lines (148 loc) · 5.33 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
import os
import platform
import uuid
import pytest
from conans.client.tools import vswhere, which
from conans.errors import ConanException
tools_default_version = {
'cmake': '3.15',
'msys2': 'default',
'cygwin': 'default',
'mingw32': 'default',
'mingw64': 'default',
'ninja': '1.10.2',
'bazel': 'default'
}
tools_locations = {
'msys2': {'Windows': {'default': os.getenv('CONAN_MSYS2_PATH', 'C:/msys64/usr/bin')}},
'cygwin': {'Windows': {'default': os.getenv('CONAN_CYGWIN_PATH', 'C:/cygwin64/bin')}},
'mingw32': {'Windows': {'default': os.getenv('CONAN_MINGW32_PATH', 'C:/msys64/mingw32/bin')}},
'mingw64': {'Windows': {'default': os.getenv('CONAN_MINGW64_PATH', 'C:/msys64/mingw64/bin')}},
'cmake': {
'Windows': {
'3.15': 'C:/cmake/cmake-3.15.7-win64-x64/bin',
'3.16': 'C:/cmake/cmake-3.16.9-win64-x64/bin',
'3.17': 'C:/cmake/cmake-3.17.5-win64-x64/bin',
'3.19': 'C:/cmake/cmake-3.19.7-win64-x64/bin'
},
'Darwin': {
'3.15': '/Users/jenkins/cmake/cmake-3.15.7/bin',
'3.16': '/Users/jenkins/cmake/cmake-3.16.9/bin',
'3.17': '/Users/jenkins/cmake/cmake-3.17.5/bin',
'3.19': '/Users/jenkins/cmake/cmake-3.19.7/bin'
},
'Linux': {
'3.15': '/usr/share/cmake-3.15.7/bin',
'3.16': '/usr/share/cmake-3.16.9/bin',
'3.17': '/usr/share/cmake-3.17.5/bin',
'3.19': '/usr/share/cmake-3.19.7/bin'
}
},
'ninja': {'Windows': {'1.10.2': 'C:/Tools/ninja/1.10.2'}},
'bazel': {
'Darwin': {'default': '/Users/jenkins/bin'},
'Windows': {'default': 'C:/bazel/bin'},
}
}
tools_environments = {
'mingw32': {'Windows': {'MSYSTEM': 'MINGW32'}},
'mingw64': {'Windows': {'MSYSTEM': 'MINGW64'}}
}
tools_available = [
'cmake',
'gcc', 'clang', 'visual_studio', 'xcode',
'msys2', 'cygwin', 'mingw32', 'mingw64',
'autotools', 'pkg_config', 'premake', 'meson', 'ninja',
'bazel',
'file',
'git', 'svn',
'compiler',
'conan', # Search the tool_conan test that needs conan itself
]
if not which("cmake"):
tools_available.remove("cmake")
if not which("gcc"):
tools_available.remove("gcc")
if not which("clang"):
tools_available.remove("clang")
try:
if not vswhere():
tools_available.remove("visual_studio")
except ConanException:
tools_available.remove("visual_studio")
if not any([x for x in ("gcc", "clang", "visual_studio") if x in tools_available]):
tools_available.remove("compiler")
if not which("xcodebuild"):
tools_available.remove("xcode")
if not which("file"):
tools_available.remove("file")
if not which("git"):
tools_available.remove("git")
if not which("svn"):
tools_available.remove("svn")
if not which("autoconf") or not which("automake"):
tools_available.remove("autotools")
if not which("meson"):
tools_available.remove("meson")
if not which("pkg-config"):
tools_available.remove("pkg_config")
if not which("premake"):
tools_available.remove("premake")
if not which("conan"):
tools_available.remove("conan")
def _get_tool_path(locations, name, version, tool_platform):
path = None
try:
path = locations[name][tool_platform][version]
except KeyError as exc:
if version in str(exc):
raise ConanException(exc)
return path
def _get_tool_environment(environments, name, tool_platform):
env = None
try:
env = environments[name][tool_platform]
except KeyError:
pass
return env
@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:]
version = mark.kwargs.get('version', None) or tools_default_version.get(tool_name)
if version:
try:
tool_path = _get_tool_path(tools_locations, tool_name, version, platform.system())
if tool_path:
tools_paths.append(tool_path)
except ConanException:
pytest.fail("Required {} version: '{}' is not available".format(tool_name, version))
tool_env = _get_tool_environment(tools_environments, tool_name, platform.system())
if tool_env:
tools_env_vars.update(tool_env)
# To fix random failures in CI because of this: https://issues.jenkins.io/browse/JENKINS-9104
if "visual_studio" in mark.name:
tools_env_vars.update({'_MSPDBSRV_ENDPOINT_': str(uuid.uuid4())})
if tools_paths or tools_env_vars:
tools_paths.append(os.environ["PATH"])
temp_env = {'PATH': os.pathsep.join(tools_paths)}
old_environ = dict(os.environ)
os.environ.update(temp_env)
os.environ.update(tools_env_vars)
yield
os.environ.clear()
os.environ.update(old_environ)
else:
yield
def tool_check(mark):
tool_name = mark.name[5:]
if tool_name not in tools_available:
pytest.fail("Required tool: '{}' is not available".format(tool_name))
def pytest_runtest_setup(item):
# Every mark is a required tool, some specify a version
for mark in item.iter_markers():
if mark.name.startswith("tool_"):
tool_check(mark)