From d6c35e01dfeaa57ddff5935b71c93ad4aaaa24e5 Mon Sep 17 00:00:00 2001 From: Jeremie Dimino Date: Fri, 29 Jun 2018 21:56:04 +0100 Subject: [PATCH] Split xxx-workspace file between jbuilder and dune - jbuilder only looks for jbuild-workspace files - dune only looks for dune-workspace files Signed-off-by: Jeremie Dimino --- bin/main.ml | 5 ++--- src/main.ml | 11 +++++------ src/workspace.ml | 5 +++++ src/workspace.mli | 3 +++ 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/bin/main.ml b/bin/main.ml index 07c9479f..ce149c07 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -147,10 +147,9 @@ 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 "dune-workspace" || - String.Set.mem files "jbuild-workspace" then + if String.Set.mem files Workspace.filename then cont counter ~candidates:((0, dir, to_cwd) :: candidates) dir ~to_cwd - else if String.Set.exists files ~f:(fun fn -> + else if Which_program.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 diff --git a/src/main.ml b/src/main.ml index f3cba367..cb9c35a8 100644 --- a/src/main.ml +++ b/src/main.ml @@ -61,12 +61,11 @@ let setup ?(log=Log.no_log) Workspace.load ?x ?profile p | _ -> match - List.find_map ["dune-workspace"; "jbuild-workspace"] ~f:(fun fn -> - let p = Path.of_string fn in - if Path.exists p then - Some p - else - None) + let p = Path.of_string Workspace.filename in + if Path.exists p then + Some p + else + None with | Some p -> Workspace.load ?x ?profile p | None -> diff --git a/src/workspace.ml b/src/workspace.ml index 42722a4f..bcfad9ba 100644 --- a/src/workspace.ml +++ b/src/workspace.ml @@ -191,3 +191,8 @@ let t ?x ?profile:cmdline_profile sexps = } let load ?x ?profile p = t ?x ?profile (Io.Sexp.load p ~mode:Many) + +let filename = + match Which_program.t with + | Dune -> "dune-workspace" + | Jbuilder -> "jbuild-workspace" diff --git a/src/workspace.mli b/src/workspace.mli index fb7c346e..a45c3908 100644 --- a/src/workspace.mli +++ b/src/workspace.mli @@ -37,3 +37,6 @@ type t = } val load : ?x:string -> ?profile:string -> Path.t -> t + +(** Default name of workspace files *) +val filename : string