aboutsummaryrefslogtreecommitdiffstats
path: root/components/style/binding_tools/check_bindings.py
blob: 67a8f6de17558e58a88fb5ec6f4d2ab0b78a1056 (plain) (blame)
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
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import os
import re

LICENSE = """\
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/* automatically generated by check_bindings.py. */

"""

BINDINGS_PATH = os.path.join("..", "gecko_bindings")
INPUT_FILE = os.path.join(BINDINGS_PATH, "bindings.rs")
OUTPUT_FILE = os.path.join(BINDINGS_PATH, "check_bindings.rs")

TEMPLATE = """\
    [ Servo_{name}, bindings::Servo_{name} ];
"""

with open(INPUT_FILE, "r") as bindings, open(OUTPUT_FILE, "w+") as tests:
    tests.write(LICENSE)
    tests.write("fn assert_types() {\n")

    pattern = re.compile("fn\s*Servo_([_a-zA-Z0-9]+)\s*\(")

    for line in bindings:
        match = pattern.search(line)

        if match:
            tests.write(TEMPLATE.format(name=match.group(1)))

    tests.write("}\n")