meson: Use dicts to initialize cfg_data objects

Instead of creating an empty object and then setting keys one
at a time, it is possible to pass a dict object to
configuration_data(). This is nicer because it doesn't require
repeating the name of the cfg_data object over and over.

There is one exception: the 'conf' object, where we store values
that are used directly by C code. In that case, using a dict
object is not feasible for two reasons: first of all, replacing
the set_quoted() calls would result in awkward code with a lot
of calls to format(); moreover, since code that modifies it is
sprinkled all over the place, refactoring it would probably
make things more complicated rather than simpler.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Andrea Bolognani 2022-03-29 11:43:36 +02:00
parent 64a7b8203b
commit b94239a61e
9 changed files with 98 additions and 78 deletions

View File

@ -1,14 +1,7 @@
syntax_check_conf = configuration_data()
syntax_check_conf.set('top_srcdir', meson.source_root())
syntax_check_conf.set('top_builddir', meson.build_root())
flake8_path = ''
if flake8_prog.found()
flake8_path = flake8_prog.path()
endif
syntax_check_conf.set('flake8_path', flake8_path)
syntax_check_conf.set('runutf8', ' '.join(runutf8))
syntax_check_conf.set('PYTHON3', python3_prog.path())
if host_machine.system() == 'freebsd' or host_machine.system() == 'darwin'
make_prog = find_program('gmake')
@ -33,8 +26,15 @@ else
grep_prog = find_program('grep')
endif
syntax_check_conf.set('GREP', grep_prog.path())
syntax_check_conf.set('SED', sed_prog.path())
syntax_check_conf = configuration_data({
'top_srcdir': meson.source_root(),
'top_builddir': meson.build_root(),
'flake8_path': flake8_path,
'runutf8': ' '.join(runutf8),
'PYTHON3': python3_prog.path(),
'GREP': grep_prog.path(),
'SED': sed_prog.path(),
})
configure_file(
input: 'Makefile.in',

View File

@ -84,10 +84,11 @@ foreach name : keyname_list
}
endforeach
docs_man_conf = configuration_data()
docs_man_conf.set('SYSCONFDIR', sysconfdir)
docs_man_conf.set('RUNSTATEDIR', runstatedir)
docs_man_conf.set('VERSION', meson.project_version())
docs_man_conf = configuration_data({
'SYSCONFDIR': sysconfdir,
'RUNSTATEDIR': runstatedir,
'VERSION': meson.project_version(),
})
foreach data : docs_man_files
rst_in_file = '@0@.rst'.format(data['name'])

View File

@ -2135,14 +2135,15 @@ pkgconfig_files = [
'libvirt-admin.pc.in',
]
pkgconfig_conf = configuration_data()
pkgconfig_conf.set('VERSION', meson.project_version())
pkgconfig_conf.set('datadir', datadir)
pkgconfig_conf.set('datarootdir', datadir)
pkgconfig_conf.set('exec_prefix', prefix)
pkgconfig_conf.set('includedir', includedir)
pkgconfig_conf.set('libdir', libdir)
pkgconfig_conf.set('prefix', prefix)
pkgconfig_conf = configuration_data({
'VERSION': meson.project_version(),
'datadir': datadir,
'datarootdir': datadir,
'exec_prefix': prefix,
'includedir': includedir,
'libdir': libdir,
'prefix': prefix,
})
pkgconfig_dir = libdir / 'pkgconfig'
@ -2165,8 +2166,9 @@ if git
'mingw-libvirt.spec.in',
]
spec_conf = configuration_data()
spec_conf.set('VERSION', meson.project_version())
spec_conf = configuration_data({
'VERSION': meson.project_version(),
})
foreach file : spec_files
configure_file(
@ -2180,8 +2182,9 @@ if git
env: runutf8, check: true)
authors_file = 'AUTHORS.rst.in'
authors_conf = configuration_data()
authors_conf.set('contributorslist', authors.stdout())
authors_conf = configuration_data({
'contributorslist': authors.stdout(),
})
configure_file(
input: authors_file,
@ -2209,9 +2212,11 @@ configure_file(output: 'meson-config.h', configuration: conf)
# generate run helper
run_conf = configuration_data()
run_conf.set('abs_builddir', meson.build_root())
run_conf.set('abs_top_builddir', meson.build_root())
run_conf = configuration_data({
'abs_builddir': meson.build_root(),
'abs_top_builddir': meson.build_root(),
})
configure_file(
input: 'run.in',
output: '@BASENAME@',

View File

@ -1,8 +1,9 @@
i18n = import('i18n')
potfiles_conf = configuration_data()
potfiles_conf.set('SRCDIR', '')
potfiles_conf.set('BUILDDIR', '')
potfiles_conf = configuration_data({
'SRCDIR': '',
'BUILDDIR': '',
})
potfiles = configure_file(
input: 'POTFILES.in',

View File

@ -698,20 +698,23 @@ endforeach
foreach data : virt_daemon_confs
capitalize_args = [ '-c', 'print("@0@".capitalize())'.format(data['name']) ]
name_uc = run_command(python3_prog, capitalize_args, check: true, env: runutf8).stdout().strip()
daemon_conf = configuration_data()
daemon_conf.set('runstatedir', runstatedir)
daemon_conf.set('sbindir', sbindir)
daemon_conf.set('sysconfdir', sysconfdir)
daemon_conf.set('DAEMON_NAME', data['name'])
daemon_conf.set('DAEMON_NAME_UC', name_uc)
# to silence meson warning about missing 'CONFIG' in the configuration_data
daemon_conf.set('CONFIG', '@CONFIG@')
if conf.has('WITH_POLKIT')
daemon_conf.set('default_auth', 'polkit')
default_auth = 'polkit'
else
daemon_conf.set('default_auth', 'none')
default_auth = 'none'
endif
daemon_conf = configuration_data({
'runstatedir': runstatedir,
'sbindir': sbindir,
'sysconfdir': sysconfdir,
'DAEMON_NAME': data['name'],
'DAEMON_NAME_UC': name_uc,
'default_auth': default_auth,
# to silence meson warning about missing 'CONFIG' in the configuration_data
'CONFIG': '@CONFIG@',
})
if data.get('with_ip', false)
conf_in = libvirtd_conf_tmp
@ -783,20 +786,23 @@ if conf.has('WITH_LIBVIRTD')
)
foreach unit : virt_daemon_units
unit_conf = configuration_data()
unit_conf.set('runstatedir', runstatedir)
unit_conf.set('sbindir', sbindir)
unit_conf.set('sysconfdir', sysconfdir)
unit_conf.set('name', unit['name'])
unit_conf.set('service', unit['service'])
unit_conf.set('sockprefix', unit['sockprefix'])
unit_conf.set('deps', unit.get('deps', ''))
if conf.has('WITH_POLKIT')
unit_conf.set('mode', '0666')
mode = '0666'
else
unit_conf.set('mode', '0600')
mode = '0600'
endif
unit_conf = configuration_data({
'runstatedir': runstatedir,
'sbindir': sbindir,
'sysconfdir': sysconfdir,
'name': unit['name'],
'service': unit['service'],
'sockprefix': unit['sockprefix'],
'deps': unit.get('deps', ''),
'mode': mode,
})
configure_file(
input: unit['service_in'],
output: '@0@.service'.format(unit['service']),
@ -829,15 +835,17 @@ if conf.has('WITH_LIBVIRTD')
# Generate openrc init files
if init_script == 'openrc'
foreach init : openrc_init_files
init_conf = configuration_data()
init_conf.set('sbindir', sbindir)
init_conf.set('runstatedir', runstatedir)
if conf.has('WITH_FIREWALLD')
need_firewalld = 'need firewalld'
else
need_firewalld = ''
endif
init_conf.set('NEED_FIREWALLD', need_firewalld)
init_conf = configuration_data({
'sbindir': sbindir,
'runstatedir': runstatedir,
'NEED_FIREWALLD': need_firewalld,
})
init_file = configure_file(
input: init['in_file'],
@ -1010,10 +1018,11 @@ run_pkg_config_files = [
'libvirt.pc.in',
]
run_pkg_config_conf = configuration_data()
run_pkg_config_conf.set('VERSION', meson.project_version())
run_pkg_config_conf.set('abs_top_builddir', meson.build_root())
run_pkg_config_conf.set('abs_top_srcdir', meson.source_root())
run_pkg_config_conf = configuration_data({
'VERSION': meson.project_version(),
'abs_top_builddir': meson.build_root(),
'abs_top_srcdir': meson.source_root(),
})
foreach file : run_pkg_config_files
configure_file(

View File

@ -240,8 +240,9 @@ if conf.has('WITH_REMOTE')
runstatedir / 'libvirt' / 'common',
]
logrotate_conf = configuration_data()
logrotate_conf.set('localstatedir', localstatedir)
logrotate_conf = configuration_data({
'localstatedir': localstatedir,
})
foreach name : logrotate_files
log_file = configure_file(

View File

@ -5,11 +5,12 @@ apparmor_gen_profiles = [
'usr.sbin.virtxend',
]
apparmor_gen_profiles_conf = configuration_data()
apparmor_gen_profiles_conf.set('sysconfdir', sysconfdir)
apparmor_gen_profiles_conf.set('sbindir', sbindir)
apparmor_gen_profiles_conf.set('runstatedir', runstatedir)
apparmor_gen_profiles_conf.set('libexecdir', libexecdir)
apparmor_gen_profiles_conf = configuration_data({
'sysconfdir': sysconfdir,
'sbindir': sbindir,
'runstatedir': runstatedir,
'libexecdir': libexecdir,
})
apparmor_dir = sysconfdir / 'apparmor.d'

View File

@ -4,8 +4,9 @@ completion_commands = [
]
foreach command : completion_commands
completion_conf = configuration_data()
completion_conf.set('command', command)
completion_conf = configuration_data({
'command': command,
})
completion = configure_file(
input: 'vsh.in',
output: command,

View File

@ -231,16 +231,17 @@ if conf.has('WITH_REMOTE')
)
endif
tools_conf = configuration_data()
tools_conf.set('PACKAGE', meson.project_name())
tools_conf.set('VERSION', meson.project_version())
tools_conf.set('bindir', bindir)
tools_conf.set('libexecdir', libexecdir)
tools_conf.set('localedir', localedir)
tools_conf.set('localstatedir', localstatedir)
tools_conf.set('sbindir', sbindir)
tools_conf.set('schemadir', pkgdatadir / 'schemas')
tools_conf.set('sysconfdir', sysconfdir)
tools_conf = configuration_data({
'PACKAGE': meson.project_name(),
'VERSION': meson.project_version(),
'bindir': bindir,
'libexecdir': libexecdir,
'localedir': localedir,
'localstatedir': localstatedir,
'sbindir': sbindir,
'schemadir': pkgdatadir / 'schemas',
'sysconfdir': sysconfdir,
})
configure_file(
input: 'virt-xml-validate.in',