2007-02-07 00:59:16 -08:00
|
|
|
(***********************************************************************)
|
2012-08-01 07:47:00 -07:00
|
|
|
(* *)
|
2007-02-07 00:59:16 -08:00
|
|
|
(* ocamlbuild *)
|
|
|
|
(* *)
|
|
|
|
(* Nicolas Pouillard, Berke Durak, projet Gallium, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 2007 Institut National de Recherche en Informatique et *)
|
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
2015-07-28 06:18:34 -07:00
|
|
|
(* under the terms of the GNU Library General Public License, with *)
|
|
|
|
(* the special exception on linking described in file ../LICENSE. *)
|
2007-02-07 00:59:16 -08:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
2009-03-03 08:54:58 -08:00
|
|
|
|
2007-02-07 00:59:16 -08:00
|
|
|
(* Original author: Nicolas Pouillard *)
|
|
|
|
open My_std
|
|
|
|
|
|
|
|
module Debug = struct
|
|
|
|
let mode _ = true
|
|
|
|
end
|
|
|
|
include Debug
|
|
|
|
|
|
|
|
let level = ref 1
|
|
|
|
|
|
|
|
let classic_display = ref false
|
2007-11-22 10:53:38 -08:00
|
|
|
let internal_display = ref None
|
|
|
|
let failsafe_display = lazy (Display.create ~mode:`Classic ~log_level:!level ())
|
2007-02-07 00:59:16 -08:00
|
|
|
|
2007-11-22 10:53:38 -08:00
|
|
|
let ( !- ) r =
|
|
|
|
match !r with
|
|
|
|
| None -> !*failsafe_display
|
|
|
|
| Some x -> x
|
|
|
|
|
|
|
|
let init log_file =
|
2007-02-07 00:59:16 -08:00
|
|
|
let mode =
|
|
|
|
if !classic_display || !*My_unix.is_degraded || !level <= 0 || not (My_unix.stdout_isatty ()) then
|
|
|
|
`Classic
|
|
|
|
else
|
|
|
|
`Sophisticated
|
|
|
|
in
|
2007-11-22 10:53:38 -08:00
|
|
|
internal_display := Some (Display.create ~mode ?log_file ~log_level:!level ())
|
2007-02-07 00:59:16 -08:00
|
|
|
|
2015-08-02 06:05:48 -07:00
|
|
|
let raw_dprintf log_level = Display.dprintf ~raw:true ~log_level !-internal_display
|
|
|
|
let dprintf log_level fmt = Display.dprintf ~log_level !-internal_display fmt
|
2015-08-02 06:05:50 -07:00
|
|
|
let is_logging log_level = Display.is_logging !-internal_display log_level
|
2007-02-07 00:59:16 -08:00
|
|
|
let eprintf fmt = dprintf (-1) fmt
|
|
|
|
|
2007-11-22 10:53:38 -08:00
|
|
|
let update () = Display.update !-internal_display
|
|
|
|
let event ?pretend x = Display.event !-internal_display ?pretend x
|
|
|
|
let display x = Display.display !-internal_display x
|
2007-02-07 00:59:16 -08:00
|
|
|
|
2014-08-22 06:45:02 -07:00
|
|
|
let do_at_end = Queue.create ()
|
2014-08-29 10:14:00 -07:00
|
|
|
let already_asked = Hashtbl.create 10
|
2014-08-22 06:45:02 -07:00
|
|
|
|
2014-08-29 10:14:00 -07:00
|
|
|
let at_end_always ~name thunk =
|
|
|
|
if not (Hashtbl.mem already_asked name) then begin
|
|
|
|
Hashtbl.add already_asked name ();
|
|
|
|
Queue.add thunk do_at_end;
|
|
|
|
end
|
|
|
|
|
|
|
|
let at_end ~name thunk = at_end_always ~name (function
|
2014-08-22 06:45:02 -07:00
|
|
|
| `Quiet -> ()
|
|
|
|
| `Success | `Error -> thunk `Error)
|
2014-08-29 10:14:00 -07:00
|
|
|
let at_failure ~name thunk = at_end_always ~name (function
|
2014-08-22 06:45:02 -07:00
|
|
|
| `Success | `Quiet -> ()
|
|
|
|
| `Error -> thunk `Error)
|
|
|
|
|
2007-02-07 00:59:16 -08:00
|
|
|
let finish ?how () =
|
2014-08-29 10:14:00 -07:00
|
|
|
while not (Queue.is_empty do_at_end) do
|
|
|
|
let actions = Queue.copy do_at_end in
|
|
|
|
Queue.clear do_at_end;
|
|
|
|
(* calling a thunk may add new actions again, hence the loop *)
|
|
|
|
Queue.iter (fun thunk ->
|
|
|
|
thunk (match how with None -> `Quiet | Some how -> how)
|
|
|
|
) actions;
|
|
|
|
done;
|
2007-11-22 10:53:38 -08:00
|
|
|
match !internal_display with
|
|
|
|
| None -> ()
|
|
|
|
| Some d -> Display.finish ?how d
|
2007-02-07 00:59:16 -08:00
|
|
|
|
|
|
|
(*let () = My_unix.at_exit_once finish*)
|