Improve 'required_by ...' messages

This commit is contained in:
Jeremie Dimino 2017-03-15 08:59:00 +00:00
parent c437069fff
commit a04b0c4dcc
10 changed files with 48 additions and 22 deletions

View File

@ -58,7 +58,7 @@ let binary t name =
die "Program %s not found in the tree or in the PATH" name die "Program %s not found in the tree or in the PATH" name
} }
let file_of_lib ?(use_provides=false) t ~lib ~file = let file_of_lib ?(use_provides=false) t ~from ~lib ~file =
match String_map.find lib t.local_libs with match String_map.find lib t.local_libs with
| Some { package; sub_dir; _ } -> | Some { package; sub_dir; _ } ->
let lib_install_dir = let lib_install_dir =
@ -71,7 +71,9 @@ let file_of_lib ?(use_provides=false) t ~lib ~file =
in in
Ok (Path.relative lib_install_dir file) Ok (Path.relative lib_install_dir file)
| None -> | None ->
match Findlib.find t.context.findlib lib with match
Findlib.find t.context.findlib lib ~required_by:[Utils.jbuild_name_in ~dir:from]
with
| Some pkg -> | Some pkg ->
Ok (Path.relative pkg.dir file) Ok (Path.relative pkg.dir file)
| None -> | None ->
@ -85,5 +87,7 @@ let file_of_lib ?(use_provides=false) t ~lib ~file =
| None -> | None ->
Error Error
{ fail = fun () -> { fail = fun () ->
die "Library %s not found in the tree or in the PATH" lib die
"Library %s not found in the tree or in the installed world"
lib
} }

View File

@ -11,6 +11,7 @@ val binary : t -> string -> (Path.t, fail) result
val file_of_lib val file_of_lib
: ?use_provides:bool : ?use_provides:bool
-> t -> t
-> from:Path.t
-> lib:string -> lib:string
-> file:string -> file:string
-> (Path.t, fail) result -> (Path.t, fail) result

View File

@ -10,3 +10,4 @@ val local_install_man_dir : context:string -> Path.t
val local_install_lib_dir : context:string -> package:string -> Path.t val local_install_lib_dir : context:string -> package:string -> Path.t
val dev_null : Path.t val dev_null : Path.t

View File

@ -242,7 +242,8 @@ let root_package_name s =
| None -> s | None -> s
| Some i -> String.sub s ~pos:0 ~len:i | Some i -> String.sub s ~pos:0 ~len:i
let rec load_meta_rec t root_name ~packages ~required_by = let rec load_meta_rec t ~fq_name ~packages ~required_by =
let root_name = root_package_name fq_name in
if String_map.mem root_name packages || if String_map.mem root_name packages ||
Hashtbl.mem t.packages root_name then Hashtbl.mem t.packages root_name then
packages packages
@ -263,6 +264,12 @@ let rec load_meta_rec t root_name ~packages ~required_by =
match String_map.find root_name Meta.builtins with match String_map.find root_name Meta.builtins with
| Some meta -> (t.stdlib_dir, meta) | Some meta -> (t.stdlib_dir, meta)
| None -> | None ->
let required_by =
if root_name = fq_name then
required_by
else
fq_name :: required_by
in
raise (Package_not_found { package = root_name raise (Package_not_found { package = root_name
; required_by ; required_by
}) })
@ -277,17 +284,16 @@ let rec load_meta_rec t root_name ~packages ~required_by =
List.fold_left new_packages ~init:String_map.empty List.fold_left new_packages ~init:String_map.empty
~f:(fun acc (pkg : Pkg_step1.t) -> ~f:(fun acc (pkg : Pkg_step1.t) ->
if pkg.exists then if pkg.exists then
let add_roots acc deps = let add_deps acc deps =
List.fold_left deps ~init:acc ~f:(fun acc dep -> List.fold_left deps ~init:acc ~f:(fun acc dep ->
String_map.add acc ~key:(root_package_name dep) String_map.add acc ~key:dep ~data:pkg.package.name)
~data:pkg.package.name)
in in
add_roots (add_roots acc pkg.requires) pkg.ppx_runtime_deps add_deps (add_deps acc pkg.requires) pkg.ppx_runtime_deps
else else
acc) acc)
in in
String_map.fold deps ~init:packages ~f:(fun ~key:dep ~data:package packages -> String_map.fold deps ~init:packages ~f:(fun ~key:dep ~data:package packages ->
load_meta_rec t dep ~packages ~required_by:(package :: required_by)) load_meta_rec t ~fq_name:dep ~packages ~required_by:(package :: required_by))
module Local_closure = module Local_closure =
Top_closure.Make Top_closure.Make
@ -316,8 +322,8 @@ let remove_dups_preserve_order pkgs =
loop String_set.empty pkgs [] loop String_set.empty pkgs []
;; ;;
let load_meta t root_name ~required_by = let load_meta t ~fq_name ~required_by =
let packages = load_meta_rec t root_name ~packages:String_map.empty ~required_by in let packages = load_meta_rec t ~fq_name ~packages:String_map.empty ~required_by in
match Local_closure.top_closure packages (String_map.values packages) with match Local_closure.top_closure packages (String_map.values packages) with
| Error cycle -> | Error cycle ->
die "dependency cycle detected between external findlib packages:\n %s" die "dependency cycle detected between external findlib packages:\n %s"
@ -389,12 +395,12 @@ let load_meta t root_name ~required_by =
end end
) )
let find_exn t name = let find_exn t ~required_by name =
match Hashtbl.find t.packages name with match Hashtbl.find t.packages name with
| Some (Present x) -> x | Some (Present x) -> x
| Some (Absent pnf) -> raise (Package_not_found pnf) | Some (Absent pnf) -> raise (Package_not_found pnf)
| None -> | None ->
match load_meta t (root_package_name name) ~required_by:[] with match load_meta t ~fq_name:name ~required_by with
| exception (Package_not_found pnf as e) -> | exception (Package_not_found pnf as e) ->
Hashtbl.add t.packages ~key:name ~data:(Absent pnf); Hashtbl.add t.packages ~key:name ~data:(Absent pnf);
raise e raise e
@ -407,14 +413,14 @@ let find_exn t name =
let pnf = let pnf =
{ Package_not_found. { Package_not_found.
package = name package = name
; required_by = [] ; required_by
} }
in in
Hashtbl.add t.packages ~key:name ~data:(Absent pnf); Hashtbl.add t.packages ~key:name ~data:(Absent pnf);
raise (Package_not_found pnf) raise (Package_not_found pnf)
let find t name = let find t ~required_by name =
match find_exn t name with match find_exn t ~required_by name with
| exception (Package_not_found _) -> None | exception (Package_not_found _) -> None
| x -> Some x | x -> Some x
@ -449,7 +455,7 @@ let root_packages t =
let all_packages t = let all_packages t =
List.iter (root_packages t) ~f:(fun pkg -> List.iter (root_packages t) ~f:(fun pkg ->
ignore (find_exn t pkg : package)); ignore (find_exn t pkg ~required_by:[] : package));
Hashtbl.fold t.packages ~init:[] ~f:(fun ~key:_ ~data acc -> Hashtbl.fold t.packages ~init:[] ~f:(fun ~key:_ ~data acc ->
match data with match data with
| Present p -> p :: acc | Present p -> p :: acc

View File

@ -31,8 +31,8 @@ type package =
; has_headers : bool ; has_headers : bool
} }
val find : t -> string -> package option val find : t -> required_by:string list -> string -> package option
val find_exn : t -> string -> package val find_exn : t -> required_by:string list -> string -> package
val available : t -> string -> bool val available : t -> string -> bool

View File

@ -265,7 +265,7 @@ module Gen(P : Params) = struct
"invalid ${lib:...} form: %s" name "invalid ${lib:...} form: %s" name
| Some x -> x | Some x -> x
in in
(lib, file_of_lib t ~lib ~file ?use_provides) (lib, file_of_lib t ~from:dir ~lib ~file ?use_provides)
(* Hides [t] so that we don't resolve things statically *) (* Hides [t] so that we don't resolve things statically *)
let t = () let t = ()

View File

@ -83,7 +83,8 @@ end
~target:generated_jbuild ~target:generated_jbuild
in in
let pkgs = let pkgs =
List.map requires ~f:(Findlib.find_exn context.findlib) List.map requires ~f:(Findlib.find_exn context.findlib
~required_by:[Utils.jbuild_name_in ~dir:dir])
|> Findlib.closure |> Findlib.closure
in in
let includes = let includes =

View File

@ -32,7 +32,8 @@ let find_exn t ~from name =
| None -> | None ->
Hashtbl.find_or_add t.by_public_name name Hashtbl.find_or_add t.by_public_name name
~f:(fun name -> ~f:(fun name ->
External (Findlib.find_exn t.findlib name)) External (Findlib.find_exn t.findlib name
~required_by:[Utils.jbuild_name_in ~dir:from]))
let find t ~from name = let find t ~from name =
match find_exn t ~from name with match find_exn t ~from name with

View File

@ -57,3 +57,12 @@ let signal_name =
match List.assoc n table with match List.assoc n table with
| exception Not_found -> sprintf "%d\n" n | exception Not_found -> sprintf "%d\n" n
| s -> s | s -> s
let jbuild_name_in ~dir =
match Path.extract_build_context dir with
| None ->
Path.to_string (Path.relative dir "jbuild")
| Some (ctx_name, dir) ->
sprintf "%s (context %s)"
(Path.to_string (Path.relative dir "jbuild"))
ctx_name

View File

@ -8,3 +8,6 @@ val system_shell : needed_to:string -> Path.t * string * fail option
(** Convert a signal number to a name: INT, TERM, ... *) (** Convert a signal number to a name: INT, TERM, ... *)
val signal_name : int -> string val signal_name : int -> string
(** Return the path to the jbuild file in this directory as a string. *)
val jbuild_name_in : dir:Path.t -> string