From a81c407985db9abd59c45ce69b1db23234d23963 Mon Sep 17 00:00:00 2001 From: Puneeth Chaganti Date: Mon, 23 Dec 2024 17:55:30 +0530 Subject: [PATCH] opam-ci-check: Command to list-revdeps in docker image The `opam-ci-check list` command can be run locally to list revdeps for a package. It creates an isolated opam root for some isolation, but for a greater extent of isolation, this commit adds a list-revdeps command that can be used to list-revdeps locally using a Docker image. This makes it easier to reproduce the CI runs more closely, when trying to reproduce locally. And adds extra flexibility to be able to test on different OSes etc. --- opam-ci-check/bin/main.ml | 42 +++++++++++++++++++++++++++++++++++++- opam-ci-check/lib/spec.ml | 4 ++++ opam-ci-check/lib/spec.mli | 5 +++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/opam-ci-check/bin/main.ml b/opam-ci-check/bin/main.ml index 359f2d34..0dbdbbf8 100644 --- a/opam-ci-check/bin/main.ml +++ b/opam-ci-check/bin/main.ml @@ -155,6 +155,23 @@ let build_run_spec ~variant ~hash ~no_cache ~only_print ~with_tests ~base config |> Result.map_error (fun _ -> "Failed to build and test the package") +let list_revdep_spec ~variant ~hash ~no_cache ~only_print ~pkg ~opam_repository + = + let pkg = OpamPackage.of_string pkg in + let base = + let hash = + Stdlib.Option.(hash |> map (fun h -> "@" ^ h) |> value ~default:"") + in + let image = + Printf.sprintf "ocaml/opam:%s%s" (Variant.docker_tag variant) hash + in + Spec.Docker image + in + let config = Spec.opam_list_revdeps ~variant ~opam_version:`Dev pkg in + Test.build_run_spec ~use_cache:(not no_cache) ~only_print ?opam_repository + ~base config + |> Result.map_error (fun _ -> "Failed to list revdeps for the package") + let make_abs_path s = if Filename.is_relative s then Filename.concat (Sys.getcwd ()) s else s @@ -498,11 +515,34 @@ let build_cmd = in Cmd.v info term +let list_revdeps_cmd = + let doc = + "List reverse dependencies for a package using the [opam-ci-check] [list] \ + command inside a Docker image." + in + let term = + to_exit_code + @@ + let+ variant = variant + and+ hash = hash + and+ no_cache = no_cache + and+ only_print = only_print + and+ pkg = pkg_term + and+ opam_repository = local_opam_repo_term in + list_revdep_spec ~variant ~hash ~no_cache ~only_print ~pkg ~opam_repository + in + let info = + Cmd.info "list-revdeps" ~doc ~sdocs:"COMMON OPTIONS" + ~exits:Cmd.Exit.defaults + in + Cmd.v info term + let cmd : Cmd.Exit.code Cmd.t = let doc = "A tool to list revdeps and test the revdeps locally" in let exits = Cmd.Exit.defaults in let default = Term.(ret (const (fun _ -> `Help (`Pager, None)) $ const ())) in let info = Cmd.info "opam-ci-check" ~doc ~sdocs:"COMMON OPTIONS" ~exits in - Cmd.group ~default info [ lint_cmd; list_cmd; test_cmd; build_cmd ] + Cmd.group ~default info + [ lint_cmd; list_cmd; test_cmd; build_cmd; list_revdeps_cmd ] let () = exit (Cmd.eval' cmd) diff --git a/opam-ci-check/lib/spec.ml b/opam-ci-check/lib/spec.ml index 5cf39dba..4aa4aeb0 100644 --- a/opam-ci-check/lib/spec.ml +++ b/opam-ci-check/lib/spec.ml @@ -37,6 +37,10 @@ let opam ?revdep ~variant ~lower_bounds ~with_tests ~opam_version pkg = let ty = `Opam (`Build { revdep; lower_bounds; with_tests; opam_version }, pkg) in { variant; ty } +let opam_list_revdeps ~variant ~opam_version pkg = + let ty = `Opam (`List_revdeps { opam_version }, pkg) in + { variant; ty } + let pp_pkg ?revdep f pkg = match revdep with | Some revdep -> Fmt.pf f "%s with %s" (OpamPackage.to_string revdep) (OpamPackage.to_string pkg) diff --git a/opam-ci-check/lib/spec.mli b/opam-ci-check/lib/spec.mli index 75e18020..6e297d37 100644 --- a/opam-ci-check/lib/spec.mli +++ b/opam-ci-check/lib/spec.mli @@ -39,6 +39,11 @@ val opam : lower_bounds:bool -> with_tests:bool -> opam_version:Opam_version.t -> package -> t +(** Generate configuration for a [list_revdeps] job *) +val opam_list_revdeps : + variant:Variant.t -> + opam_version:Opam_version.t -> package -> t + val pp_ty : Format.formatter -> [< `Opam of