summaryrefslogtreecommitdiff
path: root/ocamlbuild/digest_cache.ml
blob: dac770fc1f442274324c47b143adc637b672532a (plain)
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
(***********************************************************************)
(*                                                                     *)
(*                             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    *)
(*  under the terms of the GNU Library General Public License, with    *)
(*  the special exception on linking described in file ../LICENSE.     *)
(*                                                                     *)
(***********************************************************************)

(* Original author: Nicolas Pouillard *)

open My_std
open Pathname.Operators

let digests = Hashtbl.create 103

let get = Hashtbl.find digests

let put = Hashtbl.replace digests

let _digests = lazy (!Options.build_dir / (Pathname.mk "_digests"))

let finalize () =
  with_output_file !*_digests begin fun oc ->
    Hashtbl.iter begin fun name digest ->
      Printf.fprintf oc "%S: %S\n" name digest
    end digests
  end

let init () =
  Shell.chdir !Options.build_dir;
  if Pathname.exists !*_digests then
    with_input_file !*_digests begin fun ic ->
      try while true do
        let l = input_line ic in
        Scanf.sscanf l "%S: %S" put
      done with End_of_file -> ()
    end;
  My_unix.at_exit_once finalize