File: generate.py

package info (click to toggle)
kitty 0.41.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 25,052 kB
  • sloc: ansic: 81,083; python: 54,159; objc: 4,934; sh: 1,282; xml: 364; makefile: 143; javascript: 78
file content (47 lines) | stat: -rwxr-xr-x 1,084 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python
# vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>

import os
import re
import shlex
import shutil
import subprocess

cmdline = (
    'glad --out-path {dest} --api gl:core=3.1 '
    ' --extensions GL_ARB_texture_storage,GL_ARB_copy_image,GL_ARB_multisample,GL_ARB_robustness,GL_ARB_instanced_arrays,GL_KHR_debug '
    'c --header-only --debug'
)


def clean(x):
    if os.path.exists(x):
        shutil.rmtree(x)


def regenerate():
    clean('out')

    subprocess.check_call(
        shlex.split(cmdline.format(dest='out'))
    )


def strip_trailing_whitespace(c):
    return re.sub(r'\s+$', '', c, flags=re.MULTILINE) + '\n'


def export():
    with open('out/include/glad/gl.h', 'r', encoding='utf-8') as source:
        data = source.read()
        data = strip_trailing_whitespace(data)

        with open('../kitty/gl-wrapper.h', 'w', encoding='utf-8') as dest:
            dest.write(data)


if __name__ == '__main__':
    os.chdir(os.path.dirname(os.path.abspath(__file__)))
    regenerate()
    export()