openSUSE-release-tools/source-checker.pl

85 lines
2.5 KiB
Perl
Raw Normal View History

2011-11-22 13:00:03 +01:00
#! /usr/bin/perl
use File::Basename;
2011-11-22 14:36:27 +01:00
use File::Temp qw/ :mktemp /;
2011-11-22 15:04:01 +01:00
use XML::Simple;
use Data::Dumper;
use Cwd;
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);
if (! -f "$dir/$bname.changes") {
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);
}
if (! -f "$dir/$bname.spec") {
print "A $bname.spec is missing. Packages submitted as FooBar, need to have a FooBar.spec file\n";
exit(1);
}
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-11-22 13:55:12 +01:00
my $sname = '';
2011-11-22 14:36:27 +01:00
if ($spec =~ m/\nName:\s*(\S+)\s*/) {
2011-11-22 13:55:12 +01:00
$sname = $1;
}
if ($bname ne $sname) {
print "$bname.spec needs to contain Name: $bname, found '$sname'\n";
2011-11-22 13:00:03 +01:00
exit(1);
}
2011-11-22 13:55:12 +01:00
if ($spec =~ m/\nVendor:/) {
print "$bname.spec contains a Vendor line, this is forbidden.\n";
exit(1);
}
if (-f "$old/$bname.changes") {
if (!system("cmp -s $old/$bname.changes $dir/$bname.changes")) {
print "$bname.changes didn't change. Please use osc vc\n";
exit(1);
}
}
if ($spec !~ m/\n%changelog\s/) {
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);
}
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";
2011-11-22 14:36:27 +01:00
exit(1);
2011-11-22 13:55:12 +01:00
}
2011-11-22 13:00:03 +01:00
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";
print "Suggestion: use `osc service localrun format_spec_file` to get our default license or\n";
print "the minimal license:\n\n";
print "# This file is under MIT license\n";
exit(1);
}
my $odir = getcwd;
chdir($dir);
my $tmpdir = mkdtemp("/tmp/obs-XXXXXXX");
exit(1) if system("/usr/lib/obs/service/download_files","--enforceupstream","--enforcelocal","--outdir", $tmpdir) != 0;
chdir($odir);
2011-11-22 13:00:03 +01:00
exit(1) if system("/work/src/bin/check_if_valid_source_dir --batchmode --dest _old $dir < /dev/null 2>&1 | grep -v '##ASK'") != 0;
2011-11-22 15:04:01 +01: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");
print "Services are only allowed if they are mode='localonly'. Please change the mode of $name and use osc service localrun\n";
exit(1);
}
}