]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
remote: apply translations to polkit files
authorDaniel P. Berrangé <berrange@redhat.com>
Thu, 19 Dec 2024 09:27:27 +0000 (09:27 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Mon, 6 Jan 2025 18:58:44 +0000 (18:58 +0000)
The 'description' and 'message' fields in polkit policy files should be
translated into the user's chosen language. xgettext is told to search
in both and source and build dirs by meson.

Unfortunately a bug in xgettext means that when it searches for built
files in XML format, it'll trigger a warning message due to failure to
load the generated file from the source dir:

  xgettext: cannot read ..snip../libvirt/src/access/org.libvirt.api.policy: failed to load external entity "..snip../libvirt/src/access/org.libvirt.api.policy"

This is harmless since it then goes on to try the build dir and
succeeds, but will pollute the output of 'ninja libvirt-pot'

Related: https://gitlab.com/libvirt/libvirt/-/merge_requests/387
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
build-aux/syntax-check.mk
meson.build
po/POTFILES
po/meson.build
src/access/meson.build
src/remote/libvirtd.policy.in [moved from src/remote/libvirtd.policy with 100% similarity]
src/remote/meson.build

index 2c9593c28f302e3fba7d4e8635319e42d4c5e306..e6afb879be3b84f7acef4c46e6f4feb57b152c0b 100644 (file)
@@ -1273,9 +1273,10 @@ po_file ?= $(top_srcdir)/po/POTFILES
 # This is all generated files for RPC code.
 generated_files = \
   $(top_builddir)/src/*.[ch] \
-  $(top_builddir)/src/*/*.[ch]
+  $(top_builddir)/src/*/*.[ch] \
+  $(top_builddir)/src/*/*.policy.in
 
-_gl_translatable_string_re ?= \b(N?_|gettext *)\([^)"]*("|$$)
+_gl_translatable_string_re ?= (^<policyconfig>|\b(N?_|gettext *)\([^)"]*("|$$))
 
 # sc_po_check can fail if generated files are not built first
 sc_po_check:
index 409a44b69c5b427fbe5d99e2b9b475e41970b00f..65010dd6a8e50a0ab9a4f1fdc35260f6a7f3e9c1 100644 (file)
@@ -15,6 +15,10 @@ if meson.version().version_compare('>=0.64.0')
   fs = import('fs')
 endif
 
+i18n = import('i18n')
+
+po_dir = meson.source_root() / 'po'
+
 # figure out if we are building from git
 
 git = run_command('test', '-e', '.git', check: false).returncode() == 0
index 6100341330858125b358e781125422c4da31a1cd..484b34c3dfe0c18e63d51537d2793a7a8317dfba 100644 (file)
@@ -1,6 +1,7 @@
 src/access/viraccessapicheck.c
 src/access/viraccessapichecklxc.c
 src/access/viraccessapicheckqemu.c
+src/access/org.libvirt.api.policy.in
 src/admin/admin_client.h
 src/admin/admin_server_dispatch_stubs.h
 src/remote/remote_client_bodies.h
@@ -201,6 +202,7 @@ src/qemu/qemu_validate.c
 src/qemu/qemu_vhost_user.c
 src/qemu/qemu_vhost_user_gpu.c
 src/qemu/qemu_virtiofs.c
+src/remote/libvirtd.policy.in
 src/remote/remote_daemon.c
 src/remote/remote_daemon_config.c
 src/remote/remote_daemon_dispatch.c
index 126eeabe17b8ef49812557b1309caf41832ebd2f..0f00b4830e2e4fe0c759ee2a9bde4cb40518106b 100644 (file)
@@ -1,5 +1,3 @@
-i18n = import('i18n')
-
 i18n.gettext(
   meson.project_name(),
   args: [
@@ -18,7 +16,7 @@ i18n.gettext(
 )
 
 potfiles_dep = [
-  access_gen_sources,
+  access_generated,
   admin_client_generated,
   admin_driver_generated,
   remote_protocol_generated,
index c006ca5934600ec62ce6839493e0a09ab456c6fb..0cc9cf2b7926a6bd07e931457517b5e9f5c58d03 100644 (file)
@@ -17,6 +17,7 @@ access_gen_headers = []
 access_gen_sources = []
 access_gen_sym = []
 access_gen_xml = []
+access_generated = []
 
 foreach name : [ 'remote', 'qemu', 'lxc' ]
   if name == 'remote'
@@ -66,18 +67,29 @@ if conf.has('WITH_POLKIT')
   access_sources += access_polkit_sources
 
   if conf.has('WITH_LIBVIRTD')
-    custom_target(
-      'org.libvirt.api.policy',
+    polgen = custom_target(
+      'org.libvirt.api.policy.in',
       input: access_perm_h,
-      output: 'org.libvirt.api.policy',
+      output: 'org.libvirt.api.policy.in',
       command: [ meson_python_prog, python3_prog, genpolkit_prog, '@INPUT@' ],
       capture: true,
+      build_by_default: true,
+    )
+    access_generated += polgen
+
+    i18n.merge_file(
+      input: polgen,
+      output: 'org.libvirt.api.policy',
+      po_dir: po_dir,
+      data_dirs: [po_dir],
       install: true,
       install_dir: polkitactionsdir,
     )
   endif
 endif
 
+access_generated += access_gen_sources
+
 virt_access_lib = static_library(
   'virt_access',
   [
index 9a0288f928f87b2d21f0d42bc33c1765dcd6deee..ea063ed6cc1cc98da5cc51e1fe47f29a8af51a19 100644 (file)
@@ -294,11 +294,15 @@ if conf.has('WITH_REMOTE')
     endif
 
     if conf.has('WITH_POLKIT')
-      install_data(
-        'libvirtd.policy',
+      i18n.merge_file(
+        input: 'libvirtd.policy.in',
+        output: 'org.libvirt.unix.policy',
+        po_dir: po_dir,
+        data_dirs: [po_dir],
+        install: true,
         install_dir: polkitactionsdir,
-        rename: [ 'org.libvirt.unix.policy' ],
       )
+
       install_data(
         'libvirtd.rules',
         install_dir: polkitrulesdir,