Using Syntax.Verison.t to decide how to generate sub system files

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
Rudi Grinberg 2018-07-02 14:23:13 +07:00
parent 22cf958b0c
commit 4af1f189f0
7 changed files with 29 additions and 22 deletions

View File

@ -39,9 +39,11 @@ 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 lang)
(Lib.Sub_system.dump_config lib |> Installed_dune_file.gen ~lang))
let dune_version = Option.value_exn (Lib.dune_version lib) in
Format.asprintf "%a@."
(Sexp.pp (Stanza.File_kind.of_syntax dune_version))
(Lib.Sub_system.dump_config lib
|> Installed_dune_file.gen ~dune_version))
>>> Build.write_file_dyn
(lib_dune_file ~dir:(Lib.src_dir lib) ~name:(Lib.name lib)))

View File

@ -66,7 +66,7 @@ let load fname =
(Univ_map.singleton (Syntax.key Stanza.syntax) syntax)
(Io.Sexp.load ~lexer ~mode:Single fname))
let gen ~(lang : File_tree.Dune_file.Kind.t) confs =
let gen ~(dune_version : Syntax.Version.t) confs =
let sexps =
Sub_system_name.Map.to_list confs
|> List.map ~f:(fun (name, (ver, conf)) ->
@ -79,8 +79,11 @@ let gen ~(lang : File_tree.Dune_file.Kind.t) confs =
Sexp.List
[ Sexp.unsafe_atom_of_string "dune"
; Sexp.unsafe_atom_of_string
(match lang with
| Jbuild -> "1"
| Dune -> "2")
(match dune_version with
| (0, 0) -> "1"
| (1, 0) -> "2"
| _ ->
Exn.code_error "Cannot generate dune with unknown version"
["dune_version", Syntax.Version.sexp_of_t dune_version])
; List sexps
]

View File

@ -4,6 +4,6 @@ open Stdune
val load : Path.t -> Jbuild.Sub_system_info.t Sub_system_name.Map.t
val gen
: lang:File_tree.Dune_file.Kind.t
: dune_version:Syntax.Version.t
-> (Syntax.Version.t * Sexp.t) Sub_system_name.Map.t
-> Sexp.t

View File

@ -63,7 +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
; dune_version : Syntax.Version.t option
; sub_systems : Jbuild.Sub_system_info.t Sub_system_name.Map.t
}
@ -115,11 +115,7 @@ 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)
; dune_version = Some conf.dune_version
}
let of_findlib_package pkg =
@ -149,7 +145,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
; dune_version = None
}
end
@ -244,7 +240,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
; dune_version : Syntax.Version.t option
; (* This is mutable to avoid this error:
{[
@ -351,7 +347,7 @@ 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 dune_version t = t.dune_version
let src_dir t = t.src_dir
let obj_dir t = t.obj_dir
@ -672,7 +668,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
; dune_version = info.dune_version
}
in
t.sub_systems <-

View File

@ -26,7 +26,7 @@ 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
val dune_version : t -> Syntax.Version.t option
(** A unique integer identifier. It is only unique for the duration of
the process *)
@ -105,7 +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
; dune_version : Syntax.Version.t option
; sub_systems : Jbuild.Sub_system_info.t Sub_system_name.Map.t
}

View File

@ -13,7 +13,11 @@ let syntax =
]
module File_kind = struct
type t = Jbuild | Dune
type t = Sexp.syntax = Jbuild | Dune
let of_syntax = function
| (0, 0) -> Jbuild
| (_, _) -> Dune
end
let file_kind () =

View File

@ -18,7 +18,9 @@ end
val syntax : Syntax.t
module File_kind : sig
type t = Jbuild | Dune
type t = Sexp.syntax = Jbuild | Dune
val of_syntax : Syntax.Version.t -> t
end
(** Whether we are parsing a [jbuild] or [dune] file. *)