File: adjust-angle-include-paths.py

package info (click to toggle)
webkit2gtk 2.50.1-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 445,776 kB
  • sloc: cpp: 3,798,329; javascript: 197,914; ansic: 161,337; python: 49,141; asm: 21,987; ruby: 18,540; perl: 16,723; xml: 4,623; yacc: 2,360; sh: 2,246; java: 2,019; lex: 1,327; pascal: 366; makefile: 289
file content (58 lines) | stat: -rwxr-xr-x 2,182 bytes parent folder | download | duplicates (14)
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
#!/usr/bin/python3

# WebKit builds ANGLE as a static library, and exports some of the
# internal header files as "public headers" in the Xcode project for
# consumption by other build targets - e.g. WebCore.
#
# The build phase which copies these headers also flattens the
# directory structure (so that "ANGLE" is the top-level directory
# containing all of them - e.g., "#include <ANGLE/gl2.h>").
#
# It isn't practical to override the include paths so drastically for
# the other build targets (like WebCore) that we could make the
# original include paths, like <GLES2/gl2.h> work. Changing them so
# their namespace is "ANGLE", which implicitly occurs during the "copy
# headers" phase, is a reasonable solution.
#
# This script processes the header files after they're copied during
# the Copy Header Files build phase, and adjusts their #includes so
# that they refer to each other. This avoids modifying the ANGLE
# sources, and allows WebCore to more easily call ANGLE APIs directly.

import os
import re

if os.getenv('DEPLOYMENT_LOCATION') == 'YES':
    # Apple-internal build
    output_dir = os.getenv('DSTROOT') + os.getenv('PUBLIC_HEADERS_FOLDER_PATH')
else:
    # External build
    output_dir = os.getenv('BUILT_PRODUCTS_DIR') + os.getenv('PUBLIC_HEADERS_FOLDER_PATH')


def replace(line):
    match = re.match('#include [<"](.*)[>"]', line)
    if match:
        header = match.group(1)
        match = re.match(r'(?:\.\./)*(EGL|GLES[23]?|KHR)/(.*)', header)
        if match:
            return "#include <ANGLE/" + match.group(2) + ">\n"
        match = re.match(r'(eglext_angle|gl2ext_angle|ShaderVars)\.h', header)
        if match:
            return "#include <ANGLE/" + match.group(1) + ".h>\n"
        if header == 'export.h':
            return "#include <ANGLE/export.h>\n"

    return line


os.chdir(output_dir)
for filename in os.listdir('.'):
    if not os.path.isfile(filename):
        continue
    if not (filename.endswith('.h') or filename.endswith('.inc')):
        continue
    lines = open(filename, 'r').readlines()
    newLines = [replace(line) for line in lines]
    if lines != newLines:
        open(filename, 'w').writelines(newLines)