-
Notifications
You must be signed in to change notification settings - Fork 3
/
jsonresult
executable file
·117 lines (109 loc) · 3.63 KB
/
jsonresult
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/perl -w
use strict;
use XML::Simple;
use JSON;
use POSIX;
sub find_version($$)
{
my $dir=shift;
my $name=shift;
my $version=`sed -e '/^\(PreReq\|BuildRequires\|Requires\|Provides\|Recommends\|Suggests\):/d' $name.spec > $name.spec~ | rpmspec --query --srpm --queryformat="%{version}" $name.spec~ 2>/dev/null ; rm -f $name.spec~`;
if($version eq "") { # could not parse .spec file
$version=`grep '^Version:' $name.spec|head -1`;
chomp($version);
$version=~s/^Version:\s*//;
$version=~s/\s+$//;
if($version =~ /%/) {
my $line=`grep "Wrote: .*\.src\.rpm" $dir/.build.log $dir/RPMS/.build.log`;
if($line) {
$line =~ /.*-([^-]+)-[^-]+\.src\.rpm/ && return $1;
}
warn "cannot find version for package $name - got $version";
return "unknown";
}
}
return $version;
}
sub getline($)
{ my $file=shift;
open(my $f, "<", $file) or die "error opening $file : $!";
my $line=<$f>;
chomp($line);
return $line;
}
sub find_status($)
{ my $dir=shift;
my $build=getline("$dir/.osc-build-retval");
if($build == 2) { return "notforus" }
elsif($build ne "0") {
#TODO: check .build.log for arch mismatch/unresolvable
system(qw(grep -q), "error: Architecture is not included", "$dir/.build.log");
if(($?>>8) == 0) { return "notforus" }
system(qw(grep -q), "^unresolvable: nothing provides", "$dir/RPMS/.build.log2");
if(($?>>8) == 0) { return "waitdep" }
return "FTBFS";
}
else {
my $differed=eval{getline("$dir/.build-differed")};
if($@) { return "nobinaries" } # i.e. testsuite
if($differed eq "0") { return "reproducible" }
return "unreproducible";
}
}
sub find_verified($)
{ my $dir=shift;
my $differed=eval{getline("$dir/.build-differed-nachbau")} //1;
my $filtered=eval{getline("$dir/.build-compare-retval-nachbau")};
$::sigdate=undef;
return undef unless defined $filtered;
$_=eval{getline("$dir/binaries/signature")} // "unknown"; # grep -o "[^ ]* UTC" $dir/binaries/signature|head -1
m/\S+ UTC/ and $_=$&;
$::sigdate=$_;
return (($differed==0?1:0) + ($filtered==0?1:0));
}
sub find_build_compare_status($)
{ my $dir=shift;
my $differed=eval{getline("$dir/.build-compare-retval")};
if($@) { return "nobinaries" } # i.e. testsuite
if($differed eq "0") { return "reproducible" }
return "unreproducible";
}
sub get_build_duration($)
{ my $in=shift;
if(! -e $in) { return undef }
my $duration=int(getline($in));
if(!$duration) {$duration=undef};
return $duration;
}
sub get_status_for_one_dir($)
{
my $dir=shift;
print STDERR "processing $dir\n";
if(! -e "$dir/.osc-build-retval") {return () } # skip unbuilt
my $oscdata=XMLin("$dir/.osc/_files");
my $name=$oscdata->{name};
my $version=find_version($dir, "$dir/$name");
my $data = {
package=>$name,
version=>"$version-$oscdata->{rev}",
architecture=>(POSIX::uname())[4],
status=>find_status($dir),
verified=>find_verified($dir),
release=>getline("$dir/.osc/_project"),
opensusetweaks=>eval{getline("$dir/.build-rbkt")}||undef,
opensuseautoclassify=>eval{getline("$dir/.rb.autoclassify")}||undef,
build_date=>(stat("$dir/.osc-build-retval"))[9],
build_duration=>get_build_duration("$dir/RPMS/build-time")||get_build_duration("$dir/binaries.nachbau/build-time"),
};
if($::sigdate) {$data->{opensusesigdate}=$::sigdate}
if($data->{status} eq "unreproducible") {
$data->{build_compare_status}=find_build_compare_status($dir);
}
return $data;
}
my $result=[];
if($#ARGV == -1) {@ARGV=(".")}
for my $dir (@ARGV) {
push(@$result, get_status_for_one_dir($dir));
}
print JSON->new->ascii->pretty->allow_nonref->canonical->encode($result);