]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/ocaml/contrib/ocamlbuild/digest_cache.ml
Inital import
[l4.git] / l4 / pkg / ocaml / contrib / ocamlbuild / digest_cache.ml
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 (***********************************************************************)
11
12 (* Original author: Nicolas Pouillard *)
13
14 open My_std
15 open Pathname.Operators
16
17 let digests = Hashtbl.create 103
18
19 let get = Hashtbl.find digests
20
21 let put = Hashtbl.replace digests
22
23 let _digests = lazy (Pathname.pwd / !Options.build_dir / (Pathname.mk "_digests"))
24
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
31
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