|
|
<!DOCTYPE html>
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>InferBase__Utils (InferBase.InferBase__Utils)</title><link rel="stylesheet" href="../../odoc.css"/><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><meta name="generator" content="doc-ock-html v1.0.0-1-g1fc9bf0"/></head><body><nav id="top"><a href="../index.html">Up</a> — <span class="package">package <a href="../index.html">InferBase</a></span></nav><header><h1><span class="keyword">Module</span> <span class="module-path">InferBase__Utils</span></h1></header><div class="spec val" id="val-initial_times"><a href="#val-initial_times" class="anchor"></a><div class="def val"><code><span class="keyword">val </span>initial_times : <a href="../../InferStdlib/InferStdlib/index.html#module-IStd">InferStdlib.IStd</a>.Unix.process_times</code></div><div class="doc"><p>initial process times</p></div></div><div class="spec val" id="val-find_files"><a href="#val-find_files" class="anchor"></a><div class="def val"><code><span class="keyword">val </span>find_files : path:string <span class="keyword">‑></span> extension:string <span class="keyword">‑></span> string list</code></div><div class="doc"><p>recursively traverse a path for files ending with a given extension</p></div></div><div class="spec val" id="val-string_crc_hex32"><a href="#val-string_crc_hex32" class="anchor"></a><div class="def val"><code><span class="keyword">val </span>string_crc_hex32 : string <span class="keyword">‑></span> string</code></div><div class="doc"><p>Compute a 32-character hexadecimal crc using the Digest module</p></div></div><div class="spec val" id="val-read_file"><a href="#val-read_file" class="anchor"></a><div class="def val"><code><span class="keyword">val </span>read_file : string <span class="keyword">‑></span> (string list, string) <a href="../../InferStdlib/InferStdlib/index.html#module-IStd">InferStdlib.IStd</a>.Result.t</code></div><div class="doc"><p>read a source file and return a list of lines</p></div></div><div class="spec val" id="val-filename_to_absolute"><a href="#val-filename_to_absolute" class="anchor"></a><div class="def val"><code><span class="keyword">val </span>filename_to_absolute : root:string <span class="keyword">‑></span> string <span class="keyword">‑></span> string</code></div><div class="doc"><p>Convert a filename to an absolute one if it is relative, and normalize "." and ".."</p></div></div><div class="spec val" id="val-filename_to_relative"><a href="#val-filename_to_relative" class="anchor"></a><div class="def val"><code><span class="keyword">val </span>filename_to_relative : ?⁠backtrack:int <span class="keyword">‑></span> root:string <span class="keyword">‑></span> string <span class="keyword">‑></span> string option</code></div><div class="doc"><p>Convert an absolute filename to one relative to a root directory. Returns <code class="code">None</code> if filename is
|
|
|
not under root. The backtrack level sets the maximum level of steps in the parent directories
|
|
|
to search for a common prefix</p></div></div><div class="spec type" id="type-outfile"><a href="#type-outfile" class="anchor"></a><div class="def type"><code><span class="keyword">type </span>outfile</code><code></code><code><span class="keyword"> = </span></code><code>{</code><table class="record"><tr id="type-outfile.fname" class="anchored"><td class="def field"><a href="#type-outfile.fname" class="anchor"></a><code>fname : string;</code></td><td class="doc"><p>(** name of the file *)</p></td></tr><tr id="type-outfile.out_c" class="anchored"><td class="def field"><a href="#type-outfile.out_c" class="anchor"></a><code>out_c : <a href="../../InferStdlib/InferStdlib/index.html#module-IStd">InferStdlib.IStd</a>.Out_channel.t;</code></td><td class="doc"><p>(** output channel *)</p></td></tr><tr id="type-outfile.fmt" class="anchored"><td class="def field"><a href="#type-outfile.fmt" class="anchor"></a><code>fmt : Format.formatter;</code></td><td class="doc"><p>(** formatter for printing *)</p></td></tr></table><code>}</code><code></code></div><div class="doc"><p>type for files used for printing</p></div></div><div class="spec val" id="val-create_outfile"><a href="#val-create_outfile" class="anchor"></a><div class="def val"><code><span class="keyword">val </span>create_outfile : string <span class="keyword">‑></span> <a href="index.html#type-outfile">outfile</a> option</code></div><div class="doc"><p>create an outfile for the command line, the boolean indicates whether to do demangling when closing the file</p></div></div><div class="spec val" id="val-close_outf"><a href="#val-close_outf" class="anchor"></a><div class="def val"><code><span class="keyword">val </span>close_outf : <a href="index.html#type-outfile">outfile</a> <span class="keyword">‑></span> unit</code></div><div class="doc"><p>close an outfile</p></div></div><div class="spec val" id="val-directory_fold"><a href="#val-directory_fold" class="anchor"></a><div class="def val"><code><span class="keyword">val </span>directory_fold : (<span class="type-var">'a</span> <span class="keyword">‑></span> string <span class="keyword">‑></span> <span class="type-var">'a</span>) <span class="keyword">‑></span> <span class="type-var">'a</span> <span class="keyword">‑></span> string <span class="keyword">‑></span> <span class="type-var">'a</span></code></div><div class="doc"><p>Functional fold function over all the file of a directory</p></div></div><div class="spec val" id="val-directory_iter"><a href="#val-directory_iter" class="anchor"></a><div class="def val"><code><span class="keyword">val </span>directory_iter : (string <span class="keyword">‑></span> unit) <span class="keyword">‑></span> string <span class="keyword">‑></span> unit</code></div><div class="doc"><p>Functional iter function over all the file of a directory</p></div></div><div class="spec val" id="val-directory_is_empty"><a href="#val-directory_is_empty" class="anchor"></a><div class="def val"><code><span class="keyword">val </span>directory_is_empty : string <span class="keyword">‑></span> bool</code></div><div class="doc"><p>Returns true if a given directory is empty. The directory is assumed to exist.</p></div></div><div class="spec val" id="val-read_json_file"><a href="#val-read_json_file" class="anchor"></a><div class="def val"><code><span class="keyword">val </span>read_json_file : string <span class="keyword">‑></span> (Yojson.Basic.json, string) <a href="../../InferStdlib/InferStdlib/index.html#module-IStd">InferStdlib.IStd</a>.Result.t</code></div><div class="doc"></div></div><div class="spec val" id="val-with_file_in"><a href="#val-with_file_in" class="anchor"></a><div class="def val"><code><span class="keyword">val </span>with_file_in : string <span class="keyword">‑></span> f:(<a href="../../InferStdlib/InferStdlib/index.html#module-IStd">InferStdlib.IStd</a>.In_channel.t <span class="keyword">‑></span> <span class="type-var">'a</span>) <span class="keyword">‑></span> <span class="type-var">'a</span></code></div><div class="doc"></div></div><div class="spec val" id="val-with_file_out"><a href="#val-with_file_out" class="anchor"></a><div class="def val"><code><span class="keyword">val </span>with_file_out : string <span class="keyword">‑></span> f:(<a href="../../InferStdlib/InferStdlib/index.html#module-IStd">InferStdlib.IStd</a>.Out_channel.t <span class="keyword">‑></span> <span class="type-var">'a</span>) <span class="keyword">‑></span> <span class="type-var">'a</span></code></div><div class="doc"></div></div><div class="spec val" id="val-with_intermediate_temp_file_out"><a href="#val-with_intermediate_temp_file_out" class="anchor"></a><div class="def val"><code><span class="keyword">val </span>with_intermediate_temp_file_out : string <span class="keyword">‑></span> f:(<a href="../../InferStdlib/InferStdlib/index.html#module-IStd">InferStdlib.IStd</a>.Out_channel.t <span class="keyword">‑></span> <span class="type-var">'a</span>) <span class="keyword">‑></span> <span class="type-var">'a</span></code></div><div class="doc"><p>like <code class="code">with_file_out</code> but uses a fresh intermediate temporary file and rename to avoid write-write races</p></div></div><div class="spec val" id="val-write_json_to_file"><a href="#val-write_json_to_file" class="anchor"></a><div class="def val"><code><span class="keyword">val </span>write_json_to_file : string <span class="keyword">‑></span> Yojson.Basic.json <span class="keyword">‑></span> unit</code></div><div class="doc"></div></div><div class="spec val" id="val-consume_in"><a href="#val-consume_in" class="anchor"></a><div class="def val"><code><span class="keyword">val </span>consume_in : <a href="../../InferStdlib/InferStdlib/index.html#module-IStd">InferStdlib.IStd</a>.In_channel.t <span class="keyword">‑></span> unit</code></div><div class="doc"><p>consume and ignore all the lines from the channel until End_of_file is reached</p></div></div><div class="spec val" id="val-echo_in"><a href="#val-echo_in" class="anchor"></a><div class="def val"><code><span class="keyword">val </span>echo_in : <a href="../../InferStdlib/InferStdlib/index.html#module-IStd">InferStdlib.IStd</a>.In_channel.t <span class="keyword">‑></span> unit</code></div><div class="doc"><p>echo the lines we get to stdout until End_of_file is reached</p></div></div><div class="spec val" id="val-with_process_in"><a href="#val-with_process_in" class="anchor"></a><div class="def val"><code><span class="keyword">val </span>with_process_in : string <span class="keyword">‑></span> (<a href="../../InferStdlib/InferStdlib/index.html#module-IStd">InferStdlib.IStd</a>.In_channel.t <span class="keyword">‑></span> <span class="type-var">'a</span>) <span class="keyword">‑></span> <span class="type-var">'a</span><span class="keyword"> * </span><a href="../../InferStdlib/InferStdlib/index.html#module-IStd">InferStdlib.IStd</a>.Unix.Exit_or_signal.t</code></div><div class="doc"></div></div><div class="spec val" id="val-with_process_lines"><a href="#val-with_process_lines" class="anchor"></a><div class="def val"><code><span class="keyword">val </span>with_process_lines : debug:((string <span class="keyword">‑></span> unit, Format.formatter, unit) <a href="../../InferStdlib/InferStdlib/index.html#module-IStd">InferStdlib.IStd</a>.format <span class="keyword">‑></span> string <span class="keyword">‑></span> unit) <span class="keyword">‑></span> cmd:string list <span class="keyword">‑></span> tmp_prefix:string <span class="keyword">‑></span> f:(string list <span class="keyword">‑></span> <span class="type-var">'res</span>) <span class="keyword">‑></span> <span class="type-var">'res</span></code></div><div class="doc"><p>Runs the command <code class="code">cmd</code> and calls <code class="code">f</code> on the output lines. Uses <code class="code">debug</code> to print debug
|
|
|
information, and <code class="code">tmp_prefix</code> as a prefix for temporary files.</p></div></div><div class="spec val" id="val-create_dir"><a href="#val-create_dir" class="anchor"></a><div class="def val"><code><span class="keyword">val </span>create_dir : string <span class="keyword">‑></span> unit</code></div><div class="doc"><p>create a directory if it does not exist already</p></div></div><div class="spec val" id="val-realpath"><a href="#val-realpath" class="anchor"></a><div class="def val"><code><span class="keyword">val </span>realpath : ?⁠warn_on_error:bool <span class="keyword">‑></span> string <span class="keyword">‑></span> string</code></div><div class="doc"><p><code class="code">realpath warn_on_error path</code> returns path with all symbolic links resolved.
|
|
|
It caches results of previous calls to avoid expensive system calls.
|
|
|
WARNING: If warn_on_error is false, no warning will be shown whenever an error occurs for
|
|
|
the given path (e.g. if it does not exist).</p></div></div><div class="spec val" id="val-suppress_stderr2"><a href="#val-suppress_stderr2" class="anchor"></a><div class="def val"><code><span class="keyword">val </span>suppress_stderr2 : (<span class="type-var">'a</span> <span class="keyword">‑></span> <span class="type-var">'b</span> <span class="keyword">‑></span> <span class="type-var">'c</span>) <span class="keyword">‑></span> <span class="type-var">'a</span> <span class="keyword">‑></span> <span class="type-var">'b</span> <span class="keyword">‑></span> <span class="type-var">'c</span></code></div><div class="doc"><p>wraps a function expecting 2 arguments in another that temporarily redirects stderr to /dev/null
|
|
|
for the duration of the function call</p></div></div><div class="spec val" id="val-compare_versions"><a href="#val-compare_versions" class="anchor"></a><div class="def val"><code><span class="keyword">val </span>compare_versions : string <span class="keyword">‑></span> string <span class="keyword">‑></span> int</code></div><div class="doc"><p><code class="code">compare_versions v1 v2</code> returns 1 if v1 is newer than v2,
|
|
|
-1 if v1 is older than v2 and 0 if they are the same version.
|
|
|
The versions are strings of the shape "n.m.t", the order is lexicographic.</p></div></div><div class="spec val" id="val-write_file_with_locking"><a href="#val-write_file_with_locking" class="anchor"></a><div class="def val"><code><span class="keyword">val </span>write_file_with_locking : ?⁠delete:bool <span class="keyword">‑></span> f:(<a href="../../InferStdlib/InferStdlib/index.html#module-IStd">InferStdlib.IStd</a>.Out_channel.t <span class="keyword">‑></span> unit) <span class="keyword">‑></span> string <span class="keyword">‑></span> unit</code></div><div class="doc"><p>Lock file passed as argument and write into it using <code class="code">f</code>. If <code class="code">delete</code> then the file is unlinked
|
|
|
once this is done.</p></div></div><div class="spec val" id="val-rmtree"><a href="#val-rmtree" class="anchor"></a><div class="def val"><code><span class="keyword">val </span>rmtree : string <span class="keyword">‑></span> unit</code></div><div class="doc"><p><code class="code">rmtree path</code> removes <code class="code">path</code> and, if <code class="code">path</code> is a directory, recursively removes its contents</p></div></div><div class="spec val" id="val-try_finally_swallow_timeout"><a href="#val-try_finally_swallow_timeout" class="anchor"></a><div class="def val"><code><span class="keyword">val </span>try_finally_swallow_timeout : f:(unit <span class="keyword">‑></span> <span class="type-var">'a</span>) <span class="keyword">‑></span> finally:(unit <span class="keyword">‑></span> unit) <span class="keyword">‑></span> <span class="type-var">'a</span></code></div><div class="doc"><p>Calls <code class="code">f</code> then <code class="code">finally</code> even if <code class="code">f</code> raised an exception. The original exception is reraised afterwards.
|
|
|
Where possible use <code class="code">SymOp.try_finally</code> to avoid swallowing timeouts.</p></div></div><div class="spec val" id="val-better_hash"><a href="#val-better_hash" class="anchor"></a><div class="def val"><code><span class="keyword">val </span>better_hash : <span class="type-var">'a</span> <span class="keyword">‑></span> <a href="../../InferStdlib/InferStdlib/index.html#module-IStd">InferStdlib.IStd</a>.Caml.Digest.t</code></div><div class="doc"><p>Hashtbl.hash only hashes the first 10 meaningful values, <code class="code">better_hash</code> uses everything.</p></div></div><div class="spec val" id="val-unlink_file_on_exit"><a href="#val-unlink_file_on_exit" class="anchor"></a><div class="def val"><code><span class="keyword">val </span>unlink_file_on_exit : string <span class="keyword">‑></span> unit</code></div><div class="doc"><p>delete <code class="code">temporary</code> file on exit</p></div></div><div class="spec val" id="val-strip_balanced_once"><a href="#val-strip_balanced_once" class="anchor"></a><div class="def val"><code><span class="keyword">val </span>strip_balanced_once : drop:(char <span class="keyword">‑></span> bool) <span class="keyword">‑></span> string <span class="keyword">‑></span> string</code></div><div class="doc"><p>drop at most one layer of well-balanced first and last characters satisfying <code class="code">drop</code> from the
|
|
|
string; for instance, <code class="code">strip_balanced ~drop:(function | 'a' | 'x' -> true | _ -> false) "xaabax"</code>
|
|
|
returns "aaba"</p></div></div></body></html> |