Debian Codegraph @

.evergreen/config_generator/etc/distros.py

raw symbols SCIP
1 from typing import Literal
2
3 from packaging.version import Version
4 from pydantic import BaseModel, validator
5
6
7 class Distro(BaseModel):
8 """
9 Defines common properties of a given Evergreen distro.
10
11 * name: Name of the distro.
12 * os: Name of the operating system.
13 * os_type: One of Linux, MacOS, or Windows.
14 * os_ver: Version of the operating system.
15 * size: Size of tasks the distro is designed to handle.
16 * arch: Target architecture.
17 """
18
19 name: str
20 os: str | None = None
21 os_type: Literal['linux', 'macos', 'windows'] | None = None
22 os_ver: str | None = None
23 size: Literal['small', 'large'] | None = None
24 arch: Literal['arm64', 'power', 'zseries'] | None = None
25
26 @validator('os_ver')
27 @classmethod
28 def validate_os_ver(cls, value):
29 return value == 'latest' or Version(value)
30
31
32 def ls_distro(name, **kwargs):
33 return [
34 Distro(name=f'{name}-large', size='large', **kwargs),
35 Distro(name=f'{name}-small', size='small', **kwargs),
36 ]
37
38
39 DEBIAN_DISTROS = [
40 *ls_distro(name='debian11-latest', os='debian', os_type='linux', os_ver='11'),
41 *ls_distro(name='debian12-latest', os='debian', os_type='linux', os_ver='12'),
42 ]
43
44 MACOS_DISTROS = [
45 Distro(name='macos-14', os='macos', os_type='macos', os_ver='14'),
46 ]
47
48 MACOS_ARM64_DISTROS = [
49 Distro(name='macos-14-arm64', os='macos', os_type='macos', os_ver='14', arch='arm64'),
50 ]
51
52 RHEL_DISTROS = [
53 *ls_distro(name='rhel7-latest', os='rhel', os_type='linux', os_ver='7'),
54 *ls_distro(name='rhel8-latest', os='rhel', os_type='linux', os_ver='8'),
55 *ls_distro(name='rhel80', os='rhel', os_type='linux', os_ver='8.0'),
56 *ls_distro(name='rhel84', os='rhel', os_type='linux', os_ver='8.4'),
57 *ls_distro(name='rhel90', os='rhel', os_type='linux', os_ver='9.0'),
58 *ls_distro(name='rhel91', os='rhel', os_type='linux', os_ver='9.1'),
59 *ls_distro(name='rhel92', os='rhel', os_type='linux', os_ver='9.2'),
60 *ls_distro(name='rhel93', os='rhel', os_type='linux', os_ver='9.3'),
61 *ls_distro(name='rhel94', os='rhel', os_type='linux', os_ver='9.4'),
62 *ls_distro(name='rhel95', os='rhel', os_type='linux', os_ver='9.5'), # rhel9-latest
63 ]
64
65 RHEL_ARM64_DISTROS = [
66 *ls_distro(name='rhel8-arm64-latest', os='rhel', os_type='linux', os_ver='8', arch='arm64'),
67 ]
68
69 RHEL_POWER_DISTROS = [
70 *ls_distro(name='rhel8-power', os='rhel', os_type='linux', os_ver='8', arch='power'),
71 ]
72
73 RHEL_ZSERIES_DISTROS = [
74 *ls_distro(name='rhel8-zseries', os='rhel', os_type='linux', os_ver='8', arch='zseries'),
75 ]
76
77 UBUNTU_DISTROS = [
78 *ls_distro(name='ubuntu2004', os='ubuntu', os_type='linux', os_ver='20.04'),
79 *ls_distro(name='ubuntu2204', os='ubuntu', os_type='linux', os_ver='22.04'),
80 *ls_distro(name='ubuntu2404', os='ubuntu', os_type='linux', os_ver='24.04'),
81 ]
82
83 UBUNTU_ARM64_DISTROS = [
84 *ls_distro(name='ubuntu2204-arm64', os='ubuntu', os_type='linux', os_ver='22.04', arch='arm64'),
85 ]
86
87 WINDOWS_DISTROS = [
88 *ls_distro(name='windows-vsCurrent', os='windows', os_type='windows', os_ver='2019'), # Windows Server 2019
89 *ls_distro(name='windows-2022-latest', os='windows', os_type='windows', os_ver='2022'), # Windows Server 2022
90 ]
91
92 GRAVITON_DISTROS = [
93 Distro(name='amazon2023-arm64-latest-large-m8g', os='amazon2023', os_type='linux', os_ver='2023', arch='arm64'),
94 Distro(name='amazon2-arm64-latest-large-m8g', os='amazon2', os_type='linux', os_ver='2', arch='arm64'),
95 ]
96
97 # See: https://evergreen.mongodb.com/distros
98 # Ensure no-arch distros are ordered before arch-specific distros.
99 ALL_DISTROS = [
100 *DEBIAN_DISTROS,
101 *GRAVITON_DISTROS,
102 *MACOS_DISTROS,
103 *MACOS_ARM64_DISTROS,
104 *RHEL_DISTROS,
105 *RHEL_ARM64_DISTROS,
106 *RHEL_POWER_DISTROS,
107 *RHEL_ZSERIES_DISTROS,
108 *UBUNTU_DISTROS,
109 *UBUNTU_ARM64_DISTROS,
110 *WINDOWS_DISTROS,
111 ]
112
113
114 def find_distro(name) -> Distro:
115 candidates = [d for d in ALL_DISTROS if name == d.name]
116
117 if not candidates:
118 raise ValueError(f'could not find a distro with the name {name}')
119
120 return candidates[0]
121
122
123 def find_large_distro(name) -> Distro:
124 candidates = [d for d in ALL_DISTROS if f'{name}-large' == d.name]
125
126 if candidates:
127 return candidates[0]
128
129 return find_distro(name)
130
131
132 def find_small_distro(name) -> Distro:
133 candidates = [d for d in ALL_DISTROS if f'{name}-small' == d.name]
134
135 if candidates:
136 return candidates[0]
137
138 return find_distro(name)
139
140
141 def make_distro_str(distro_name, compiler, arch) -> str:
142 if distro_name.startswith('windows-vsCurrent'):
143 # Rename `windows-vsCurrent-*` distros to `windows-<year>` where`<year>`
144 # is the Windows Server version used by the distro, e.g.:
145 # ('windows-vsCurrent-2022', 'vs2017x64', None) -> windows-2022-vs2017-x64
146 # ('windows-vsCurrent-2022', 'mingw', None) -> windows-2022-mingw
147 # ('windows-vsCurrent', 'vs2017x64', None) -> windows-2019-vs2017-x64
148 # ('windows-vsCurrent', 'mingw', None) -> windows-2019-mingw
149 maybe_arch = compiler[len('vs20XY') :]
150 if maybe_arch in ('x86', 'x64'):
151 compiler_str = compiler[: -len(maybe_arch)] + '-' + maybe_arch
152 else:
153 compiler_str = compiler
154 if distro_name.startswith('windows-vsCurrent-'):
155 distro_str = 'windows-' + distro_name[len('windows-vsCurrent-') :] + f'-{compiler_str}'
156 else:
157 distro_str = 'windows-2019-' + compiler_str
158 else:
159 distro_str = distro_name
160 if compiler:
161 distro_str += f'-{compiler}'
162
163 if arch:
164 distro_str += f'-{arch}'
165
166 return distro_str
167
168
169 def to_cc(compiler):
170 return {
171 'vs2017x64': 'Visual Studio 15 2017',
172 'vs2017x86': 'Visual Studio 15 2017',
173 'vs2019x64': 'Visual Studio 16 2019',
174 'vs2019x86': 'Visual Studio 16 2019',
175 'vs2022x64': 'Visual Studio 17 2022',
176 'vs2022x86': 'Visual Studio 17 2022',
177 }.get(compiler, compiler)
178
179
180 def to_platform(compiler):
181 return {
182 'vs2017x64': 'x64',
183 'vs2017x86': 'Win32',
184 'vs2019x64': 'x64',
185 'vs2019x86': 'Win32',
186 'vs2022x64': 'x64',
187 'vs2022x86': 'Win32',
188 }.get(compiler, compiler)
189
190
191 def compiler_to_vars(compiler):
192 if compiler is None:
193 return {}
194
195 match compiler, compiler.split('-'):
196 case _, ['gcc', *rest]:
197 return {
198 'CC': '-'.join(['gcc'] + rest),
199 'CXX': '-'.join(['g++'] + rest),
200 }
201
202 case _, ['clang', *rest]:
203 return {
204 'CC': '-'.join(['clang'] + rest),
205 'CXX': '-'.join(['clang++'] + rest),
206 }
207
208 case str(vs), _ if 'vs' in vs:
209 return {
210 'CMAKE_GENERATOR': to_cc(vs),
211 'CMAKE_GENERATOR_PLATFORM': to_platform(vs),
212 }
213
214 case _, ['mingw', *rest]:
215 return {
216 'CC': '-'.join(['gcc'] + rest),
217 'CXX': '-'.join(['g++'] + rest),
218 }
219
220 case compiler, _:
221 return {
222 'CC': compiler,
223 'CXX': compiler,
224 }