Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg: Print all the depexts #11145

Merged
merged 3 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/describe/describe.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ let subcommands =
; Package_entries.command
; Describe_pkg.command
; Describe_contexts.command
; Describe_depexts.command
]
;;

Expand Down
49 changes: 49 additions & 0 deletions bin/describe/describe_depexts.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
open Import
open Pkg_common
module Lock_dir = Dune_pkg.Lock_dir

let enumerate_lock_dirs_by_path workspace ~lock_dirs =
let lock_dirs = Pkg_common.Lock_dirs_arg.lock_dirs_of_workspace lock_dirs workspace in
List.filter_map lock_dirs ~f:(fun lock_dir_path ->
if Path.exists (Path.source lock_dir_path)
then (
try Some (Lock_dir.read_disk_exn lock_dir_path) with
| User_error.E e ->
User_warning.emit
[ Pp.textf
"Failed to parse lockdir %s:"
(Path.Source.to_string_maybe_quoted lock_dir_path)
; User_message.pp e
];
None)
else None)
;;

let print_depexts ~lock_dirs_arg =
let open Fiber.O in
let open Lock_dir in
let+ workspace = Memo.run (Workspace.workspace ()) in
let depexts =
enumerate_lock_dirs_by_path workspace ~lock_dirs:lock_dirs_arg
|> List.concat_map ~f:(fun lock_dir ->
lock_dir.packages
|> Package_name.Map.values
|> List.concat_map ~f:(fun (pkg : Lock_dir.Pkg.t) -> pkg.depexts))
in
Console.print [ Pp.concat_map ~sep:Pp.newline ~f:Pp.verbatim depexts ]
;;

let term =
let+ builder = Common.Builder.term
and+ lock_dirs_arg = Lock_dirs_arg.term in
let builder = Common.Builder.forbid_builds builder in
let common, config = Common.init builder in
Scheduler.go ~common ~config (fun () -> print_depexts ~lock_dirs_arg)
;;

let info =
let doc = "Print the list of all the available depexts" in
Cmd.info "depexts" ~doc
;;

let command = Cmd.v info term
4 changes: 4 additions & 0 deletions bin/describe/describe_depexts.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
open Import

(** Command to print all depexts *)
val command : unit Cmd.t
24 changes: 24 additions & 0 deletions test/blackbox-tests/test-cases/pkg/depexts/print-depexts.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Show that the depexts that a project has can be printed.

$ . ../helpers.sh
$ mkrepo

Make a project:

$ cat > dune-project <<EOF
> (lang dune 3.13)
> EOF

Create a lockdir with a package that features some depexts.

$ make_lockdir
$ cat > dune.lock/foo.pkg <<EOF
> (version 0.0.1)
> (depexts unzip gnupg)
> EOF

Printing the depexts should show all the depexts that the project has:

$ dune show depexts
unzip
gnupg
Loading