Merge branch '1993-codegen-version-args' into 'master'

Rename gdbus-codegen --glib-min-version argument to --glib-min-required and add --glib-max-allowed

Closes #1993

See merge request GNOME/glib!1342
This commit is contained in:
Philip Withnall 2020-01-31 13:49:20 +00:00
commit a0e74a8c47
8 changed files with 168 additions and 81 deletions

View File

@ -50,7 +50,8 @@
<replaceable>VALUE</replaceable> <replaceable>VALUE</replaceable>
</arg> </arg>
</group> </group>
<arg><option>--glib-min-version</option> <replaceable>VERSION</replaceable></arg> <arg><option>--glib-min-required</option> <replaceable>VERSION</replaceable></arg>
<arg><option>--glib-max-allowed</option> <replaceable>VERSION</replaceable></arg>
<arg choice="plain">FILE</arg> <arg choice="plain">FILE</arg>
<arg> <arg>
<arg choice="plain" rep="repeat">FILE</arg> <arg choice="plain" rep="repeat">FILE</arg>
@ -422,14 +423,14 @@ gdbus-codegen --c-namespace MyApp \
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term><option>--glib-min-version</option> <replaceable>VERSION</replaceable></term> <term><option>--glib-min-required</option> <replaceable>VERSION</replaceable></term>
<listitem> <listitem>
<para> <para>
Specifies the minimum version of GLib which the code generated by Specifies the minimum version of GLib which the code generated by
<command>gdbus-codegen</command> can depend on. This may be used to <command>gdbus-codegen</command> can depend on. This may be used to
make backwards-incompatible changes in the output or behaviour of make backwards-incompatible changes in the output or behaviour of
<command>gdbus-codegen</command> in future, which users may opt in to <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> 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 is guaranteed to be compatible with all versions of GLib from 2.30
upwards, as that is when <command>gdbus-codegen</command> was first upwards, as that is when <command>gdbus-codegen</command> was first
@ -460,6 +461,27 @@ gdbus-codegen --c-namespace MyApp \
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><option>--glib-max-allowed</option> <replaceable>VERSION</replaceable></term>
<listitem>
<para>
Specifies the maximum version of GLib which the code generated by
<command>gdbus-codegen</command> can depend on. This may be used to
ensure that code generated by <command>gdbus-codegen</command> is
compilable with specific older versions of GLib that your software has
to support.
</para>
<para>
The version number must be of the form
<literal><replaceable>MAJOR</replaceable>.<replaceable>MINOR</replaceable>.<replaceable>MICRO</replaceable></literal>,
where all parts are integers. <replaceable>MINOR</replaceable> and
<replaceable>MICRO</replaceable> are optional. The version number must
be greater than or equal to that passed to <option>--glib-min-required</option>.
It defaults to the version of GLib which provides this <command>gdbus-codegen</command>.
</para>
</listitem>
</varlistentry>
</variablelist> </variablelist>
</refsect1> </refsect1>

View File

@ -62,7 +62,7 @@ def generate_header_guard(header_name):
class HeaderCodeGenerator: class HeaderCodeGenerator:
def __init__(self, ifaces, namespace, generate_objmanager, def __init__(self, ifaces, namespace, generate_objmanager,
generate_autocleanup, header_name, input_files_basenames, generate_autocleanup, header_name, input_files_basenames,
use_pragma, glib_min_version, outfile): use_pragma, glib_min_required, outfile):
self.ifaces = ifaces self.ifaces = ifaces
self.namespace, self.ns_upper, self.ns_lower = generate_namespace(namespace) self.namespace, self.ns_upper, self.ns_lower = generate_namespace(namespace)
self.generate_objmanager = generate_objmanager self.generate_objmanager = generate_objmanager
@ -70,13 +70,9 @@ class HeaderCodeGenerator:
self.header_guard = generate_header_guard(header_name) self.header_guard = generate_header_guard(header_name)
self.input_files_basenames = input_files_basenames self.input_files_basenames = input_files_basenames
self.use_pragma = use_pragma self.use_pragma = use_pragma
self.glib_min_version = glib_min_version self.glib_min_required = glib_min_required
self.outfile = outfile 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))
# ---------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------
def generate_header_preamble(self): def generate_header_preamble(self):
@ -226,7 +222,7 @@ class HeaderCodeGenerator:
' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name)) ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
for a in m.in_args: for a in m.in_args:
self.outfile.write(',\n %sarg_%s'%(a.ctype_in, a.name)) self.outfile.write(',\n %sarg_%s'%(a.ctype_in, a.name))
if self.glib_min_version_is_2_64: if self.glib_min_required >= (2, 64):
self.outfile.write(',\n GDBusCallFlags call_flags' self.outfile.write(',\n GDBusCallFlags call_flags'
',\n gint timeout_msec') ',\n gint timeout_msec')
if m.unix_fd: if m.unix_fd:
@ -256,7 +252,7 @@ class HeaderCodeGenerator:
' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name)) ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
for a in m.in_args: for a in m.in_args:
self.outfile.write(',\n %sarg_%s'%(a.ctype_in, a.name)) self.outfile.write(',\n %sarg_%s'%(a.ctype_in, a.name))
if self.glib_min_version_is_2_64: if self.glib_min_required >= (2, 64):
self.outfile.write(',\n GDBusCallFlags call_flags' self.outfile.write(',\n GDBusCallFlags call_flags'
',\n gint timeout_msec') ',\n gint timeout_msec')
if m.unix_fd: if m.unix_fd:
@ -629,13 +625,13 @@ class HeaderCodeGenerator:
# ---------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------
class InterfaceInfoHeaderCodeGenerator: 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.ifaces = ifaces
self.namespace, self.ns_upper, self.ns_lower = generate_namespace(namespace) self.namespace, self.ns_upper, self.ns_lower = generate_namespace(namespace)
self.header_guard = generate_header_guard(header_name) self.header_guard = generate_header_guard(header_name)
self.input_files_basenames = input_files_basenames self.input_files_basenames = input_files_basenames
self.use_pragma = use_pragma self.use_pragma = use_pragma
self.glib_min_version = glib_min_version self.glib_min_required = glib_min_required
self.outfile = outfile self.outfile = outfile
# ---------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------
@ -683,12 +679,12 @@ class InterfaceInfoHeaderCodeGenerator:
# ---------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------
class InterfaceInfoBodyCodeGenerator: 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.ifaces = ifaces
self.namespace, self.ns_upper, self.ns_lower = generate_namespace(namespace) self.namespace, self.ns_upper, self.ns_lower = generate_namespace(namespace)
self.header_name = header_name self.header_name = header_name
self.input_files_basenames = input_files_basenames self.input_files_basenames = input_files_basenames
self.glib_min_version = glib_min_version self.glib_min_required = glib_min_required
self.outfile = outfile self.outfile = outfile
# ---------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------
@ -916,20 +912,16 @@ class InterfaceInfoBodyCodeGenerator:
class CodeGenerator: class CodeGenerator:
def __init__(self, ifaces, namespace, generate_objmanager, header_name, 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.ifaces = ifaces
self.namespace, self.ns_upper, self.ns_lower = generate_namespace(namespace) self.namespace, self.ns_upper, self.ns_lower = generate_namespace(namespace)
self.generate_objmanager = generate_objmanager self.generate_objmanager = generate_objmanager
self.header_name = header_name self.header_name = header_name
self.input_files_basenames = input_files_basenames self.input_files_basenames = input_files_basenames
self.docbook_gen = docbook_gen self.docbook_gen = docbook_gen
self.glib_min_version = glib_min_version self.glib_min_required = glib_min_required
self.outfile = outfile 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))
# ---------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------
def generate_body_preamble(self): def generate_body_preamble(self):
@ -1680,7 +1672,7 @@ class CodeGenerator:
%(i.name_lower, m.name_lower, i.camel_name)) %(i.name_lower, m.name_lower, i.camel_name))
for a in m.in_args: for a in m.in_args:
self.outfile.write(' * @arg_%s: Argument to pass with the method invocation.\n'%(a.name)) 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 >= (2, 64):
self.outfile.write(' * @call_flags: Flags from the #GDBusCallFlags enumeration. If you want to allow interactive\n' 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' ' 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' ' * @timeout_msec: The timeout in milliseconds (with %G_MAXINT meaning "infinite") or\n'
@ -1704,7 +1696,7 @@ class CodeGenerator:
' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name)) ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
for a in m.in_args: for a in m.in_args:
self.outfile.write(',\n %sarg_%s'%(a.ctype_in, a.name)) self.outfile.write(',\n %sarg_%s'%(a.ctype_in, a.name))
if self.glib_min_version_is_2_64: if self.glib_min_required >= (2, 64):
self.outfile.write(',\n GDBusCallFlags call_flags' self.outfile.write(',\n GDBusCallFlags call_flags'
',\n gint timeout_msec') ',\n gint timeout_msec')
if m.unix_fd: if m.unix_fd:
@ -1726,7 +1718,7 @@ class CodeGenerator:
for a in m.in_args: for a in m.in_args:
self.outfile.write(',\n arg_%s'%(a.name)) self.outfile.write(',\n arg_%s'%(a.name))
self.outfile.write('),\n') self.outfile.write('),\n')
if self.glib_min_version_is_2_64: if self.glib_min_required >= (2, 64):
self.outfile.write(' call_flags,\n' self.outfile.write(' call_flags,\n'
' timeout_msec,\n') ' timeout_msec,\n')
else: else:
@ -1797,7 +1789,7 @@ class CodeGenerator:
%(i.name_lower, m.name_lower, i.camel_name)) %(i.name_lower, m.name_lower, i.camel_name))
for a in m.in_args: for a in m.in_args:
self.outfile.write(' * @arg_%s: Argument to pass with the method invocation.\n'%(a.name)) 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 >= (2, 64):
self.outfile.write(' * @call_flags: Flags from the #GDBusCallFlags enumeration. If you want to allow interactive\n' 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' ' 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' ' * @timeout_msec: The timeout in milliseconds (with %G_MAXINT meaning "infinite") or\n'
@ -1824,7 +1816,7 @@ class CodeGenerator:
' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name)) ' %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
for a in m.in_args: for a in m.in_args:
self.outfile.write(',\n %sarg_%s'%(a.ctype_in, a.name)) self.outfile.write(',\n %sarg_%s'%(a.ctype_in, a.name))
if self.glib_min_version_is_2_64: if self.glib_min_required >= (2, 64):
self.outfile.write(',\n GDBusCallFlags call_flags' self.outfile.write(',\n GDBusCallFlags call_flags'
',\n gint timeout_msec') ',\n gint timeout_msec')
if m.unix_fd: if m.unix_fd:
@ -1850,7 +1842,7 @@ class CodeGenerator:
for a in m.in_args: for a in m.in_args:
self.outfile.write(',\n arg_%s'%(a.name)) self.outfile.write(',\n arg_%s'%(a.name))
self.outfile.write('),\n') self.outfile.write('),\n')
if self.glib_min_version_is_2_64: if self.glib_min_required >= (2, 64):
self.outfile.write(' call_flags,\n' self.outfile.write(' call_flags,\n'
' timeout_msec,\n') ' timeout_msec,\n')
else: else:

View File

@ -167,8 +167,10 @@ def codegen_main():
help='Use "pragma once" as the inclusion guard') help='Use "pragma once" as the inclusion guard')
arg_parser.add_argument('--annotate', nargs=3, action='append', metavar='WHAT KEY VALUE', arg_parser.add_argument('--annotate', nargs=3, action='append', metavar='WHAT KEY VALUE',
help='Add annotation (may be used several times)') 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)') help='Minimum version of GLib to be supported by the outputted code (default: 2.30)')
arg_parser.add_argument('--glib-max-allowed', metavar='VERSION',
help='Maximum version of GLib to be used by the outputted code (default: current GLib version)')
group = arg_parser.add_mutually_exclusive_group() group = arg_parser.add_mutually_exclusive_group()
group.add_argument('--generate-c-code', metavar='OUTFILES', group.add_argument('--generate-c-code', metavar='OUTFILES',
@ -235,30 +237,47 @@ def codegen_main():
c_file = args.output c_file = args.output
header_name = os.path.splitext(os.path.basename(c_file))[0] + '.h' 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 # because thats when gdbus-codegen was introduced. Support 1, 2 or 3
# component versions, but ignore the micro component if its present. # component versions, but ignore the micro component if its present.
if args.glib_min_version: if args.glib_min_required:
try: try:
parts = args.glib_min_version.split('.', 3) parts = args.glib_min_required.split('.', 3)
glib_min_version = (int(parts[0]), 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-required string {}'.format(
args.glib_min_required))
if glib_min_required < (2, 30):
print_error('Invalid --glib-min-required string {}: minimum '
'version is 2.30'.format(args.glib_min_required))
else:
glib_min_required = (2, 30)
# And the maximum GLib version.
if args.glib_max_allowed:
try:
parts = args.glib_max_allowed.split('.', 3)
glib_max_allowed = (int(parts[0]),
int(parts[1] if len(parts) > 1 else 0)) int(parts[1] if len(parts) > 1 else 0))
# Ignore micro component, but still validate it: # Ignore micro component, but still validate it:
_ = int(parts[2] if len(parts) > 2 else 0) _ = int(parts[2] if len(parts) > 2 else 0)
except (ValueError, IndexError): except (ValueError, IndexError):
print_error('Unrecognized --glib-min-version string {}'.format( print_error('Unrecognized --glib-max-allowed string {}'.format(
args.glib_min_version)) args.glib_max_allowed))
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))
else: else:
glib_min_version = (2, 30) glib_max_allowed = (config.MAJOR_VERSION, config.MINOR_VERSION)
glib_min_version_is_2_64 = (glib_min_version[0] > 2 or # Round --glib-max-allowed up to the next stable release.
(glib_min_version[0] == 2 and glib_max_allowed = \
glib_min_version[1] >= 64)) (glib_max_allowed[0], glib_max_allowed[1] + (glib_max_allowed[1] % 2))
if glib_max_allowed < glib_min_required:
print_error('Invalid versions: --glib-min-required ({}) must be '
'less than or equal to --glib-max-allowed ({})'.format(glib_min_required, glib_max_allowed))
all_ifaces = [] all_ifaces = []
input_files_basenames = [] input_files_basenames = []
@ -266,7 +285,7 @@ def codegen_main():
with open(fname, 'rb') as f: with open(fname, 'rb') as f:
xml_data = f.read() xml_data = f.read()
parsed_ifaces = parser.parse_dbus_xml(xml_data, 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 >= (2, 64)))
all_ifaces.extend(parsed_ifaces) all_ifaces.extend(parsed_ifaces)
input_files_basenames.append(os.path.basename(fname)) input_files_basenames.append(os.path.basename(fname))
@ -290,7 +309,7 @@ def codegen_main():
header_name, header_name,
input_files_basenames, input_files_basenames,
args.pragma_once, args.pragma_once,
glib_min_version, glib_min_required,
outfile) outfile)
gen.generate() gen.generate()
@ -302,7 +321,7 @@ def codegen_main():
header_name, header_name,
input_files_basenames, input_files_basenames,
docbook_gen, docbook_gen,
glib_min_version, glib_min_required,
outfile) outfile)
gen.generate() gen.generate()
@ -313,7 +332,7 @@ def codegen_main():
header_name, header_name,
input_files_basenames, input_files_basenames,
args.pragma_once, args.pragma_once,
glib_min_version, glib_min_required,
outfile) outfile)
gen.generate() gen.generate()
@ -323,7 +342,7 @@ def codegen_main():
args.c_namespace, args.c_namespace,
header_name, header_name,
input_files_basenames, input_files_basenames,
glib_min_version, glib_min_required,
outfile) outfile)
gen.generate() gen.generate()

View File

@ -20,3 +20,5 @@
# Author: David Zeuthen <davidz@redhat.com> # Author: David Zeuthen <davidz@redhat.com>
VERSION = "@VERSION@" VERSION = "@VERSION@"
MAJOR_VERSION = @MAJOR_VERSION@
MINOR_VERSION = @MINOR_VERSION@

View File

@ -10,6 +10,8 @@ gdbus_codegen_files = [
gdbus_codegen_conf = configuration_data() gdbus_codegen_conf = configuration_data()
gdbus_codegen_conf.set('VERSION', glib_version) gdbus_codegen_conf.set('VERSION', glib_version)
gdbus_codegen_conf.set('MAJOR_VERSION', major_version)
gdbus_codegen_conf.set('MINOR_VERSION', minor_version)
gdbus_codegen_conf.set('PYTHON', python_name) gdbus_codegen_conf.set('PYTHON', python_name)
gdbus_codegen_conf.set('DATADIR', glib_datadir) gdbus_codegen_conf.set('DATADIR', glib_datadir)

View File

@ -362,41 +362,91 @@ G_END_DECLS
# The output should be the same. # The output should be the same.
self.assertEqual(result1.out, result2.out) self.assertEqual(result1.out, result2.out)
def test_glib_min_version_invalid(self): def test_glib_min_required_invalid(self):
"""Test running with an invalid --glib-min-version.""" """Test running with an invalid --glib-min-required."""
with self.assertRaises(subprocess.CalledProcessError): with self.assertRaises(subprocess.CalledProcessError):
self.runCodegenWithInterface('', self.runCodegenWithInterface('',
'--output', '/dev/stdout', '--output', '/dev/stdout',
'--body', '--body',
'--glib-min-version', 'hello mum') '--glib-min-required', 'hello mum')
def test_glib_min_version_too_low(self): def test_glib_min_required_too_low(self):
"""Test running with a --glib-min-version which is too low (and hence """Test running with a --glib-min-required which is too low (and hence
probably a typo).""" probably a typo)."""
with self.assertRaises(subprocess.CalledProcessError): with self.assertRaises(subprocess.CalledProcessError):
self.runCodegenWithInterface('', self.runCodegenWithInterface('',
'--output', '/dev/stdout', '--output', '/dev/stdout',
'--body', '--body',
'--glib-min-version', '2.6') '--glib-min-required', '2.6')
def test_glib_min_version_major_only(self): def test_glib_min_required_major_only(self):
"""Test running with a --glib-min-version which contains only a major version.""" """Test running with a --glib-min-required which contains only a major version."""
result = self.runCodegenWithInterface('', result = self.runCodegenWithInterface('',
'--output', '/dev/stdout', '--output', '/dev/stdout',
'--header', '--header',
'--glib-min-version', '3') '--glib-min-required', '3',
'--glib-max-allowed', '3.2')
self.assertEqual('', result.err) self.assertEqual('', result.err)
self.assertNotEqual('', result.out.strip()) self.assertNotEqual('', result.out.strip())
def test_glib_min_version_with_micro(self): def test_glib_min_required_with_micro(self):
"""Test running with a --glib-min-version which contains a micro version.""" """Test running with a --glib-min-required which contains a micro version."""
result = self.runCodegenWithInterface('', result = self.runCodegenWithInterface('',
'--output', '/dev/stdout', '--output', '/dev/stdout',
'--header', '--header',
'--glib-min-version', '2.46.2') '--glib-min-required', '2.46.2')
self.assertEqual('', result.err) self.assertEqual('', result.err)
self.assertNotEqual('', result.out.strip()) self.assertNotEqual('', result.out.strip())
def test_glib_max_allowed_too_low(self):
"""Test running with a --glib-max-allowed which is too low (and hence
probably a typo)."""
with self.assertRaises(subprocess.CalledProcessError):
self.runCodegenWithInterface('',
'--output', '/dev/stdout',
'--body',
'--glib-max-allowed', '2.6')
def test_glib_max_allowed_major_only(self):
"""Test running with a --glib-max-allowed which contains only a major version."""
result = self.runCodegenWithInterface('',
'--output', '/dev/stdout',
'--header',
'--glib-max-allowed', '3')
self.assertEqual('', result.err)
self.assertNotEqual('', result.out.strip())
def test_glib_max_allowed_with_micro(self):
"""Test running with a --glib-max-allowed which contains a micro version."""
result = self.runCodegenWithInterface('',
'--output', '/dev/stdout',
'--header',
'--glib-max-allowed', '2.46.2')
self.assertEqual('', result.err)
self.assertNotEqual('', result.out.strip())
def test_glib_max_allowed_unstable(self):
"""Test running with a --glib-max-allowed which is unstable. It should
be rounded up to the next stable version number, and hence should not
end up less than --glib-min-required."""
result = self.runCodegenWithInterface('',
'--output', '/dev/stdout',
'--header',
'--glib-max-allowed', '2.63',
'--glib-min-required', '2.64')
self.assertEqual('', result.err)
self.assertNotEqual('', result.out.strip())
def test_glib_max_allowed_less_than_min_required(self):
"""Test running with a --glib-max-allowed which is less than
--glib-min-required."""
with self.assertRaises(subprocess.CalledProcessError):
self.runCodegenWithInterface('',
'--output', '/dev/stdout',
'--body',
'--glib-max-allowed', '2.62',
'--glib-min-required', '2.64')
def test_unix_fd_types_and_annotations(self): def test_unix_fd_types_and_annotations(self):
"""Test an interface with `h` arguments, no annotation, and GLib < 2.64. """Test an interface with `h` arguments, no annotation, and GLib < 2.64.
@ -422,28 +472,28 @@ G_END_DECLS
</interface> </interface>
</node>''' </node>'''
# Try without specifying --glib-min-version. # Try without specifying --glib-min-required.
result = self.runCodegenWithInterface(interface_xml, result = self.runCodegenWithInterface(interface_xml,
'--output', '/dev/stdout', '--output', '/dev/stdout',
'--header') '--header')
self.assertEqual('', result.err) self.assertEqual('', result.err)
self.assertEqual(result.out.strip().count('GUnixFDList'), 6) 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, result = self.runCodegenWithInterface(interface_xml,
'--output', '/dev/stdout', '--output', '/dev/stdout',
'--header', '--header',
'--glib-min-version', '2.32') '--glib-min-required', '2.32')
self.assertEqual('', result.err) self.assertEqual('', result.err)
self.assertEqual(result.out.strip().count('GUnixFDList'), 6) 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 # mentions of `GUnixFDList` now, since the annotation is not needed to
# trigger its use. # trigger its use.
result = self.runCodegenWithInterface(interface_xml, result = self.runCodegenWithInterface(interface_xml,
'--output', '/dev/stdout', '--output', '/dev/stdout',
'--header', '--header',
'--glib-min-version', '2.64') '--glib-min-required', '2.64')
self.assertEqual('', result.err) self.assertEqual('', result.err)
self.assertEqual(result.out.strip().count('GUnixFDList'), 18) self.assertEqual(result.out.strip().count('GUnixFDList'), 18)
@ -458,7 +508,7 @@ G_END_DECLS
</interface> </interface>
</node>''' </node>'''
# Try without specifying --glib-min-version. # Try without specifying --glib-min-required.
result = self.runCodegenWithInterface(interface_xml, result = self.runCodegenWithInterface(interface_xml,
'--output', '/dev/stdout', '--output', '/dev/stdout',
'--header') '--header')
@ -466,21 +516,21 @@ G_END_DECLS
self.assertEqual(result.out.strip().count('GDBusCallFlags call_flags,'), 0) self.assertEqual(result.out.strip().count('GDBusCallFlags call_flags,'), 0)
self.assertEqual(result.out.strip().count('gint timeout_msec,'), 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, result = self.runCodegenWithInterface(interface_xml,
'--output', '/dev/stdout', '--output', '/dev/stdout',
'--header', '--header',
'--glib-min-version', '2.32') '--glib-min-required', '2.32')
self.assertEqual('', result.err) self.assertEqual('', result.err)
self.assertEqual(result.out.strip().count('GDBusCallFlags call_flags,'), 0) self.assertEqual(result.out.strip().count('GDBusCallFlags call_flags,'), 0)
self.assertEqual(result.out.strip().count('gint timeout_msec,'), 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. # present for both the async and sync method call functions.
result = self.runCodegenWithInterface(interface_xml, result = self.runCodegenWithInterface(interface_xml,
'--output', '/dev/stdout', '--output', '/dev/stdout',
'--header', '--header',
'--glib-min-version', '2.64') '--glib-min-required', '2.64')
self.assertEqual('', result.err) self.assertEqual('', result.err)
self.assertEqual(result.out.strip().count('GDBusCallFlags call_flags,'), 2) self.assertEqual(result.out.strip().count('GDBusCallFlags call_flags,'), 2)
self.assertEqual(result.out.strip().count('gint timeout_msec,'), 2) self.assertEqual(result.out.strip().count('gint timeout_msec,'), 2)

View File

@ -26,7 +26,7 @@
#include "gdbus-tests.h" #include "gdbus-tests.h"
#if GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_64 #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 #else
#include "gdbus-test-codegen-generated.h" #include "gdbus-test-codegen-generated.h"
#endif #endif
@ -2693,7 +2693,7 @@ handle_no_annotation_nested (FooiGenFDPassing *object,
/* Test that generated code for methods includes GUnixFDList arguments /* Test that generated code for methods includes GUnixFDList arguments
* unconditionally if the method is explicitly annotated as C.UnixFD, and only * unconditionally if the method is explicitly annotated as C.UnixFD, and only
* emits GUnixFDList arguments when there's merely an 'h' parameter if * 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 static void
test_unix_fd_list (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' /* This one is not annotated; even though it's got an in and out 'h'
* parameter, for backwards compatibility we cannot emit GUnixFDList * 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; 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', '--generate-docbook', 'gdbus-test-codegen-generated-doc',
annotate_args, annotate_args,
'@INPUT@']) '@INPUT@'])
# Generate gdbus-test-codegen-generated-min-version-2-64.{c,h} # Generate gdbus-test-codegen-generated-min-required-2-64.{c,h}
gdbus_test_codegen_generated_min_version_2_64 = custom_target('gdbus-test-codegen-generated-min-version-2-64', gdbus_test_codegen_generated_min_required_2_64 = custom_target('gdbus-test-codegen-generated-min-required-2-64',
input : ['test-codegen.xml'], input : ['test-codegen.xml'],
output : ['gdbus-test-codegen-generated-min-version-2-64.h', output : ['gdbus-test-codegen-generated-min-required-2-64.h',
'gdbus-test-codegen-generated-min-version-2-64.c'], 'gdbus-test-codegen-generated-min-required-2-64.c'],
depend_files : gdbus_codegen_built_files, depend_files : gdbus_codegen_built_files,
command : [python, gdbus_codegen, command : [python, gdbus_codegen,
'--glib-min-version', '2.64', '--glib-min-required', '2.64',
'--interface-prefix', 'org.project.', '--interface-prefix', 'org.project.',
'--output-directory', '@OUTDIR@', '--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-object-manager',
'--c-generate-autocleanup', 'all', '--c-generate-autocleanup', 'all',
'--c-namespace', 'Foo_iGen', '--c-namespace', 'Foo_iGen',
@ -318,9 +318,9 @@ if host_machine.system() != 'windows'
'c_args' : ['-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_36', 'c_args' : ['-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_36',
'-DGLIB_VERSION_MAX_ALLOWED=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', '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'], 'c_args' : ['-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_64'],
}, },
'gapplication' : {'extra_sources' : extra_sources}, 'gapplication' : {'extra_sources' : extra_sources},