Generate dune file version correctly

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
Rudi Grinberg 2018-07-01 23:18:36 +07:00
parent 9c0daa24de
commit f6fe5d20bb
6 changed files with 29 additions and 8 deletions

View File

@ -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)))

View File

@ -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
]

View File

@ -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

View File

@ -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 <-

View File

@ -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
}

View File

@ -22,7 +22,7 @@
$ dune runtest dune-file
(dune
1
2
((inline_tests.backend
1.0
((runner_libraries (str))