Change Package.Name.t to interned type

This commit is contained in:
Rudi Grinberg 2018-03-03 20:41:29 +07:00
parent ff05369868
commit 7c287a5e0a
10 changed files with 36 additions and 32 deletions

View File

@ -528,9 +528,11 @@ let resolve_package_install setup pkg =
match Main.package_install_file setup pkg with match Main.package_install_file setup pkg with
| Ok path -> path | Ok path -> path
| Error () -> | Error () ->
die "Unknown package %s!%s" (pkg :> string) let pkg = Package.Name.to_string pkg in
(hint (pkg :> string) die "Unknown package %s!%s" pkg
((Package.Name.Map.keys setup.packages) :> string list)) (hint pkg
(Package.Name.Map.keys setup.packages
|> List.map ~f:Package.Name.to_string))
let target_hint (setup : Main.setup) path = let target_hint (setup : Main.setup) path =
assert (Path.is_local path); assert (Path.is_local path);

View File

@ -63,7 +63,7 @@ module Section = struct
end end
let install_dir t ~(package : Package.Name.t) = let install_dir t ~(package : Package.Name.t) =
let package = (package :> string) in let package = Package.Name.to_string package in
match t with match t with
| Bin -> Paths.bin | Bin -> Paths.bin
| Sbin -> Paths.sbin | Sbin -> Paths.sbin

View File

@ -57,7 +57,7 @@ module Gen(P : Install_params) = struct
|> Package.Name.Map.iter ~f:(fun ((pkg : Package.t), libs) -> |> Package.Name.Map.iter ~f:(fun ((pkg : Package.t), libs) ->
let path = Path.append ctx.build_dir pkg.path in let path = Path.append ctx.build_dir pkg.path in
SC.on_load_dir sctx ~dir:path ~f:(fun () -> SC.on_load_dir sctx ~dir:path ~f:(fun () ->
let meta_fn = "META." ^ (pkg.name :> string) in let meta_fn = "META." ^ (Package.Name.to_string pkg.name) in
let meta_template = Path.relative path (meta_fn ^ ".template" ) in let meta_template = Path.relative path (meta_fn ^ ".template" ) in
let meta = Path.relative path meta_fn in let meta = Path.relative path meta_fn in
@ -79,7 +79,7 @@ module Gen(P : Install_params) = struct
~else_:(loop rest) ~else_:(loop rest)
in in
loop loop
[ (pkg.name :> string) ^ ".version" [ (Package.Name.to_string pkg.name) ^ ".version"
; "version" ; "version"
; "VERSION" ; "VERSION"
] ]
@ -95,7 +95,7 @@ module Gen(P : Install_params) = struct
let meta_contents = let meta_contents =
version >>^ fun version -> version >>^ fun version ->
Gen_meta.gen Gen_meta.gen
~package:(pkg.name :> string) ~package:(Package.Name.to_string pkg.name)
~version ~version
libs libs
in in
@ -233,7 +233,7 @@ module Gen(P : Install_params) = struct
Install.Entry.make Lib opam ~dst:"opam" :: entries Install.Entry.make Lib opam ~dst:"opam" :: entries
in in
let entries = let entries =
let meta_fn = "META." ^ (package :> string) in let meta_fn = "META." ^ (Package.Name.to_string package) in
let meta = Path.append ctx.build_dir (Path.relative package_path meta_fn) in let meta = Path.append ctx.build_dir (Path.relative package_path meta_fn) in
Install.Entry.make Lib meta ~dst:"META" :: entries Install.Entry.make Lib meta ~dst:"META" :: entries
in in

View File

@ -109,7 +109,7 @@ module Scope_info = struct
in in
let root = pkg.path in let root = pkg.path in
List.iter rest ~f:(fun pkg -> assert (pkg.Package.path = root)); List.iter rest ~f:(fun pkg -> assert (pkg.Package.path = root));
{ name = Some (name :> string) { name = Some (Package.Name.to_string name)
; packages = ; packages =
Package.Name.Map.of_list_exn (List.map pkgs ~f:(fun pkg -> Package.Name.Map.of_list_exn (List.map pkgs ~f:(fun pkg ->
pkg.Package.name, pkg)) pkg.Package.name, pkg))
@ -118,11 +118,13 @@ module Scope_info = struct
let package_listing packages = let package_listing packages =
let longest_pkg = let longest_pkg =
String.longest_map packages ~f:(fun p -> (p.Package.name :> string)) String.longest_map packages ~f:(fun p ->
Package.Name.to_string p.Package.name)
in in
String.concat ~sep:"\n" String.concat ~sep:"\n"
(List.map packages ~f:(fun pkg -> (List.map packages ~f:(fun pkg ->
sprintf "- %-*s (because of %s)" longest_pkg (pkg.Package.name :> string) sprintf "- %-*s (because of %s)" longest_pkg
(Package.Name.to_string pkg.Package.name)
(Path.to_string (Package.opam_file pkg)))) (Path.to_string (Package.opam_file pkg))))
let default t = let default t =
@ -149,22 +151,24 @@ module Scope_info = struct
| Some pkg -> | Some pkg ->
Ok pkg Ok pkg
| None -> | None ->
let name_s = Package.Name.to_string name in
if Package.Name.Map.is_empty t.packages then if Package.Name.Map.is_empty t.packages then
Error (sprintf Error (sprintf
"You cannot declare items to be installed without \ "You cannot declare items to be installed without \
adding a <package>.opam file at the root of your project.\n\ adding a <package>.opam file at the root of your project.\n\
To declare elements to be installed as part of package %S, \ To declare elements to be installed as part of package %S, \
add a %S file at the root of your project." add a %S file at the root of your project."
(name :> string) (Package.Name.opam_fn name)) name_s (Package.Name.opam_fn name))
else else
Error (sprintf Error (sprintf
"The current scope doesn't define package %S.\n\ "The current scope doesn't define package %S.\n\
The only packages for which you can declare \ The only packages for which you can declare \
elements to be installed in this directory are:\n\ elements to be installed in this directory are:\n\
%s%s" %s%s"
(name :> string) name_s
(package_listing (Package.Name.Map.values t.packages)) (package_listing (Package.Name.Map.values t.packages))
(hint (name :> string) (Package.Name.Map.keys t.packages :> string list))) (hint name_s (Package.Name.Map.keys t.packages
|> List.map ~f:Package.Name.to_string)))
let package t sexp = let package t sexp =
match resolve t (Package.Name.of_string (string sexp)) with match resolve t (Package.Name.of_string (string sexp)) with

View File

@ -201,7 +201,7 @@ let load ?extra_ignored_subtrees ?(ignore_promoted_rules=false) () =
| [pkg] -> pkg | [pkg] -> pkg
| _ -> | _ ->
die "Too many opam files for package %S:\n%s" die "Too many opam files for package %S:\n%s"
(name :> string) (Package.Name.to_string name)
(String.concat ~sep:"\n" (String.concat ~sep:"\n"
(List.map pkgs ~f:(fun pkg -> (List.map pkgs ~f:(fun pkg ->
sprintf "- %s" (Path.to_string (Package.opam_file pkg)))))) sprintf "- %s" (Path.to_string (Package.opam_file pkg))))))

View File

@ -31,11 +31,13 @@ let setup ?(log=Log.no_log)
Option.iter only_packages ~f:(fun set -> Option.iter only_packages ~f:(fun set ->
Package.Name.Set.iter set ~f:(fun pkg -> Package.Name.Set.iter set ~f:(fun pkg ->
if not (Package.Name.Map.mem conf.packages pkg) then if not (Package.Name.Map.mem conf.packages pkg) then
let pkg_name = Package.Name.to_string pkg in
die "@{<error>Error@}: I don't know about package %s \ die "@{<error>Error@}: I don't know about package %s \
(passed through --only-packages/--release)%s" (passed through --only-packages/--release)%s"
(pkg :> string) pkg_name
(hint (pkg :> string) (hint pkg_name
(Package.Name.Map.keys conf.packages :> string list)))); (Package.Name.Map.keys conf.packages
|> List.map ~f:Package.Name.to_string))));
let workspace = let workspace =
match workspace with match workspace with
| Some w -> w | Some w -> w
@ -96,7 +98,7 @@ let external_lib_deps ?log ~packages () =
List.map packages ~f:(fun pkg -> List.map packages ~f:(fun pkg ->
match package_install_file setup pkg with match package_install_file setup pkg with
| Ok path -> path | Ok path -> path
| Error () -> die "Unknown package %S" (pkg :> string)) | Error () -> die "Unknown package %S" (Package.Name.to_string pkg))
in in
match String_map.find setup.stanzas "default" with match String_map.find setup.stanzas "default" with
| None -> die "You need to set a default context to use external-lib-deps" | None -> die "You need to set a default context to use external-lib-deps"

View File

@ -1,15 +1,12 @@
module Name = struct module Name = struct
type t = string include Interned.Make()
let of_string x = x let of_string = make
let opam_fn t = t ^ ".opam" let opam_fn (t : t) = to_string t ^ ".opam"
module Map = Import.String_map let pp fmt t = Format.pp_print_string fmt (to_string t)
module Set = Import.String_set
let pp = Format.pp_print_string
end end

View File

@ -1,16 +1,15 @@
(** Information about a package defined in the workspace *) (** Information about a package defined in the workspace *)
module Name : sig module Name : sig
type t = private string type t
val of_string : string -> t val of_string : string -> t
val opam_fn : t -> string val opam_fn : t -> string
module Map : Stdune.Map.S with type key = t
module Set : Stdune.Set.S with type elt = t
val pp : Format.formatter -> t -> unit val pp : Format.formatter -> t -> unit
include Interned.S with type t := t
end end
type t = type t =

View File

@ -336,7 +336,7 @@ module Pkg_version = struct
let spec sctx (p : Package.t) = let spec sctx (p : Package.t) =
let fn = let fn =
Path.relative (Path.append sctx.context.build_dir p.path) Path.relative (Path.append sctx.context.build_dir p.path)
(sprintf "%s.version.sexp" (p.name :> string)) (sprintf "%s.version.sexp" (Package.Name.to_string p.name))
in in
Build.Vspec.T (fn, (module V)) Build.Vspec.T (fn, (module V))

View File

@ -143,7 +143,7 @@ let g () =
[] []
let install_file ~(package : Package.Name.t) ~findlib_toolchain = let install_file ~(package : Package.Name.t) ~findlib_toolchain =
let package = (package :> string) in let package = Package.Name.to_string package in
match findlib_toolchain with match findlib_toolchain with
| None -> package ^ ".install" | None -> package ^ ".install"
| Some x -> sprintf "%s-%s.install" package x | Some x -> sprintf "%s-%s.install" package x