Module IBase.Utils
val find_files : path:string -> extension:string -> string listrecursively traverse a path for files ending with a given extension
val fold_folders : init:'acc -> f:('acc -> string -> 'acc) -> path:string -> 'accrecursively traverse a path for folders, returning resuls by a given fold function
val string_crc_hex32 : string -> stringCompute a 32-character hexadecimal crc using the Digest module
val read_file : string -> (string list, string) IStdlib.IStd.Result.tread a source file and return a list of lines
val normalize_path_from : root:string -> string -> string * stringnormalize_path_from ~root pathremoves ".." and "." parts ofroot/pathwhen possible and returns the newrootandpath, eg ifroot = "r"andpath = "a/../../../foo/./bar"then the result is("../foo/bar", ".")(in particular "r/a/../../../foo/./bar" and "./../foo/bar" represent the same file)
val filename_to_absolute : root:string -> string -> stringConvert a filename to an absolute one if it is relative, and normalize "." and ".."
val filename_to_relative : ?force_full_backtrack:bool -> ?backtrack:int -> root:string -> string -> string optionConvert an absolute filename to one relative to a root directory. Returns
Noneif filename is not under root. The backtrack level sets the maximum level of steps in the parent directories to search for a common prefix
type outfile={fname : string;name of the file
out_c : IStdlib.IStd.Out_channel.t;output channel
fmt : Stdlib.Format.formatter;formatter for printing
}type for files used for printing
val create_outfile : string -> outfile optioncreate an outfile for the command line, the boolean indicates whether to do demangling when closing the file
val close_outf : outfile -> unitclose an outfile
val directory_fold : ('a -> string -> 'a) -> 'a -> string -> 'aFunctional fold function over all the file of a directory
val directory_iter : (string -> unit) -> string -> unitFunctional iter function over all the file of a directory
val directory_is_empty : string -> boolReturns true if a given directory is empty. The directory is assumed to exist.
val read_json_file : string -> (Yojson.Basic.t, string) IStdlib.IStd.Result.tval with_file_in : string -> f:(IStdlib.IStd.In_channel.t -> 'a) -> 'aval with_file_out : string -> f:(IStdlib.IStd.Out_channel.t -> 'a) -> 'aval with_intermediate_temp_file_out : string -> f:(IStdlib.IStd.Out_channel.t -> 'a) -> 'alike
with_file_outbut uses a fresh intermediate temporary file and rename to avoid write-write races
val write_json_to_file : string -> Yojson.Basic.t -> unitval consume_in : IStdlib.IStd.In_channel.t -> unitconsume and ignore all the lines from the channel until End_of_file is reached
val echo_in : IStdlib.IStd.In_channel.t -> unitecho the lines we get to stdout until End_of_file is reached
val with_channel_in : f:(string -> unit) -> IStdlib.IStd.In_channel.t -> unitval with_process_in : string -> (IStdlib.IStd.In_channel.t -> 'a) -> 'a * IStdlib.IStd.Unix.Exit_or_signal.tval create_dir : string -> unitrecursively create a directory if it does not exist already
val out_channel_create_with_dir : IStdlib.IStd.Filename.t -> IStdlib.IStd.Out_channel.tcreate an out channel with creating missing directories
val realpath : ?warn_on_error:bool -> string -> stringrealpath warn_on_error pathreturns 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).
val suppress_stderr2 : ('a -> 'b -> 'c) -> 'a -> 'b -> 'cwraps a function expecting 2 arguments in another that temporarily redirects stderr to /dev/null for the duration of the function call
val rmtree : string -> unitrmtree pathremovespathand, ifpathis a directory, recursively removes its contents
val try_finally_swallow_timeout : f:(unit -> 'a) -> finally:(unit -> unit) -> 'aCalls
fthenfinallyeven iffraised an exception. The original exception is reraised afterwards. Where possible useSymOp.try_finallyto avoid swallowing timeouts.
val better_hash : 'a -> IStdlib.IStd.Caml.Digest.tHashtbl.hash only hashes the first 10 meaningful values,
better_hashuses everything.
val strip_balanced_once : drop:(char -> bool) -> string -> stringdrop at most one layer of well-balanced first and last characters satisfying
dropfrom the string; for instance,strip_balanced ~drop:(function | 'a' | 'x' -> true | _ -> false) "xaabax"returns "aaba"
val assoc_of_yojson : Yojson.Basic.t -> src:string -> (string, Yojson.Basic.t) IStdlib.IStd.List.Assoc.tVerify we have a json object (or empty list) and return the corresponding assoc list. Otherwise die with a message including src.
val string_of_yojson : Yojson.Basic.t -> src:string -> stringVerify we have a json string and return the corresponding ocaml string. Otherwise die with a message including src.
val string_list_of_yojson : Yojson.Basic.t -> src:string -> string listVerify we have a json list of strings and return the corresponding ocaml string list. Otherwise die with a message including src.
val yojson_lookup : (string, Yojson.Basic.t) IStdlib.IStd.List.Assoc.t -> string -> src:string -> f:(Yojson.Basic.t -> src:string -> 'a) -> default:'a -> 'aLookup a json value on an assoc list. If not present, returns default. Otherwise returns (f json_value ~src) where src has element name appended. f is typically one of the above _of_yojson functions.
val timeit : f:(unit -> 'a) -> 'a * intReturns the execution time of
fin milliseconds together with its result
val do_in_dir : dir:string -> f:(unit -> 'a) -> 'aexecutes
fafter cding intodirand then restores original cwd
val get_available_memory_MB : unit -> int optionOn Linux systems, return
Some xwhereMemAvailable xis in/proc/meminfo. ReturnsNonein all other cases.
val iter_infer_deps : project_root:string -> f:(string -> unit) -> string -> unitParse each line of the given infer_deps.txt file (split on tabs, assume 3 elements per line) and run
fon the third element.project_rootis an argument to avoid dependency cycles.