forked from openSUSE/obs-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createrpmdeps
executable file
·146 lines (135 loc) · 4.03 KB
/
createrpmdeps
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/perl -w
BEGIN {
unshift @INC, ($::ENV{'BUILD_DIR'} || '/usr/lib/build');
}
use Build;
use strict;
######################################################################
my $rpmdepfile = $ARGV[0];
my %tag;
my %oldp;
my %oldr;
if (defined($rpmdepfile) && open(F, '<', $rpmdepfile)) {
while (<F>) {
chomp;
if (/^P:([^ ]): /) {
$oldp{$1} = $_;
} elsif (/^R:([^ ]): /) {
$oldr{$1} = $_;
}
}
close F;
}
my $redo = 1;
foreach my $dir (@ARGV) {
$redo = 0;
my @known;
my %known2fn;
my %known2path;
my %fnsize2id;
my $cmd = "find $dir -follow -type f \\( -name \"*.rpm\" -o -name \"*.deb\" \\) -a ! -name \"*src.rpm\" -printf '\%T@/\%s/\%i \%p\\n'";
open(F, '-|', $cmd) or next;
while (<F>) {
chomp;
next unless /^([\d\.]+\/\d+\/\d+) (.*)$/;
my $id = $1;
my $path = $2;
# new find added a fraction part to %T@, ignore it
$id =~ s/^(\d+)\.\d+/$1/;
next unless $path =~ /\.(?:rpm|deb)$/;
my $fn = $path;
$fn =~ s/.*\///;
next if $fn =~ /\.(?:patch|delta)\.rpm$/;
my ($r, $arch);
if ($fn =~ /^(.*)-[^-]+-[^-]+\.([^\. ]+)\.rpm$/) {
$r = $1;
$arch = $2;
} elsif ($path =~ /^(?:.*\/)?([^\/ ]+)\/([^\/ ]+)\.rpm$/) {
#next if $1 eq '.';
$r = $2;
$arch = $1;
} elsif ($fn =~ /^([^_]*)_(?:[^_]*)_([^_]*)\.deb$/) {
$r = $1;
$arch = $2;
$arch = 'noarch' if $arch eq 'all';
} else {
next;
}
next if $arch eq 'src' || $arch eq 'nosrc';
push @known, "$r.$arch-$id";
$known2fn{"$r.$arch-$id"} = $fn;
$known2path{"$r.$arch-$id"} = $path;
my $size = (split('/', $id))[1];
$fnsize2id{"$fn-$size"} = $id;
}
close F;
my %newp;
my %newr;
for (@known) {
$newp{$_} = $oldp{$_} if $oldp{$_};
$newr{$_} = $oldr{$_} if $oldr{$_};
}
my @todo = grep {!($newp{$_} && $newr{$_})} @known;
if (@todo) {
for my $known (@todo) {
my $path = $known2path{$known};
if ($path =~ /\.rpm$/) {
my %res = Build::Rpm::rpmq($path, 1000, 1001, 1002, 1006, 1022, 1047, 1049, 1048, 1050, 1112, 1113);
next unless %res;
Build::Rpm::add_flagsvers(\%res, 1047, 1112, 1113);
Build::Rpm::add_flagsvers(\%res, 1049, 1048, 1050);
my $id = $known;
$id =~ s/.*-//;
if ($known ne "$res{1000}->[0].$res{1022}->[0]-$id") {
$known = "$res{1000}->[0].$res{1022}->[0]-$id";
if (!$known2path{$known}) {
push @known, $known;
$known2path{$known} = $path;
}
}
# rpm3 compatibility: retrofit missing self provides
my $name = $res{1000}->[0];
if (!@{$res{1047} || []} || $res{1047}->[-1] !~ /^\Q$name\E =/) {
my $evr = "$res{1001}->[0]-$res{1002}->[0]";
$evr = "$res{1003}->[0]:$evr" if $res{1003} && $res{1003}->[0];
push @{$res{1047}}, "$name = $evr";
}
$newp{$known} = "P:$known: ".join(' ', @{$res{1047} || []});
$newr{$known} = "R:$known: ".join(' ', @{$res{1049} || []});
#$tag{$known} = $res{1000}->[0]."-".$res{1001}->[0]."-".$res{1002}->[0]." ".$res{1007}->[0]."-".$res{1006}->[0];
$tag{$known} = $res{1000}->[0]."-".$res{1001}->[0]."-".$res{1002}->[0]." ".$res{1006}->[0];
} else {
my %res = Build::Deb::debq($path);
next unless %res;
my ($dn, $da) = ($res{'PACKAGE'}, $res{'ARCHITECTURE'});
$da = 'noarch' if $da eq 'all';
my $id = $known;
$id =~ s/.*-//;
if ($known ne "$dn.$da-$id") {
$known = "$dn.$da-$id";
if (!$known2path{$known}) {
push @known, $known;
$known2path{$known} = $path;
}
}
my @provides = split(',\s*', $res{'PROVIDES'} || '');
my @depends = split(',\s*', $res{'DEPENDS'} || '');
my @predepends = split(',\s*', $res{'PRE-DEPENDS'} || '');
s/\s.*// for @provides; #for now
s/\s.*// for @depends; #for now
s/\s.*// for @predepends; #for now
push @depends, @predepends;
push @provides, $res{'PACKAGE'};
$newp{$known} = "P:$known: ".join(' ', @provides);
$newr{$known} = "R:$known: ".join(' ', @depends);
}
}
}
@known = grep {$newp{$_} && $newr{$_}} @known;
for (@known) {
print "F:$_: $known2path{$_}\n";
print "$newp{$_}\n";
print "$newr{$_}\n";
print "I:$_: $tag{$_}\n" if exists $tag{$_};
}
}