@@ -15,6 +15,8 @@ module Kind = struct
1515 | Dune_project -> 2
1616 | Cwd -> 3
1717
18+ let lowest_priority = max_int
19+
1820 let of_dir_contents files =
1921 if String.Set. mem files Workspace. filename then
2022 Some Dune_workspace
@@ -31,11 +33,18 @@ type t =
3133 ; kind : Kind .t
3234 }
3335
34- let make kind dir = { kind; dir; to_cwd = [] ; reach_from_root_prefix = " " }
36+ module Candidate = struct
37+ type t =
38+ { dir : string
39+ ; to_cwd : string list
40+ ; kind : Kind .t
41+ }
42+ end
3543
3644let find () =
3745 let cwd = Sys. getcwd () in
38- let rec loop counter ~candidate ~to_cwd dir =
46+ let rec loop counter ~(candidate : Candidate.t option ) ~to_cwd dir :
47+ Candidate. t option =
3948 match Sys. readdir dir with
4049 | exception Sys_error msg ->
4150 User_warning. emit
@@ -54,17 +63,11 @@ let find () =
5463 let candidate_priority =
5564 match candidate with
5665 | Some c -> Kind. priority c.kind
57- | None -> 10
66+ | None -> Kind. lowest_priority
5867 in
5968 match Kind. of_dir_contents files with
6069 | Some kind when Kind. priority kind < = candidate_priority ->
61- Some
62- { kind
63- ; dir
64- ; to_cwd
65- ; (* This field is computed at the end *) reach_from_root_prefix =
66- " "
67- }
70+ Some { Candidate. kind; dir; to_cwd }
6871 | _ -> candidate
6972 in
7073 cont counter ~candidate dir ~to_cwd
@@ -84,20 +87,21 @@ let find () =
8487let create ~default_is_cwd ~specified_by_user =
8588 match
8689 match specified_by_user with
87- | Some dn -> Some (make Explicit dn)
90+ | Some dn -> Some { Candidate. kind = Explicit ; dir = dn; to_cwd = [] }
8891 | None -> (
92+ let cwd = { Candidate. kind = Cwd ; dir = " ." ; to_cwd = [] } in
8993 if Dune_util.Config. inside_dune then
90- Some (make Cwd " . " )
94+ Some cwd
9195 else
9296 match find () with
9397 | Some s -> Some s
9498 | None ->
9599 if default_is_cwd then
96- Some (make Cwd " . " )
100+ Some cwd
97101 else
98102 None )
99103 with
100- | Some { dir; to_cwd; kind; _ } ->
104+ | Some { Candidate. dir; to_cwd; kind } ->
101105 { kind
102106 ; dir
103107 ; to_cwd
0 commit comments