Move the existing rpcgen_fix.pl script to rpcgenprotocol.pl
and adjust it so that the script runs 'rpcgen' itself via
a pipe, avoiding the need for any intermediate files.
* Makefile.am: Re-write RPC generator rules
* remote/rpcgen_fix.pl -> rpc/genprotocol.pl
* remote/qemu_protocol.h, remote/remote_protocol.h,
rpc/virnetprotocol.h: Re-generate
---
src/Makefile.am | 75 ++++++++------------------
src/remote/qemu_protocol.h | 6 +-
src/remote/remote_protocol.h | 6 +-
src/remote/rpcgen_fix.pl | 91 -------------------------------
src/rpc/genprotocol.pl | 124 ++++++++++++++++++++++++++++++++++++++++++
src/rpc/virnetprotocol.h | 6 +-
6 files changed, 156 insertions(+), 152 deletions(-)
delete mode 100644 src/remote/rpcgen_fix.pl
create mode 100644 src/rpc/genprotocol.pl
diff --git a/src/Makefile.am b/src/Makefile.am
index 334d535..178a274 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -160,8 +160,7 @@ REMOTE_DRIVER_SOURCES = \
remote/qemu_protocol.c \
remote/qemu_protocol.h
-EXTRA_DIST += remote/remote_protocol.x remote/qemu_protocol.x \
- remote/rpcgen_fix.pl
+EXTRA_DIST += remote/remote_protocol.x remote/qemu_protocol.x
# Ensure that we don't change the struct or member names or member ordering
# in remote_protocol.x The embedded perl below needs a few comments, and
@@ -496,58 +495,29 @@ if HAVE_RPCGEN
# non-Linux people needing to test changes during dev.
#
rpcgen-normal:
- rm -f rp.c-t rp.h-t rp.c-t1 rp.c-t2 rp.h-t1
- $(RPCGEN) -h -o rp.h-t $(srcdir)/remote/remote_protocol.x
- $(RPCGEN) -c -o rp.c-t $(srcdir)/remote/remote_protocol.x
-if HAVE_GLIBC_RPCGEN
- perl -w $(srcdir)/remote/rpcgen_fix.pl rp.h-t > rp.h-t1
- perl -w $(srcdir)/remote/rpcgen_fix.pl rp.c-t > rp.c-t1
- (echo '#include <config.h>'; cat rp.c-t1) > rp.c-t2
- chmod 0444 rp.c-t2 rp.h-t1
- mv -f rp.h-t1 $(srcdir)/remote/remote_protocol.h
- mv -f rp.c-t2 $(srcdir)/remote/remote_protocol.c
- rm -f rp.c-t rp.h-t rp.c-t1
-else
- chmod 0444 rp.c-t rp.h-t
- mv -f rp.h-t $(srcdir)/remote/remote_protocol.h
- mv -f rp.c-t $(srcdir)/remote/remote_protocol.c
-endif
+ $(AM_V_GEN)perl -w $(srcdir)/rpc/genprotocol.pl $(RPCGEN) -h \
+ $(srcdir)/remote/remote_protocol.x \
+ $(srcdir)/remote/remote_protocol.h
+ $(AM_V_GEN)perl -w $(srcdir)/rpc/genprotocol.pl $(RPCGEN) -c \
+ $(srcdir)/remote/remote_protocol.x \
+ $(srcdir)/remote/remote_protocol.c
+
rpcgen-qemu:
- rm -f rp_qemu.c-t rp_qemu.h-t rp_qemu.c-t1 rp_qemu.c-t2 rp_qemu.h-t1
- $(RPCGEN) -h -o rp_qemu.h-t $(srcdir)/remote/qemu_protocol.x
- $(RPCGEN) -c -o rp_qemu.c-t $(srcdir)/remote/qemu_protocol.x
-if HAVE_GLIBC_RPCGEN
- perl -w $(srcdir)/remote/rpcgen_fix.pl rp_qemu.h-t > rp_qemu.h-t1
- perl -w $(srcdir)/remote/rpcgen_fix.pl rp_qemu.c-t > rp_qemu.c-t1
- (echo '#include <config.h>'; cat rp_qemu.c-t1) > rp_qemu.c-t2
- chmod 0444 rp_qemu.c-t2 rp_qemu.h-t1
- mv -f rp_qemu.h-t1 $(srcdir)/remote/qemu_protocol.h
- mv -f rp_qemu.c-t2 $(srcdir)/remote/qemu_protocol.c
- rm -f rp_qemu.c-t rp_qemu.h-t rp_qemu.c-t1
-else
- chmod 0444 rp_qemu.c-t rp_qemu.h-t
- mv -f rp_qemu.h-t $(srcdir)/remote/qemu_protocol.h
- mv -f rp_qemu.c-t $(srcdir)/remote/qemu_protocol.c
-endif
+ $(AM_V_GEN)perl -w $(srcdir)/rpc/genprotocol.pl $(RPCGEN) -h \
+ $(srcdir)/remote/qemu_protocol.x \
+ $(srcdir)/remote/qemu_protocol.h
+ $(AM_V_GEN)perl -w $(srcdir)/rpc/genprotocol.pl $(RPCGEN) -c \
+ $(srcdir)/remote/qemu_protocol.x \
+ $(srcdir)/remote/qemu_protocol.c
rpcgen-net:
- rm -f rp_net.c-t rp_net.h-t rp_net.c-t1 rp_net.c-t2 rp_net.h-t1
- $(RPCGEN) -h -o rp_net.h-t $(srcdir)/rpc/virnetprotocol.x
- $(RPCGEN) -c -o rp_net.c-t $(srcdir)/rpc/virnetprotocol.x
-if HAVE_GLIBC_RPCGEN
- perl -w $(srcdir)/remote/rpcgen_fix.pl rp_net.h-t > rp_net.h-t1
- perl -w $(srcdir)/remote/rpcgen_fix.pl rp_net.c-t > rp_net.c-t1
- (echo '#include <config.h>'; cat rp_net.c-t1) > rp_net.c-t2
- chmod 0444 rp_net.c-t2 rp_net.h-t1
- mv -f rp_net.h-t1 $(srcdir)/rpc/virnetprotocol.h
- mv -f rp_net.c-t2 $(srcdir)/rpc/virnetprotocol.c
- rm -f rp_net.c-t rp_net.h-t rp_net.c-t1
-else
- chmod 0444 rp_net.c-t rp_net.h-t
- mv -f rp_net.h-t $(srcdir)/rpc/virnetprotocol.h
- mv -f rp_net.c-t $(srcdir)/rpc/virnetprotocol.c
-endif
+ $(AM_V_GEN)perl -w $(srcdir)/rpc/genprotocol.pl $(RPCGEN) -h \
+ $(srcdir)/rpc/virnetprotocol.x \
+ $(srcdir)/rpc/virnetprotocol.h
+ $(AM_V_GEN)perl -w $(srcdir)/rpc/genprotocol.pl $(RPCGEN) -c \
+ $(srcdir)/rpc/virnetprotocol.x \
+ $(srcdir)/rpc/virnetprotocol.c
#
# Maintainer-only target for re-generating the derived .c/.h source
@@ -1121,8 +1091,9 @@ EXTRA_DIST += $(LIBVIRT_QEMU_SYMBOL_FILE)
noinst_LTLIBRARIES += libvirt-net-rpc.la libvirt-net-rpc-server.la
libvirt-net-rpc-client.la
EXTRA_DIST += \
- rpc/virnetprotocol.x \
- rpc/gendispatch.pl
+ rpc/virnetprotocol.x \
+ rpc/gendispatch.pl \
+ rpc/genprotocol.pl
libvirt_net_rpc_la_SOURCES = \
../daemon/event.c \
diff --git a/src/remote/qemu_protocol.h b/src/remote/qemu_protocol.h
index b822187..26f11fb 100644
--- a/src/remote/qemu_protocol.h
+++ b/src/remote/qemu_protocol.h
@@ -3,8 +3,8 @@
* It was generated using rpcgen.
*/
-#ifndef _RP_QEMU_H_RPCGEN
-#define _RP_QEMU_H_RPCGEN
+#ifndef _QEMU_PROTOCOL_H_RPCGEN
+#define _QEMU_PROTOCOL_H_RPCGEN
#include <rpc/rpc.h>
@@ -54,4 +54,4 @@ extern bool_t xdr_qemu_procedure ();
}
#endif
-#endif /* !_RP_QEMU_H_RPCGEN */
+#endif /* !_QEMU_PROTOCOL_H_RPCGEN */
diff --git a/src/remote/remote_protocol.h b/src/remote/remote_protocol.h
index bbff882..7e9fd1c 100644
--- a/src/remote/remote_protocol.h
+++ b/src/remote/remote_protocol.h
@@ -3,8 +3,8 @@
* It was generated using rpcgen.
*/
-#ifndef _RP_H_RPCGEN
-#define _RP_H_RPCGEN
+#ifndef _REMOTE_PROTOCOL_H_RPCGEN
+#define _REMOTE_PROTOCOL_H_RPCGEN
#include <rpc/rpc.h>
@@ -3014,4 +3014,4 @@ extern bool_t xdr_remote_procedure ();
}
#endif
-#endif /* !_RP_H_RPCGEN */
+#endif /* !_REMOTE_PROTOCOL_H_RPCGEN */
diff --git a/src/remote/rpcgen_fix.pl b/src/remote/rpcgen_fix.pl
deleted file mode 100644
index 3cf5479..0000000
--- a/src/remote/rpcgen_fix.pl
+++ /dev/null
@@ -1,91 +0,0 @@
-# Fix XDR code (generated by rpcgen) 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 Red Hat, Inc.
-#
-# See COPYING for the license of this software.
-#
-# Richard Jones <rjones(a)redhat.com>
-
-use strict;
-
-my $in_function = 0;
-my @function = ();
-
-while (<>) {
- if (m/^{/) {
- $in_function = 1;
- print;
- next;
- }
-
- s/\t/ /g;
-
- # 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;
- s,#include "\./remote/remote_protocol\.h",#include
"remote_protocol.h",;
-
- 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;
-
- # (char **)&objp->... gives:
- # warning: dereferencing type-punned pointer will break
- # strict-aliasing rules
- # so rewrite it.
- my %uses = ();
- my $i = 0;
- foreach (@function) {
- $uses{$1} = $i++ if m/\(char \*\*\)\&(objp->[a-z_.]+_val)/i;
- }
- if (keys %uses >= 1) {
- my $i = 1;
-
- foreach (keys %uses) {
- $i = $uses{$_};
- unshift @function,
- (" char **objp_cpp$i = (char **) (void *) &$_;\n");
- $i++;
- }
- @function =
- map { s{\(char \*\*\)\&(objp->[a-z_.]+_val)}
- {objp_cpp$uses{$1}}gi; $_ } @function;
- }
-
- # 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 (join ("", @function));
- @function = ();
- }
-
- unless ($in_function) {
- print;
- } else {
- push @function, $_;
- }
-}
diff --git a/src/rpc/genprotocol.pl b/src/rpc/genprotocol.pl
new file mode 100644
index 0000000..9144fe9
--- /dev/null
+++ b/src/rpc/genprotocol.pl
@@ -0,0 +1,124 @@
+#
+# 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 Red Hat, Inc.
+#
+# See COPYING for the license of this software.
+#
+# Richard Jones <rjones(a)redhat.com>
+
+use strict;
+
+my $in_function = 0;
+my @function = ();
+
+my $rpcgen = shift;
+my $mode = shift;
+my $xdrdef = shift;
+my $target = shift;
+
+unlink $target;
+
+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";
+
+if ($mode eq "-c") {
+ print TARGET "#include <config.h>\n";
+}
+
+while (<RPCGEN>) {
+ unless ($fixup) {
+ print TARGET;
+ next;
+ }
+
+ if (m/^{/) {
+ $in_function = 1;
+ print TARGET;
+ next;
+ }
+
+ s/\t/ /g;
+
+ # 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;
+ s,#include "\./remote/remote_protocol\.h",#include
"remote_protocol.h",;
+
+ 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;
+
+ # (char **)&objp->... gives:
+ # warning: dereferencing type-punned pointer will break
+ # strict-aliasing rules
+ # so rewrite it.
+ my %uses = ();
+ my $i = 0;
+ foreach (@function) {
+ $uses{$1} = $i++ if m/\(char \*\*\)\&(objp->[a-z_.]+_val)/i;
+ }
+ if (keys %uses >= 1) {
+ my $i = 1;
+
+ foreach (keys %uses) {
+ $i = $uses{$_};
+ unshift @function,
+ (" char **objp_cpp$i = (char **) (void *) &$_;\n");
+ $i++;
+ }
+ @function =
+ map { s{\(char \*\*\)\&(objp->[a-z_.]+_val)}
+ {objp_cpp$uses{$1}}gi; $_ } @function;
+ }
+
+ # 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/virnetprotocol.h b/src/rpc/virnetprotocol.h
index 9f4a79a..9d0021c 100644
--- a/src/rpc/virnetprotocol.h
+++ b/src/rpc/virnetprotocol.h
@@ -3,8 +3,8 @@
* It was generated using rpcgen.
*/
-#ifndef _RP_NET_H_RPCGEN
-#define _RP_NET_H_RPCGEN
+#ifndef _VIRNETPROTOCOL_H_RPCGEN
+#define _VIRNETPROTOCOL_H_RPCGEN
#include <rpc/rpc.h>
@@ -133,4 +133,4 @@ extern bool_t xdr_virNetMessageError ();
}
#endif
-#endif /* !_RP_NET_H_RPCGEN */
+#endif /* !_VIRNETPROTOCOL_H_RPCGEN */
--
1.7.2.3