-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtransition.ml
3747 lines (3526 loc) · 128 KB
/
transition.ml
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(* Co-installability tools
* http://coinst.irill.org/
* Copyright (C) 2011 Jérôme Vouillon
* Laboratoire PPS - CNRS Université Paris Diderot
*
* These programs are free software; you can redistribute them and/or
* modify them under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*)
(*
- incremental (re)computations (of repositories, flattened repositories, ...)
- repeat the remove commands from the input to the hint ouput?
- cache reverse dependencies: then, either we have a lot of work to do and
we can afford to compute them, or we can get them rapidly
- better report issues preventing migration:
=> show source package version numbers
=> example: empathy
- improve '--migrate option': multiple files, bin_nmus
- could the 'migrate' option automatically generate removal hints?
(seems difficult, as there can be many possible choices...)
- parse more options from britney config file
- make Deb_lib more abstract...
- SVG graphs: use CSS styles
- revise hints: check hint parsing; block binary packages
EXPLANATIONS
==> summaries; in particular, show packages that only wait for age,
for bugs
LATER
==> user interaction
- interactive mode
==> performance
- for migration, is it possible to focus on a small part of
the repositories?
- urgency information is huge; can we reduce it?
(filter, depending on source informations...)
- reducing size with installability:
===> flatten a superposition of testing and sid
===> needs to be very conservative!!
packages with no deps after flattening do not need deps before that
===> robustness
- find_coinst_constraints: check whether we have a larger set
of unconstrained packages and automatically recompute the set
of packages to consider in that case
*)
(**** Configuration settings ****)
let archs =
ref ["i386"; "amd64"; "arm64"; "armel"; "armhf"; "mips"; "mipsel";
"powerpc"; "ppc64el"; "s390x"]
let smooth_updates = ref ["libs"; "oldlibs"]
let dir = ref ""
let options = Hashtbl.create 17
let get_option key def =
try
match Hashtbl.find options key with
[s] -> s
| _ -> assert false
with Not_found ->
def
let testing () = get_option "TESTING" (Filename.concat !dir "testing")
let unstable () = get_option "UNSTABLE" (Filename.concat !dir "unstable")
let bug_url n = "http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=" ^ n
let pts_url nm = Format.sprintf "http://packages.qa.debian.org/%s" nm
let build_log_url nm arch =
Format.sprintf
"https://buildd.debian.org/status/logs.php?arch=%s&pkg=%s" arch nm
let cache_dir =
let cache_home = try Sys.getenv "XDG_CACHE_HOME" with Not_found -> "" in
let base_dir =
if cache_home = "" then
Filename.concat (Sys.getenv "HOME") ".cache"
else
cache_home
in
Filename.concat base_dir "coinst"
let urgency_delay u =
match u with
"low" -> 10
| "medium" -> 5
| "high" -> 2
| "critical" -> 0
| "emergency" -> 0
| _ -> assert false
let default_urgency = urgency_delay "medium"
let update_data = ref false
let hint_file = ref ""
let heidi_file = ref ""
let excuse_file = ref ""
let explain_dir = ref ""
let offset = ref 0
let all_hints = ref false
let to_migrate = ref None
let to_remove = ref []
let check_coinstallability = ref true
let equivocal = ref false
let svg = ref false
let broken_sets = Upgrade_common.empty_break_set ()
let popcon_file = ref ""
(**** Debug options ****)
let debug = Debug.make "normal" "Set normal debug output level." []
let verbose =
Debug.make "explain" "Explain why packages are not propagated." ["normal"]
let debug_time = Debug.make "time" "Print execution times" []
let debug_reduction =
Debug.make "reduction" "Debug repository size reduction" ["normal"]
let debug_coinst =
Debug.make "coinst" "Debug co-installability issue analyse" ["normal"]
let debug_outcome =
Debug.make "outcome" "Print the possible changes" ["normal"]
let debug_hints =
Debug.make "hints" "Output suggested hints to standard output" ["normal"]
let debug_migration =
Debug.make "migration" "Debug migration option" ["normal"]
let debug_gc =
Debug.make "gc" "Output gc stats" []
let debug_remove = Debug.make "remove" "Debug removal hints" ["normal"]
let debug_choice =
Debug.make "choice" "Warn about arbitrary choices performed by the solver"
["normal"]
(**** Useful modules from Util ****)
module StringSet = Util.StringSet
module IntSet = Util.IntSet
module Timer = Util.Timer
module ListTbl = Util.ListTbl
module StringTbl = Util.StringTbl
module IntTbl = Util.IntTbl
module BitVect = Util.BitVect
module Union_find = Util.Union_find
let (>>) v f = f v
(*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX*)
let _ =
Printexc.record_backtrace true;
Gc.set { (Gc.get ())
with Gc.space_overhead = 200; max_overhead = 1000000;
major_heap_increment = 5 * 1024 * 1024 }
module M = Deb_lib
(**** Parsing of input files ****)
let whitespaces = Str.regexp "[ \t]+"
let comma = Str.regexp ","
let slash = Str.regexp "/"
let now = truncate ((Unix.time () /. 3600. -. 15.) /. 24.)
let read_package_info file f =
let h = M.PkgTbl.create 32768 in
if not (Sys.file_exists file) then
Util.print_warning (Format.sprintf "file '%s' not found." file)
else begin
let ch = open_in file in
begin try
while true do
let l = input_line ch in
match Str.split whitespaces l with
[name; version; info] ->
let version = Deb_lib.parse_version version in
if M.name_exists name then
M.PkgTbl.add h (M.id_of_name name) (version, f info)
| [] ->
()
| _ ->
assert false
done;
with End_of_file -> () end;
close_in ch
end;
h
let read_dates src_uid file =
let cache = Filename.concat cache_dir "Dates" in
fst (Cache.cached [file] cache ("version 2\n" ^ src_uid)
(fun () -> read_package_info file int_of_string))
let read_urgencies src_uid file =
let cache = Filename.concat cache_dir "Urgencies" in
fst (Cache.cached [file] cache ("version 2\n" ^ src_uid)
(fun () -> read_package_info file urgency_delay))
let read_bugs file =
let h = StringTbl.create 4096 in
if not (Sys.file_exists file) then
Util.print_warning (Format.sprintf "file '%s' not found." file)
else begin
let ch = open_in file in
begin try
while true do
let l = input_line ch in
match Str.split whitespaces l with
[name; bugs] ->
StringTbl.add h name
(List.fold_right StringSet.add
(Str.split comma bugs) StringSet.empty)
| _ ->
assert false
done;
with End_of_file -> () end;
close_in ch
end;
h
type hint =
{ h_block : string StringTbl.t;
h_block_udeb : string M.PkgTbl.t;
mutable h_block_all : string option;
h_unblock : Deb_lib.version M.PkgTbl.t;
h_unblock_udeb : Deb_lib.version M.PkgTbl.t;
h_urgent : Deb_lib.version M.PkgTbl.t;
h_remove : Deb_lib.version M.PkgTbl.t;
h_age_days : (Deb_lib.version option * int) M.PkgTbl.t }
let debug_read_hints = Debug.make "read_hints" "Show input hints." ["normal"]
let process_unblock_request h l =
List.iter
(fun p ->
match Str.split slash p with
[nm; v] when M.name_exists nm ->
let nm = M.id_of_name nm in
let v = Deb_lib.parse_version v in
begin try
let v' = M.PkgTbl.find h nm in
if Deb_lib.compare_version v' v < 0 then raise Not_found
with Not_found ->
M.PkgTbl.replace h nm v
end
| _ ->
())
l
exception Ignored_hint
let hint_files () =
let hint_re = Str.regexp "^HINTS_\\(.*\\)$" in
Hashtbl.fold
(fun key _ l ->
if Str.string_match hint_re key 0 then
String.lowercase (Str.matched_group 1 key) :: l
else
l)
options []
>> List.sort compare
let read_hints dir =
let hints =
{ h_block = StringTbl.create 16;
h_block_udeb = M.PkgTbl.create 16;
h_block_all = None;
h_unblock = M.PkgTbl.create 16;
h_unblock_udeb = M.PkgTbl.create 16;
h_urgent = M.PkgTbl.create 16;
h_remove = M.PkgTbl.create 16;
h_age_days = M.PkgTbl.create 16 }
in
if debug_read_hints () then
Format.eprintf "Reading hints:@.";
let files =
List.filter
(fun who ->
Sys.file_exists (Filename.concat dir who)
||
(Format.eprintf "Warning: hint file '%s' does not exists.@." who;
false))
(hint_files ())
in
List.iter
(fun who ->
let ch = open_in (Filename.concat dir who) in
begin try
while true do
let l = input_line ch in
let l = Str.split whitespaces l in
try
let add tbl nm v =
if M.name_exists nm then
M.PkgTbl.replace tbl (M.id_of_name nm) v
in
begin match l with
| "block" :: l ->
List.iter
(fun p -> StringTbl.replace hints.h_block p who) l
| "block-udeb" :: l ->
List.iter
(fun p -> add hints.h_block_udeb p who) l
| "block-all" :: l ->
if List.mem "source" l then hints.h_block_all <- Some who
| "unblock" :: l ->
process_unblock_request hints.h_unblock l
| "unblock-udeb" :: l ->
process_unblock_request hints.h_unblock_udeb l
| "urgent" :: l ->
List.iter
(fun p ->
match Str.split slash p with
[nm; v] -> add hints.h_urgent
nm (Deb_lib.parse_version v)
| _ -> ())
l
| "remove" :: l ->
List.iter
(fun p ->
match Str.split slash p with
[nm; v] -> add hints.h_remove
nm (Deb_lib.parse_version v)
| _ -> ())
l
| "age-days" :: n :: l ->
let n = int_of_string n in
List.iter
(fun p ->
match Str.split slash p with
[nm; v] ->
let v =
if v = "-" then None else
Some (Deb_lib.parse_version v)
in
add hints.h_age_days nm (v, n)
| _ ->
())
l
| "finished" :: _ ->
raise End_of_file
| [] ->
raise Ignored_hint
| s :: _ when s.[0] = '#' ->
raise Ignored_hint
| _ ->
if debug_read_hints () then
Format.eprintf "> (ignored) %s@." (String.concat " " l);
raise Ignored_hint
end;
if debug_read_hints () then
Format.eprintf "> %s@." (String.concat " " l)
with Ignored_hint ->
()
done
with End_of_file -> () end;
close_in ch
)
files;
hints
let read_extra_info src_uid =
let dates = read_dates src_uid (Filename.concat (testing ()) "Dates") in
let urgencies =
read_urgencies src_uid (Filename.concat (testing ()) "Urgency") in
let hints = read_hints (Filename.concat (unstable ()) "Hints") in
(dates, urgencies, hints)
let read_bugs () =
let testing_bugs = read_bugs (Filename.concat (testing ()) "BugsV") in
let unstable_bugs = read_bugs (Filename.concat (unstable ()) "BugsV") in
(testing_bugs, unstable_bugs)
(**** Conversion from dot to svg ****)
let send_to_dot_process (oc, _) s = output_string oc s; flush oc
let send_to_dot_process = Task.funct send_to_dot_process
let shutdown_dot_process (oc, pid) () =
close_out oc; ignore (Unix.waitpid [] pid)
let shutdown_dot_process = Task.funct shutdown_dot_process
let create_dot_process () =
let (out_read, out_write) = Unix.pipe () in
flush_all ();
let helper =
Task.spawn
(fun () ->
Unix.close out_read;
let (in_read, in_write) = Unix.pipe () in
match Unix.fork () with
0 ->
Unix.close in_write;
Unix.dup2 in_read Unix.stdin; Unix.dup2 out_write Unix.stdout;
Unix.close in_read; Unix.close out_write;
Unix.execv "/bin/sh" [| "/bin/sh"; "-c"; "dot" |]
| pid ->
Unix.close in_read;
(Unix.out_channel_of_descr in_write, pid))
in
Unix.close out_write;
(helper, Unix.in_channel_of_descr out_read)
let dot_process = lazy (create_dot_process ())
let dot_to_svg s =
let (t, ic) = Lazy.force dot_process in
let send = send_to_dot_process t s in
let (_, g) = Dot_graph.of_channel ic in
ignore (Task.wait send);
let (bbox, scene) = Dot_render.f g in
let l = Scene.get scene in
let b = Buffer.create 200 in
Scene_svg.format (Format.formatter_of_buffer b) (bbox, l);
Buffer.contents b
(**** Parsing of Debian control files ****)
module Repository = Upgrade_common.Repository
open Repository
let bin_package_file suite arch =
Filename.concat suite (Format.sprintf "Packages_%s" arch)
let src_package_file suite = Filename.concat suite "Sources"
let load_bin_packages suite arch =
let file = bin_package_file suite arch in
let dist = M.new_pool () in
assert (not (Sys.is_directory file));
let ch = File.open_in file in
M.parse_packages dist [] ch;
close_in ch;
M.only_latest dist
let load_src_packages suite =
let file = src_package_file suite in
let dist = M.new_src_pool () in
assert (not (Sys.is_directory file));
let ch = File.open_in file in
M.parse_src_packages dist ch;
close_in ch;
M.src_only_latest dist
let has_bin_packages arch =
Sys.file_exists (bin_package_file (testing ()) arch)
let filter_architectures () =
if !dir <> "" then begin
archs := List.filter has_bin_packages !archs;
if !archs = [] then begin
Format.eprintf "No binary package control file found.@.";
exit 1
end
end
(**** Possible reasons for a package not to be upgraded ****)
type reason =
| Unchanged
(* Source *)
| Blocked of (string * string)
| Too_young of int * int
| Binary_not_added | Binary_not_removed
| No_binary
(* Both *)
| More_bugs of StringSet.t
(* Binaries *)
| Conflict of IntSet.t * IntSet.t * Upgrade_common.problem
| Not_yet_built of string * M.version * M.version * bool
| Source_not_propagated
| Atomic
module L = Layout
let (&) = L.(&)
let print_pkg_ref (nm, t, u) =
match t, u with
true, true -> L.code (L.s nm)
| true, false -> L.code (L.s nm) & L.s " (testing)"
| false, true -> L.code (L.s nm) & L.s " (sid)"
| false, false -> assert false
let print_cstr r =
match r with
Upgrade_common.R_depends (pkg, dep, pkgs) ->
print_pkg_ref pkg & L.s " depends on " &
L.code (L.format M.print_package_dependency [dep]) &
L.s " {" & L.seq ", " print_pkg_ref pkgs & L.s "}"
| Upgrade_common.R_conflict (pkg, confl, pkg') ->
print_pkg_ref pkg & L.s " conflicts with " &
L.code
(L.format M.print_package_dependency (List.map (fun c -> [c]) confl)) &
L.s " {" & print_pkg_ref pkg' & L.s "}"
let print_explanation problem =
let conflict_graph () =
let b = Buffer.create 200 in
Upgrade_common.output_conflict_graph (Format.formatter_of_buffer b)
problem;
dot_to_svg (Buffer.contents b)
in
let expl = problem.Upgrade_common.p_explain in
L.ul ~prefix:" - " (L.list (fun r -> L.li (print_cstr r)) expl) &
(if !svg then L.raw_html conflict_graph else L.emp)
let print_binaries conj print_binary s =
let l =
IntSet.elements s
>> List.map print_binary
>> List.sort (Util.compare_pair compare compare)
>> List.map snd
in
match l with
[] -> L.emp
| [p] -> p
| [p; q] -> p & L.s " " & L.s conj & L.s " " & q
| _ -> L.seq ", " (fun x -> x)
(l
>> List.rev
>> (fun l ->
match l with
[] | [_] -> l
| p :: (_ :: _ as r) -> (L.s conj & L.s " " & p) :: r)
>> List.rev)
let print_reason capitalize print_binary print_source lits reason =
let c = if capitalize then String.capitalize else String.uncapitalize in
match reason with
Unchanged ->
L.s (c "No update")
| Blocked (kind, who) ->
L.s (c "Left unchanged due to ") & L.s kind &
L.s " request by " & L.s who & L.s "."
| Too_young (cur_ag, req_ag) ->
L.s (c "Only ") & L.i cur_ag & L.s " days old; must be " & L.i req_ag &
L.s " days old to go in."
| More_bugs s ->
L.s (c "Has new bugs: ") &
L.seq ", " (fun s -> L.anchor (bug_url s) (L.s "#" & L.s s))
(StringSet.elements s) &
L.s "."
| Conflict (s, s', problem) ->
begin match IntSet.cardinal s with
0 ->
L.s (c "A dependency would not be satisfied")
| 1 ->
L.s (c "Needs migration of binary package ") &
snd (print_binary false (IntSet.choose s))
| _ ->
L.s (c "Needs migration of one of the binary packages ") &
print_binaries "or" (print_binary false) s
end
&
begin
if IntSet.cardinal s' > 1 || not (IntSet.mem lits.(0) s') then begin
if IntSet.cardinal s' = 1 then begin
L.s " (would break package " &
snd (print_binary false (IntSet.choose s')) & L.s ")"
end else begin
L.s " (would break co-installability of packages " &
print_binaries "and" (print_binary false) s' & L.s ")"
end
end else
L.emp
end
&
L.s ":" & L.div ~clss:"problem" (print_explanation problem)
| Not_yet_built (src, v1, v2, outdated) ->
(if outdated then
L.s (c "Not yet rebuilt (source ")
else
L.s (c "Obsolete (source "))
&
L.s src & L.s " version " & L.format M.print_version v1 &
L.s " rather than " & L.format M.print_version v2 & L.s ")."
| Source_not_propagated ->
L.s (c "Source package ") & print_source lits.(1) &
L.s " cannot migrate."
| Atomic ->
L.s (c "Binary package ") & snd (print_binary false lits.(1)) &
L.s " cannot migrate."
| Binary_not_added ->
L.s (c "Binary package ") & snd (print_binary true lits.(1)) &
L.s " cannot migrate."
| Binary_not_removed ->
L.s (c "Binary package ") & snd (print_binary true lits.(1)) &
L.s " cannot be removed."
| No_binary ->
L.s (c "No associated binary package.")
let print_reason' get_name_arch lits reason =
let print_binary verbose id =
let (nm, arch) = get_name_arch id in
(nm, if verbose then L.s nm & L.s "/" & L.s arch else L.s nm)
in
let print_source id = let (nm, _) = get_name_arch id in L.s nm in
print_reason false print_binary print_source lits reason
(**** Constraint solver ****)
module HornSolver = Horn.F (struct type t = reason type reason = t end)
(**** Caching of non-coinstallability issues ****)
let learnt_rules = ref []
let learn_rule r neg s problem =
learnt_rules := (r, neg, s, problem) :: !learnt_rules
let coinst_rules = ref []
let switch_to_installability solver =
assert !check_coinstallability;
List.iter (fun r -> HornSolver.retract_rule solver r) !coinst_rules;
check_coinstallability := false
let ambiguous_rules = ref []
let discard_ambiguous_rules solver =
List.iter (fun r -> HornSolver.retract_rule solver r) !ambiguous_rules;
ambiguous_rules := []
let broken_arch_all_packages = ref StringSet.empty
let learn_broken_arch_all_packages s =
broken_arch_all_packages := StringSet.union !broken_arch_all_packages s
let load_rules solver uids =
let cache = Filename.concat cache_dir "Rules" in
let uids = String.concat "\n" uids in
let ((rules, broken_packages), _) =
Cache.cached [] cache ("version 8\n" ^ uids)
(fun () -> ([], StringSet.empty))
in
List.iter
(fun (r, neg, s, problem) ->
let n = IntSet.cardinal s in
if
(!check_coinstallability || n = 1)
&&
not (Upgrade_common.is_ignored_set broken_sets
problem.Upgrade_common.p_issue)
then begin
let r = HornSolver.add_rule solver r (Conflict (neg, s, problem)) in
if n > 1 then coinst_rules := r :: !coinst_rules
end)
rules;
learnt_rules := List.rev rules;
broken_arch_all_packages := broken_packages
let save_rules uids =
let cache = Filename.concat cache_dir "Rules" in
let uids = String.concat "\n" uids in
ignore (Cache.cached ~force:true [] cache ("version 8\n" ^ uids)
(fun () -> (List.rev !learnt_rules, !broken_arch_all_packages)))
(**** Global state for per-architecture processes ****)
type st =
{ arch : string;
testing : M.pool; unstable : M.pool;
testing_srcs : M.s_pool; unstable_srcs : M.s_pool;
unstable_bugs : StringSet.t StringTbl.t;
testing_bugs : StringSet.t StringTbl.t;
mutable outdated_binaries : M.p list;
first_bin_id : int;
id_of_bin : HornSolver.var M.PkgDenseTbl.t;
bin_of_id : M.package_name array;
id_of_source : HornSolver.var M.PkgDenseTbl.t;
mutable upgrade_state :
(Upgrade_common.state * Upgrade_common.state) option;
uid : string;
mutable break_arch_all : bool;
broken_sets : Upgrade_common.ignored_sets }
(**** Misc. useful functions ****)
let source_version src nm =
try
Some (M.find_source_by_name src nm).M.s_version
with Not_found ->
None
let same_source_version t u nm =
match source_version t nm, source_version u nm with
None, None -> true
| Some v, Some v' -> M.compare_version v v' = 0
| _ -> false
let no_new_source t u nm =
match source_version t nm, source_version u nm with
None, None -> true
| Some v, Some v' -> M.compare_version v v' >= 0
| _ -> false
let bin_version dist nm =
match M.find_packages_by_name dist nm with
p :: _ -> Some p.M.version
| [] -> None
let same_bin_version t u nm =
match bin_version t nm, bin_version u nm with
None, None -> true
| Some v, Some v' -> M.compare_version v v' = 0
| _ -> false
let no_new_bin t u nm =
match bin_version t nm, bin_version u nm with
None, None -> true
| Some v, Some v' -> M.compare_version v v' >= 0
| _ -> false
let allow_smooth_updates p =
List.mem "ALL" !smooth_updates || List.mem p.M.section !smooth_updates
let compute_ages dates urgencies hints nm uv tv =
let d =
try
let (v, d) = M.PkgTbl.find dates nm in
if M.compare_version uv v = 0 then d else now
with Not_found ->
now
in
let u =
if
try
M.compare_version uv (M.PkgTbl.find hints.h_urgent nm) = 0
with Not_found ->
false
then
0
else
try
let (v, d) = M.PkgTbl.find hints.h_age_days nm in
if
match v with
Some v -> M.compare_version v uv <> 0
| None -> false
then
raise Not_found;
d
with Not_found ->
let l =
List.filter
(fun (v', d) ->
(match tv with
Some v -> M.compare_version v v' < 0
| None -> true)
&&
M.compare_version v' uv <= 0)
(M.PkgTbl.find_all urgencies nm)
in
let u =
match l with
[] -> default_urgency
| (_, u) :: rem -> List.fold_left (fun u (_, u') -> min u u') u rem
in
match tv with
None -> max u default_urgency
| Some _ -> u
in
(now + !offset - d, u)
(**** Writing of an excuse file ****)
let rec interesting_reason solver (lits, reason) =
match reason with
Unchanged ->
false
| Binary_not_added | Binary_not_removed ->
List.exists (interesting_reason solver)
(HornSolver.direct_reasons solver lits.(1))
| Source_not_propagated ->
false
| Atomic ->
false
| _ ->
true
let binary_names st (offset, l) =
List.map
(fun id ->
let nm = st.bin_of_id.(id - offset) in
let p =
match M.find_packages_by_name st.unstable nm with
p :: _ -> p
| [] -> match M.find_packages_by_name st.testing nm with
p :: _ -> p
| [] -> List.find (fun p -> p.M.package = nm)
st.outdated_binaries
in
(* For faux packages, the source name is not available in the
driving processus, so we have to translate here. *)
(id, M.name_of_id nm, M.name_of_id (fst p.M.source)))
l
let binary_names = Task.funct binary_names
let output_reasons
l dates urgencies hints solver source_of_id id_offsets filename t u =
let reason_t = Timer.start () in
let blocked_source = Hashtbl.create 1024 in
let sources = ref [] in
let binaries = ref IntSet.empty in
Array.iteri
(fun id nm ->
let reasons = HornSolver.direct_reasons solver id in
if List.exists (interesting_reason solver) reasons then begin
sources := (M.name_of_id nm, nm, (id, reasons)) :: !sources;
Hashtbl.add blocked_source (M.name_of_id nm) ();
List.iter
(fun (lits, reason) ->
match reason with
Binary_not_added | Binary_not_removed ->
let id = lits.(1) in
binaries := IntSet.add id !binaries;
List.iter
(fun (lits, reason) ->
match reason with
Conflict (s, s', _) ->
binaries :=
IntSet.union (IntSet.union s s') !binaries
| _ ->
())
(HornSolver.direct_reasons solver id)
| _ ->
())
reasons
end)
source_of_id;
let name_of_binary = IntTbl.create 1024 in
Task.iteri l
(fun (arch, st) ->
let (first, offset, len) = StringTbl.find id_offsets arch in
let pos = first + offset in
let l =
IntSet.elements
(IntSet.filter (fun id -> id >= pos && id < pos + len) !binaries)
in
(arch, binary_names st (pos, l)))
(fun arch l ->
List.iter
(fun (id, nm, src) ->
IntTbl.add name_of_binary id (nm, arch, src))
l);
let print_binary _ id =
let (nm, arch, source_name) = IntTbl.find name_of_binary id in
let txt =
if nm = source_name then
L.code (L.s nm)
else
(L.code (L.s nm) & L.s " (from " & L.code (L.s source_name) & L.s ")")
in
if not (Hashtbl.mem blocked_source source_name) then (nm, txt) else
(nm, L.anchor ("#" ^ source_name) txt)
in
let print_source id = assert false in
let lst =
L.dl (L.list
(fun (source_name, nm, (id, reasons)) ->
let about_bin (_, r) =
match r with
Binary_not_added | Binary_not_removed -> true
| _ -> false
in
let src_reasons =
begin try
let p = M.find_source_by_name u nm in
if same_source_version t u nm then L.emp else
let (cur_ag, req_ag) =
compute_ages dates urgencies hints
nm p.M.s_version (source_version t nm)
in
if cur_ag < req_ag then L.emp else
L.li (L.s "Package is " & L.i cur_ag &
L.s " days old (needed " & L.i req_ag & L.s " days).")
with Not_found ->
L.emp
end
&
L.list
(fun r ->
if interesting_reason solver r && not (about_bin r) then
L.li (print_reason true print_binary print_source
(fst r) (snd r))
else
L.emp)
reasons
in
let binaries =
reasons
>> List.filter
(fun r -> interesting_reason solver r && about_bin r)
>> List.map (fun (lits, r) -> (lits.(1), r))
>> List.sort (Util.compare_pair compare compare)
>> Util.group compare
>> List.map
(fun (id, l) ->
let (name, arch, _) = IntTbl.find name_of_binary id in
let is_removal =
List.for_all (fun r -> r = Binary_not_removed) l in
(name, (arch, (id, is_removal))))
>> List.sort
(Util.compare_pair compare (Util.compare_pair compare compare))
in
let not_yet_built =
binaries
>>
List.filter
(fun (_, (_, (id, _))) ->
List.exists
(fun (_, r) ->
match r with Not_yet_built _ -> true | _ -> false)
(HornSolver.direct_reasons solver id))
>> List.map (fun (name, (arch, _)) -> (name, arch))
>> List.sort (Util.compare_pair compare compare)
>> Util.group compare
>> List.map (fun (name, l) -> (l, name))
>> List.sort (Util.compare_pair (Util.compare_list compare) compare)
>> Util.group (Util.compare_list compare)
in
let build_reasons =
L.list
(fun (al, bl) ->
L.li (L.s (if List.length bl = 1 then "Binary package "
else "Binary packages ") &
L.seq ", " (fun nm -> L.code (L.s nm)) bl &
L.s " not yet rebuilt on " &
L.seq ", "
(fun arch ->
L.anchor (build_log_url source_name arch)
(L.s arch)) al &
L.s "."))
not_yet_built
in
let with_new_bugs =
Util.group compare
(List.flatten
(List.map
(fun (nm, (_, (id, _))) ->
List.flatten
(List.map
(fun (_, reason) ->
match reason with
More_bugs s -> [(nm, s)]
| _ -> [])
(HornSolver.direct_reasons solver id)))
binaries))
in
let bug_reasons =
L.list
(fun (nm', s) ->
let s = List.hd s in (* Same bugs on all archs. *)
if nm' <> source_name then
L.li (L.s "Binary package " & L.code (L.s nm') &
L.s " has new bugs: " &
L.seq ", "
(fun s -> L.anchor (bug_url s) (L.s "#" & L.s s))
(StringSet.elements s) &
L.s ".")
else
L.emp)
with_new_bugs
in
let compare_conflict r r' =
match r, r' with
Conflict (s1, s1', p1), Conflict (s2, s2', p2) ->
compare p1.Upgrade_common.p_explain p2.Upgrade_common.p_explain
| _ ->
assert false
in
let compare_reason =
Util.compare_pair (fun x y -> 0) compare_conflict in
let binaries =
binaries >> Util.group compare >>
List.map
(fun (nm, l) ->
l >>
List.map
(fun (arch, (id, is_removal)) ->
(HornSolver.direct_reasons solver id
>>
List.filter
(fun r ->
interesting_reason solver r &&
match snd r with
Not_yet_built _ | More_bugs _ -> false
| Conflict _ -> true