mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 11:26:16 +01:00
Merge branch 'fix-style-check' into 'main'
tools: Fix code style warnings in gen-visibility-macros.py See merge request GNOME/glib!2954
This commit is contained in:
commit
2bf3b7c314
@ -10,13 +10,21 @@ import argparse
|
||||
import textwrap
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
# Disable line length warnings as wrapping the C code templates would be hard
|
||||
# flake8: noqa: E501
|
||||
|
||||
|
||||
def gen_versions_macros(args, current_minor_version):
|
||||
with args.out_path.open('w', encoding='utf-8') as ofile, \
|
||||
args.in_path.open('r', encoding='utf-8') as ifile:
|
||||
with args.out_path.open("w", encoding="utf-8") as ofile, args.in_path.open(
|
||||
"r", encoding="utf-8"
|
||||
) as ifile:
|
||||
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):
|
||||
ofile.write(textwrap.dedent(f'''\
|
||||
ofile.write(
|
||||
textwrap.dedent(
|
||||
f"""\
|
||||
/**
|
||||
* GLIB_VERSION_2_{minor}:
|
||||
*
|
||||
@ -26,24 +34,33 @@ def gen_versions_macros(args, current_minor_version):
|
||||
* Since: 2.{max(minor, 32)}
|
||||
*/
|
||||
#define GLIB_VERSION_2_{minor} (G_ENCODE_VERSION (2, {minor}))
|
||||
'''))
|
||||
"""
|
||||
)
|
||||
)
|
||||
else:
|
||||
ofile.write(line)
|
||||
|
||||
|
||||
def gen_doc_sections(args, current_minor_version):
|
||||
with args.out_path.open('w', encoding='utf-8') as ofile, \
|
||||
args.in_path.open('r', encoding='utf-8') as ifile:
|
||||
with args.out_path.open("w", encoding="utf-8") as ofile, args.in_path.open(
|
||||
"r", encoding="utf-8"
|
||||
) as ifile:
|
||||
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):
|
||||
ofile.write(textwrap.dedent(f'''\
|
||||
ofile.write(
|
||||
textwrap.dedent(
|
||||
f"""\
|
||||
GLIB_VERSION_2_{minor}
|
||||
'''))
|
||||
"""
|
||||
)
|
||||
)
|
||||
else:
|
||||
ofile.write(line)
|
||||
|
||||
|
||||
def gen_visibility_macros(args, current_minor_version):
|
||||
'''
|
||||
"""
|
||||
Generates a set of macros for each minor stable version of GLib
|
||||
|
||||
- GLIB_VAR
|
||||
@ -65,11 +82,13 @@ def gen_visibility_macros(args, current_minor_version):
|
||||
- GLIB_UNAVAILABLE_STATIC_INLINE(maj,min)
|
||||
|
||||
The GLIB namespace can be replaced with one of GOBJECT, GIO, GMODULE.
|
||||
'''
|
||||
"""
|
||||
|
||||
ns = args.namespace
|
||||
with args.out_path.open('w', encoding='utf-8') as f:
|
||||
f.write(textwrap.dedent(f'''\
|
||||
with args.out_path.open("w", encoding="utf-8") as f:
|
||||
f.write(
|
||||
textwrap.dedent(
|
||||
f"""\
|
||||
#pragma once
|
||||
|
||||
#if (defined(_WIN32) || defined(__CYGWIN__)) && !defined({ns}_STATIC_COMPILATION)
|
||||
@ -104,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_STATIC_INLINE(maj,min) G_UNAVAILABLE(maj,min)
|
||||
#endif
|
||||
'''))
|
||||
"""
|
||||
)
|
||||
)
|
||||
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}
|
||||
#define {ns}_DEPRECATED_IN_2_{minor} {ns}_DEPRECATED
|
||||
#define {ns}_DEPRECATED_IN_2_{minor}_FOR(f) {ns}_DEPRECATED_FOR (f)
|
||||
@ -140,32 +163,42 @@ def gen_visibility_macros(args, current_minor_version):
|
||||
#define {ns}_AVAILABLE_ENUMERATOR_IN_2_{minor}
|
||||
#define {ns}_AVAILABLE_TYPE_IN_2_{minor}
|
||||
#endif
|
||||
'''))
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
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()
|
||||
|
||||
versions_parser = subparsers.add_parser('versions-macros', help='Generate versions macros')
|
||||
versions_parser.add_argument('in_path', help='input file', type=Path)
|
||||
versions_parser.add_argument('out_path', help='output file', type=Path)
|
||||
versions_parser = subparsers.add_parser(
|
||||
"versions-macros", help="Generate versions macros"
|
||||
)
|
||||
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)
|
||||
|
||||
doc_parser = subparsers.add_parser('doc-sections', help='Generate glib-sections.txt')
|
||||
doc_parser.add_argument('in_path', help='input file', type=Path)
|
||||
doc_parser.add_argument('out_path', help='output file', type=Path)
|
||||
doc_parser = subparsers.add_parser(
|
||||
"doc-sections", help="Generate glib-sections.txt"
|
||||
)
|
||||
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)
|
||||
|
||||
visibility_parser = subparsers.add_parser('visibility-macros', help='Generate visibility macros')
|
||||
visibility_parser.add_argument('namespace', help='Macro namespace')
|
||||
visibility_parser.add_argument('out_path', help='output file', type=Path)
|
||||
visibility_parser = subparsers.add_parser(
|
||||
"visibility-macros", help="Generate visibility macros"
|
||||
)
|
||||
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)
|
||||
|
||||
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
|
||||
args.func(args, version[1])
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user