From f6fe5d20bbe4d6c9c008433ffb2c8065e4917279 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Sun, 1 Jul 2018 23:18:36 +0700 Subject: [PATCH] Generate dune file version correctly Signed-off-by: Rudi Grinberg --- src/install_rules.ml | 3 ++- src/installed_dune_file.ml | 13 ++++++++----- src/installed_dune_file.mli | 5 ++++- src/lib.ml | 11 +++++++++++ src/lib.mli | 3 +++ test/blackbox-tests/test-cases/inline_tests/run.t | 2 +- 6 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/install_rules.ml b/src/install_rules.ml index 3c679e40..6b8b763d 100644 --- a/src/install_rules.ml +++ b/src/install_rules.ml @@ -39,8 +39,9 @@ module Gen(P : Install_params) = struct let gen_lib_dune_file lib = SC.add_rule sctx (Build.arr (fun () -> + let lang = Option.value_exn (Lib.defined_using_lang lib) in Format.asprintf "%a@." (Sexp.pp Dune) - (Lib.Sub_system.dump_config lib |> Installed_dune_file.gen)) + (Lib.Sub_system.dump_config lib |> Installed_dune_file.gen ~lang)) >>> Build.write_file_dyn (lib_dune_file ~dir:(Lib.src_dir lib) ~name:(Lib.name lib))) diff --git a/src/installed_dune_file.ml b/src/installed_dune_file.ml index 422f20fc..b3abe8d6 100644 --- a/src/installed_dune_file.ml +++ b/src/installed_dune_file.ml @@ -27,10 +27,10 @@ let of_sexp = let open Sexp.Of_sexp in let version = plain_string (fun ~loc -> function - | "1" -> () - | _ -> + | "1" | "2" -> () + | v -> of_sexp_errorf loc - "Unsupported version, only version 1 is supported") + "Unsupported version %S, only version 1 is supported" v) in sum [ "dune", @@ -68,7 +68,7 @@ let load fname = (Univ_map.singleton (Syntax.key Stanza.syntax) syntax) (Io.Sexp.load ~lexer ~mode:Single fname)) -let gen confs = +let gen ~(lang : File_tree.Dune_file.Kind.t) confs = let sexps = Sub_system_name.Map.to_list confs |> List.map ~f:(fun (name, (ver, conf)) -> @@ -80,6 +80,9 @@ let gen confs = in Sexp.List [ Sexp.unsafe_atom_of_string "dune" - ; Sexp.unsafe_atom_of_string "1" + ; Sexp.unsafe_atom_of_string + (match lang with + | Jbuild -> "1" + | Dune -> "2") ; List sexps ] diff --git a/src/installed_dune_file.mli b/src/installed_dune_file.mli index d498cb00..019e5c88 100644 --- a/src/installed_dune_file.mli +++ b/src/installed_dune_file.mli @@ -3,4 +3,7 @@ open Stdune val load : Path.t -> Jbuild.Sub_system_info.t Sub_system_name.Map.t -val gen : (Syntax.Version.t * Sexp.t) Sub_system_name.Map.t -> Sexp.t +val gen + : lang:File_tree.Dune_file.Kind.t + -> (Syntax.Version.t * Sexp.t) Sub_system_name.Map.t + -> Sexp.t diff --git a/src/lib.ml b/src/lib.ml index 5a2a3920..4635a120 100644 --- a/src/lib.ml +++ b/src/lib.ml @@ -63,6 +63,7 @@ module Info = struct ; pps : (Loc.t * Jbuild.Pp.t) list ; optional : bool ; virtual_deps : (Loc.t * string) list + ; defined_using_lang : File_tree.Dune_file.Kind.t option ; sub_systems : Jbuild.Sub_system_info.t Sub_system_name.Map.t } @@ -114,6 +115,11 @@ module Info = struct ; ppx_runtime_deps = conf.ppx_runtime_libraries ; pps = Jbuild.Preprocess_map.pps conf.buildable.preprocess ; sub_systems = conf.sub_systems + ; defined_using_lang = + Some + (match conf.project.kind with + | Dune -> Dune + | Jbuilder -> Jbuild) } let of_findlib_package pkg = @@ -143,6 +149,7 @@ module Info = struct ; (* We don't know how these are named for external libraries *) foreign_archives = Mode.Dict.make_both [] ; sub_systems = sub_systems + ; defined_using_lang = None } end @@ -237,6 +244,7 @@ type t = ; resolved_selects : Resolved_select.t list ; optional : bool ; user_written_deps : Jbuild.Lib_deps.t + ; defined_using_lang : File_tree.Dune_file.Kind.t option ; (* This is mutable to avoid this error: {[ @@ -343,6 +351,8 @@ let plugins t = t.plugins let jsoo_runtime t = t.jsoo_runtime let unique_id t = t.unique_id +let defined_using_lang t = t.defined_using_lang + let src_dir t = t.src_dir let obj_dir t = t.obj_dir @@ -662,6 +672,7 @@ let rec instantiate db name (info : Info.t) ~stack ~hidden = ; optional = info.optional ; user_written_deps = Info.user_written_deps info ; sub_systems = Sub_system_name.Map.empty + ; defined_using_lang = info.defined_using_lang } in t.sub_systems <- diff --git a/src/lib.mli b/src/lib.mli index d70ef8c9..795727fb 100644 --- a/src/lib.mli +++ b/src/lib.mli @@ -26,6 +26,8 @@ val archives : t -> Path.t list Mode.Dict.t val plugins : t -> Path.t list Mode.Dict.t val jsoo_runtime : t -> Path.t list +val defined_using_lang : t -> File_tree.Dune_file.Kind.t option + (** A unique integer identifier. It is only unique for the duration of the process *) val unique_id : t -> int @@ -103,6 +105,7 @@ module Info : sig ; pps : (Loc.t * Jbuild.Pp.t) list ; optional : bool ; virtual_deps : (Loc.t * string) list + ; defined_using_lang : File_tree.Dune_file.Kind.t option ; sub_systems : Jbuild.Sub_system_info.t Sub_system_name.Map.t } diff --git a/test/blackbox-tests/test-cases/inline_tests/run.t b/test/blackbox-tests/test-cases/inline_tests/run.t index 3646e4ae..d46693c7 100644 --- a/test/blackbox-tests/test-cases/inline_tests/run.t +++ b/test/blackbox-tests/test-cases/inline_tests/run.t @@ -22,7 +22,7 @@ $ dune runtest dune-file (dune - 1 + 2 ((inline_tests.backend 1.0 ((runner_libraries (str))