[PATCH 11/16] build: switch over to new rpc generator code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This replaces use of 'rpcgen' with our new python impl of
the RPC code generator. Since the new impl generates code
that matches our style/coding rules, and does not contain
long standing bugs, we no longer need to post-process the
output.

Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 libvirt.spec.in                   |   1 -
 meson.build                       |  11 ---
 scripts/rpcgen/meson.build        |   5 ++
 scripts/rpcgen/rpcgen/meson.build |   7 ++
 src/admin/meson.build             |   8 +-
 src/locking/meson.build           |   8 +-
 src/logging/meson.build           |   8 +-
 src/lxc/meson.build               |  12 ++-
 src/remote/meson.build            |   8 +-
 src/rpc/genprotocol.pl            | 121 ------------------------------
 src/rpc/meson.build               |   9 ++-
 11 files changed, 52 insertions(+), 146 deletions(-)
 create mode 100644 scripts/rpcgen/rpcgen/meson.build
 delete mode 100755 src/rpc/genprotocol.pl

diff --git a/libvirt.spec.in b/libvirt.spec.in
index 84d2f1c65a..aca7e23512 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -377,7 +377,6 @@ BuildRequires: wireshark-devel
 %if %{with_libssh}
 BuildRequires: libssh-devel >= 0.8.1
 %endif
-BuildRequires: rpcgen
 BuildRequires: libtirpc-devel
 # Needed for the firewalld_reload macro
 %if %{with_firewalld_zone}
diff --git a/meson.build b/meson.build
index 9f660c7604..ef1f697e0b 100644
--- a/meson.build
+++ b/meson.build
@@ -743,10 +743,6 @@ required_programs = [
   'xsltproc',
 ]
 
-required_programs_groups = [
-  { 'name': 'rpcgen', 'prog': [ 'rpcgen', 'portable-rpcgen' ] },
-]
-
 if host_machine.system() == 'freebsd'
   required_programs += 'ifconfig'
 endif
@@ -758,13 +754,6 @@ foreach name : required_programs
   set_variable('@0@_prog'.format(varname), prog)
 endforeach
 
-foreach item : required_programs_groups
-  prog = find_program(item.get('prog'), dirs: libvirt_sbin_path)
-  varname = item.get('name').underscorify()
-  conf.set_quoted(varname.to_upper(), prog.full_path())
-  set_variable('@0@_prog'.format(varname), prog)
-endforeach
-
 # optional programs
 
 optional_programs = [
diff --git a/scripts/rpcgen/meson.build b/scripts/rpcgen/meson.build
index 52526bf812..65236457be 100644
--- a/scripts/rpcgen/meson.build
+++ b/scripts/rpcgen/meson.build
@@ -1,3 +1,5 @@
+subdir('rpcgen')
+
 if pytest_prog.found()
     subdir('tests')
 
@@ -9,3 +11,6 @@ if pytest_prog.found()
         workdir: meson.current_source_dir(),
     )
 endif
+
+rpcgen_prog = find_program('main.py')
+rpcgen_src += files(['main.py'])
diff --git a/scripts/rpcgen/rpcgen/meson.build b/scripts/rpcgen/rpcgen/meson.build
new file mode 100644
index 0000000000..5a0f59eecf
--- /dev/null
+++ b/scripts/rpcgen/rpcgen/meson.build
@@ -0,0 +1,7 @@
+rpcgen_src = files([
+    'ast.py',
+    'lexer.py',
+    'generator.py',
+    'parser.py',
+    'visitor.py',
+])
diff --git a/src/admin/meson.build b/src/admin/meson.build
index 692cc128a3..e5e6a87706 100644
--- a/src/admin/meson.build
+++ b/src/admin/meson.build
@@ -13,8 +13,10 @@ admin_protocol_h = custom_target(
   'admin_protocol.h',
   input: admin_driver_protocol,
   output: 'admin_protocol.h',
+  depend_files: rpcgen_src,
   command: [
-    genprotocol_prog, rpcgen_prog, '-h', '@INPUT@', '@OUTPUT@',
+    meson_python_prog, python3_prog, rpcgen_prog,
+    '--mode=header', '@INPUT@', '@OUTPUT@',
   ],
 )
 admin_driver_generated += admin_protocol_h
@@ -23,8 +25,10 @@ admin_driver_generated += custom_target(
   'admin_protocol.c',
   input: admin_driver_protocol,
   output: 'admin_protocol.c',
+  depend_files: rpcgen_src,
   command: [
-    genprotocol_prog, rpcgen_prog, '-c', '@INPUT@', '@OUTPUT@',
+    meson_python_prog, python3_prog, rpcgen_prog,
+    '--mode=source', '--header=admin_protocol.h', '@INPUT@', '@OUTPUT@',
   ],
 )
 
diff --git a/src/locking/meson.build b/src/locking/meson.build
index 72f7780438..529caa1b9e 100644
--- a/src/locking/meson.build
+++ b/src/locking/meson.build
@@ -18,8 +18,10 @@ lock_protocol_generated += custom_target(
   'lock_protocol.h',
   input: lock_protocol,
   output: 'lock_protocol.h',
+  depend_files: rpcgen_src,
   command: [
-    genprotocol_prog, rpcgen_prog, '-h', '@INPUT@', '@OUTPUT@',
+    meson_python_prog, python3_prog, rpcgen_prog,
+    '--mode=header', '@INPUT@', '@OUTPUT@',
   ],
 )
 
@@ -27,8 +29,10 @@ lock_protocol_generated += custom_target(
   'lock_protocol.c',
   input: lock_protocol,
   output: 'lock_protocol.c',
+  depend_files: rpcgen_src,
   command: [
-    genprotocol_prog, rpcgen_prog, '-c', '@INPUT@', '@OUTPUT@',
+    meson_python_prog, python3_prog, rpcgen_prog,
+    '--mode=source', '--header=lock_protocol.h', '@INPUT@', '@OUTPUT@',
   ],
 )
 
diff --git a/src/logging/meson.build b/src/logging/meson.build
index fa6af50fa6..4f5ca92052 100644
--- a/src/logging/meson.build
+++ b/src/logging/meson.build
@@ -10,8 +10,10 @@ log_protocol_header_generated = custom_target(
   'log_protocol.h',
   input: log_protocol,
   output: 'log_protocol.h',
+  depend_files: rpcgen_src,
   command: [
-    genprotocol_prog, rpcgen_prog, '-h', '@INPUT@', '@OUTPUT@'
+    meson_python_prog, python3_prog, rpcgen_prog,
+    '--mode=header', '@INPUT@', '@OUTPUT@',
   ],
 )
 log_protocol_generated += log_protocol_header_generated
@@ -20,8 +22,10 @@ log_protocol_generated += custom_target(
   'log_protocol.c',
   input: log_protocol,
   output: 'log_protocol.c',
+  depend_files: rpcgen_src,
   command: [
-    genprotocol_prog, rpcgen_prog, '-c', '@INPUT@', '@OUTPUT@'
+    meson_python_prog, python3_prog, rpcgen_prog,
+    '--mode=source', '--header=log_protocol.h', '@INPUT@', '@OUTPUT@',
   ],
 )
 
diff --git a/src/lxc/meson.build b/src/lxc/meson.build
index 99d4a34213..3a21f1f006 100644
--- a/src/lxc/meson.build
+++ b/src/lxc/meson.build
@@ -21,14 +21,22 @@ lxc_monitor_protocol_generated += custom_target(
   'lxc_monitor_protocol_h',
   input: lxc_monitor_protocol,
   output: 'lxc_monitor_protocol.h',
-  command: [ genprotocol_prog, rpcgen_prog, '-h', '@INPUT@', '@OUTPUT@' ]
+  depend_files: rpcgen_src,
+  command: [
+    meson_python_prog, python3_prog, rpcgen_prog,
+    '--mode=header', '@INPUT@', '@OUTPUT@',
+  ]
 )
 
 lxc_monitor_protocol_generated += custom_target(
   'lxc_monitor_protocol_c',
   input: lxc_monitor_protocol,
   output: 'lxc_monitor_protocol.c',
-  command: [ genprotocol_prog, rpcgen_prog, '-c', '@INPUT@', '@OUTPUT@' ]
+  depend_files: rpcgen_src,
+  command: [
+    meson_python_prog, python3_prog, rpcgen_prog,
+    '--mode=source', '--header=lxc_monitor_protocol.h', '@INPUT@', '@OUTPUT@',
+  ],
 )
 
 lxc_monitor_generated = custom_target(
diff --git a/src/remote/meson.build b/src/remote/meson.build
index eb4f7a0068..ce41591f5b 100644
--- a/src/remote/meson.build
+++ b/src/remote/meson.build
@@ -25,8 +25,10 @@ foreach name : [ 'remote', 'qemu', 'lxc' ]
     protocol_h,
     input: protocol_x,
     output: protocol_h,
+    depend_files: rpcgen_src,
     command: [
-      genprotocol_prog, rpcgen_prog, '-h', '@INPUT@', '@OUTPUT@',
+      meson_python_prog, python3_prog, rpcgen_prog,
+      '--mode=header', '@INPUT@', '@OUTPUT@',
     ],
   )
 
@@ -34,8 +36,10 @@ foreach name : [ 'remote', 'qemu', 'lxc' ]
     protocol_c,
     input: protocol_x,
     output: protocol_c,
+    depend_files: rpcgen_src,
     command: [
-      genprotocol_prog, rpcgen_prog, '-c', '@INPUT@', '@OUTPUT@',
+      meson_python_prog, python3_prog, rpcgen_prog,
+      '--mode=source', '--header=' + protocol_h, '@INPUT@', '@OUTPUT@',
     ],
   )
 
diff --git a/src/rpc/genprotocol.pl b/src/rpc/genprotocol.pl
deleted file mode 100755
index 079627964f..0000000000
--- a/src/rpc/genprotocol.pl
+++ /dev/null
@@ -1,121 +0,0 @@
-#!/usr/bin/env perl
-#
-# Generate code for an XDR protocol, optionally applying
-# fixups to the glibc rpcgen code so that it compiles
-# with warnings turned on.
-#
-# This code is evil.  Arguably better would be just to compile
-# without -Werror.  Update: The IXDR_PUT_LONG replacements are
-# actually fixes for 64 bit, so this file is necessary.  Arguably
-# so is the type-punning fix.
-#
-# Copyright (C) 2007, 2011-2013 Red Hat, Inc.
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library.  If not, see
-# <http://www.gnu.org/licenses/>.
-#
-# Richard Jones <rjones@xxxxxxxxxx>
-
-use strict;
-
-my $in_function = 0;
-my @function = ();
-
-my $rpcgen = shift;
-my $mode = shift;
-my $xdrdef = shift;
-my $target = shift;
-
-unlink $target;
-
-if ($rpcgen =~ /portable-rpcgen/) {
-    $rpcgen = "$rpcgen -o -";
-}
-open RPCGEN, "-|", "$rpcgen $mode $xdrdef"
-    or die "cannot run $rpcgen $mode $xdrdef: $!";
-open TARGET, ">$target"
-    or die "cannot create $target: $!";
-
-my $fixup = $^O eq "linux" || $^O eq "gnukfreebsd" || $^O eq "freebsd" || $^O eq "darwin";
-
-if ($mode eq "-c") {
-    print TARGET "#include <config.h>\n";
-}
-
-while (<RPCGEN>) {
-    # We only want to fixup the GLibc rpcgen output
-    # So just print data unchanged, if non-Linux
-    unless ($fixup) {
-        print TARGET;
-        next;
-    }
-
-    if (m/^{/) {
-        $in_function = 1;
-        print TARGET;
-        next;
-    }
-
-    s/\t/        /g;
-
-    # Fix VPATH builds
-    s,#include ".*/([^/]+)protocol\.h",#include "${1}protocol.h",;
-
-    # Portability for Solaris RPC
-    s/u_quad_t/uint64_t/g;
-    s/quad_t/int64_t/g;
-    s/xdr_u_quad_t/xdr_uint64_t/g;
-    s/xdr_quad_t/xdr_int64_t/g;
-    s/(?<!IXDR_GET_INT32 )IXDR_GET_LONG/IXDR_GET_INT32/g;
-
-    if (m/^}/) {
-        $in_function = 0;
-
-        # Note: The body of the function is in @function.
-
-        # Remove decl of buf, if buf isn't used in the function.
-        my @uses = grep /[^.>]\bbuf\b/, @function;
-        @function = grep !/[^.>]\bbuf\b/, @function if @uses == 1;
-
-        # Remove decl of i, if i isn't used in the function.
-        @uses = grep /[^.>]\bi\b/, @function;
-        @function = grep !/[^.>]\bi\b/, @function if @uses == 1;
-
-        # The code uses 'IXDR_PUT_{U_,}LONG' but it's wrong in two
-        # ways: Firstly these functions are deprecated and don't
-        # work on 64 bit platforms.  Secondly the return value should
-        # be ignored.  Correct both these mistakes.
-        @function =
-            map { s/\bIXDR_PUT_((U_)?)LONG\b/(void)IXDR_PUT_$1INT32/; $_ }
-            map { s/\bXDR_INLINE\b/(int32_t*)XDR_INLINE/; $_ }
-            @function;
-
-        print TARGET (join ("", @function));
-        @function = ();
-    }
-
-    unless ($in_function) {
-        print TARGET;
-    } else {
-        push @function, $_;
-    }
-}
-
-close TARGET
-    or die "cannot save $target: $!";
-close RPCGEN
-    or die "cannot shutdown $rpcgen: $!";
-
-chmod 0444, $target
-    or die "cannot set $target readonly: $!";
diff --git a/src/rpc/meson.build b/src/rpc/meson.build
index 36a2809adf..d58f3caaf5 100644
--- a/src/rpc/meson.build
+++ b/src/rpc/meson.build
@@ -1,4 +1,3 @@
-genprotocol_prog = find_program('genprotocol.pl')
 gendispatch_prog = find_program('gendispatch.pl')
 
 socket_sources = [
@@ -53,8 +52,10 @@ foreach name : [ 'virnet', 'virkeepalive' ]
     header_file,
     input: protocol_file,
     output: header_file,
+    depend_files: rpcgen_src,
     command: [
-      genprotocol_prog, rpcgen_prog, '-h', '@INPUT@', '@OUTPUT@',
+      meson_python_prog, python3_prog, rpcgen_prog,
+      '--mode=header', '@INPUT@', '@OUTPUT@',
     ],
   )
 
@@ -62,8 +63,10 @@ foreach name : [ 'virnet', 'virkeepalive' ]
     source_file,
     input: protocol_file,
     output: source_file,
+    depend_files: rpcgen_src,
     command: [
-      genprotocol_prog, rpcgen_prog, '-c', '@INPUT@', '@OUTPUT@',
+      meson_python_prog, python3_prog, rpcgen_prog,
+      '--mode=source', '--header=' + header_file, '@INPUT@', '@OUTPUT@',
     ],
   )
 
-- 
2.39.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux