radeonsi: clean up code for loading VS inputs
[mesa.git] / bin / khronos-update.py
1 #!/usr/bin/env python3
2
3 import argparse
4 import base64
5 import pathlib
6 import requests
7 import subprocess
8 import typing
9
10
11 def error(msg: str) -> None:
12 print('\033[31m' + msg + '\033[0m')
13
14
15 class Source:
16 def __init__(self, filename: str, url: typing.Optional[str]):
17 self.file = pathlib.Path(filename)
18 self.url = url
19
20 def sync(self) -> None:
21 if self.url is None:
22 return
23
24 print('Syncing {}...'.format(self.file), end=' ', flush=True)
25 req = requests.get(self.url)
26
27 if not req.ok:
28 error('Failed to retrieve file: {} {}'.format(req.status_code, req.reason))
29 return
30
31 # Gitiles returns base64-encoded strings.
32 # Google has been resisting for years to the idea of allowing plain text: https://github.com/google/gitiles/issues/7
33 if 'format=TEXT' in self.url:
34 content = base64.b64decode(req.content)
35 else:
36 content = req.content
37
38 with open(self.file, 'wb') as f:
39 f.write(content)
40
41 print('Done')
42
43
44 # a URL of `None` means there is no upstream, because *we* are the upstream
45 SOURCES = [
46 {
47 'api': 'khr',
48 'inc_folder': 'KHR',
49 'sources': [
50 Source('include/KHR/khrplatform.h', 'https://github.com/KhronosGroup/EGL-Registry/raw/master/api/KHR/khrplatform.h'),
51 ],
52 },
53
54 {
55 'api': 'egl',
56 'inc_folder': 'EGL',
57 'sources': [
58 Source('src/egl/generate/egl.xml', 'https://github.com/KhronosGroup/EGL-Registry/raw/master/api/egl.xml'),
59 Source('include/EGL/egl.h', 'https://github.com/KhronosGroup/EGL-Registry/raw/master/api/EGL/egl.h'),
60 Source('include/EGL/eglplatform.h', 'https://github.com/KhronosGroup/EGL-Registry/raw/master/api/EGL/eglplatform.h'),
61 Source('include/EGL/eglext.h', 'https://github.com/KhronosGroup/EGL-Registry/raw/master/api/EGL/eglext.h'),
62 Source('include/EGL/eglextchromium.h', 'https://chromium.googlesource.com/chromium/src/+/refs/heads/master/ui/gl/EGL/eglextchromium.h?format=TEXT'),
63 Source('include/EGL/eglext_angle.h', 'https://chromium.googlesource.com/angle/angle/+/refs/heads/master/include/EGL/eglext_angle.h?format=TEXT'),
64 Source('include/EGL/eglmesaext.h', None),
65 ],
66 },
67
68 {
69 'api': 'gl',
70 'inc_folder': 'GL',
71 'sources': [
72 Source('src/mapi/glapi/registry/gl.xml', 'https://github.com/KhronosGroup/OpenGL-Registry/raw/master/xml/gl.xml'),
73 Source('include/GL/glcorearb.h', 'https://github.com/KhronosGroup/OpenGL-Registry/raw/master/api/GL/glcorearb.h'),
74 Source('include/GL/glext.h', 'https://github.com/KhronosGroup/OpenGL-Registry/raw/master/api/GL/glext.h'),
75 Source('include/GL/glxext.h', 'https://github.com/KhronosGroup/OpenGL-Registry/raw/master/api/GL/glxext.h'),
76 Source('include/GL/wglext.h', 'https://github.com/KhronosGroup/OpenGL-Registry/raw/master/api/GL/wglext.h'),
77 Source('include/GL/gl.h', None), # FIXME: I don't know what the canonical source is
78 Source('include/GL/glx.h', None), # FIXME: I don't know what the canonical source is
79 Source('include/GL/internal/', None),
80 Source('include/GL/mesa_glinterop.h', None),
81 Source('include/GL/osmesa.h', None),
82 ],
83 },
84
85 {
86 'api': 'gles1',
87 'inc_folder': 'GLES',
88 'sources': [
89 Source('include/GLES/gl.h', 'https://github.com/KhronosGroup/OpenGL-Registry/raw/master/api/GLES/gl.h'),
90 Source('include/GLES/glplatform.h', 'https://github.com/KhronosGroup/OpenGL-Registry/raw/master/api/GLES/glplatform.h'),
91 Source('include/GLES/glext.h', 'https://github.com/KhronosGroup/OpenGL-Registry/raw/master/api/GLES/glext.h'),
92 Source('include/GLES/egl.h', 'https://github.com/KhronosGroup/OpenGL-Registry/raw/master/api/GLES/egl.h'),
93 ],
94 },
95
96 {
97 'api': 'gles2',
98 'inc_folder': 'GLES2',
99 'sources': [
100 Source('include/GLES2/gl2.h', 'https://github.com/KhronosGroup/OpenGL-Registry/raw/master/api/GLES2/gl2.h'),
101 Source('include/GLES2/gl2platform.h', 'https://github.com/KhronosGroup/OpenGL-Registry/raw/master/api/GLES2/gl2platform.h'),
102 Source('include/GLES2/gl2ext.h', 'https://github.com/KhronosGroup/OpenGL-Registry/raw/master/api/GLES2/gl2ext.h'),
103 ],
104 },
105
106 {
107 'api': 'gles3',
108 'inc_folder': 'GLES3',
109 'sources': [
110 Source('include/GLES3/gl3.h', 'https://github.com/KhronosGroup/OpenGL-Registry/raw/master/api/GLES3/gl3.h'),
111 Source('include/GLES3/gl31.h', 'https://github.com/KhronosGroup/OpenGL-Registry/raw/master/api/GLES3/gl31.h'),
112 Source('include/GLES3/gl32.h', 'https://github.com/KhronosGroup/OpenGL-Registry/raw/master/api/GLES3/gl32.h'),
113 Source('include/GLES3/gl3platform.h', 'https://github.com/KhronosGroup/OpenGL-Registry/raw/master/api/GLES3/gl3platform.h'),
114 Source('include/GLES3/gl3ext.h', None), # FIXME: I don't know what the canonical source is
115 ],
116 },
117
118 {
119 'api': 'opencl',
120 'inc_folder': 'CL',
121 'sources': [
122 Source('include/CL/opencl.h', 'https://github.com/KhronosGroup/OpenCL-Headers/raw/master/CL/opencl.h'),
123 Source('include/CL/cl.h', 'https://github.com/KhronosGroup/OpenCL-Headers/raw/master/CL/cl.h'),
124 Source('include/CL/cl_platform.h', 'https://github.com/KhronosGroup/OpenCL-Headers/raw/master/CL/cl_platform.h'),
125 Source('include/CL/cl_gl.h', 'https://github.com/KhronosGroup/OpenCL-Headers/raw/master/CL/cl_gl.h'),
126 Source('include/CL/cl_gl_ext.h', 'https://github.com/KhronosGroup/OpenCL-Headers/raw/master/CL/cl_gl_ext.h'),
127 Source('include/CL/cl_ext.h', 'https://github.com/KhronosGroup/OpenCL-Headers/raw/master/CL/cl_ext.h'),
128 Source('include/CL/cl_version.h', 'https://github.com/KhronosGroup/OpenCL-Headers/raw/master/CL/cl_version.h'),
129 Source('include/CL/cl_icd.h', 'https://github.com/KhronosGroup/OpenCL-Headers/raw/master/CL/cl_icd.h'),
130 Source('include/CL/cl_egl.h', 'https://github.com/KhronosGroup/OpenCL-Headers/raw/master/CL/cl_egl.h'),
131 Source('include/CL/cl_d3d10.h', 'https://github.com/KhronosGroup/OpenCL-Headers/raw/master/CL/cl_d3d10.h'),
132 Source('include/CL/cl_d3d11.h', 'https://github.com/KhronosGroup/OpenCL-Headers/raw/master/CL/cl_d3d11.h'),
133 Source('include/CL/cl_dx9_media_sharing.h', 'https://github.com/KhronosGroup/OpenCL-Headers/raw/master/CL/cl_dx9_media_sharing.h'),
134 Source('include/CL/cl_dx9_media_sharing_intel.h', 'https://github.com/KhronosGroup/OpenCL-Headers/raw/master/CL/cl_dx9_media_sharing_intel.h'),
135 Source('include/CL/cl_ext_intel.h', 'https://github.com/KhronosGroup/OpenCL-Headers/raw/master/CL/cl_ext_intel.h'),
136 Source('include/CL/cl_va_api_media_sharing_intel.h', 'https://github.com/KhronosGroup/OpenCL-Headers/raw/master/CL/cl_va_api_media_sharing_intel.h'),
137
138 Source('include/CL/cl.hpp', 'https://github.com/KhronosGroup/OpenCL-CLHPP/raw/master/include/CL/cl.hpp'),
139 Source('include/CL/cl2.hpp', 'https://github.com/KhronosGroup/OpenCL-CLHPP/raw/master/include/CL/cl2.hpp'),
140 ],
141 },
142
143 {
144 'api': 'spirv',
145 'sources': [
146 Source('src/compiler/spirv/spirv.h', 'https://github.com/KhronosGroup/SPIRV-Headers/raw/master/include/spirv/unified1/spirv.h'),
147 Source('src/compiler/spirv/spirv.core.grammar.json', 'https://github.com/KhronosGroup/SPIRV-Headers/raw/master/include/spirv/unified1/spirv.core.grammar.json'),
148 Source('src/compiler/spirv/OpenCL.std.h', 'https://github.com/KhronosGroup/SPIRV-Headers/raw/master/include/spirv/unified1/OpenCL.std.h'),
149 Source('src/compiler/spirv/GLSL.std.450.h', 'https://github.com/KhronosGroup/SPIRV-Headers/raw/master/include/spirv/unified1/GLSL.std.450.h'),
150 Source('src/compiler/spirv/GLSL.ext.AMD.h', 'https://github.com/KhronosGroup/glslang/raw/master/SPIRV/GLSL.ext.AMD.h'), # FIXME: is this the canonical source?
151 ],
152 },
153
154 {
155 'api': 'vulkan',
156 'inc_folder': 'vulkan',
157 'sources': [
158 Source('src/vulkan/registry/vk.xml', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/master/registry/vk.xml'),
159 Source('include/vulkan/vulkan.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/master/include/vulkan/vulkan.h'),
160 Source('include/vulkan/vulkan_core.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/master/include/vulkan/vulkan_core.h'),
161 Source('include/vulkan/vulkan_beta.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/master/include/vulkan/vulkan_beta.h'),
162 Source('include/vulkan/vk_icd.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/master/include/vulkan/vk_icd.h'),
163 Source('include/vulkan/vk_layer.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/master/include/vulkan/vk_layer.h'),
164 Source('include/vulkan/vk_platform.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/master/include/vulkan/vk_platform.h'),
165 Source('include/vulkan/vulkan_android.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/master/include/vulkan/vulkan_android.h'),
166 Source('include/vulkan/vulkan_fuchsia.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/master/include/vulkan/vulkan_fuchsia.h'),
167 Source('include/vulkan/vulkan_ggp.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/master/include/vulkan/vulkan_ggp.h'),
168 Source('include/vulkan/vulkan_ios.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/master/include/vulkan/vulkan_ios.h'),
169 Source('include/vulkan/vulkan_macos.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/master/include/vulkan/vulkan_macos.h'),
170 Source('include/vulkan/vulkan_metal.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/master/include/vulkan/vulkan_metal.h'),
171 Source('include/vulkan/vulkan_vi.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/master/include/vulkan/vulkan_vi.h'),
172 Source('include/vulkan/vulkan_wayland.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/master/include/vulkan/vulkan_wayland.h'),
173 Source('include/vulkan/vulkan_win32.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/master/include/vulkan/vulkan_win32.h'),
174 Source('include/vulkan/vulkan_xcb.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/master/include/vulkan/vulkan_xcb.h'),
175 Source('include/vulkan/vulkan_xlib.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/master/include/vulkan/vulkan_xlib.h'),
176 Source('include/vulkan/vulkan_xlib_xrandr.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/master/include/vulkan/vulkan_xlib_xrandr.h'),
177 Source('include/vulkan/vk_android_native_buffer.h', 'https://android.googlesource.com/platform/frameworks/native/+/master/vulkan/include/vulkan/vk_android_native_buffer.h?format=TEXT'),
178 Source('include/vulkan/vulkan_intel.h', None),
179 Source('include/vulkan/.editorconfig', None),
180 ],
181 },
182 ]
183
184
185 if __name__ == '__main__':
186 git_toplevel = subprocess.check_output(['git', 'rev-parse', '--show-toplevel'],
187 stderr=subprocess.DEVNULL).decode("ascii").strip()
188 if not pathlib.Path(git_toplevel).resolve() == pathlib.Path('.').resolve():
189 error('Please run this script from the root folder ({})'.format(git_toplevel))
190 exit(1)
191
192 parser = argparse.ArgumentParser()
193 parser.add_argument('apis', nargs='*',
194 # the `[[]]` here is a workaround for python bug 9625
195 # where having `choices` breaks `nargs='*'`:
196 # https://bugs.python.org/issue9625
197 choices=[group['api'] for group in SOURCES] + [[]],
198 help='Only update the APIs specified.')
199 args = parser.parse_args()
200
201 # These APIs all depend on the KHR header
202 depend_on_khr = set(['egl', 'gl', 'gles', 'gles2', 'gles3'])
203 if args.apis and 'khr' not in args.apis and depend_on_khr.intersection(set(args.apis)):
204 args.apis = ['khr'] + args.apis
205
206 for group in SOURCES:
207 if args.apis and group['api'] not in args.apis:
208 continue
209
210 for source in group['sources']:
211 source.sync()
212
213 # Make sure all the API files are handled by this script
214 if 'inc_folder' in group:
215 for file in pathlib.Path('include/' + group['inc_folder']).iterdir():
216 if file not in [source.file for source in group['sources']]:
217 error('{} is unknown, please add it to SOURCES'.format(file))