Stdune.PathRepresentation of paths
The aim of this module is to provide a solid basis to reason about file and directory paths inside the Dune code base. What it is not is a complete API for paths management that handles all the aspects of file system paths. It simply exposes a high-level and portable API that covers the needs of Dune.
Dune sees the file system as two parts. The first part is composed of the source tree and the build directory. In this part, Dune doesn't know about symlinks and has a fully expanded view of the file system. This means that if the user has a symlink `src/foo` pointing to `bar`, then `src/foo/x` and `bar/x` are seen as two different paths.
A path in this world is called a local path and is simply a sequence of path components. A path component being a string other than "." or ".." and not containing the path separator character ('/').
Such a path can be rooted at the source tree root, the build directory or an unspecified root. All these paths are represented by values of type 'a Path.Local_gen.t where 'a denotes the root of the path.
The second part is the "external world". It is all the paths that live outside of the workspace and build directory. To be on the safe side Dune makes no assumption does nothing clever with these paths.
External paths are represented as Path.External.t values.
The Path.t type represents all possible paths, i.e. both local and external paths.
module Local_gen : sig ... endRelative path relative to the root tracked by the type system.
module Unspecified : sig ... endmodule Local : sig ... endRelative path with unspecified root.
module External : sig ... endmodule Source : sig ... endIn the source section of the current workspace.
module Permissions : sig ... endmodule Outside_build_dir : sig ... endmodule Build : sig ... endval to_string : t -> stringval of_string : string -> tval parse_string_exn : loc:Stdune__.Loc0.t -> string -> ta directory is smaller than its descendants
include Comparator.S with type t := tval compare : t -> t -> Ordering.tval extension : t -> stringmap_extension path ~f replaces extension of path by f extension
val basename : t -> Filename.tval basename_opt : t -> Filename.t optionmodule Set : sig ... endmodule Table : sig ... endSpecialized tables for path. We do implement all of Hashtbl_intf.S - only what we use in dune.
val as_outside_build_dir : t -> Outside_build_dir.t optionval as_outside_build_dir_exn : t -> Outside_build_dir.tval destruct_build_dir :
t ->
[ `Inside of Build.t | `Outside of Outside_build_dir.t ]val outside_build_dir : Outside_build_dir.t -> tval hash : t -> intval to_string_maybe_quoted : t -> stringto_string_maybe_quoted t is maybe_quoted (to_string t)
val root : tval external_ : External.t -> tval is_root : t -> boolval is_managed : t -> boolval relative_to_source_in_build_or_external :
?error_loc:Stdune__.Loc0.t ->
dir:Build.t ->
string ->
trelative_to_source_in_build ~dir s compute the path s relative to the source directory corresponding to dir
val of_filename_relative_to_initial_cwd : string -> tCreate an external path. If the argument is relative, assume it is relative to the initial directory dune was launched in.
val to_absolute_filename : t -> stringConvert a path to an absolute filename. Must be called after the workspace root has been set. root is the root directory of local paths
Reach a given path from a directory. For example, let p be a path to the file some/dir/file and d be a path to the directory some/another/dir. Then reach p ~from:d evaluates to ../../dir/file.
val extend_basename : t -> suffix:Filename.t -> textend_basename p ~suffix adds suffix at the end of the path
val extract_build_context : t -> (Filename.t * Source.t) optionExtract the build context from a path. For instance, representing paths as strings:
extract_build_context "_build/blah/foo/bar" = Some ("blah", "foo/bar")It doesn't work correctly (doesn't return a sensible source path) for build directories that are not build contexts, e.g. "_build/install" and "_build/.aliases".
val extract_build_context_exn : t -> Filename.t * Source.tSame as extract_build_context but return the build context as a path:
extract_build_context "_build/blah/foo/bar" = Some ("_build/blah", "foo/bar")Drop the "_build/blah" prefix if present, return t otherwise
Drop the "_build/blah" prefix if present, return t if it's a source file, otherwise fail.
val explode : t -> Filename.t list optionval explode_exn : t -> Filename.t listval build_dir : tThe build directory
val is_in_build_dir : t -> boolis_in_build_dir t = is_descendant t ~of:build_dir
val is_in_source_tree : t -> boolis_in_source_tree t = is_managed t && not (is_in_build_dir t)
val as_external : t -> External.t optionval is_strict_descendant_of_build_dir : t -> boolis_strict_descendant_of_build_dir t = is_in_build_dir t && t <> build_dir
val split_first_component : t -> (Filename.t * t) optionSplit after the first component if t is local
val exists : t -> boolval readdir_unsorted :
t ->
(Filename.t list, Dune_filesystem_stubs.Unix_error.Detailed.t) Result.tval readdir_unsorted_with_kinds :
t ->
((Filename.t * Unix.file_kind) list,
Dune_filesystem_stubs.Unix_error.Detailed.t)
Result.tval is_directory : t -> boolis_dir t checks if t is a directory. It swallows permission errors so the preferred way is to use stat instead
val rmdir : t -> unitval unlink_exn : t -> unitval unlink_no_err : t -> unitval rm_rf : ?allow_external:bool -> t -> unitIf the path does not exist, this function is a no-op.
val clear_dir : t -> Fpath.clear_dir_resultclear_dir t deletes all the contents of directory t without removing t itself.
val mkdir_p : ?perms:int -> t -> unitval in_source : string -> tpaths guaranteed to be in the source directory
val set_root : External.t -> unitSet the workspace root. Can only be called once and the path must be absolute
module L : sig ... endReturn the "local part" of a path. For local paths (in build directory or source tree), this returns the path itself. For external paths, it returns a path that is relative to the current directory. For example, the local part of /a/b is ./a/b.
val stat :
t ->
(Unix.stats, Dune_filesystem_stubs.Unix_error.Detailed.t) Result.tval stat_exn : t -> Unix.statsval lstat :
t ->
(Unix.stats, Dune_filesystem_stubs.Unix_error.Detailed.t) Result.tval lstat_exn : t -> Unix.statsval set_of_source_paths : Source.Set.t -> Set.tval set_of_external_paths : External.Set.t -> Set.tRename a file. rename oldpath newpath renames the file called oldpath to newpath, moving it between directories if needed. If newpath already exists, its contents will be replaced with those of oldpath.
val chmod : t -> mode:int -> unitSet permissions for a given path. You can use the Permissions module if you need to modify existing permissions in a non-trivial way.
val follow_symlink : t -> (t, Fpath.follow_symlink_error) resultAttempts to resolve a symlink. Returns:
Ok path with the resolved destinationError Not_a_symlink if the path isn't a symlinkError Max_depth_exceeded if the function reached the maximum symbolic link depthError (Unix_error _) with the underlying syscall error.drop_prefix_exn t ~prefix drops the prefix from a path, including any leftover `/` prefix. Raises a Code_error.t if the prefix wasn't found.
drop_prefix t ~prefix drops the prefix from a path, including any leftover `/` prefix. Returns None if the prefix wasn't found.
module Expert : sig ... end