[RFCv3 03/25] maint: Call xmlgen automatically when c-head-files change

Shi Lei shi_lei at massclouds.com
Thu Apr 22 07:25:11 UTC 2021


Monitor changes of header-files in src/util and src/conf.
Whenever that happens, the tool xmlgen will generate
parse/format functions based on these files automatically.

Signed-off-by: Shi Lei <shi_lei at massclouds.com>
---
 scripts/meson.build  |  8 ++++++++
 src/conf/meson.build | 36 ++++++++++++++++++++++++++++++++++++
 src/meson.build      |  6 ++++++
 src/util/meson.build | 36 ++++++++++++++++++++++++++++++++++++
 tests/meson.build    |  2 ++
 tools/meson.build    |  3 +++
 6 files changed, 91 insertions(+)

diff --git a/scripts/meson.build b/scripts/meson.build
index 421e3d2a..5399868c 100644
--- a/scripts/meson.build
+++ b/scripts/meson.build
@@ -35,3 +35,11 @@ foreach name : scripts
   sname = name.split('.')[0].underscorify()
   set_variable('@0 at _prog'.format(sname), find_program(name))
 endforeach
+
+xmlgen_self = files(
+  'xmlgen/main.py',
+  'xmlgen/directive.py',
+  'xmlgen/utils.py'
+)
+
+set_variable('virxmlgen_prog', find_program('xmlgen/main.py'))
diff --git a/src/conf/meson.build b/src/conf/meson.build
index bd35d87e..1439c31d 100644
--- a/src/conf/meson.build
+++ b/src/conf/meson.build
@@ -1,3 +1,38 @@
+conf_xmlgen_input = [
+]
+
+conf_xmlgen_output = []
+foreach name : conf_xmlgen_input
+  conf_xmlgen_output += '@0 at .generated.c'.format(name.split('.')[0])
+  conf_xmlgen_output += '@0 at .generated.h'.format(name.split('.')[0])
+endforeach
+
+conf_xmlgen_headers = []
+if conf_xmlgen_output.length() > 0
+  conf_xmlgen_objects = custom_target(
+    'virxmlgen',
+    input: xmlgen_self + conf_xmlgen_input,
+    output: conf_xmlgen_output,
+    command: [
+      meson_python_prog, python3_prog.path(), '-B', virxmlgen_prog.path(),
+      '-s', meson.source_root() / 'src', '-b', meson.build_root() / 'src',
+      '-d', 'conf', 'generate',
+    ],
+  )
+
+  index = 0
+  foreach header : conf_xmlgen_objects.to_list()
+    if index % 2 == 1
+      conf_xmlgen_headers += header
+    endif
+    index += 1
+  endforeach
+else
+  conf_xmlgen_objects = []
+endif
+
+conf_xmlgen_dep = declare_dependency(sources: conf_xmlgen_headers)
+
 netdev_conf_sources = [
   'netdev_bandwidth_conf.c',
   'netdev_vlan_conf.c',
@@ -90,6 +125,7 @@ device_conf_sources = [
 virt_conf_lib = static_library(
   'virt_conf',
   [
+    conf_xmlgen_objects,
     chrdev_conf_sources,
     cpu_conf_sources,
     device_conf_sources,
diff --git a/src/meson.build b/src/meson.build
index c7ff9e97..f8ae47b4 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -245,6 +245,12 @@ src_dep = declare_dependency(
 )
 
 subdir('conf')
+
+src_dep = declare_dependency(
+  dependencies: [ src_dep, util_xmlgen_dep, conf_xmlgen_dep ],
+  include_directories: [ conf_inc_dir ],
+)
+
 subdir('rpc')
 subdir('access')
 subdir('cpu')
diff --git a/src/util/meson.build b/src/util/meson.build
index 05934f68..0d41de92 100644
--- a/src/util/meson.build
+++ b/src/util/meson.build
@@ -1,3 +1,38 @@
+util_xmlgen_input = [
+]
+
+util_xmlgen_output = []
+foreach name : util_xmlgen_input
+  util_xmlgen_output += '@0 at .generated.c'.format(name.split('.')[0])
+  util_xmlgen_output += '@0 at .generated.h'.format(name.split('.')[0])
+endforeach
+
+util_xmlgen_headers = []
+if util_xmlgen_output.length() > 0
+  util_xmlgen_objects = custom_target(
+    'virxmlgen',
+    input: xmlgen_self + util_xmlgen_input,
+    output: util_xmlgen_output,
+    command: [
+      meson_python_prog, python3_prog.path(), '-B', virxmlgen_prog.path(),
+      '-s', meson.source_root() / 'src', '-b', meson.build_root() / 'src',
+      '-d', 'util', 'generate',
+    ],
+  )
+
+  index = 0
+  foreach header : util_xmlgen_objects.to_list()
+    if index % 2 == 1
+      util_xmlgen_headers += header
+    endif
+    index += 1
+  endforeach
+else
+  util_xmlgen_objects = []
+endif
+
+util_xmlgen_dep = declare_dependency(sources: util_xmlgen_headers)
+
 util_sources = [
   'glibcompat.c',
   'viralloc.c',
@@ -179,6 +214,7 @@ io_helper_sources = [
 virt_util_lib = static_library(
   'virt_util',
   [
+    util_xmlgen_objects,
     util_sources,
     util_public_sources,
     keycode_gen_sources,
diff --git a/tests/meson.build b/tests/meson.build
index 05c3e901..14ace476 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -17,6 +17,8 @@ tests_dep = declare_dependency(
     selinux_dep,
     xdr_dep,
     yajl_dep,
+    util_xmlgen_dep,
+    conf_xmlgen_dep,
   ],
   include_directories: [
     conf_inc_dir,
diff --git a/tools/meson.build b/tools/meson.build
index 2acf7b0a..162db0e8 100644
--- a/tools/meson.build
+++ b/tools/meson.build
@@ -5,11 +5,14 @@ tools_dep = declare_dependency(
   dependencies: [
     libxml_dep,
     glib_dep,
+    util_xmlgen_dep,
+    conf_xmlgen_dep,
   ],
   include_directories: [
     libvirt_inc,
     src_inc_dir,
     util_inc_dir,
+    conf_inc_dir,
     top_inc_dir,
   ],
   link_args: (
-- 
2.25.1





More information about the libvir-list mailing list