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;
|
2014-06-04 10:44:14 +02:00
|
|
|
use Text::Diff;
|
2013-06-21 10:05:54 +02:00
|
|
|
BEGIN {
|
2014-06-04 10:44:14 +02:00
|
|
|
unshift @INC, ($::ENV{'BUILD_DIR'} || '/usr/lib/build');
|
2013-06-21 10:05:54 +02:00
|
|
|
}
|
|
|
|
use Build;
|
2011-11-22 13:00:03 +01:00
|
|
|
|
2014-06-04 10:44:14 +02:00
|
|
|
my $ret = 0;
|
|
|
|
|
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);
|
|
|
|
|
2018-03-23 16:20:55 +01:00
|
|
|
my @specs = map basename($_), glob("$dir/*.spec");
|
2011-11-22 13:00:03 +01:00
|
|
|
|
2018-03-23 16:20:55 +01:00
|
|
|
if (@specs) {
|
|
|
|
if (!-f "$dir/$bname.changes") {
|
2019-03-25 12:15:36 +01:00
|
|
|
print "$bname.changes is missing. A package submitted as FooBar needs to have a FooBar.changes file with a format created by `osc vc`.\n";
|
2018-03-23 16:20:55 +01:00
|
|
|
$ret = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!-f "$dir/$bname.spec") {
|
2019-03-25 12:15:36 +01:00
|
|
|
print "$bname.spec is missing. A package submitted as FooBar needs to have a FooBar.spec file.\n";
|
2018-03-23 16:20:55 +01:00
|
|
|
$ret = 1;
|
|
|
|
}
|
|
|
|
exit($ret) if ($ret);
|
|
|
|
} else {
|
|
|
|
# package without spec files, eg kiwi only
|
|
|
|
exit($ret);
|
|
|
|
}
|
2014-06-04 10:44:14 +02: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
|
|
|
|
2015-09-08 14:16:44 +02:00
|
|
|
if ($spec !~ m/#[*\s]+Copyright\s/) {
|
2011-12-22 12:47:45 +01:00
|
|
|
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";
|
2020-12-07 13:44:44 +01:00
|
|
|
print "or use osc service runall format_spec_file\n";
|
2014-06-04 10:44:14 +02:00
|
|
|
$ret = 1;
|
2011-12-22 12:47:45 +01:00
|
|
|
}
|
|
|
|
|
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";
|
2014-06-04 10:44:14 +02:00
|
|
|
$ret = 1;
|
2011-11-22 13:55:12 +01:00
|
|
|
}
|
|
|
|
|
2012-01-26 15:11:10 +01:00
|
|
|
# Check that we have for each spec file a changes file - and that at least one
|
|
|
|
# contains changes
|
|
|
|
my $changes_updated = 0;
|
2018-03-23 16:20:55 +01:00
|
|
|
for my $spec (@specs) {
|
|
|
|
$changes = $spec;
|
2012-01-26 15:11:10 +01:00
|
|
|
$changes =~ s/\.spec$/.changes/;
|
2020-12-10 13:49:06 +01:00
|
|
|
|
|
|
|
# new or deleted .changes files also count
|
|
|
|
if ((-f "$old/$changes") != (-f "$dir/$changes")) {
|
|
|
|
$changes_updated = 1;
|
|
|
|
last;
|
2011-11-22 13:55:12 +01:00
|
|
|
}
|
2020-12-10 13:49:06 +01:00
|
|
|
elsif ((-f "$old/$changes") && (-f "$dir/$changes")) {
|
2017-03-21 23:47:11 -05:00
|
|
|
if (system(("cmp", "-s", "$old/$changes", "$dir/$changes"))) {
|
2014-06-04 10:44:14 +02:00
|
|
|
$changes_updated = 1;
|
2020-12-10 13:49:06 +01:00
|
|
|
last;
|
2014-06-04 10:44:14 +02:00
|
|
|
}
|
|
|
|
}
|
2012-01-26 15:11:10 +01:00
|
|
|
}
|
2014-06-26 13:11:08 +02:00
|
|
|
|
2012-01-26 15:11:10 +01:00
|
|
|
if (!$changes_updated) {
|
|
|
|
print "No changelog. Please use 'osc vc' to update the changes file(s).\n";
|
2014-06-04 10:44:14 +02:00
|
|
|
$ret = 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";
|
2014-06-04 10:44:14 +02:00
|
|
|
$ret = 1;
|
2011-11-22 13:55:12 +01:00
|
|
|
}
|
|
|
|
|
2011-11-22 14:36:27 +01:00
|
|
|
if ($spec !~ m/(#[^\n]*license)/i) {
|
2019-03-25 12:15:36 +01:00
|
|
|
print "$bname.spec does not appear to have a license. The file needs to contain a free software license\n";
|
2020-12-07 13:44:44 +01:00
|
|
|
print "Suggestion: use \"osc service runall 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";
|
2014-06-04 10:44:14 +02:00
|
|
|
$ret = 1;
|
2011-11-22 14:36:27 +01:00
|
|
|
}
|
|
|
|
|
2014-06-04 10:44:14 +02:00
|
|
|
my %patches = ();
|
|
|
|
|
2018-03-23 16:20:55 +01:00
|
|
|
for my $test (glob("/usr/lib/obs/service/source_validators/*")) {
|
2013-06-21 10:05:54 +02:00
|
|
|
next if (!-f "$test");
|
2014-06-04 14:29:41 +02:00
|
|
|
my $checkivsd = `/bin/bash $test --batchmode $dir $old < /dev/null 2>&1`;
|
2013-06-21 10:05:54 +02:00
|
|
|
if ($?) {
|
2020-12-07 13:44:44 +01:00
|
|
|
print "Source validator failed. Try \"osc service runall source_validator\"\n";
|
2014-06-04 10:44:14 +02:00
|
|
|
print $checkivsd;
|
|
|
|
print "\n";
|
|
|
|
$ret = 1;
|
2013-06-21 10:05:54 +02:00
|
|
|
}
|
2014-06-04 10:44:14 +02:00
|
|
|
else {
|
|
|
|
for my $line (split(/\n/, $checkivsd)) {
|
|
|
|
# pimp up some warnings
|
|
|
|
if ($line =~ m/Attention.*not mentioned/) {
|
|
|
|
$line =~ s,\(W\) ,,;
|
|
|
|
print "$line\n";
|
|
|
|
$ret = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
my $odir = getcwd();
|
|
|
|
|
2021-07-01 22:02:40 +02:00
|
|
|
chdir($dir) || die "chdir $dir failed";
|
2014-06-04 10:44:14 +02:00
|
|
|
for my $patch (glob("*.diff *.patch *.dif")) {
|
|
|
|
$patches{$patch} = 'current';
|
2011-12-22 12:47:45 +01:00
|
|
|
}
|
2014-06-04 10:44:14 +02:00
|
|
|
chdir($odir) || die "chdir $odir failed";
|
2011-12-22 12:47:45 +01:00
|
|
|
|
2013-06-21 10:05:54 +02:00
|
|
|
if (-d "$old") {
|
2014-06-04 10:44:14 +02:00
|
|
|
|
2013-06-21 10:05:54 +02:00
|
|
|
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 = ();
|
|
|
|
for my $spec (glob("*.spec")) {
|
2014-06-04 10:44:14 +02:00
|
|
|
my $ps = Build::Rpm::parse($cf, $spec);
|
2013-06-21 10:05:54 +02:00
|
|
|
|
2014-06-04 10:44:14 +02:00
|
|
|
while (my ($k, $v) = each %$ps) {
|
|
|
|
if ($k =~ m/^source/) {
|
|
|
|
$thash{$v} = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for my $patch (glob("*.diff *.patch *.dif")) {
|
|
|
|
if ($patches{$patch}) {
|
|
|
|
delete $patches{$patch};
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$patches{$patch} = 'old';
|
|
|
|
}
|
2011-12-22 12:47:45 +01:00
|
|
|
}
|
2014-06-04 10:44:14 +02: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")) {
|
2014-06-04 10:44:14 +02:00
|
|
|
my $ps = Build::Rpm::parse($cf, $spec);
|
|
|
|
open(OSPEC, "$spec");
|
|
|
|
open(NSPEC, ">$spec.new");
|
|
|
|
while (<OSPEC>) {
|
|
|
|
chomp;
|
|
|
|
if (m/^Source/) {
|
|
|
|
my $line = $_;
|
|
|
|
$line =~ s/^(Source[0-9]*)\s*:\s*//;
|
2015-02-18 12:08:42 +01:00
|
|
|
if ($patches{$line}) {
|
|
|
|
delete $patches{$line};
|
|
|
|
}
|
2014-06-04 10:44:14 +02:00
|
|
|
my $prefix = $1;
|
|
|
|
my $parsedline = $ps->{lc $prefix};
|
|
|
|
if (defined $thash{$parsedline}) {
|
|
|
|
my $file = $line;
|
|
|
|
my $bname = basename($file);
|
|
|
|
print NSPEC "$prefix: $bname\n";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
print NSPEC "$_\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
print NSPEC "$_\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(OSPEC);
|
|
|
|
close(NSPEC);
|
2017-03-21 23:47:11 -05:00
|
|
|
system(("cp", "$spec", "$spec.beforeurlstrip"));
|
2014-06-04 10:44:14 +02:00
|
|
|
rename("$spec.new", "$spec") || die "rename failed";
|
2011-12-22 12:47:45 +01:00
|
|
|
}
|
2014-06-04 10:44:14 +02:00
|
|
|
|
2014-06-05 11:27:51 +02:00
|
|
|
chdir($dir);
|
|
|
|
my @changes = glob("*.changes");
|
2013-06-21 10:05:54 +02:00
|
|
|
chdir($odir);
|
2014-06-04 10:44:14 +02:00
|
|
|
|
|
|
|
if (%patches) {
|
2019-03-25 12:15:36 +01:00
|
|
|
# parse changes
|
2014-06-05 11:27:51 +02:00
|
|
|
for my $changes (@changes) {
|
2017-02-08 11:31:20 -06:00
|
|
|
my $diff = "";
|
|
|
|
if (! -e "$old/$changes") {
|
|
|
|
$diff = diff "/dev/null", "$dir/$changes";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$diff = diff "$old/$changes", "$dir/$changes";
|
|
|
|
}
|
2014-06-05 11:27:51 +02:00
|
|
|
for my $line (split(/\n/, $diff)) {
|
2021-09-22 22:14:12 +02:00
|
|
|
# Check if the line mentions a patch being added (starts with +)
|
|
|
|
# or removed (starts with -)
|
|
|
|
next unless $line =~ m/^[+-]/;
|
|
|
|
# In any of those cases, remove the patch from the list
|
|
|
|
$line =~ s/^[+-]//;
|
2014-06-05 11:27:51 +02:00
|
|
|
for my $patch (keys %patches) {
|
2014-06-25 16:10:08 +02:00
|
|
|
if (index($line, $patch) != -1) {
|
2014-06-05 11:27:51 +02:00
|
|
|
delete $patches{$patch};
|
|
|
|
}
|
2014-06-04 10:44:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# still some left?
|
|
|
|
if (%patches) {
|
|
|
|
$ret = 1;
|
|
|
|
for my $patch (keys %patches) {
|
|
|
|
# wording stolen from Raymond's declines :)
|
|
|
|
if ($patches{$patch} eq 'current') {
|
2019-03-25 12:15:36 +01:00
|
|
|
print "A patch ($patch) is being added without this addition being mentioned in the changelog.\n";
|
2014-06-04 10:44:14 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-03-25 12:15:36 +01:00
|
|
|
print "A patch ($patch) is being deleted without this removal being mentioned in the changelog.\n";
|
2014-06-04 10:44:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-12-22 12:47:45 +01:00
|
|
|
}
|
|
|
|
|
2017-09-27 08:36:23 -05:00
|
|
|
my $tmpdir = tempdir("obs-XXXXXXX", TMPDIR => 1, CLEANUP => 1);
|
2013-01-11 07:17:41 +01:00
|
|
|
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)) {
|
2020-12-07 13:44:44 +01:00
|
|
|
print "Source URLs are not valid. Try \"osc service runall download_files\".\n";
|
2017-11-22 17:29:14 +08:00
|
|
|
$ret = 2;
|
2011-12-22 12:47:45 +01:00
|
|
|
}
|
2014-06-04 10:44:14 +02:00
|
|
|
|
2022-03-24 08:32:08 +01:00
|
|
|
exit($ret);
|