maint: enforce private symbol section sorting

Automating a sorting check is the only way to ensure we don't
regress.  Suggested by Dan Berrange.

* src/check-symsorting.pl (check_sorting): Add a parameter,
validate that groups are in order, and that files exist.
* src/Makefile.am (check-symsorting): Adjust caller.
* src/libvirt_private.syms: Fix typo.
* src/libvirt_linux.syms: Fix file name.
* src/libvirt_vmx.syms: Likewise.
* src/libvirt_xenxs.syms: Likewise.
* src/libvirt_sasl.syms: Likewise.
* src/libvirt_libssh2.syms: Likewise.
* src/libvirt_esx.syms: Mention file name.
* src/libvirt_openvz.syms: Likewise.
This commit is contained in:
Eric Blake 2013-02-19 17:59:20 -07:00
parent 69660042fb
commit 6ea7b3e8d1
10 changed files with 45 additions and 18 deletions

View File

@ -388,7 +388,8 @@ else
check-symfile: check-symfile:
endif endif
check-symsorting: check-symsorting:
$(AM_V_GEN)$(PERL) $(srcdir)/check-symsorting.pl $(USED_SYM_FILES) $(AM_V_GEN)$(PERL) $(srcdir)/check-symsorting.pl \
$(srcdir) $(USED_SYM_FILES)
EXTRA_DIST += check-symfile.pl check-symsorting.pl EXTRA_DIST += check-symfile.pl check-symsorting.pl
PROTOCOL_STRUCTS = \ PROTOCOL_STRUCTS = \

View File

@ -3,22 +3,28 @@
use strict; use strict;
use warnings; use warnings;
die "syntax: $0 SYMFILE..." unless int(@ARGV) >= 1; die "syntax: $0 SRCDIR SYMFILE..." unless int(@ARGV) >= 2;
my $ret = 0; my $ret = 0;
my $srcdir = shift;
my $lastgroup = undef;
foreach my $symfile (@ARGV) { foreach my $symfile (@ARGV) {
open SYMFILE, $symfile or die "cannot read $symfile: $!"; open SYMFILE, $symfile or die "cannot read $symfile: $!";
my $line; my $line;
my $groupfile = "";
my @group; my @group;
while (<SYMFILE>) { while (<SYMFILE>) {
chomp; chomp;
next if /^#/;
if (/^\s*$/) { if (/^#\s*((\w+\/)*(\w+\.h))\s*$/) {
$groupfile = $1;
} elsif (/^#/) {
# Ignore comments
} elsif (/^\s*$/) {
if (@group) { if (@group) {
&check_sorting(\@group, $symfile, $line); &check_sorting(\@group, $symfile, $line, $groupfile);
} }
@group = (); @group = ();
$line = $.; $line = $.;
@ -30,20 +36,38 @@ foreach my $symfile (@ARGV) {
close SYMFILE; close SYMFILE;
if (@group) { if (@group) {
&check_sorting(\@group, $symfile, $line); &check_sorting(\@group, $symfile, $line, $groupfile);
} }
$lastgroup = undef;
} }
sub check_sorting { sub check_sorting {
my $group = shift; my $group = shift;
my $symfile = shift; my $symfile = shift;
my $line = shift; my $line = shift;
my $groupfile = shift;
my @group = @{$group}; my @group = @{$group};
my @sorted = sort { lc $a cmp lc $b } @group; my @sorted = sort { lc $a cmp lc $b } @group;
my $sorted = 1; my $sorted = 1;
my $first; my $first;
my $last; my $last;
# Check that groups are in order and groupfile exists
if (defined $lastgroup && lc $lastgroup ge lc $groupfile) {
print "Symbol block at $symfile:$line: block not sorted\n";
print "Move $groupfile block before $lastgroup block\n";
print "\n";
$ret = 1;
}
if (! -e "$srcdir/$groupfile") {
print "Symbol block at $symfile:$line: $groupfile not found\n";
print "\n";
$ret = 1;
}
$lastgroup = $groupfile;
# Check that symbols within a group are in order
for (my $i = 0 ; $i <= $#sorted ; $i++) { for (my $i = 0 ; $i <= $#sorted ; $i++) {
if ($sorted[$i] ne $group[$i]) { if ($sorted[$i] ne $group[$i]) {
$first = $i unless defined $first; $first = $i unless defined $first;
@ -54,7 +78,7 @@ sub check_sorting {
if (!$sorted) { if (!$sorted) {
@group = splice @group, $first, ($last-$first+1); @group = splice @group, $first, ($last-$first+1);
@sorted = splice @sorted, $first, ($last-$first+1); @sorted = splice @sorted, $first, ($last-$first+1);
print "Symbol block at $symfile:$line symbols not sorted\n"; print "Symbol block at $symfile:$line: symbols not sorted\n";
print map { " " . $_ . "\n" } @group; print map { " " . $_ . "\n" } @group;
print "Correct ordering\n"; print "Correct ordering\n";
print map { " " . $_ . "\n" } @sorted; print map { " " . $_ . "\n" } @sorted;

View File

@ -2,6 +2,7 @@
# These symbols are dependent upon --with-esx via WITH_ESX # These symbols are dependent upon --with-esx via WITH_ESX
# #
# esx/esx_util.h
esxUtil_EscapeDatastoreItem; esxUtil_EscapeDatastoreItem;
esxUtil_ParseDatastorePath; esxUtil_ParseDatastorePath;
esxVI_DateTime_ConvertToCalendarTime; esxVI_DateTime_ConvertToCalendarTime;

View File

@ -2,8 +2,7 @@
# ssh session - specific symbols # ssh session - specific symbols
# #
# virnetsshsession.h # rpc/virnetsshsession.h
#
virNetSSHChannelRead; virNetSSHChannelRead;
virNetSSHChannelWrite; virNetSSHChannelWrite;
virNetSSHSessionAuthAddAgentAuth; virNetSSHSessionAuthAddAgentAuth;

View File

@ -5,7 +5,7 @@
# nodeinfo.h # nodeinfo.h
linuxNodeInfoCPUPopulate; linuxNodeInfoCPUPopulate;
# stats_linux.h # util/virstatslinux.h
linuxDomainInterfaceStats; linuxDomainInterfaceStats;
# Let emacs know we want case-insensitive sorting # Let emacs know we want case-insensitive sorting

View File

@ -1,6 +1,8 @@
# #
# These symbols are dependent upon --with-openvz via WITH_OPENVZ # These symbols are dependent upon --with-openvz via WITH_OPENVZ
# #
# openvz/openvz_conf.h
openvzLocateConfFile; openvzLocateConfFile;
openvzReadConfigParam; openvzReadConfigParam;
openvzReadNetworkConf; openvzReadNetworkConf;

View File

@ -420,7 +420,7 @@ virNetDevVlanFormat;
virNetDevVlanParse; virNetDevVlanParse;
# conf/netdev_vportprofile_conf.h # conf/netdev_vport_profile_conf.h
virNetDevVPortProfileFormat; virNetDevVPortProfileFormat;
virNetDevVPortProfileParse; virNetDevVPortProfileParse;
virNetDevVPortTypeFromString; virNetDevVPortTypeFromString;

View File

@ -2,10 +2,10 @@
# SASL-specific symbols # SASL-specific symbols
# #
# virnetclient.h # rpc/virnetclient.h
virNetClientSetSASLSession; virNetClientSetSASLSession;
# virnetsaslcontext.h # rpc/virnetsaslcontext.h
virNetSASLContextCheckIdentity; virNetSASLContextCheckIdentity;
virNetSASLContextNewClient; virNetSASLContextNewClient;
virNetSASLContextNewServer; virNetSASLContextNewServer;
@ -25,11 +25,11 @@ virNetSASLSessionServerStart;
virNetSASLSessionServerStep; virNetSASLSessionServerStep;
# virnetserverclient.h # rpc/virnetserverclient.h
virNetServerClientSetSASLSession; virNetServerClientSetSASLSession;
# virnetsocket.h # rpc/virnetsocket.h
virNetSocketSetSASLSession; virNetSocketSetSASLSession;
# Let emacs know we want case-insensitive sorting # Let emacs know we want case-insensitive sorting

View File

@ -2,7 +2,7 @@
# These symbols are dependent upon --with-esx via WITH_ESX or --with-vmware via WITH_VMWARE. # These symbols are dependent upon --with-esx via WITH_ESX or --with-vmware via WITH_VMWARE.
# #
# vmx.h # vmx/vmx.h
virVMXConvertToUTF8; virVMXConvertToUTF8;
virVMXEscapeHex; virVMXEscapeHex;
virVMXFormatCDROM; virVMXFormatCDROM;

View File

@ -2,7 +2,7 @@
# These symbols are dependent upon --with-xen via WITH_XEN or --with-libxl via WITH_LIBXL. # These symbols are dependent upon --with-xen via WITH_XEN or --with-libxl via WITH_LIBXL.
# #
# xen_sxpr.h # xenxs/xen_sxpr.h
xenFormatSxpr; xenFormatSxpr;
xenFormatSxprChr; xenFormatSxprChr;
xenFormatSxprDisk; xenFormatSxprDisk;
@ -16,7 +16,7 @@ xenParseSxprChar;
xenParseSxprSound; xenParseSxprSound;
xenParseSxprString; xenParseSxprString;
# xen_xm.h # xenxs/xen_xm.h
xenFormatXM; xenFormatXM;
xenParseXM; xenParseXM;