Skip to content

Commit

Permalink
make fmt
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>
  • Loading branch information
nojb committed Oct 16, 2019
1 parent d0a014d commit 8e45eb8
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 34 deletions.
3 changes: 2 additions & 1 deletion src/dune/dialect.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ module File_kind = struct
, option (fun (_, x) -> Action_dune_lang.to_dyn x) preprocess )
; ( "format"
, option
(fun (_, x, y) -> pair Action_dune_lang.to_dyn (list string) (x, y))
(fun (_, x, y) ->
pair Action_dune_lang.to_dyn (list string) (x, y))
format )
]
end
Expand Down
5 changes: 2 additions & 3 deletions src/dune/dune_file.mli
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,8 @@ end
module Deprecated_library_name : sig
module Old_public_name : sig
type t =
{
deprecated: bool;
public: Public_lib.t;
{ deprecated : bool
; public : Public_lib.t
}
end

Expand Down
31 changes: 16 additions & 15 deletions src/dune/dune_package.ml
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,12 @@ module Lib = struct

let info dp = dp.info

let to_dyn { info ; modules ; main_module_name } =
let to_dyn { info; modules; main_module_name } =
let open Dyn.Encoder in
record
[ "info", Lib_info.to_dyn Path.to_dyn info
; "modules", option Modules.to_dyn modules
; "main_module_name", option Module_name.to_dyn main_module_name
[ ("info", Lib_info.to_dyn Path.to_dyn info)
; ("modules", option Modules.to_dyn modules)
; ("main_module_name", option Module_name.to_dyn main_module_name)
]
end

Expand Down Expand Up @@ -230,8 +230,8 @@ module Deprecated_library_name = struct
let to_dyn { loc = _; old_public_name; new_public_name } =
let open Dyn.Encoder in
record
[ "old_public_name", Lib_name.to_dyn old_public_name
; "new_public_name", Lib_name.to_dyn new_public_name
[ ("old_public_name", Lib_name.to_dyn old_public_name)
; ("new_public_name", Lib_name.to_dyn new_public_name)
]
end

Expand Down Expand Up @@ -261,10 +261,9 @@ module Entry = struct
let to_dyn x =
let open Dyn.Encoder in
match x with
| Library lib ->
constr "Library" [Lib.to_dyn lib]
| Library lib -> constr "Library" [ Lib.to_dyn lib ]
| Deprecated_library_name lib ->
constr "Deprecated_library_name" [Deprecated_library_name.to_dyn lib]
constr "Deprecated_library_name" [ Deprecated_library_name.to_dyn lib ]
end

type t =
Expand Down Expand Up @@ -330,10 +329,10 @@ let encode ~dune_version { entries; name; version; dir } =
let to_dyn { entries; name; version; dir } =
let open Dyn.Encoder in
record
[ "entries", list Entry.to_dyn entries
; "name", Package.Name.to_dyn name
; "version", option string version
; "dir", Path.to_dyn dir
[ ("entries", list Entry.to_dyn entries)
; ("name", Package.Name.to_dyn name)
; ("version", option string version)
; ("dir", Path.to_dyn dir)
]

module Or_meta = struct
Expand Down Expand Up @@ -361,11 +360,13 @@ module Or_meta = struct

let pp ~dune_version ppf t =
let t = encode ~dune_version t in
Format.fprintf ppf "%a@." (Fmt.list ~pp_sep:Fmt.nl Dune_lang.Deprecated.pp) t
Format.fprintf ppf "%a@."
(Fmt.list ~pp_sep:Fmt.nl Dune_lang.Deprecated.pp)
t

let to_dyn x =
let open Dyn.Encoder in
match x with
| Use_meta -> constr "Use_meta" []
| Dune_package t -> constr "Dune_package" [to_dyn t]
| Dune_package t -> constr "Dune_package" [ to_dyn t ]
end
4 changes: 3 additions & 1 deletion src/dune/dune_package.mli
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ module Or_meta : sig
| Dune_package of t

val encode : dune_version:Dune_lang.Syntax.Version.t -> t -> Dune_lang.t list
val pp : dune_version:Dune_lang.Syntax.Version.t -> Format.formatter -> t -> unit

val pp :
dune_version:Dune_lang.Syntax.Version.t -> Format.formatter -> t -> unit

val load : Dpath.t -> t

Expand Down
12 changes: 7 additions & 5 deletions src/dune/dune_project.ml
Original file line number Diff line number Diff line change
Expand Up @@ -727,20 +727,22 @@ let parse ~dir ~lang ~opam_packages ~file =
| _, _ -> () );
let package_defined_twice name loc1 loc2 =
User_error.raise
[ Pp.textf "Package name %s is defined twice:" (Package.Name.to_string name)
[ Pp.textf "Package name %s is defined twice:"
(Package.Name.to_string name)
; Pp.textf "- %s" (Loc.to_file_colon_line loc1)
; Pp.textf "- %s" (Loc.to_file_colon_line loc2)
]
in
let deprecated_package_names =
List.fold_left packages ~init:Package.Name.Map.empty
~f:(fun acc {Package.deprecated_package_names; _} ->
~f:(fun acc { Package.deprecated_package_names; _ } ->
Package.Name.Map.union acc deprecated_package_names
~f:package_defined_twice
)
~f:package_defined_twice)
in
List.iter packages ~f:(fun p ->
match Package.Name.Map.find deprecated_package_names p.Package.name with
match
Package.Name.Map.find deprecated_package_names p.Package.name
with
| None -> ()
| Some loc -> package_defined_twice p.Package.name loc p.loc);
match
Expand Down
5 changes: 4 additions & 1 deletion src/dune/lib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1615,7 +1615,10 @@ module DB = struct
match (stanza : Library_related_stanza.t) with
| External_variant _ -> []
| Deprecated_library_name
{ old_public_name = { public = old_public_name; _ }; new_public_name; _ } ->
{ old_public_name = { public = old_public_name; _ }
; new_public_name
; _
} ->
[ ( Dune_file.Public_lib.name old_public_name
, Redirect (None, new_public_name) )
]
Expand Down
12 changes: 8 additions & 4 deletions src/dune/package.ml
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,19 @@ let decode ~dir =
and+ tags = field "tags" (enter (repeat string)) ~default:[]
and+ deprecated_package_names =
field ~default:[] "deprecated_package_names"
(Dune_lang.Syntax.since Stanza.syntax (2, 0) >>>
repeat (located Name.decode))
( Dune_lang.Syntax.since Stanza.syntax (2, 0)
>>> repeat (located Name.decode) )
in
let deprecated_package_names =
match Name.Map.of_list_map deprecated_package_names ~f:(fun (loc, s) -> s, loc) with
match
Name.Map.of_list_map deprecated_package_names ~f:(fun (loc, s) ->
(s, loc))
with
| Ok x -> x
| Error (name, (loc1, _), (loc2, _)) ->
User_error.raise
[ Pp.textf "Deprecated package name %s is declared twice:" (Name.to_string name)
[ Pp.textf "Deprecated package name %s is declared twice:"
(Name.to_string name)
; Pp.textf "- %s" (Loc.to_file_colon_line loc1)
; Pp.textf "- %s" (Loc.to_file_colon_line loc2)
]
Expand Down
8 changes: 6 additions & 2 deletions src/dune/scope.ml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ module DB = struct
| Library _ -> None
| External_variant _ -> None
| Deprecated_library_name
{ old_public_name = { public = old_public_name; _ }; new_public_name; _ } ->
{ old_public_name = { public = old_public_name; _ }
; new_public_name
; _
} ->
Some
(Dune_file.Public_lib.name old_public_name, Name new_public_name))
|> Lib_name.Map.of_list
Expand All @@ -72,7 +75,8 @@ module DB = struct
List.filter_map stanzas ~f:(fun stanza ->
match stanza with
| Library (_, { buildable = { loc; _ }; public = Some p; _ })
| Deprecated_library_name { loc; old_public_name = { public = p; _ }; _ } ->
| Deprecated_library_name
{ loc; old_public_name = { public = p; _ }; _ } ->
Option.some_if (name = Dune_file.Public_lib.name p) loc
| _ -> None)
with
Expand Down
6 changes: 4 additions & 2 deletions src/dune/super_context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ module Lib_entry = struct

let name = function
| Library lib -> Lib.Local.to_lib lib |> Lib.name
| Deprecated_library_name { old_public_name = { public = old_public_name; _ }; _ } ->
| Deprecated_library_name
{ old_public_name = { public = old_public_name; _ }; _ } ->
Dune_file.Public_lib.name old_public_name
end

Expand Down Expand Up @@ -529,7 +530,8 @@ let create ~(context : Context.t) ?host ~projects ~packages ~stanzas
, Lib_entry.Library (Option.value_exn (Lib.Local.of_lib lib)) )
:: acc )
| Dune_file.Deprecated_library_name
({ old_public_name = { public = old_public_name; _ }; _ } as d) ->
({ old_public_name = { public = old_public_name; _ }; _ } as d)
->
( (Dune_file.Public_lib.package old_public_name).name
, Lib_entry.Deprecated_library_name d )
:: acc
Expand Down

0 comments on commit 8e45eb8

Please sign in to comment.