| 1 |
#!/usr/bin/env python3 |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
import sys |
| 5 |
import re |
| 6 |
import os |
| 7 |
|
| 8 |
debug = os.getenv("GIO_GENTYPEFUNCS_DEBUG") is not None |
| 9 |
|
| 10 |
out_file = sys.argv[1] |
| 11 |
in_files = sys.argv[2:] |
| 12 |
|
| 13 |
funcs = [] |
| 14 |
|
| 15 |
|
| 16 |
if debug: |
| 17 |
print("Output file: ", out_file) |
| 18 |
|
| 19 |
if debug: |
| 20 |
print(len(in_files), "input files") |
| 21 |
|
| 22 |
for filename in in_files: |
| 23 |
if debug: |
| 24 |
print("Input file: ", filename) |
| 25 |
with open(filename, "rb") as f: |
| 26 |
for line in f: |
| 27 |
line = line.rstrip(b"\n").rstrip(b"\r") |
| 28 |
match = re.search(rb"\bg_[a-zA-Z0-9_]*_get_type\b", line) |
| 29 |
if match: |
| 30 |
func = match.group(0).decode("utf-8") |
| 31 |
if func not in funcs: |
| 32 |
funcs.append(func) |
| 33 |
if debug: |
| 34 |
print("Found ", func) |
| 35 |
|
| 36 |
file_output = "G_GNUC_BEGIN_IGNORE_DEPRECATIONS\n" |
| 37 |
|
| 38 |
funcs = sorted(funcs) |
| 39 |
|
| 40 |
# These types generally emit critical warnings if constructed in the wrong |
| 41 |
# environment (for example, without D-Bus running), so skip them. |
| 42 |
ignored_types = [ |
| 43 |
"g_io_extension_get_type", |
| 44 |
"g_settings_backend_get_type", |
| 45 |
"g_debug_controller_dbus_get_type", |
| 46 |
"g_file_icon_get_type", |
| 47 |
"g_unix_credentials_message_get_type", |
| 48 |
"g_unix_socket_address_get_type", |
| 49 |
] |
| 50 |
|
| 51 |
for f in funcs: |
| 52 |
if f not in ignored_types: |
| 53 |
file_output += "*tp++ = {0} ();\n".format(f) |
| 54 |
|
| 55 |
file_output += "G_GNUC_END_IGNORE_DEPRECATIONS\n" |
| 56 |
|
| 57 |
if debug: |
| 58 |
print(len(funcs), "functions") |
| 59 |
|
| 60 |
ofile = open(out_file, "w") |
| 61 |
ofile.write(file_output) |
| 62 |
ofile.close() |