Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of File_tree.Settings.root #2866

Merged
1 commit merged into from Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions bin/upgrade.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ let term =
let+ common = Common.term in
Common.set_common common ~targets:[];
Scheduler.go ~common (fun () ->
Dune.File_tree.init Path.Source.root ~recognize_jbuilder_projects:true
~ancestor_vcs:None;
Dune.File_tree.init ~recognize_jbuilder_projects:true ~ancestor_vcs:None;
Dune.Upgrader.upgrade () |> Fiber.return)

let command = (term, info)
3 changes: 1 addition & 2 deletions src/dune/dune_load.ml
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,7 @@ let interpret ~dir ~project ~(dune_file : File_tree.Dune_file.t) =
Literal (Dune_file.parse sexps ~dir ~file ~project)

let load ~ancestor_vcs () =
File_tree.init Path.Source.root ~ancestor_vcs
~recognize_jbuilder_projects:false;
File_tree.init ~ancestor_vcs ~recognize_jbuilder_projects:false;
let projects =
File_tree.fold_with_progress
~traverse:{ data_only = false; vendored = true; normal = true } ~init:[]
Expand Down
34 changes: 13 additions & 21 deletions src/dune/file_tree.ml
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,7 @@ end

module Settings : sig
type t =
{ root : Path.Source.t
; ancestor_vcs : Vcs.t option
{ ancestor_vcs : Vcs.t option
; recognize_jbuilder_projects : bool
}

Expand All @@ -236,21 +235,18 @@ module Settings : sig
val get : unit -> t
end = struct
type t =
{ root : Path.Source.t
; ancestor_vcs : Vcs.t option
{ ancestor_vcs : Vcs.t option
; recognize_jbuilder_projects : bool
}

let equal { root; ancestor_vcs; recognize_jbuilder_projects } y =
Path.Source.equal root y.root
&& Option.equal Vcs.equal ancestor_vcs y.ancestor_vcs
let equal { ancestor_vcs; recognize_jbuilder_projects } y =
Option.equal Vcs.equal ancestor_vcs y.ancestor_vcs
&& Bool.equal recognize_jbuilder_projects y.recognize_jbuilder_projects

let to_dyn { root; ancestor_vcs; recognize_jbuilder_projects } =
let to_dyn { ancestor_vcs; recognize_jbuilder_projects } =
let open Dyn.Encoder in
record
[ ("root", Path.Source.to_dyn root)
; ("ancestor_vcs", option Vcs.to_dyn ancestor_vcs)
[ ("ancestor_vcs", option Vcs.to_dyn ancestor_vcs)
; ("recognize_jbuilder_projects", bool recognize_jbuilder_projects)
]

Expand All @@ -269,8 +265,8 @@ end = struct
Fdecl.get t
end

let init root ~ancestor_vcs ~recognize_jbuilder_projects =
Settings.set { Settings.root; ancestor_vcs; recognize_jbuilder_projects }
let init ~ancestor_vcs ~recognize_jbuilder_projects =
Settings.set { ancestor_vcs; recognize_jbuilder_projects }

module rec Memoized : sig
module Output : sig
Expand Down Expand Up @@ -382,7 +378,7 @@ end = struct

let root () =
let settings = Settings.get () in
let path = settings.root in
let path = Path.Source.root in
let dir_status : Sub_dirs.Status.t = Normal in
let readdir =
match Readdir.of_source_path path with
Expand Down Expand Up @@ -422,12 +418,10 @@ end = struct
| Some kind -> Some { Vcs.kind; root = Path.(append_source root) path }

let find_dir_raw_impl path =
let settings = Settings.get () in
if Path.Source.equal settings.root path then
Some (root ())
else
match Path.Source.parent path with
| None -> Some (root ())
| Some parent_dir ->
let open Option.O in
let* parent_dir = Path.Source.parent path in
let* parent_dir, dirs_visited = find_dir_raw parent_dir in
let* dir_status =
let basename = Path.Source.basename path in
Expand Down Expand Up @@ -480,9 +474,7 @@ end = struct
let+ dir, _ = find_dir_raw p in
dir

let root () =
let settings = Settings.get () in
Option.value_exn (find_dir settings.root)
let root () = Option.value_exn (find_dir Path.Source.root)
end

let root () = Memoized.root ()
Expand Down
5 changes: 1 addition & 4 deletions src/dune/file_tree.mli
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ end
before all other calls to the file tree. All of these settings can only be
set once per dune process *)
val init :
Path.Source.t
-> ancestor_vcs:Vcs.t option
-> recognize_jbuilder_projects:bool
-> unit
ancestor_vcs:Vcs.t option -> recognize_jbuilder_projects:bool -> unit

val root : unit -> Dir.t

Expand Down