gnome: Fix indentation of mkenums_simple generated code

Commit 83facb3959 switched to using
`textwrap.dedent` for the code templates for `gnome.mkenums_simple`.
That changed indentation, however, making the generated code harder to
understand.

We improve this by properly indenting the multiline strings before
dedenting them. For optional parameters `decl_decorator` and
`header_prefix`, we add a newline if they are set to keep separation
between generated code blocks.
pull/13040/merge
Matthijs Velsink 8 months ago committed by Dylan Baker
parent 2b37101998
commit 7ebbce2072
  1. 18
      mesonbuild/modules/gnome.py

@ -1881,7 +1881,8 @@ class GnomeModule(ExtensionModule):
c_cmd.append('--vtail')
c_cmd.append(textwrap.dedent(
''' { 0, NULL, NULL }
'''\
{ 0, NULL, NULL }
};
if (g_once_init_enter (&gtype_id)) {
GType new_type = g_@type@_register_static (g_intern_static_string ("@EnumName@"), values);
@ -1896,13 +1897,16 @@ class GnomeModule(ExtensionModule):
# .h file generation
h_cmd = cmd.copy()
if header_prefix and not header_prefix.endswith('\n'):
header_prefix += '\n' # Extra trailing newline for style
h_cmd.append('--fhead')
h_cmd.append(textwrap.dedent(
f'''#pragma once
f'''\
#pragma once
#include <glib-object.h>
{header_prefix}
G_BEGIN_DECLS
'''))
@ -1912,9 +1916,13 @@ class GnomeModule(ExtensionModule):
/* enumerations from "@basename@" */
'''))
extra_newline = ''
if decl_decorator:
extra_newline = '\n' # Extra leading newline for style
h_cmd.append('--vhead')
h_cmd.append(textwrap.dedent(
f'''
h_cmd.append(extra_newline + textwrap.dedent(
f'''\
{decl_decorator}
GType {func_prefix}@enum_name@_get_type (void);
#define @ENUMPREFIX@_TYPE_@ENUMSHORT@ ({func_prefix}@enum_name@_get_type())'''))

Loading…
Cancel
Save