| 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 | (** {5 Rocq REPL specific system utilities} *) |
| 12 | |
| 13 | (** {6 Directories} *) |
| 14 | |
| 15 | type unix_path = string (* path in unix-style, with '/' separator *) |
| 16 | |
| 17 | type file_kind = |
| 18 | | FileDir of unix_path * (* basename of path: *) string |
| 19 | | FileRegular of string (* basename of file *) |
| 20 | |
| 21 | val (//) : unix_path -> string -> unix_path |
| 22 | |
| 23 | val exists_dir : unix_path -> bool |
| 24 | |
| 25 | (** [mkdir path] ensures that [path] exists as a directory, creating |
| 26 | the missing suffix if necessary (like Unix' mkdirhier) *) |
| 27 | |
| 28 | val mkdir : unix_path -> unit |
| 29 | |
| 30 | (** [exclude_search_in_dirname path] excludes [path] when processing |
| 31 | directories *) |
| 32 | |
| 33 | val exclude_directory : unix_path -> unit |
| 34 | |
| 35 | (** [process_directory f path] applies [f] on contents of directory |
| 36 | [path]; fails with Unix_error if the latter does not exists; skips |
| 37 | all files or dirs starting with "." *) |
| 38 | |
| 39 | val process_directory : (file_kind -> unit) -> unix_path -> unit |
| 40 | |
| 41 | (** [process_subdirectories f path] applies [f path/file file] on each |
| 42 | [file] of the directory [path]; fails with Unix_error if the |
| 43 | latter does not exists; kips all files or dirs starting with "." *) |
| 44 | |
| 45 | val process_subdirectories : (unix_path -> string -> unit) -> unix_path -> unit |
| 46 | |
| 47 | (** {6 Files and load paths} *) |
| 48 | |
| 49 | val warn_cannot_open_dir : ?loc:Loc.t -> string -> unit |
| 50 | |
| 51 | (** Load path entries remember the original root |
| 52 | given by the user. For efficiency, we keep the full path (field |
| 53 | [directory]), the root path and the path relative to the root. *) |
| 54 | |
| 55 | val all_subdirs : unix_path:string -> (CUnix.physical_path * string list) list |
| 56 | val is_in_path : CUnix.load_path -> string -> bool |
| 57 | val is_in_system_path : string -> bool |
| 58 | val where_in_path : |
| 59 | ?warn:bool -> CUnix.load_path -> string -> CUnix.physical_path * string |
| 60 | |
| 61 | (** [get_output_path fname] relativizes [fname] with respect to the |
| 62 | default output directory if [fname] is not absolute *) |
| 63 | val get_output_path : CUnix.physical_path -> CUnix.physical_path |
| 64 | |
| 65 | (** Default output directory. Make sure to emit a warning if using |
| 66 | this directly (cf extraction Table.output_directory) *) |
| 67 | val output_directory : CUnix.physical_path option ref |
| 68 | |
| 69 | (** [find_file_in_path ?warn loadpath filename] returns the directory |
| 70 | name and long name of the first physical occurrence [filename] in |
| 71 | one of the directory of the [loadpath]; |
| 72 | fails with a user error if no such file exists; |
| 73 | warn if two or more files exist in the loadpath; |
| 74 | returns instead the directory name of [filename] is [filename] is |
| 75 | an absolute path *) |
| 76 | val find_file_in_path : |
| 77 | ?warn:bool -> CUnix.load_path -> string -> CUnix.physical_path * string |
| 78 | |
| 79 | (** [all_in_path loadpath filename] returns the list of the directory |
| 80 | name and full name of all physical occurrences of [filename] in a |
| 81 | [loadpath] binding physical paths to some arbitrary key *) |
| 82 | val all_in_path : |
| 83 | (CUnix.physical_path * 'a) list -> string -> ('a * string) list |
| 84 | |
| 85 | val trust_file_cache : bool ref |
| 86 | (** [trust_file_cache] indicates whether we trust the underlying |
| 87 | mapped file-system not to change along the execution of Rocq. This |
| 88 | assumption greatly speeds up file search, but it is often |
| 89 | inconvenient in interactive mode *) |
| 90 | |
| 91 | val file_exists_respecting_case : string -> string -> bool |
| 92 | |
| 93 | (** {6 I/O functions } *) |
| 94 | (** Generic input and output functions, parameterized by a magic number |
| 95 | and a suffix. The intern functions raise the exception [Bad_magic_number] |
| 96 | when the check fails, with the full file name and expected/observed magic |
| 97 | numbers. *) |
| 98 | |
| 99 | type magic_number_error = {filename: string; actual: int32; expected: int32} |
| 100 | exception Bad_magic_number of magic_number_error |
| 101 | exception Bad_version_number of magic_number_error |
| 102 | |
| 103 | val with_magic_number_check : ?loc:Loc.t -> ('a -> 'b) -> 'a -> 'b |
| 104 | |
| 105 | (** big-endian encoding and decoding of int32 (4 btyes) and int64 (8 bytes) *) |
| 106 | |
| 107 | val input_int32 : in_channel -> int32 |
| 108 | |
| 109 | val input_int64 : in_channel -> int64 |
| 110 | |
| 111 | val output_int32 : out_channel -> int32 -> unit |
| 112 | |
| 113 | val output_int64 : out_channel -> int64 -> unit |
| 114 | |
| 115 | (** Clones of Marshal.to_channel (with flush) and |
| 116 | Marshal.from_channel (with nice error message) *) |
| 117 | |
| 118 | val marshal_out : out_channel -> 'a -> unit |
| 119 | val marshal_in : string -> in_channel -> 'a |
| 120 | |
| 121 | val check_caml_version : caml:string -> file:string -> unit |
| 122 | |
| 123 | (** {6 Time stamps.} *) |
| 124 | |
| 125 | type time |
| 126 | type duration |
| 127 | |
| 128 | val empty_duration : duration |
| 129 | |
| 130 | val get_time : unit -> time |
| 131 | val time_difference : time -> time -> float (** in seconds *) |
| 132 | |
| 133 | val duration_between : start:time -> stop:time -> duration |
| 134 | val duration_add : duration -> duration -> duration |
| 135 | val duration_real : duration -> float |
| 136 | |
| 137 | val fmt_time_difference : time -> time -> Pp.t |
| 138 | val fmt_duration : duration -> Pp.t |
| 139 | |
| 140 | type 'a transaction_result = (('a * duration), (Exninfo.iexn * duration)) Result.t |
| 141 | val measure_duration : ('a -> 'b) -> 'a -> 'b transaction_result |
| 142 | val fmt_transaction_result : 'a transaction_result -> Pp.t |
| 143 | |
| 144 | (** {6 Instruction count.} *) |
| 145 | |
| 146 | type instruction_count = (Int64.t, string) Result.t |
| 147 | |
| 148 | val instructions_between : c_start:instruction_count -> c_end:instruction_count -> instruction_count |
| 149 | val instruction_count_add : instruction_count -> instruction_count -> instruction_count |
| 150 | |
| 151 | type 'a instructions_result = |
| 152 | (('a * instruction_count), (Exninfo.iexn * instruction_count)) Result.t |
| 153 | |
| 154 | val count_instructions : ('a -> 'b) -> 'a -> 'b instructions_result |
| 155 | |
| 156 | val fmt_instructions_result : 'a instructions_result -> Pp.t |
| 157 | |
| 158 | (** [get_toplevel_path program] builds a complete path to the |
| 159 | executable denoted by [program]. This involves: |
| 160 | |
| 161 | - locating the directory: we don't rely on PATH as to make calls to |
| 162 | /foo/bin/coqtop chose the right /foo/bin/coqproofworker |
| 163 | |
| 164 | - adding the proper suffix: .exe if in windows. |
| 165 | |
| 166 | Note that this function doesn't check that the executable actually |
| 167 | exists. This is left back to caller, as well as the choice of |
| 168 | fallback strategy. We could add a fallback strategy here but it is |
| 169 | better not to as in most cases if this function fails to construct |
| 170 | the right name you want you execution to fail rather than fall into |
| 171 | choosing some random binary from the system-wide installation of |
| 172 | Rocq. *) |
| 173 | val get_toplevel_path : string -> string |