2011-11-22 13:00:03 +01:00
|
|
|
#! /usr/bin/perl
|
|
|
|
|
|
|
|
use File::Basename;
|
2013-01-11 07:17:41 +01:00
|
|
|
use File::Temp qw/ tempdir /;
|
2011-11-22 15:04:01 +01:00
|
|
|
use XML::Simple;
|
|
|
|
use Data::Dumper;
|
|
|
|
use Cwd;
|
2013-06-21 10:05:54 +02:00
|
|
|
BEGIN {
|
|
|
|
unshift @INC, ($::ENV{'BUILD_DIR'} || '/usr/lib/build');
|
|
|
|
}
|
|
|
|
use Build;
|
2011-11-22 13:00:03 +01:00
|
|
|
|
2011-11-22 13:55:12 +01:00
|
|
|
my $old = $ARGV[0];
|
|
|
|
my $dir = $ARGV[1];
|
2011-11-22 13:00:03 +01:00
|
|
|
my $bname = basename($dir);
|
|
|
|
|
2012-09-04 12:17:48 +02:00
|
|
|
if (-f "$dir/_service") {
|
|
|
|
my $service = XMLin("$dir/_service", ForceArray => [ 'service' ]);
|
|
|
|
while( my ($name, $s) = each %{$service->{service}} ) {
|
|
|
|
my $mode = $s->{mode} || '';
|
|
|
|
next if ($mode eq "localonly" || $mode eq "disabled");
|
|
|
|
print "Services are only allowed if they are mode='localonly'. Please change the mode of $name and use osc service localrun\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
2013-01-11 07:17:41 +01:00
|
|
|
# now remove it to have full service from source validator
|
|
|
|
unlink("$dir/_service");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (-f "$dir/_constraints") {
|
|
|
|
unlink("$dir/_constraints");
|
2012-09-04 12:17:48 +02:00
|
|
|
}
|
|
|
|
|
2011-11-22 13:00:03 +01:00
|
|
|
if (! -f "$dir/$bname.changes") {
|
2013-06-21 10:05:54 +02:00
|
|
|
print "A $bname.changes is missing. Packages submitted as FooBar, need to have a FooBar.changes file with a format created by osc vc\n";
|
|
|
|
exit(1);
|
2011-11-22 13:00:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (! -f "$dir/$bname.spec") {
|
2013-06-21 10:05:54 +02:00
|
|
|
print "A $bname.spec is missing. Packages submitted as FooBar, need to have a FooBar.spec file\n";
|
|
|
|
exit(1);
|
2011-11-22 13:00:03 +01:00
|
|
|
}
|
|
|
|
|
2011-11-22 13:55:12 +01:00
|
|
|
open(SPEC, "$dir/$bname.spec");
|
|
|
|
my $spec = join("", <SPEC>);
|
2011-11-22 13:00:03 +01:00
|
|
|
close(SPEC);
|
2011-12-22 12:47:45 +01:00
|
|
|
|
|
|
|
if ($spec !~ m/#\s+Copyright\s/) {
|
|
|
|
print "$bname.spec does not appear to contain a Copyright comment. Please stick to the format\n\n";
|
|
|
|
print "# Copyright (c) 2011 Stephan Kulow\n\n";
|
|
|
|
print "or use osc service localrun format_spec_file\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2011-11-22 13:55:12 +01:00
|
|
|
if ($spec =~ m/\nVendor:/) {
|
2013-06-21 10:05:54 +02:00
|
|
|
print "$bname.spec contains a Vendor line, this is forbidden.\n";
|
|
|
|
exit(1);
|
2011-11-22 13:55:12 +01:00
|
|
|
}
|
|
|
|
|
2012-01-26 15:11:10 +01:00
|
|
|
foreach my $file (glob("$dir/_service:*")) {
|
|
|
|
$file=basename($file);
|
|
|
|
print "Found _service generate file $file in checkout. Please clean this up first.";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check that we have for each spec file a changes file - and that at least one
|
|
|
|
# contains changes
|
|
|
|
my $changes_updated = 0;
|
|
|
|
for my $spec (glob ("$dir/*.spec")) {
|
|
|
|
$changes = basename ($spec);
|
|
|
|
$changes =~ s/\.spec$/.changes/;
|
|
|
|
if (! -f "$dir/$changes") {
|
|
|
|
print "A $changes is missing. Packages submitted as FooBar, need to have a FooBar.changes file with a format created by osc vc\n";
|
2011-11-22 13:55:12 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
2012-01-26 15:11:10 +01:00
|
|
|
if (-f "$old/$changes") {
|
|
|
|
if (system("cmp -s $old/$changes $dir/$changes")) {
|
|
|
|
$changes_updated = 1;
|
|
|
|
}
|
|
|
|
} else { # a new file is an update too
|
|
|
|
$changes_updated = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$changes_updated) {
|
|
|
|
print "No changelog. Please use 'osc vc' to update the changes file(s).\n";
|
|
|
|
exit(1);
|
2011-11-22 13:55:12 +01:00
|
|
|
}
|
|
|
|
|
2012-08-09 11:47:27 +02:00
|
|
|
if ($spec !~ m/\n%changelog\s/ && $spec != m/\n%changelog$/) {
|
2011-11-22 13:55:12 +01:00
|
|
|
print "$bname.spec does not contain a %changelog line. We don't want a changelog in the spec file, but the %changelog section needs to be present\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2011-11-22 14:36:27 +01:00
|
|
|
if ($spec !~ m/(#[^\n]*license)/i) {
|
|
|
|
print "$bname.spec does not appear to have a license, the file needs to contain a free software license\n";
|
2011-12-22 12:47:45 +01:00
|
|
|
print "Suggestion: use \"osc service localrun format_spec_file\" to get our default license or\n";
|
2011-11-22 14:36:27 +01:00
|
|
|
print "the minimal license:\n\n";
|
|
|
|
print "# This file is under MIT license\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2013-01-15 16:33:14 +01:00
|
|
|
foreach my $test (glob("/usr/lib/obs/service/source_validators/*")) {
|
2013-06-21 10:05:54 +02:00
|
|
|
next if (!-f "$test");
|
|
|
|
my $checkivsd = `/bin/bash $test --batchmode --verbose $dir $old < /dev/null 2>&1`;
|
|
|
|
if ($?) {
|
|
|
|
print "Source validator failed. Try \"osc service localrun source_validator\"\n";
|
|
|
|
print $checkivsd;
|
|
|
|
print "\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
2011-12-22 12:47:45 +01:00
|
|
|
}
|
|
|
|
|
2013-06-21 10:05:54 +02:00
|
|
|
if (-d "$old") {
|
|
|
|
my $odir = getcwd();
|
|
|
|
chdir($old) || die "chdir $old failed";
|
|
|
|
my $cf = Build::read_config("x86_64", "/usr/lib/build/configs/default.conf");
|
|
|
|
|
2011-12-22 12:47:45 +01:00
|
|
|
my %thash = ();
|
|
|
|
my %rhash = ();
|
|
|
|
for my $spec (glob("*.spec")) {
|
2013-06-21 10:05:54 +02:00
|
|
|
my $ps = Build::Rpm::parse($cf, $spec);
|
|
|
|
|
|
|
|
while (my ($k, $v) = each %$ps) {
|
|
|
|
if ($k =~ m/^source/) {
|
|
|
|
$thash{$v} = 1;
|
|
|
|
}
|
2011-12-22 12:47:45 +01:00
|
|
|
}
|
|
|
|
}
|
2013-06-21 10:05:54 +02:00
|
|
|
chdir($odir) || die "chdir $odir failed";
|
|
|
|
chdir($dir) || die "chdir $dir failed";
|
2011-12-22 12:47:45 +01:00
|
|
|
for my $spec (glob("*.spec")) {
|
2013-06-21 10:05:54 +02:00
|
|
|
my $ps = Build::Rpm::parse($cf, $spec);
|
2011-12-22 12:47:45 +01:00
|
|
|
open(OSPEC, "$spec");
|
|
|
|
open(NSPEC, ">$spec.new");
|
|
|
|
while (<OSPEC>) {
|
|
|
|
chomp;
|
|
|
|
if (m/^Source/) {
|
|
|
|
my $line = $_;
|
|
|
|
$line =~ s/^(Source[0-9]*)\s*:\s*//;
|
|
|
|
my $prefix = $1;
|
2013-06-21 10:05:54 +02:00
|
|
|
my $parsedline = $ps->{lc $prefix};
|
|
|
|
if (defined $thash{$parsedline}) {
|
2011-12-22 12:47:45 +01:00
|
|
|
my $file = $line;
|
|
|
|
my $bname = basename($file);
|
|
|
|
print NSPEC "$prefix: $bname\n";
|
|
|
|
} else {
|
|
|
|
print NSPEC "$_\n";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
print NSPEC "$_\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(OSPEC);
|
|
|
|
close(NSPEC);
|
2013-06-21 10:05:54 +02:00
|
|
|
#system("diff -u $spec $spec.new");
|
|
|
|
#exit(0);
|
2013-07-24 06:44:50 +02:00
|
|
|
rename("$spec.new", "$spec") || die "rename failed";
|
2011-12-22 12:47:45 +01:00
|
|
|
}
|
2013-06-21 10:05:54 +02:00
|
|
|
chdir($odir);
|
2011-12-22 12:47:45 +01:00
|
|
|
}
|
|
|
|
|
2011-11-22 14:36:27 +01:00
|
|
|
my $odir = getcwd;
|
2013-01-11 07:17:41 +01:00
|
|
|
my $tmpdir = tempdir ( "obs-XXXXXXX", TMPDIR => 1 );
|
|
|
|
chdir($dir) || die 'tempdir failed';
|
2011-12-22 12:47:45 +01:00
|
|
|
if (system("/usr/lib/obs/service/download_files","--enforceupstream", "yes", "--enforcelocal", "yes", "--outdir", $tmpdir)) {
|
|
|
|
print "Source URLs are not valid. Try \"osc service localrun download_files\"\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
2011-11-22 14:36:27 +01:00
|
|
|
chdir($odir);
|
|
|
|
|
2011-12-22 12:47:45 +01:00
|
|
|
foreach my $rpmlint (glob("$dir/*rpmlintrc")) {
|
|
|
|
open(RPMLINTRC, $rpmlint);
|
|
|
|
while ( <RPMLINTRC> ) {
|
|
|
|
if ( m/^\s*setBadness/ ) {
|
|
|
|
print "For Factory submissions, you can not use setBadness. Use filters in $rpmlint\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|