Merge commit 'ocaml3102'
[ocaml.git] / ocamlbuild / digest_cache.ml
blob95ddfed1c83dd680b3cc6ff8dd76d49991cd505a
1 (***********************************************************************)
2 (* ocamlbuild *)
3 (* *)
4 (* Nicolas Pouillard, Berke Durak, projet Gallium, INRIA Rocquencourt *)
5 (* *)
6 (* Copyright 2007 Institut National de Recherche en Informatique et *)
7 (* en Automatique. All rights reserved. This file is distributed *)
8 (* under the terms of the Q Public License version 1.0. *)
9 (* *)
10 (***********************************************************************)
12 (* Original author: Nicolas Pouillard *)
14 open My_std
15 open Pathname.Operators
17 let digests = Hashtbl.create 103
19 let get = Hashtbl.find digests
21 let put = Hashtbl.replace digests
23 let _digests = lazy (Pathname.pwd / !Options.build_dir / (Pathname.mk "_digests"))
25 let finalize () =
26 with_output_file !*_digests begin fun oc ->
27 Hashtbl.iter begin fun name digest ->
28 Printf.fprintf oc "%S: %S\n" name digest
29 end digests
30 end
32 let init () =
33 Shell.chdir !Options.build_dir;
34 if Pathname.exists !*_digests then
35 with_input_file !*_digests begin fun ic ->
36 try while true do
37 let l = input_line ic in
38 Scanf.sscanf l "%S: %S" put
39 done with End_of_file -> ()
40 end;
41 My_unix.at_exit_once finalize