-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This pulls in the new Load_path module from the compiler distribution, but adds a layer of caching on directories content.
- Loading branch information
Showing
14 changed files
with
196 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
(**************************************************************************) | ||
(* *) | ||
(* OCaml *) | ||
(* *) | ||
(* Jeremie Dimino, Jane Street Europe *) | ||
(* *) | ||
(* Copyright 2018 Jane Street Group LLC *) | ||
(* *) | ||
(* All rights reserved. This file is distributed under the terms of *) | ||
(* the GNU Lesser General Public License version 2.1, with the *) | ||
(* special exception on linking described in the file LICENSE. *) | ||
(* *) | ||
(**************************************************************************) | ||
|
||
module SMap = Misc.StringMap | ||
|
||
(* Mapping from basenames to full filenames *) | ||
type registry = string SMap.t ref | ||
|
||
let state = Local_store.new_bindings () | ||
let srefk k = Local_store.ref state (fun () -> k) | ||
|
||
let files : registry = srefk SMap.empty | ||
let files_uncap : registry = srefk SMap.empty | ||
|
||
module Dir = struct | ||
type t = { | ||
path : string; | ||
files : string list; | ||
} | ||
|
||
let path t = t.path | ||
let files t = t.files | ||
|
||
let create path = | ||
{ path; files = Array.to_list (Directory_content_cache.read path) } | ||
end | ||
|
||
let dirs = srefk [] | ||
|
||
let reset () = | ||
files := SMap.empty; | ||
files_uncap := SMap.empty; | ||
dirs := [] | ||
|
||
let get () = !dirs | ||
let get_paths () = List.map Dir.path !dirs | ||
|
||
let add dir = | ||
let add_file base = | ||
let fn = Filename.concat dir.Dir.path base in | ||
files := SMap.add base fn !files; | ||
files_uncap := SMap.add (String.uncapitalize_ascii base) fn !files_uncap; | ||
in | ||
List.iter add_file dir.Dir.files; | ||
dirs := dir :: !dirs | ||
|
||
let remove_dir dir = | ||
let new_dirs = List.filter (fun d -> Dir.path d <> dir) !dirs in | ||
if new_dirs <> !dirs then begin | ||
reset (); | ||
List.iter add (List.rev new_dirs) | ||
end | ||
|
||
let add_dir dir = add (Dir.create dir) | ||
|
||
let init l = | ||
reset (); | ||
List.iter add_dir (List.rev l) | ||
|
||
let is_basename fn = Filename.basename fn = fn | ||
|
||
let find fn = | ||
if is_basename fn then | ||
SMap.find fn !files | ||
else | ||
Misc.find_in_path (get_paths ()) fn | ||
|
||
let find_uncap fn = | ||
if is_basename fn then | ||
SMap.find (String.uncapitalize_ascii fn) !files_uncap | ||
else | ||
Misc.find_in_path_uncap (get_paths ()) fn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
(**************************************************************************) | ||
(* *) | ||
(* OCaml *) | ||
(* *) | ||
(* Jeremie Dimino, Jane Street Europe *) | ||
(* *) | ||
(* Copyright 2018 Jane Street Group LLC *) | ||
(* *) | ||
(* All rights reserved. This file is distributed under the terms of *) | ||
(* the GNU Lesser General Public License version 2.1, with the *) | ||
(* special exception on linking described in the file LICENSE. *) | ||
(* *) | ||
(**************************************************************************) | ||
|
||
(** Management of include directories. | ||
This module offers a high level interface to locating files in the | ||
load path, which is constructed from [-I] command line flags and a few | ||
other parameters. | ||
It makes the assumption that the contents of include directories | ||
doesn't change during the execution of the compiler. | ||
*) | ||
|
||
val add_dir : string -> unit | ||
(** Add a directory to the load path *) | ||
|
||
val remove_dir : string -> unit | ||
(** Remove a directory from the load path *) | ||
|
||
val reset : unit -> unit | ||
(** Remove all directories *) | ||
|
||
val init : string list -> unit | ||
(** [init l] is the same as [reset (); List.iter add_dir (List.rev l)] *) | ||
|
||
val get_paths : unit -> string list | ||
(** Return the list of directories passed to [add_dir] so far, in | ||
reverse order. *) | ||
|
||
val find : string -> string | ||
(** Locate a file in the load path. Raise [Not_found] if the file | ||
cannot be found. This function is optimized for the case where the | ||
filename is a basename, i.e. doesn't contain a directory | ||
separator. *) | ||
|
||
val find_uncap : string -> string | ||
(** Same as [find], but search also for uncapitalized name, i.e. if | ||
name is Foo.ml, allow /path/Foo.ml and /path/foo.ml to match. *) | ||
|
||
module Dir : sig | ||
type t | ||
(** Represent one directory in the load path. *) | ||
|
||
val create : string -> t | ||
|
||
val path : t -> string | ||
|
||
val files : t -> string list | ||
(** All the files in that directory. This doesn't include files in | ||
sub-directories of this directory. *) | ||
end | ||
|
||
val add : Dir.t -> unit | ||
|
||
val get : unit -> Dir.t list | ||
(** Same as [get_paths ()], except that it returns a [Dir.t list]. *) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
include File_cache.Make (struct | ||
let cache_name = "Directory_content_cache" | ||
type t = string array | ||
|
||
(* For backward compatibility reason, simulate the behavior of | ||
[Misc.find_in_path]: silently ignore directories that don't exist | ||
+ treat [""] as the current directory. *) | ||
let read dir = | ||
try | ||
Sys.readdir (if dir = "" then Filename.current_dir_name else dir) | ||
with Sys_error _ -> | ||
[||] | ||
end) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
let init build_path = | ||
Config.load_path := build_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.