From 75370cf635a878f10f87c8dc0db472db3f67a850 Mon Sep 17 00:00:00 2001 From: Jeremie Dimino Date: Wed, 25 Apr 2018 17:45:14 +0100 Subject: [PATCH] Make dune look for dune-workspace rather than jbuild-workspace --- bin/main.ml | 19 ++++++++++++++----- src/dune_project.ml | 6 +++--- src/dune_project.mli | 2 ++ src/main.ml | 9 +++++---- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/bin/main.ml b/bin/main.ml index d1b64cb5e8b3..eea4ab6ee925 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -15,6 +15,11 @@ module Make(M : sig val which : which end) = struct | Jbuilder -> "jbuilder" | Dune -> "dune" + let workspace_file = + match M.which with + | Jbuilder -> "jbuild-workspace" + | Dune -> "dune-workspace" + type common = { debug_dep_path : bool ; debug_findlib : bool @@ -83,7 +88,11 @@ module Make(M : sig val which : which end) = struct let setup ~log ?external_lib_deps_mode common = setup ~log - ?workspace_file:(Option.map ~f:Path.of_string common.workspace_file) + ~workspace_file:( + Path.of_string ( + match common.workspace_file with + | Some fn -> fn + | None -> workspace_file)) ?only_packages:common.only_packages ?external_lib_deps_mode ?x:common.x @@ -145,13 +154,13 @@ module Make(M : sig val which : which end) = struct 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 "jbuild-workspace" then + if String.Set.mem files workspace_file then cont counter ~candidates:((0, dir, to_cwd) :: candidates) dir ~to_cwd else if M.which = Jbuilder && String.Set.exists files ~f:(fun fn -> - String.is_prefix fn ~prefix:"jbuild-workspace") then + String.is_prefix fn ~prefix:workspace_file) then cont counter ~candidates:((1, dir, to_cwd) :: candidates) dir ~to_cwd - else if String.Set.mem files "dune-project" then + 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 @@ -479,7 +488,7 @@ module Make(M : sig val which : which end) = struct else [] ; (match config_file with - | This fn -> ["--config-file"; fn] + | This fn -> ["--config-file"; Path.to_string fn] | No_config -> ["--no-config"] | Default -> []) ] diff --git a/src/dune_project.ml b/src/dune_project.ml index 3d68083d71e9..4baf76ab66f2 100644 --- a/src/dune_project.ml +++ b/src/dune_project.ml @@ -34,8 +34,8 @@ module Acc = struct end let load ~dir = - let fname = Path.to_string (Path.relative dir filename) in - let sexps = Sexp.load ~fname ~mode:Many in + let fname = Path.relative dir filename in + let sexps = Io.Sexp.load fname ~mode:Many in let langs, sexps = List.partition_map sexps ~f:(function | List (loc, Atom (_, A "lang") :: _) as sexp -> @@ -45,7 +45,7 @@ let load ~dir = let _lang = match langs with | [] -> - Loc.fail (Loc.in_file fname) + Loc.fail (Loc.in_file (Path.to_string fname)) "language not specified, you need to add (lang dune 0.1)" | [(v, _)] -> v | _ :: (_, loc) :: _ -> diff --git a/src/dune_project.mli b/src/dune_project.mli index 9a6e7a59468f..07dbf30a84fb 100644 --- a/src/dune_project.mli +++ b/src/dune_project.mli @@ -1,5 +1,7 @@ (** dune-project files *) +open Import + type t = { name : string } diff --git a/src/main.ml b/src/main.ml index 8d942f777adc..b493bb56a6c4 100644 --- a/src/main.ml +++ b/src/main.ml @@ -30,7 +30,7 @@ let setup_env ~capture_outputs = let setup ?(log=Log.no_log) ?external_lib_deps_mode - ?workspace ?(workspace_file=Path.of_string "jbuild-workspace") + ?workspace ?workspace_file ?only_packages ?extra_ignored_subtrees ?x @@ -55,9 +55,10 @@ let setup ?(log=Log.no_log) match workspace with | Some w -> w | None -> - if Path.exists workspace_file then - Workspace.load ?x workspace_file - else + match workspace_file with + | Some p when Path.exists p -> + Workspace.load ?x p + | _ -> { merlin_context = Some "default" ; contexts = [Default [ match x with