let pkgcheck global_constraints callback solver failed tested id =
  (* global id is a fake package id encoding the global constraints of the
   * universe. it is the last element of the id array *)

  let req = 
    if global_constraints then begin
      let globalid = (Array.length tested) - 1 in
      Diagnostic_int.Sng (Some globalid,id) 
    end else
      Diagnostic_int.Sng (None,id)
  in
  let res =
    Util.Progress.progress progressbar_univcheck;
    if not(tested.(id)) then begin
      match solve ~tested solver req with
      |Diagnostic_int.Success _ as res -> res
      |Diagnostic_int.Failure _ as res -> (incr failed;  res)
    end
    else begin
      (* this branch is true only if the package was previously
         added to the tested packages and therefore it is installable
         if all = true then the solver is called again to provide the list
         of installed packages despite the fact the the package was already
         tested. This is done to provide one installation set for each package
         in the universe *)

      let f ?(all=false) () =
        if all then begin
          match solve solver req with
          |Diagnostic_int.Success(f_int) -> f_int ()
          |Diagnostic_int.Failure _ -> assert false (* impossible *)
        end else []
      in Diagnostic_int.Success(f) 
    end
  in
  match callback with
  |None -> ()
  |Some f -> f (res,req)