openSUSE-release-tools/repo-checker.pl

223 lines
5.5 KiB
Perl
Raw Normal View History

2013-03-21 20:48:17 +01:00
#! /usr/bin/perl -w
2013-03-21 11:34:18 +01:00
2013-03-21 20:37:23 +01:00
BEGIN {
unshift @INC, "/usr/lib/build/Build";
}
2013-03-21 11:34:18 +01:00
use File::Basename;
use File::Temp qw/ tempdir /;
use XML::Simple;
use Data::Dumper;
use Cwd;
2013-03-21 20:37:23 +01:00
use Rpm;
2013-03-21 11:34:18 +01:00
2013-03-21 20:48:17 +01:00
use strict;
2013-03-26 16:57:16 +01:00
my $ret = 0;
2013-03-21 11:34:18 +01:00
my $dir = $ARGV[0];
2013-03-21 20:37:23 +01:00
my %toignore;
foreach my $name (split(/,/, $ARGV[1])) {
$toignore{$name} = 1;
}
2013-03-21 11:34:18 +01:00
2013-04-17 20:43:50 +02:00
for my $pdir (glob("$dir/*")) {
if (! -f "$pdir/rpmlint.log") {
print "Couldn't find a rpmlint.log in the build results in $pdir. This is mandatory\n";
2013-04-18 13:33:25 +02:00
my $name = basename($pdir);
2013-06-04 17:29:59 +02:00
if ($name eq "rpm" || $name eq "rpm-python" || $name eq "popt" || $name eq "rpmlint" ) {
2013-04-18 13:33:25 +02:00
print "ignoring - whitelist\n";
} else {
$ret = 1;
}
2013-04-17 20:43:50 +02:00
} else {
open(GREP, "grep 'W:.*invalid-license ' $pdir/rpmlint.log |");
while ( <GREP> ) {
print "Found rpmlint warning: ";
print $_;
$ret = 1;
}
2013-03-26 16:57:16 +01:00
}
2013-03-21 11:34:18 +01:00
}
2013-03-24 07:48:00 +01:00
my %targets;
my %cache;
foreach my $file (glob("~/cache/*")) {
if ($file =~ m,/(\d+)\.(\d+)-([^/]*)$,) {
$cache{"$1.$2"} = $3;
}
}
sub write_package($$)
2013-03-21 20:48:17 +01:00
{
my $ignore = shift;
2013-03-21 20:54:55 +01:00
my $package = shift;
2013-03-21 20:48:17 +01:00
# RPMTAG_FILEMODES = 1030, /* h[] */
# RPMTAG_FILEFLAGS = 1037, /* i[] */
# RPMTAG_FILEUSERNAME = 1039, /* s[] */
# RPMTAG_FILEGROUPNAME = 1040, /* s[] */
2013-03-24 07:48:00 +01:00
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks);
# use cache
if ($ignore == 1) {
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks) = stat($package);
if ($cache{"$mtime.$ino"}) {
my $name = $cache{"$mtime.$ino"};
if (defined $toignore{$name}) {
return;
}
open(C, $ENV{'HOME'} . "/cache/$mtime.$ino-$name") || die "no cache for $package";
while ( <C> ) {
print PACKAGES $_;
}
close(C);
return;
}
}
2013-03-21 20:37:23 +01:00
my %qq = Build::Rpm::rpmq("$package", qw{NAME VERSION RELEASE ARCH OLDFILENAMES DIRNAMES BASENAMES DIRINDEXES 1030 1037 1039 1040
2013-03-24 07:48:00 +01:00
1047 1112 1113 1049 1048 1050 1090 1114 1115 1054 1053 1055
2013-03-21 20:37:23 +01:00
});
2013-03-24 07:48:00 +01:00
my $name = $qq{'NAME'}[0];
if ($ignore == 1 && defined $toignore{$name}) {
2013-03-21 20:54:55 +01:00
return;
2013-03-21 20:37:23 +01:00
}
2013-03-21 11:34:18 +01:00
2013-03-24 07:48:00 +01:00
if ($ignore == 0) {
$targets{$name} = 1;
}
2013-03-21 20:37:23 +01:00
Build::Rpm::add_flagsvers(\%qq, 1049, 1048, 1050); # requires
Build::Rpm::add_flagsvers(\%qq, 1047, 1112, 1113); # provides
Build::Rpm::add_flagsvers(\%qq, 1090, 1114, 1115); # obsoletes
Build::Rpm::add_flagsvers(\%qq, 1054, 1053, 1055); # conflicts
2013-03-24 07:48:00 +01:00
my $out = '';
$out .= sprintf("=Pkg: %s %s %s %s\n", $name, $qq{'VERSION'}[0], $qq{'RELEASE'}[0], $qq{'ARCH'}[0]);
$out .= "+Flx:\n";
2013-03-21 20:37:23 +01:00
my @modes = @{$qq{1030} || []};
my @basenames = @{$qq{BASENAMES} || []};
my @dirs = @{$qq{DIRNAMES} || []};
my @dirindexes = @{$qq{DIRINDEXES} || []};
my @users = @{$qq{1039} || []};
my @groups = @{$qq{1040} || []};
my @flags = @{$qq{1037} || []};
my @xprvs;
foreach my $bname (@basenames) {
my $mode = shift @modes;
my $di = shift @dirindexes;
my $user = shift @users;
my $group = shift @groups;
my $flag = shift @flags;
2013-03-24 07:48:00 +01:00
2013-03-21 20:37:23 +01:00
my $filename = $dirs[$di] . $bname;
2013-03-24 07:48:00 +01:00
$out .= sprintf "%o %o %s:%s %s\n", $mode, $flag, $user, $group, $filename;
2013-03-21 20:37:23 +01:00
if ( $filename =~ /^\/etc\// || $filename =~ /bin\// || $filename eq "/usr/lib/sendmail" ) {
push @xprvs, $filename;
}
}
2013-03-24 07:48:00 +01:00
$out .= "-Flx:\n";
$out .= "+Prv:\n";
2013-03-21 20:48:17 +01:00
foreach my $prv (@{$qq{1047} || []}) {
2013-03-24 07:48:00 +01:00
$out .= "$prv\n";
2013-03-21 20:37:23 +01:00
}
foreach my $prv (@xprvs) {
2013-03-24 07:48:00 +01:00
$out .= "$prv\n";
2013-03-21 20:37:23 +01:00
}
2013-03-24 07:48:00 +01:00
$out .= "-Prv:\n";
$out .= "+Con:\n";
2013-03-21 20:37:23 +01:00
foreach my $prv (@{$qq{1054} || []}) {
2013-03-24 07:48:00 +01:00
$out .= "$prv\n";
2013-03-21 20:37:23 +01:00
}
2013-03-24 07:48:00 +01:00
$out .= "-Con:\n";
$out .= "+Req:\n";
2013-03-21 20:37:23 +01:00
foreach my $prv (@{$qq{1049} || []}) {
2013-04-30 11:49:26 +02:00
next if ($prv =~ m/^rpmlib/);
next if ($name eq "libqmmp0-plugin-mplayer" && $prv eq "/usr/bin/mplayer");
next if ($name eq "systemd-mini" && $prv eq "this-is-only-for-build-envs");
2013-06-04 17:29:59 +02:00
next if ($name eq "build-config" && $prv eq "this-is-only-for-build-envs");
2013-04-30 11:49:26 +02:00
$out .= "$prv\n";
2013-03-21 20:37:23 +01:00
}
2013-03-24 07:48:00 +01:00
$out .= "-Req:\n";
$out .= "+Obs:\n";
2013-03-21 20:37:23 +01:00
foreach my $prv (@{$qq{1090} || []}) {
2013-03-24 07:48:00 +01:00
$out .= "$prv\n";
}
$out .= "-Obs:\n";
if ($ignore == 1) {
open(C, '>', $ENV{'HOME'} . "/cache/$mtime.$ino-$name") || die "no writeable cache for $package";
print C $out;
close(C);
2013-03-21 20:37:23 +01:00
}
2013-03-24 07:48:00 +01:00
print PACKAGES $out;
2013-03-21 20:37:23 +01:00
}
2013-03-21 20:48:17 +01:00
2013-03-21 21:07:15 +01:00
my @rpms = glob("~/factory-repo/*.rpm");
my $pfile = $ENV{'HOME'} . "/packages";
open(PACKAGES, ">", $pfile) || die 'can not open';
print PACKAGES "=Ver: 2.0\n";
2013-03-21 20:48:17 +01:00
foreach my $package (@rpms) {
write_package(1, $package);
}
2013-04-17 20:43:50 +02:00
@rpms = glob("$dir/*/*.rpm");
2013-03-21 20:48:17 +01:00
foreach my $package (@rpms) {
write_package(0, $package);
}
2013-03-21 20:37:23 +01:00
close(PACKAGES);
2013-03-24 07:48:00 +01:00
#print "calling installcheck\n";
#print Dumper(%targets);
2013-03-25 14:50:19 +01:00
open(INSTALL, "~mls/bin/installcheck x86_64 $pfile 2>&1|") || die 'exec installcheck';
2013-03-21 21:07:15 +01:00
while ( <INSTALL> ) {
chomp;
2013-03-24 07:48:00 +01:00
next if (m/unknown line:.*Flx/);
if ($_ =~ m/can't install (.*)-([^-]*)-[^-\.]/) {
# print "CI $1\n";
if (defined $targets{$1}) {
print "$_\n";
while ( <INSTALL> ) {
last if (m/^can't install /);
print "$_";
}
2013-03-26 16:57:16 +01:00
$ret = 1;
last;
2013-03-24 07:48:00 +01:00
}
}
}
close(INSTALL);
#print "checking file conflicts\n";
2013-04-02 15:15:42 +02:00
my $cmd = sprintf("perl %s/findfileconflicts $pfile", dirname($0));
open(INSTALL, "$cmd |") || die 'exec fileconflicts';
my $inc = 0;
2013-03-24 07:48:00 +01:00
while ( <INSTALL> ) {
chomp;
#print STDERR "$_\n";
2013-04-02 15:15:42 +02:00
if ($_ =~ m/found conflict of (.*)-[^-]*-[^-]* with (.*)-[^-]*-[^-]*:/) {
$inc = 0;
#print STDERR "F $1 $2\n";
2013-03-24 07:48:00 +01:00
if (defined $targets{$1} || defined $targets{$2}) {
2013-04-02 15:15:42 +02:00
$inc = 1;
2013-03-26 16:57:16 +01:00
$ret = 1;
2013-03-24 07:48:00 +01:00
}
}
2013-04-02 15:15:42 +02:00
if ($inc) {
print "$_\n";
}
2013-03-21 21:07:15 +01:00
}
close(INSTALL);
2013-03-26 16:57:16 +01:00
exit($ret);