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
|
(**************************************************************************)
(* This file is part of a library developed with the support of the *)
(* Mancoosi Project. http://www.mancoosi.org *)
(* *)
(* Main author(s): Pietro Abate *)
(* *)
(* Contributor(s): ADD minor contributors here *)
(* *)
(* This library is free software: you can redistribute it and/or modify *)
(* it under the terms of the GNU Lesser General Public License as *)
(* published by the Free Software Foundation, either version 3 of the *)
(* License, or (at your option) any later version. A special linking *)
(* exception to the GNU Lesser General Public License applies to this *)
(* library, see the COPYING file for more information. *)
(**************************************************************************)
open ExtLib
open Common
open Algo
open DoseparseNoRpm
include Util.Logging(struct let label = __FILE__ end) ;;
module Options = struct
open OptParse
let description =
"Report packages that aren't installable in any futures of a repository"
let options = OptParser.make ~description
include StdOptions.MakeOptions(struct let options = options end)
include StdOptions.DistcheckOptions
StdOptions.DistcheckOptions.add_options options ;;
include StdOptions.InputOptions
StdOptions.InputOptions.add_options ~default:["checkonly"] options ;;
include StdOptions.DistribOptions;;
StdOptions.DistribOptions.add_options options ;;
let dump = StdOpt.store_true ()
open OptParser
add options ~long_name:"dump" ~help:"Dump the cudf package list and exit" dump;
end
let sync (sn,sv,v) p =
let cn = CudfAdd.encode ("src/"^sn^"/"^sv) in
{p with
Cudf.provides = (cn, Some (`Eq, v))::p.Cudf.provides;
Cudf.conflicts = (cn, Some (`Neq, v))::p.Cudf.conflicts;
}
;;
let dummy (sn,sv) pkg number equivs version =
{Cudf.default_package with
Cudf.package = pkg.Cudf.package;
version = version;
conflicts = [(pkg.Cudf.package, None)];
provides = pkg.Cudf.provides;
keep = pkg.Cudf.keep;
pkg_extra = [
("number",`String number);
("architecture",`String "dummy");
("equivs", `String (String.concat "," equivs));
("source", `String sn);
("sourcenumber", `String number)
]
}
;;
let evalsel getv target constr =
let evalsel v = function
|(`Eq,w) -> v = (getv w)
|(`Geq,w) -> v >= (getv w)
|(`Leq,w) -> v <= (getv w)
|(`Gt,w) -> v > (getv w)
|(`Lt,w) -> v < (getv w)
|(`Neq,w) -> v <> (getv w)
in
match target with
|`Hi v -> evalsel ((getv v) + 1) constr
|`Lo v -> evalsel ((getv v) - 1) constr
|`Eq v -> evalsel (getv v) constr
|`In (v1,v2) -> evalsel ((getv v2) - 1) constr
;;
let version_of_target getv = function
|`Eq v -> getv v
|`Hi v -> (getv v) + 1
|`Lo v |`In (_,v) -> (getv v) - 1
;;
let timer = Util.Timer.create "Solver"
(* the repository should contain only the most recent version of each
package *)
let future ?options ?(checklist=[]) repository =
let worktable = Hashtbl.create 1024 in
let version_acc = ref [] in
let constraints_table = Debian.Evolution.constraints repository in
let realpackages = Hashtbl.create 1023 in
let clusters = Debian.Debutil.cluster repository in
(* for each cluster, I associate to it: its discriminants,
* its cluster name and its binary version *)
let cluster_iter (sn,sv) l =
List.iter (fun (version,realversion,cluster) ->
List.iter (fun pkg ->
let pn = pkg.Debian.Packages.name in
if Hashtbl.mem constraints_table pn then begin
Hashtbl.add realpackages pn ()
end
) cluster;
let (versionlist, constr) =
Debian.Evolution.all_ver_constr constraints_table cluster
in
version_acc := versionlist @ !version_acc;
Hashtbl.add worktable (sn,version) (cluster,versionlist,constr)
) l
in
(* for each package name, that is not a real package,
* I create a package with version 1 and I put it in a
* cluster by itself *)
let constraints_iter name constr =
if not(Hashtbl.mem realpackages name) then begin
let vl = Debian.Evolution.all_versions constr in
let pkg = {
Debian.Packages.default_package with
Debian.Packages.name = name;
version = "1";
}
in
let cluster = [pkg] in
version_acc := vl @ !version_acc;
Hashtbl.add worktable (name,"1") (cluster,vl,constr)
end
in
(* if List.length checklist > 0 then
List.iter (fun (sn,_,sv) ->
begin try cluster_iter (sn,sv) (Hashtbl.find clusters (sn,sv)) with Not_found -> () end;
begin try constraints_iter sn (Hashtbl.find constraints_table sn) with Not_found -> () end;
) checklist
else *) begin
Hashtbl.iter cluster_iter clusters;
Hashtbl.iter constraints_iter constraints_table;
end;
Hashtbl.clear realpackages;
let versionlist = Util.list_unique ("1"::!version_acc) in
info "Total Names: %d" (Hashtbl.length worktable);
info "Total versions: %d" (List.length versionlist);
let tables = Debian.Debcudf.init_tables ~step:2 ~versionlist repository in
let getv v = Debian.Debcudf.get_cudf_version tables ("",v) in
let pkgset =
Hashtbl.fold (fun (sn,version) (cluster,vl,constr) acc0 ->
let sync_index = ref 1 in
let discr = Debian.Evolution.discriminant (evalsel getv) vl constr in
let acc0 =
(* by assumption all packages in a cluster are syncronized *)
List.fold_left (fun l pkg ->
let p = Debian.Debcudf.tocudf ?options tables pkg in
CudfAdd.Cudf_set.add (sync (sn,version,1) p) l
) acc0 cluster
in
(* the target version is always greater then all versions in equivs *)
List.fold_left (fun acc1 (target,equiv) ->
incr sync_index;
List.fold_left (fun acc2 pkg ->
let p = Debian.Debcudf.tocudf tables pkg in
let pv = p.Cudf.version in
let target = Debian.Evolution.align pkg.Debian.Packages.version target in
let newv = version_of_target getv target in
let number = Debian.Evolution.string_of_range target in
let equivs = List.map Debian.Evolution.string_of_range equiv in
if newv > pv then begin
let d = dummy (sn,version) p number equivs newv in
if List.length cluster > 1 then
CudfAdd.Cudf_set.add (sync (sn,version,!sync_index) d) acc2
else
CudfAdd.Cudf_set.add d acc2
end else acc2
) acc1 cluster
) acc0 discr
) worktable CudfAdd.Cudf_set.empty
in
Hashtbl.clear worktable;
Hashtbl.clear constraints_table;
let universe = Cudf.load_universe (CudfAdd.Cudf_set.elements pkgset) in
universe, tables
;;
let outdated
?(dump=false)
?(failure=false)
?(explain=false)
?(summary=false)
?(checklist=None)
?options repository =
let universe, tables = future ?options repository in
let universe_size = Cudf.universe_size universe in
info "Total future: %d" universe_size;
if dump then begin
Cudf_printer.pp_preamble stdout Debian.Debcudf.preamble;
print_newline ();
Cudf_printer.pp_universe stdout universe;
exit(0)
end;
let checklist =
let to_cudf (p,v) = (p,Debian.Debcudf.get_cudf_version tables (p,v)) in
if OptParse.Opt.is_set Options.checkonly then begin
List.flatten (
List.map (fun ((n,a),c) ->
let (name,filter) = Debian.Debutil.debvpkg to_cudf ((n,a),c) in
Cudf.lookup_packages ~filter universe name
) (OptParse.Opt.get Options.checkonly)
)
end else []
in
let pp pkg =
let p =
if String.starts_with pkg.Cudf.package "src/" then
Printf.sprintf "Source conflict (%s)" pkg.Cudf.package
else pkg.Cudf.package
in
let v =
if pkg.Cudf.version > 0 then begin
if String.starts_with pkg.Cudf.package "src/" then
string_of_int pkg.Cudf.version
else
try Cudf.lookup_package_property pkg "number"
with Not_found ->
if (pkg.Cudf.version mod 2) = 1 then
Debian.Debcudf.get_real_version tables
(pkg.Cudf.package,pkg.Cudf.version)
else
fatal "Real package without Debian Version"
end
else "nan"
in
let l =
List.filter_map (fun k ->
try Some(k,Cudf.lookup_package_property pkg k)
with Not_found -> None
) ["architecture";"source";"sourcenumber";"equivs"]
in
(CudfAdd.decode p,v,l)
in
let fmt = Format.std_formatter in
Format.fprintf fmt "@[<v 1>report:@,";
let results = Diagnostic.default_result universe_size in
let callback d =
if summary then Diagnostic.collect results d ;
Diagnostic.fprintf ~pp ~failure ~explain fmt d
in
Util.Timer.start timer;
let broken =
if checklist <> [] then
Depsolver.listcheck ~callback ~global_constraints:false universe checklist
else
Depsolver.univcheck ~callback ~global_constraints:false universe
in
ignore(Util.Timer.stop timer ());
if failure then Format.fprintf fmt "@]@.";
Format.fprintf fmt "total-packages: %d@." universe_size;
Format.fprintf fmt "broken-packages: %d@." broken;
if summary then
Format.fprintf fmt "@[%a@]@." (Diagnostic.pp_summary ~pp ()) results;
results
;;
let main () =
let args = OptParse.OptParser.parse_argv Options.options in
let options =
match Option.get (Options.set_options `Deb) with
|StdOptions.Deb o -> o
|_ -> fatal "impossible"
in
StdDebug.enable_debug (OptParse.Opt.get Options.verbose);
StdDebug.enable_bars (OptParse.Opt.get Options.progress)
["Depsolver_int.univcheck";"Depsolver_int.init_solver"] ;
StdDebug.enable_timers (OptParse.Opt.get Options.timers) ["Solver"];
StdDebug.all_quiet (OptParse.Opt.get Options.quiet);
let checklist = OptParse.Opt.opt Options.checkonly in
let failure = OptParse.Opt.get Options.failure in
let explain = OptParse.Opt.get Options.explain in
let summary = OptParse.Opt.get Options.summary in
let dump = OptParse.Opt.get Options.dump in
let archs =
if not(Option.is_none options.Debian.Debcudf.native) then
(Option.get options.Debian.Debcudf.native) :: options.Debian.Debcudf.foreign
else []
in
let packagelist = Debian.Packages.input_raw ~archs args in
let result = outdated ~summary ~failure ~explain ~dump ~checklist ~options packagelist in
if (result.Diagnostic.missing = 0) && (result.Diagnostic.conflict = 0)
then 0 (* no broken packages *)
else 1 (* at least one broken package *)
;;
StdUtils.if_application
~alternatives:["dose-outdated";"dose3-outdated";"edos-outdated";"deb-outdated"]
__FILE__ main ;;
|