-
Notifications
You must be signed in to change notification settings - Fork 3
/
binnmuscheduler.dpr
341 lines (310 loc) · 10.9 KB
/
binnmuscheduler.dpr
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
program binnmuscheduler;
uses
readtxt2,sysutils, contnrs, versions, classes, util;
const
architecture = 'armhf';
type
tsourcepackage=class
version : string;
name : string;
binaries : tfphashlist;
constructor createcopy(sourcepackage:tsourcepackage);
end;
tbinarypackage=class
version : string;
source : tsourcepackage;
sourceversion : string;
//note: depends is sorted for easier comparisons
depends : tfphashlist;
end;
constructor tsourcepackage.createcopy(sourcepackage:tsourcepackage);
var
i : integer;
binarypackage : tbinarypackage;
newbinarypackage : tbinarypackage;
binarypackagename : string;
begin
version := sourcepackage.version;
name := sourcepackage.name;
if assigned(sourcepackage.binaries) then begin
binaries := tfphashlist.create;
for i := 0 to sourcepackage.binaries.count-1 do begin
binarypackage := sourcepackage.binaries[i];
binarypackagename := sourcepackage.binaries.nameofindex(i);
newbinarypackage := tbinarypackage.create;
newbinarypackage.source := self;
newbinarypackage.version := binarypackage.version;
newbinarypackage.sourceversion := binarypackage.sourceversion;
newbinarypackage.depends := binarypackage.depends;
binaries.add(binarypackagename,newbinarypackage);
end;
end;
end;
type
tdistribution=class
t : treadtxt;
currentpackage, currentversion, currentsourcepackage, currentsourceversion , currentdepends :string;
sources : tfphashlist;
//rdeps : tfpobjecthashtable;
procedure reset;
procedure processsource;
//procedure processdependency(const sourcepackage:string; const dependency : string);
procedure processpackage;
//constructor create(sourcesfile : string ;packagesfile :string);
procedure getbinaries(binaries:tfphashlist);
procedure readsources(sourcesfile : string);
procedure readpackages(packagesfile : string);
//WARNING: copy is shallow, the tfphashlist is copied but it's contents is not.
constructor createcopy(distribution : tdistribution);
end;
procedure tdistribution.reset;
begin
currentpackage := '';
currentversion := '';
currentsourcepackage := '';
currentsourceversion := '';
currentdepends := '';
end;
procedure tdistribution.processsource;
var
sourcepackage : tsourcepackage;
begin
if currentversion = '' then begin
writeln('package without version!');
halt(1);
end;
sourcepackage := sources.find(currentpackage);
if sourcepackage = nil then begin
sourcepackage := tsourcepackage.create();
sourcepackage.name := currentpackage;
sourcepackage.version := currentversion;
sources.add(currentpackage, sourcepackage);
end else begin
writeln('multiple instances of source package '+currentpackage+' found, please use componentcleaner');
halt(1);
end;
end;
{procedure tdistribution.processdependency(const sourcepackage:string; const dependency : string);
var
rdeplist : tfphashlist;
begin
rdeplist := tfphashlist(rdeps[dependency]);
if rdeplist = nil then begin
rdeplist := tfphashlist.create;
rdeps[dependency] := rdeplist;
end;
if rdeplist.findindexof(sourcepackage) < 0 then rdeplist.add(sourcepackage,0);
end;}
procedure tdistribution.processpackage;
var
sourceversionfromsources : string;
versioncomparison : integer;
inbrackets : boolean;
dependency : string;
c : char;
i : integer;
rdeplist : tstringlist;
sourcepackage : tsourcepackage;
binarypackage : tbinarypackage;
depends : tfphashlist;
begin
if currentversion = '' then begin
writeln('package without version!');
halt(1);
end;
if currentsourcepackage = '' then currentsourcepackage := currentpackage;
if currentsourceversion = '' then currentsourceversion := currentversion;
depends := tfphashlist.create();
dependency := '';
inbrackets := false;
for i := 1 to length(currentdepends) do begin
c := currentdepends[i];
if c = '(' then inbrackets := true;
if c = ')' then inbrackets := false;
if (not inbrackets) and (c in ['a'..'z','0'..'9','+','-','.']) then begin
dependency := dependency + c;
end else begin
if dependency <> '' then depends.add(dependency,pointer($deadbeef));
dependency := '';
end;
end;
if dependency <> '' then depends.add(dependency,pointer($deadbeef));
sourcepackage := tsourcepackage(sources.find(currentsourcepackage));
if sourcepackage = nil then begin
sourcepackage := tsourcepackage.create();
sourcepackage.name := currentsourcepackage;
sourcepackage.version := '__NOT_PRESENT_BUT_HAS_BINARIES__';
sources.add(currentsourcepackage, sourcepackage);
end;
if sourcepackage.binaries = nil then begin
sourcepackage.binaries := tfphashlist.create;
end;
binarypackage := tbinarypackage.create;
binarypackage.version := currentversion;
binarypackage.source := sourcepackage;
binarypackage.sourceversion := currentsourceversion;
binarypackage.depends := depends;
sourcepackage.binaries.add(currentpackage,binarypackage);
end;
procedure tdistribution.readsources(sourcesfile :string);
var
p : integer;
pass : byte;
i : integer;
line : string;
t : treadtxt;
begin
//writeln(compareversion('1','2'));
//writeln(compareversion('1-1','1-2'));
//writeln(compareversion('2','1'));
//writeln(compareversion('1','1'));
//halt;
if sources = nil then sources := tfphashlist.create;
t := treadtxt.createf(sourcesfile);
reset;
repeat
line := t.readline;
if copy(line,1,8) = 'Package:' then begin
currentpackage := trim(copy(line,9,255));
end;
if copy(line,1,8) = 'Version:' then begin
currentversion := trim(copy(line,9,255));
end;
if line = '' then begin
//end of block
if currentpackage <> '' then processsource;
reset;
end;
until t.eof;
if currentpackage <> '' then processsource;
t.free;
end;
procedure tdistribution.readpackages(packagesfile : string);
var
line : string;
t : treadtxt;
sourcelinecontent : string;
p : integer;
begin
t := treadtxt.createf(packagesfile);
reset;
repeat
line := t.readline;
if stringstartis(line,'Package:') then begin
currentpackage := trim(copy(line,9,maxlongint));
end;
if stringstartis(line,'Version:') then begin
currentversion := trim(copy(line,9,maxlongint));
end;
if stringstartis(line,'Source:') then begin
sourcelinecontent := trim(copy(line,8,maxlongint));
p := pos('(',sourcelinecontent);
if p = 0 then begin
currentsourcepackage := sourcelinecontent;
end else begin
currentsourcepackage := trim(copy(sourcelinecontent,1,p-1));
currentsourceversion := copy(sourcelinecontent,p+1,255);
p := pos(')',currentsourceversion);
currentsourceversion := trim(copy(currentsourceversion,1,p-1));
end;
end;
if stringstartis(line,'Depends:') then begin
currentdepends := trim(copy(line,9,maxlongint));
end;
if line = '' then begin
//end of block
if currentpackage <> '' then processpackage;
reset;
end;
until t.eof;
if currentpackage <> '' then processpackage;
t.free;
end;
procedure tdistribution.getbinaries(binaries : tfphashlist);
var
i,j : integer;
sourcepackage : tsourcepackage;
binarypackagename : string;
binarypackage : tbinarypackage;
begin
binaries.clear;
for i := 0 to sources.count-1 do begin
sourcepackage := tsourcepackage(sources[i]);
if sourcepackage.binaries <> nil then for j := 0 to sourcepackage.binaries.count -1 do begin
binarypackage := tbinarypackage(sourcepackage.binaries[j]);
binarypackagename := sourcepackage.binaries.nameofindex(j);
binaries.add(binarypackagename,binarypackage);
end;
end;
end;
constructor tdistribution.createcopy(distribution: tdistribution);
var
i : integer;
begin
sources := tfphashlist.create;
for i := 0 to distribution.sources.count -1 do begin
sources.add(distribution.sources.nameofindex(i),distribution.sources[i]);
end;
end;
var
stagingdistribution: tdistribution;
i,j,k: integer;
stagingsourcepackage: tsourcepackage;
binarypackage: tbinarypackage;
binarypackagename: string;
t : textfile;
b : boolean;
sourcepackagename : string;
binnmunumber : integer;
newbinnmunumber : integer;
binaryversion : string;
reporoot : string;
codenamestaging : string;
outputfilename : string;
outputfile : textfile;
begin
reporoot := paramstr(1);
if reporoot[length(reporoot)] <> '/' then reporoot := reporoot + '/';
codenamestaging := paramstr(2);
outputfilename := paramstr(3);
writeln('reading packages and sources files for staging distribution');
stagingdistribution := tdistribution.create;
stagingdistribution.readsources(reporoot+'dists/'+codenamestaging+'/main/source/Sources');
stagingdistribution.readsources(reporoot+'dists/'+codenamestaging+'/contrib/source/Sources');
stagingdistribution.readsources(reporoot+'dists/'+codenamestaging+'/non-free/source/Sources');
stagingdistribution.readpackages(reporoot+'dists/'+codenamestaging+'/main/binary-'+architecture+'/Packages');
stagingdistribution.readpackages(reporoot+'dists/'+codenamestaging+'/contrib/binary-'+architecture+'/Packages');
stagingdistribution.readpackages(reporoot+'dists/'+codenamestaging+'/non-free/binary-'+architecture+'/Packages');
stagingdistribution.readpackages(reporoot+'dists/'+codenamestaging+'/main/debian-installer/binary-'+architecture+'/Packages');
assignfile(outputfile,outputfilename);
rewrite(outputfile);
repeat
readln(sourcepackagename);
stagingsourcepackage := tsourcepackage(stagingdistribution.sources.find(sourcepackagename));
if assigned(stagingsourcepackage) then begin
//writeln(sourcepackagename+'_'+stagingsourcepackage.version);
binnmunumber := 1;
for i := 0 to stagingsourcepackage.binaries.count-1 do begin
binaryversion := tbinarypackage(stagingsourcepackage.binaries[i]).version;
j := length(binaryversion);
if (j >= 4) and (binaryversion[j] in ['0'..'9']) then begin
while (j >= 4) and (binaryversion[j] in ['0'..'9']) do j := j -1;
if (binaryversion[j] = 'b') and (binaryversion[j-1] = '+') then begin
//we have a binnmu version.
newbinnmunumber := 0;
while j < length(binaryversion) do begin
j := j +1;
newbinnmunumber := (newbinnmunumber * 10)+ord(binaryversion[j])-ord('0');
end;
newbinnmunumber := newbinnmunumber + 1;
if newbinnmunumber > binnmunumber then binnmunumber := newbinnmunumber;
end;
end;
end;
writeln(outputfile,'wanna-build -A armhf -d '+codenamestaging+' -m "rebuild due to debcheck failure" --binNMU '+inttostr(binnmunumber)+' '+sourcepackagename+'_'+stagingsourcepackage.version);
end else begin
writeln(outputfile,'echo can\''t find information needed to generate binnmu for '+sourcepackagename);
end;
until eof(input);
closefile(outputfile);
end.