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

Do not crash if unable to find root #2024

Merged
merged 1 commit into from
Apr 8, 2019
Merged
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
31 changes: 21 additions & 10 deletions bin/util.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Dune_project = Dune.Dune_project

let die = Dune.Import.die
let hint = Dune.Import.hint
let warn = Dune.Errors.warn

let check_path contexts =
let contexts =
Expand All @@ -30,16 +31,26 @@ let check_path contexts =
let find_root () =
let cwd = Sys.getcwd () in
let rec loop counter ~candidates ~to_cwd dir =
let files = Sys.readdir dir |> Array.to_list |> String.Set.of_list in
if String.Set.mem files Workspace.filename then
cont counter ~candidates:((0, dir, to_cwd) :: candidates) dir ~to_cwd
else if Wp.t = Jbuilder && String.Set.exists files ~f:(fun fn ->
String.is_prefix fn ~prefix:"jbuild-workspace") then
cont counter ~candidates:((1, dir, to_cwd) :: candidates) dir ~to_cwd
else if String.Set.mem files Dune_project.filename then
cont counter ~candidates:((2, dir, to_cwd) :: candidates) dir ~to_cwd
else
cont counter ~candidates dir ~to_cwd
match Sys.readdir dir with
rgrinberg marked this conversation as resolved.
Show resolved Hide resolved
| exception (Sys_error msg) ->
warn Loc.none
"Unable to read directory %s. \
Will not look for root in parent directories@.\
Reason: %s@.\
To remove this warning, set your root explicitly using --root.@."
dir msg;
candidates
| files ->
let files = String.Set.of_list (Array.to_list files) in
if String.Set.mem files Workspace.filename then
cont counter ~candidates:((0, dir, to_cwd) :: candidates) dir ~to_cwd
else if Wp.t = Jbuilder && String.Set.exists files ~f:(fun fn ->
String.is_prefix fn ~prefix:"jbuild-workspace") then
cont counter ~candidates:((1, dir, to_cwd) :: candidates) dir ~to_cwd
else if String.Set.mem files Dune_project.filename then
cont counter ~candidates:((2, dir, to_cwd) :: candidates) dir ~to_cwd
else
cont counter ~candidates dir ~to_cwd
and cont counter ~candidates ~to_cwd dir =
if counter > String.length cwd then
candidates
Expand Down