mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 23:16:14 +01:00
tools: Reformat gen-visibility-macros.py with black
This satisfies the style-check CI job.
This commit is contained in:
parent
24aaff658b
commit
f8981e9b49
@ -16,12 +16,15 @@ from pathlib import Path
|
|||||||
|
|
||||||
|
|
||||||
def gen_versions_macros(args, current_minor_version):
|
def gen_versions_macros(args, current_minor_version):
|
||||||
with args.out_path.open('w', encoding='utf-8') as ofile, \
|
with args.out_path.open("w", encoding="utf-8") as ofile, args.in_path.open(
|
||||||
args.in_path.open('r', encoding='utf-8') as ifile:
|
"r", encoding="utf-8"
|
||||||
|
) as ifile:
|
||||||
for line in ifile.readlines():
|
for line in ifile.readlines():
|
||||||
if '@GLIB_VERSIONS@' in line:
|
if "@GLIB_VERSIONS@" in line:
|
||||||
for minor in range(2, current_minor_version + 2, 2):
|
for minor in range(2, current_minor_version + 2, 2):
|
||||||
ofile.write(textwrap.dedent(f'''\
|
ofile.write(
|
||||||
|
textwrap.dedent(
|
||||||
|
f"""\
|
||||||
/**
|
/**
|
||||||
* GLIB_VERSION_2_{minor}:
|
* GLIB_VERSION_2_{minor}:
|
||||||
*
|
*
|
||||||
@ -31,24 +34,33 @@ def gen_versions_macros(args, current_minor_version):
|
|||||||
* Since: 2.{max(minor, 32)}
|
* Since: 2.{max(minor, 32)}
|
||||||
*/
|
*/
|
||||||
#define GLIB_VERSION_2_{minor} (G_ENCODE_VERSION (2, {minor}))
|
#define GLIB_VERSION_2_{minor} (G_ENCODE_VERSION (2, {minor}))
|
||||||
'''))
|
"""
|
||||||
|
)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
ofile.write(line)
|
ofile.write(line)
|
||||||
|
|
||||||
|
|
||||||
def gen_doc_sections(args, current_minor_version):
|
def gen_doc_sections(args, current_minor_version):
|
||||||
with args.out_path.open('w', encoding='utf-8') as ofile, \
|
with args.out_path.open("w", encoding="utf-8") as ofile, args.in_path.open(
|
||||||
args.in_path.open('r', encoding='utf-8') as ifile:
|
"r", encoding="utf-8"
|
||||||
|
) as ifile:
|
||||||
for line in ifile.readlines():
|
for line in ifile.readlines():
|
||||||
if '@GLIB_VERSIONS@' in line:
|
if "@GLIB_VERSIONS@" in line:
|
||||||
for minor in range(2, current_minor_version + 2, 2):
|
for minor in range(2, current_minor_version + 2, 2):
|
||||||
ofile.write(textwrap.dedent(f'''\
|
ofile.write(
|
||||||
|
textwrap.dedent(
|
||||||
|
f"""\
|
||||||
GLIB_VERSION_2_{minor}
|
GLIB_VERSION_2_{minor}
|
||||||
'''))
|
"""
|
||||||
|
)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
ofile.write(line)
|
ofile.write(line)
|
||||||
|
|
||||||
|
|
||||||
def gen_visibility_macros(args, current_minor_version):
|
def gen_visibility_macros(args, current_minor_version):
|
||||||
'''
|
"""
|
||||||
Generates a set of macros for each minor stable version of GLib
|
Generates a set of macros for each minor stable version of GLib
|
||||||
|
|
||||||
- GLIB_VAR
|
- GLIB_VAR
|
||||||
@ -70,11 +82,13 @@ def gen_visibility_macros(args, current_minor_version):
|
|||||||
- GLIB_UNAVAILABLE_STATIC_INLINE(maj,min)
|
- GLIB_UNAVAILABLE_STATIC_INLINE(maj,min)
|
||||||
|
|
||||||
The GLIB namespace can be replaced with one of GOBJECT, GIO, GMODULE.
|
The GLIB namespace can be replaced with one of GOBJECT, GIO, GMODULE.
|
||||||
'''
|
"""
|
||||||
|
|
||||||
ns = args.namespace
|
ns = args.namespace
|
||||||
with args.out_path.open('w', encoding='utf-8') as f:
|
with args.out_path.open("w", encoding="utf-8") as f:
|
||||||
f.write(textwrap.dedent(f'''\
|
f.write(
|
||||||
|
textwrap.dedent(
|
||||||
|
f"""\
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#if (defined(_WIN32) || defined(__CYGWIN__)) && !defined({ns}_STATIC_COMPILATION)
|
#if (defined(_WIN32) || defined(__CYGWIN__)) && !defined({ns}_STATIC_COMPILATION)
|
||||||
@ -109,9 +123,13 @@ def gen_visibility_macros(args, current_minor_version):
|
|||||||
#define {ns}_UNAVAILABLE(maj,min) G_UNAVAILABLE(maj,min) _{ns}_EXTERN
|
#define {ns}_UNAVAILABLE(maj,min) G_UNAVAILABLE(maj,min) _{ns}_EXTERN
|
||||||
#define {ns}_UNAVAILABLE_STATIC_INLINE(maj,min) G_UNAVAILABLE(maj,min)
|
#define {ns}_UNAVAILABLE_STATIC_INLINE(maj,min) G_UNAVAILABLE(maj,min)
|
||||||
#endif
|
#endif
|
||||||
'''))
|
"""
|
||||||
|
)
|
||||||
|
)
|
||||||
for minor in range(26, current_minor_version + 2, 2):
|
for minor in range(26, current_minor_version + 2, 2):
|
||||||
f.write(textwrap.dedent(f'''
|
f.write(
|
||||||
|
textwrap.dedent(
|
||||||
|
f"""
|
||||||
#if GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_{minor}
|
#if GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_{minor}
|
||||||
#define {ns}_DEPRECATED_IN_2_{minor} {ns}_DEPRECATED
|
#define {ns}_DEPRECATED_IN_2_{minor} {ns}_DEPRECATED
|
||||||
#define {ns}_DEPRECATED_IN_2_{minor}_FOR(f) {ns}_DEPRECATED_FOR (f)
|
#define {ns}_DEPRECATED_IN_2_{minor}_FOR(f) {ns}_DEPRECATED_FOR (f)
|
||||||
@ -145,32 +163,42 @@ def gen_visibility_macros(args, current_minor_version):
|
|||||||
#define {ns}_AVAILABLE_ENUMERATOR_IN_2_{minor}
|
#define {ns}_AVAILABLE_ENUMERATOR_IN_2_{minor}
|
||||||
#define {ns}_AVAILABLE_TYPE_IN_2_{minor}
|
#define {ns}_AVAILABLE_TYPE_IN_2_{minor}
|
||||||
#endif
|
#endif
|
||||||
'''))
|
"""
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('glib_version', help='Current GLib version')
|
parser.add_argument("glib_version", help="Current GLib version")
|
||||||
subparsers = parser.add_subparsers()
|
subparsers = parser.add_subparsers()
|
||||||
|
|
||||||
versions_parser = subparsers.add_parser('versions-macros', help='Generate versions macros')
|
versions_parser = subparsers.add_parser(
|
||||||
versions_parser.add_argument('in_path', help='input file', type=Path)
|
"versions-macros", help="Generate versions macros"
|
||||||
versions_parser.add_argument('out_path', help='output file', type=Path)
|
)
|
||||||
|
versions_parser.add_argument("in_path", help="input file", type=Path)
|
||||||
|
versions_parser.add_argument("out_path", help="output file", type=Path)
|
||||||
versions_parser.set_defaults(func=gen_versions_macros)
|
versions_parser.set_defaults(func=gen_versions_macros)
|
||||||
|
|
||||||
doc_parser = subparsers.add_parser('doc-sections', help='Generate glib-sections.txt')
|
doc_parser = subparsers.add_parser(
|
||||||
doc_parser.add_argument('in_path', help='input file', type=Path)
|
"doc-sections", help="Generate glib-sections.txt"
|
||||||
doc_parser.add_argument('out_path', help='output file', type=Path)
|
)
|
||||||
|
doc_parser.add_argument("in_path", help="input file", type=Path)
|
||||||
|
doc_parser.add_argument("out_path", help="output file", type=Path)
|
||||||
doc_parser.set_defaults(func=gen_doc_sections)
|
doc_parser.set_defaults(func=gen_doc_sections)
|
||||||
|
|
||||||
visibility_parser = subparsers.add_parser('visibility-macros', help='Generate visibility macros')
|
visibility_parser = subparsers.add_parser(
|
||||||
visibility_parser.add_argument('namespace', help='Macro namespace')
|
"visibility-macros", help="Generate visibility macros"
|
||||||
visibility_parser.add_argument('out_path', help='output file', type=Path)
|
)
|
||||||
|
visibility_parser.add_argument("namespace", help="Macro namespace")
|
||||||
|
visibility_parser.add_argument("out_path", help="output file", type=Path)
|
||||||
visibility_parser.set_defaults(func=gen_visibility_macros)
|
visibility_parser.set_defaults(func=gen_visibility_macros)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
version = [int(i) for i in args.glib_version.split('.')]
|
version = [int(i) for i in args.glib_version.split(".")]
|
||||||
assert version[0] == 2
|
assert version[0] == 2
|
||||||
args.func(args, version[1])
|
args.func(args, version[1])
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user