forked from ocaml/dune
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Print resolved external library dependencies
Adding '--external-lib-deps' flag in order to print all resolved library dependencies. It's motivated by opam-dune-lint. opam-dune-lint is using 'external-lib-deps' subcommand which is removed on the previous version ocaml#4298. Signed-off-by: Alpha DIALLO <[email protected]>
- Loading branch information
1 parent
b434075
commit bea0089
Showing
10 changed files
with
148 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
open Import | ||
|
||
module Kind = struct | ||
|
||
type t = | ||
| Required | ||
| Optional | ||
|
||
let to_dyn kind = | ||
match kind with | ||
| Required -> Dyn.String "require" | ||
| Optional -> Dyn.String "optional" | ||
|
||
let merge x y = | ||
match (x,y) with | ||
| Optional,Optional -> Optional | ||
| _ -> Required | ||
|
||
let merge_opt x y= | ||
match (x,y) with | ||
| Some x,Some y -> Some (merge x y) | ||
| None, y -> y | ||
| x, None -> x | ||
|
||
end | ||
|
||
module External_libs = struct | ||
|
||
module Hashtbl = Hashtbl.Make(Context_name) | ||
module Map = Lib_name.Map | ||
|
||
let libs_by_ctx = Hashtbl.create 1 | ||
|
||
let add ctx lib = | ||
match Hashtbl.find libs_by_ctx ctx with | ||
| Some libs -> | ||
if not(Map.mem libs lib) | ||
then ignore(Hashtbl.set libs_by_ctx ctx (Lib_name.Map.add_exn libs lib None)) | ||
| None -> | ||
ignore(Hashtbl.add libs_by_ctx ctx (Lib_name.Map.add_exn Lib_name.Map.empty lib None)) | ||
|
||
let set ctx lib kind = | ||
let f v = | ||
match v with | ||
| Some k -> Some (Kind.merge_opt k (Some (kind))) | ||
| None -> None | ||
in | ||
match Hashtbl.find libs_by_ctx ctx with | ||
| Some libs -> ignore(Hashtbl.set libs_by_ctx ctx (Lib_name.Map.update libs lib ~f:f)) | ||
| None -> () | ||
|
||
let filter_libs libs = Lib_name.Map.filter_map libs ~f:(fun kind -> | ||
match kind with | ||
| Some k -> Some k | ||
| None -> None) | ||
|
||
let print () = | ||
let pp libs = | ||
let libs = | ||
List.sort (Lib_name.Map.to_list (filter_libs libs)) ~compare:(fun (x,_) (y,_) -> Lib_name.compare x y) | ||
in | ||
Pp.enumerate libs ~f:(fun (lib,kind) -> | ||
match kind with | ||
| Kind.Required -> Pp.textf "%s" (Lib_name.to_string lib) | ||
| Kind.Optional -> Pp.textf "%s (optional)" (Lib_name.to_string lib)) | ||
in | ||
(User_message.make | ||
(Hashtbl.foldi libs_by_ctx ~init:[] ~f:(fun ctx libs acc -> | ||
[ Pp.textf | ||
"These are the external library dependencies in the %s context" | ||
(Context_name.to_string ctx); | ||
pp libs ] @ acc))) | ||
|
||
let sexp () = | ||
let dyn libs = Lib_name.Map.to_dyn (fun kind -> Kind.to_dyn kind) libs in | ||
(User_message.make | ||
(Hashtbl.foldi libs_by_ctx ~init:[] ~f:(fun ctx libs acc -> | ||
[(Sexp.pp | ||
(List | ||
[ Atom (Context_name.to_string ctx); Sexp.of_dyn (dyn (filter_libs libs))] )); | ||
] @ acc))) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
open Import | ||
|
||
module Kind :sig | ||
type t = | ||
| Required | ||
| Optional | ||
end | ||
|
||
module External_libs : sig | ||
val add : Context_name.t -> Lib_name.t -> unit | ||
val set : Context_name.t -> Lib_name.t -> Kind.t -> unit | ||
val print : unit -> Stdune.User_message.t | ||
val sexp : unit -> Stdune.User_message.t | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters