gdbus-codegen: Rename --glib-min-version to --glib-min-required

This makes it consistent with the `GLIB_MIN_REQUIRED` defines which are
used for API stability/versioning in C code.

It doesn’t otherwise change the behaviour of the `--glib-min-version`
argument.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #1993
This commit is contained in:
Philip Withnall 2020-01-27 10:11:46 +00:00
parent 93607c4137
commit 4d1c3e15f9
6 changed files with 79 additions and 79 deletions

View File

@ -50,7 +50,7 @@
<replaceable>VALUE</replaceable>
</arg>
</group>
<arg><option>--glib-min-version</option> <replaceable>VERSION</replaceable></arg>
<arg><option>--glib-min-required</option> <replaceable>VERSION</replaceable></arg>
<arg choice="plain">FILE</arg>
<arg>
<arg choice="plain" rep="repeat">FILE</arg>
@ -422,14 +422,14 @@ gdbus-codegen --c-namespace MyApp \
</varlistentry>
<varlistentry>
<term><option>--glib-min-version</option> <replaceable>VERSION</replaceable></term>
<term><option>--glib-min-required</option> <replaceable>VERSION</replaceable></term>
<listitem>
<para>
Specifies the minimum version of GLib which the code generated by
<command>gdbus-codegen</command> can depend on. This may be used to
make backwards-incompatible changes in the output or behaviour of
<command>gdbus-codegen</command> in future, which users may opt in to
by increasing the value they pass for <option>--glib-min-version</option>.
by increasing the value they pass for <option>--glib-min-required</option>.
If this option is not passed, the output from <command>gdbus-codegen</command>
is guaranteed to be compatible with all versions of GLib from 2.30
upwards, as that is when <command>gdbus-codegen</command> was first

View File

@ -62,7 +62,7 @@ def generate_header_guard(header_name):
class HeaderCodeGenerator:
def __init__(self, ifaces, namespace, generate_objmanager,
generate_autocleanup, header_name, input_files_basenames,
use_pragma, glib_min_version, outfile):
use_pragma, glib_min_required, outfile):
self.ifaces = ifaces
self.namespace, self.ns_upper, self.ns_lower = generate_namespace(namespace)
self.generate_objmanager = generate_objmanager
@ -70,12 +70,12 @@ class HeaderCodeGenerator:
self.header_guard = generate_header_guard(header_name)
self.input_files_basenames = input_files_basenames
self.use_pragma = use_pragma
self.glib_min_version = glib_min_version
self.glib_min_required = glib_min_required
self.outfile = outfile
self.glib_min_version_is_2_64 = (glib_min_version[0] > 2 or
(glib_min_version[0] == 2 and
glib_min_version[1] >= 64))
self.glib_min_required_is_2_64 = (glib_min_required[0] > 2 or
(glib_min_required[0] == 2 and
glib_min_required[1] >= 64))
# ----------------------------------------------------------------------------------------------------
@ -226,7 +226,7 @@ class HeaderCodeGenerator:
' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
for a in m.in_args:
self.outfile.write(',\n %sarg_%s'%(a.ctype_in, a.name))
if self.glib_min_version_is_2_64:
if self.glib_min_required_is_2_64:
self.outfile.write(',\n GDBusCallFlags call_flags'
',\n gint timeout_msec')
if m.unix_fd:
@ -256,7 +256,7 @@ class HeaderCodeGenerator:
' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
for a in m.in_args:
self.outfile.write(',\n %sarg_%s'%(a.ctype_in, a.name))
if self.glib_min_version_is_2_64:
if self.glib_min_required_is_2_64:
self.outfile.write(',\n GDBusCallFlags call_flags'
',\n gint timeout_msec')
if m.unix_fd:
@ -629,13 +629,13 @@ class HeaderCodeGenerator:
# ----------------------------------------------------------------------------------------------------
class InterfaceInfoHeaderCodeGenerator:
def __init__(self, ifaces, namespace, header_name, input_files_basenames, use_pragma, glib_min_version, outfile):
def __init__(self, ifaces, namespace, header_name, input_files_basenames, use_pragma, glib_min_required, outfile):
self.ifaces = ifaces
self.namespace, self.ns_upper, self.ns_lower = generate_namespace(namespace)
self.header_guard = generate_header_guard(header_name)
self.input_files_basenames = input_files_basenames
self.use_pragma = use_pragma
self.glib_min_version = glib_min_version
self.glib_min_required = glib_min_required
self.outfile = outfile
# ----------------------------------------------------------------------------------------------------
@ -683,12 +683,12 @@ class InterfaceInfoHeaderCodeGenerator:
# ----------------------------------------------------------------------------------------------------
class InterfaceInfoBodyCodeGenerator:
def __init__(self, ifaces, namespace, header_name, input_files_basenames, glib_min_version, outfile):
def __init__(self, ifaces, namespace, header_name, input_files_basenames, glib_min_required, outfile):
self.ifaces = ifaces
self.namespace, self.ns_upper, self.ns_lower = generate_namespace(namespace)
self.header_name = header_name
self.input_files_basenames = input_files_basenames
self.glib_min_version = glib_min_version
self.glib_min_required = glib_min_required
self.outfile = outfile
# ----------------------------------------------------------------------------------------------------
@ -916,19 +916,19 @@ class InterfaceInfoBodyCodeGenerator:
class CodeGenerator:
def __init__(self, ifaces, namespace, generate_objmanager, header_name,
input_files_basenames, docbook_gen, glib_min_version, outfile):
input_files_basenames, docbook_gen, glib_min_required, outfile):
self.ifaces = ifaces
self.namespace, self.ns_upper, self.ns_lower = generate_namespace(namespace)
self.generate_objmanager = generate_objmanager
self.header_name = header_name
self.input_files_basenames = input_files_basenames
self.docbook_gen = docbook_gen
self.glib_min_version = glib_min_version
self.glib_min_required = glib_min_required
self.outfile = outfile
self.glib_min_version_is_2_64 = (glib_min_version[0] > 2 or
(glib_min_version[0] == 2 and
glib_min_version[1] >= 64))
self.glib_min_required_is_2_64 = (glib_min_required[0] > 2 or
(glib_min_required[0] == 2 and
glib_min_required[1] >= 64))
# ----------------------------------------------------------------------------------------------------
@ -1680,7 +1680,7 @@ class CodeGenerator:
%(i.name_lower, m.name_lower, i.camel_name))
for a in m.in_args:
self.outfile.write(' * @arg_%s: Argument to pass with the method invocation.\n'%(a.name))
if self.glib_min_version_is_2_64:
if self.glib_min_required_is_2_64:
self.outfile.write(' * @call_flags: Flags from the #GDBusCallFlags enumeration. If you want to allow interactive\n'
' authorization be sure to set %G_DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION.\n'
' * @timeout_msec: The timeout in milliseconds (with %G_MAXINT meaning "infinite") or\n'
@ -1704,7 +1704,7 @@ class CodeGenerator:
' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
for a in m.in_args:
self.outfile.write(',\n %sarg_%s'%(a.ctype_in, a.name))
if self.glib_min_version_is_2_64:
if self.glib_min_required_is_2_64:
self.outfile.write(',\n GDBusCallFlags call_flags'
',\n gint timeout_msec')
if m.unix_fd:
@ -1726,7 +1726,7 @@ class CodeGenerator:
for a in m.in_args:
self.outfile.write(',\n arg_%s'%(a.name))
self.outfile.write('),\n')
if self.glib_min_version_is_2_64:
if self.glib_min_required_is_2_64:
self.outfile.write(' call_flags,\n'
' timeout_msec,\n')
else:
@ -1797,7 +1797,7 @@ class CodeGenerator:
%(i.name_lower, m.name_lower, i.camel_name))
for a in m.in_args:
self.outfile.write(' * @arg_%s: Argument to pass with the method invocation.\n'%(a.name))
if self.glib_min_version_is_2_64:
if self.glib_min_required_is_2_64:
self.outfile.write(' * @call_flags: Flags from the #GDBusCallFlags enumeration. If you want to allow interactive\n'
' authorization be sure to set %G_DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION.\n'
' * @timeout_msec: The timeout in milliseconds (with %G_MAXINT meaning "infinite") or\n'
@ -1824,7 +1824,7 @@ class CodeGenerator:
' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
for a in m.in_args:
self.outfile.write(',\n %sarg_%s'%(a.ctype_in, a.name))
if self.glib_min_version_is_2_64:
if self.glib_min_required_is_2_64:
self.outfile.write(',\n GDBusCallFlags call_flags'
',\n gint timeout_msec')
if m.unix_fd:
@ -1850,7 +1850,7 @@ class CodeGenerator:
for a in m.in_args:
self.outfile.write(',\n arg_%s'%(a.name))
self.outfile.write('),\n')
if self.glib_min_version_is_2_64:
if self.glib_min_required_is_2_64:
self.outfile.write(' call_flags,\n'
' timeout_msec,\n')
else:

View File

@ -167,7 +167,7 @@ def codegen_main():
help='Use "pragma once" as the inclusion guard')
arg_parser.add_argument('--annotate', nargs=3, action='append', metavar='WHAT KEY VALUE',
help='Add annotation (may be used several times)')
arg_parser.add_argument('--glib-min-version', metavar='VERSION',
arg_parser.add_argument('--glib-min-required', metavar='VERSION',
help='Minimum version of GLib to be supported by the outputted code (default: 2.30)')
group = arg_parser.add_mutually_exclusive_group()
@ -235,30 +235,30 @@ def codegen_main():
c_file = args.output
header_name = os.path.splitext(os.path.basename(c_file))[0] + '.h'
# Check the minimum GLib version. The minimum --glib-min-version is 2.30,
# Check the minimum GLib version. The minimum --glib-min-required is 2.30,
# because thats when gdbus-codegen was introduced. Support 1, 2 or 3
# component versions, but ignore the micro component if its present.
if args.glib_min_version:
if args.glib_min_required:
try:
parts = args.glib_min_version.split('.', 3)
glib_min_version = (int(parts[0]),
int(parts[1] if len(parts) > 1 else 0))
parts = args.glib_min_required.split('.', 3)
glib_min_required = (int(parts[0]),
int(parts[1] if len(parts) > 1 else 0))
# Ignore micro component, but still validate it:
_ = int(parts[2] if len(parts) > 2 else 0)
except (ValueError, IndexError):
print_error('Unrecognized --glib-min-version string {}'.format(
args.glib_min_version))
print_error('Unrecognized --glib-min-required string {}'.format(
args.glib_min_required))
if glib_min_version[0] < 2 or \
(glib_min_version[0] == 2 and glib_min_version[1] < 30):
print_error('Invalid --glib-min-version string {}: minimum '
'version is 2.30'.format(args.glib_min_version))
if glib_min_required[0] < 2 or \
(glib_min_required[0] == 2 and glib_min_required[1] < 30):
print_error('Invalid --glib-min-required string {}: minimum '
'version is 2.30'.format(args.glib_min_required))
else:
glib_min_version = (2, 30)
glib_min_required = (2, 30)
glib_min_version_is_2_64 = (glib_min_version[0] > 2 or
(glib_min_version[0] == 2 and
glib_min_version[1] >= 64))
glib_min_required_is_2_64 = (glib_min_required[0] > 2 or
(glib_min_required[0] == 2 and
glib_min_required[1] >= 64))
all_ifaces = []
input_files_basenames = []
@ -266,7 +266,7 @@ def codegen_main():
with open(fname, 'rb') as f:
xml_data = f.read()
parsed_ifaces = parser.parse_dbus_xml(xml_data,
h_type_implies_unix_fd=glib_min_version_is_2_64)
h_type_implies_unix_fd=glib_min_required_is_2_64)
all_ifaces.extend(parsed_ifaces)
input_files_basenames.append(os.path.basename(fname))
@ -290,7 +290,7 @@ def codegen_main():
header_name,
input_files_basenames,
args.pragma_once,
glib_min_version,
glib_min_required,
outfile)
gen.generate()
@ -302,7 +302,7 @@ def codegen_main():
header_name,
input_files_basenames,
docbook_gen,
glib_min_version,
glib_min_required,
outfile)
gen.generate()
@ -313,7 +313,7 @@ def codegen_main():
header_name,
input_files_basenames,
args.pragma_once,
glib_min_version,
glib_min_required,
outfile)
gen.generate()
@ -323,7 +323,7 @@ def codegen_main():
args.c_namespace,
header_name,
input_files_basenames,
glib_min_version,
glib_min_required,
outfile)
gen.generate()

View File

@ -362,38 +362,38 @@ G_END_DECLS
# The output should be the same.
self.assertEqual(result1.out, result2.out)
def test_glib_min_version_invalid(self):
"""Test running with an invalid --glib-min-version."""
def test_glib_min_required_invalid(self):
"""Test running with an invalid --glib-min-required."""
with self.assertRaises(subprocess.CalledProcessError):
self.runCodegenWithInterface('',
'--output', '/dev/stdout',
'--body',
'--glib-min-version', 'hello mum')
'--glib-min-required', 'hello mum')
def test_glib_min_version_too_low(self):
"""Test running with a --glib-min-version which is too low (and hence
def test_glib_min_required_too_low(self):
"""Test running with a --glib-min-required which is too low (and hence
probably a typo)."""
with self.assertRaises(subprocess.CalledProcessError):
self.runCodegenWithInterface('',
'--output', '/dev/stdout',
'--body',
'--glib-min-version', '2.6')
'--glib-min-required', '2.6')
def test_glib_min_version_major_only(self):
"""Test running with a --glib-min-version which contains only a major version."""
def test_glib_min_required_major_only(self):
"""Test running with a --glib-min-required which contains only a major version."""
result = self.runCodegenWithInterface('',
'--output', '/dev/stdout',
'--header',
'--glib-min-version', '3')
'--glib-min-required', '3')
self.assertEqual('', result.err)
self.assertNotEqual('', result.out.strip())
def test_glib_min_version_with_micro(self):
"""Test running with a --glib-min-version which contains a micro version."""
def test_glib_min_required_with_micro(self):
"""Test running with a --glib-min-required which contains a micro version."""
result = self.runCodegenWithInterface('',
'--output', '/dev/stdout',
'--header',
'--glib-min-version', '2.46.2')
'--glib-min-required', '2.46.2')
self.assertEqual('', result.err)
self.assertNotEqual('', result.out.strip())
@ -422,28 +422,28 @@ G_END_DECLS
</interface>
</node>'''
# Try without specifying --glib-min-version.
# Try without specifying --glib-min-required.
result = self.runCodegenWithInterface(interface_xml,
'--output', '/dev/stdout',
'--header')
self.assertEqual('', result.err)
self.assertEqual(result.out.strip().count('GUnixFDList'), 6)
# Specify an old --glib-min-version.
# Specify an old --glib-min-required.
result = self.runCodegenWithInterface(interface_xml,
'--output', '/dev/stdout',
'--header',
'--glib-min-version', '2.32')
'--glib-min-required', '2.32')
self.assertEqual('', result.err)
self.assertEqual(result.out.strip().count('GUnixFDList'), 6)
# Specify a --glib-min-version ≥ 2.64. There should be more
# Specify a --glib-min-required ≥ 2.64. There should be more
# mentions of `GUnixFDList` now, since the annotation is not needed to
# trigger its use.
result = self.runCodegenWithInterface(interface_xml,
'--output', '/dev/stdout',
'--header',
'--glib-min-version', '2.64')
'--glib-min-required', '2.64')
self.assertEqual('', result.err)
self.assertEqual(result.out.strip().count('GUnixFDList'), 18)
@ -458,7 +458,7 @@ G_END_DECLS
</interface>
</node>'''
# Try without specifying --glib-min-version.
# Try without specifying --glib-min-required.
result = self.runCodegenWithInterface(interface_xml,
'--output', '/dev/stdout',
'--header')
@ -466,21 +466,21 @@ G_END_DECLS
self.assertEqual(result.out.strip().count('GDBusCallFlags call_flags,'), 0)
self.assertEqual(result.out.strip().count('gint timeout_msec,'), 0)
# Specify an old --glib-min-version.
# Specify an old --glib-min-required.
result = self.runCodegenWithInterface(interface_xml,
'--output', '/dev/stdout',
'--header',
'--glib-min-version', '2.32')
'--glib-min-required', '2.32')
self.assertEqual('', result.err)
self.assertEqual(result.out.strip().count('GDBusCallFlags call_flags,'), 0)
self.assertEqual(result.out.strip().count('gint timeout_msec,'), 0)
# Specify a --glib-min-version ≥ 2.64. The two arguments should be
# Specify a --glib-min-required ≥ 2.64. The two arguments should be
# present for both the async and sync method call functions.
result = self.runCodegenWithInterface(interface_xml,
'--output', '/dev/stdout',
'--header',
'--glib-min-version', '2.64')
'--glib-min-required', '2.64')
self.assertEqual('', result.err)
self.assertEqual(result.out.strip().count('GDBusCallFlags call_flags,'), 2)
self.assertEqual(result.out.strip().count('gint timeout_msec,'), 2)

View File

@ -26,7 +26,7 @@
#include "gdbus-tests.h"
#if GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_64
#include "gdbus-test-codegen-generated-min-version-2-64.h"
#include "gdbus-test-codegen-generated-min-required-2-64.h"
#else
#include "gdbus-test-codegen-generated.h"
#endif
@ -2693,7 +2693,7 @@ handle_no_annotation_nested (FooiGenFDPassing *object,
/* Test that generated code for methods includes GUnixFDList arguments
* unconditionally if the method is explicitly annotated as C.UnixFD, and only
* emits GUnixFDList arguments when there's merely an 'h' parameter if
* --glib-min-version=2.64 or greater.
* --glib-min-required=2.64 or greater.
*/
static void
test_unix_fd_list (void)
@ -2707,7 +2707,7 @@ test_unix_fd_list (void)
/* This one is not annotated; even though it's got an in and out 'h'
* parameter, for backwards compatibility we cannot emit GUnixFDList
* arguments unless --glib-min-version >= 2.64 was used.
* arguments unless --glib-min-required >= 2.64 was used.
*/
iface.handle_no_annotation = handle_no_annotation;

View File

@ -231,17 +231,17 @@ if host_machine.system() != 'windows'
'--generate-docbook', 'gdbus-test-codegen-generated-doc',
annotate_args,
'@INPUT@'])
# Generate gdbus-test-codegen-generated-min-version-2-64.{c,h}
gdbus_test_codegen_generated_min_version_2_64 = custom_target('gdbus-test-codegen-generated-min-version-2-64',
# Generate gdbus-test-codegen-generated-min-required-2-64.{c,h}
gdbus_test_codegen_generated_min_required_2_64 = custom_target('gdbus-test-codegen-generated-min-required-2-64',
input : ['test-codegen.xml'],
output : ['gdbus-test-codegen-generated-min-version-2-64.h',
'gdbus-test-codegen-generated-min-version-2-64.c'],
output : ['gdbus-test-codegen-generated-min-required-2-64.h',
'gdbus-test-codegen-generated-min-required-2-64.c'],
depend_files : gdbus_codegen_built_files,
command : [python, gdbus_codegen,
'--glib-min-version', '2.64',
'--glib-min-required', '2.64',
'--interface-prefix', 'org.project.',
'--output-directory', '@OUTDIR@',
'--generate-c-code', 'gdbus-test-codegen-generated-min-version-2-64',
'--generate-c-code', 'gdbus-test-codegen-generated-min-required-2-64',
'--c-generate-object-manager',
'--c-generate-autocleanup', 'all',
'--c-namespace', 'Foo_iGen',
@ -318,9 +318,9 @@ if host_machine.system() != 'windows'
'c_args' : ['-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_36',
'-DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_36'],
},
'gdbus-test-codegen-min-version-2-64' : {
'gdbus-test-codegen-min-required-2-64' : {
'source' : 'gdbus-test-codegen.c',
'extra_sources' : [extra_sources, gdbus_test_codegen_generated_min_version_2_64, gdbus_test_codegen_generated_interface_info],
'extra_sources' : [extra_sources, gdbus_test_codegen_generated_min_required_2_64, gdbus_test_codegen_generated_interface_info],
'c_args' : ['-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_64'],
},
'gapplication' : {'extra_sources' : extra_sources},