Debian Codegraph @

boot/util.ml

raw symbols SCIP
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 let parse_env_line l =
12 try Scanf.sscanf l "%[^=]=%S" (fun name value -> Some(name,value))
13 with Scanf.Scan_failure _ | End_of_file -> None
14
15 let with_ic file f =
16 let ic = open_in file in
17 try
18 let rc = f ic in
19 close_in ic;
20 rc
21 with e -> close_in ic; raise e
22
23 let getenv_from_file name =
24 let base = Filename.dirname Sys.executable_name in
25 try
26 with_ic (base ^ "/coq_environment.txt") (fun ic ->
27 let rec find () =
28 let l = input_line ic in
29 match parse_env_line l with
30 | Some(n,v) when n = name -> Some v
31 | _ -> find ()
32 in
33 find ())
34 with
35 | Sys_error s -> None
36 | End_of_file -> None
37
38
39 let getenv_opt name =
40 match Sys.getenv_opt name with
41 | Some _ as v -> v
42 | None -> getenv_from_file name
43
44 let warn_deprecated_coq_var = ref (fun ~rocq ~coq ->
45 Printf.eprintf "Deprecated environment variable %s, use %s instead.\n%!" coq rocq)
46
47 let set_warn_deprecated_coq_var f = warn_deprecated_coq_var := f
48
49 let warn_deprecated_coq_var ~rocq ~coq = !warn_deprecated_coq_var ~rocq ~coq
50
51 let getenv_rocq_gen ~rocq ~coq =
52 match getenv_opt rocq with
53 | Some _ as v -> v
54 | None ->
55 match getenv_opt coq with
56 | Some _ as v ->
57 warn_deprecated_coq_var ~rocq ~coq;
58 v
59 | None -> None
60
61 let getenv_rocq name =
62 getenv_rocq_gen ~rocq:("ROCQ"^name) ~coq:("COQ"^name)