From e2525b35362a212e0416a45b541c884875ad77b8 Mon Sep 17 00:00:00 2001 From: Torben Ewert Date: Sun, 8 Jan 2023 14:26:33 +0100 Subject: [PATCH] chore: rewrite chromium-version to eio --- Makefile | 3 +- bin/ChromiumVersion.ml | 127 ++++++++++++++++----------------- bin/dune | 2 +- chromium-version.opam | 8 ++- chromium-version.opam.locked | 59 +++++++-------- chromium-version.opam.template | 4 ++ dune-project | 4 +- lib/OSnap_Config/dune | 2 +- osnap.opam.locked | 6 +- 9 files changed, 109 insertions(+), 106 deletions(-) create mode 100644 chromium-version.opam.template diff --git a/Makefile b/Makefile index 241a705..9a6680e 100644 --- a/Makefile +++ b/Makefile @@ -4,8 +4,7 @@ all: build build: - dune build -p chromium-version --profile=release - dune build -p osnap --profile=release + dune build -p chromium-version,osnap --profile=release install: if ! [ -e _opam ]; then \ diff --git a/bin/ChromiumVersion.ml b/bin/ChromiumVersion.ml index b3e1c94..966c092 100644 --- a/bin/ChromiumVersion.ml +++ b/bin/ChromiumVersion.ml @@ -1,5 +1,4 @@ -open Cohttp_lwt_unix -open Lwt.Syntax +open Cohttp_eio type platform = | Win64 @@ -11,35 +10,27 @@ type platform = Fmt.set_style_renderer Fmt.stdout `Ansi_tty let print_green msg = - let printer = Fmt.pr " %a " (Fmt.styled `Green Fmt.string) in + let printer = Fmt.pr "%a" (Fmt.styled `Green Fmt.string) in printer msg ;; let print_red msg = - let printer = Fmt.pr " %a " (Fmt.styled `Red Fmt.string) in + let printer = Fmt.pr "%a" (Fmt.styled `Red Fmt.string) in printer msg ;; -let check_availability revision platform = - let uri = - Uri.make - ~scheme:"http" - ~host:"storage.googleapis.com" - ~port:80 - ~path: - (match platform with - | MacOS -> "/chromium-browser-snapshots/Mac/" ^ revision ^ "/chrome-mac.zip" - | MacOS_ARM -> - "/chromium-browser-snapshots/Mac_Arm/" ^ revision ^ "/chrome-mac.zip" - | Linux -> - "/chromium-browser-snapshots/Linux_x64/" ^ revision ^ "/chrome-linux.zip" - | Win64 -> "/chromium-browser-snapshots/Win_x64/" ^ revision ^ "/chrome-win.zip") - () +let check_availability env revision platform = + let path = + match platform with + | MacOS -> "/chromium-browser-snapshots/Mac/" ^ revision ^ "/chrome-mac.zip" + | MacOS_ARM -> "/chromium-browser-snapshots/Mac_Arm/" ^ revision ^ "/chrome-mac.zip" + | Linux -> "/chromium-browser-snapshots/Linux_x64/" ^ revision ^ "/chrome-linux.zip" + | Win64 -> "/chromium-browser-snapshots/Win_x64/" ^ revision ^ "/chrome-win.zip" in - let* response = Client.head uri in + let response, _ = Client.head env ~host:"storage.googleapis.com" path in match response with - | { status = `OK; _ } -> Lwt_result.return platform - | _ -> Lwt_result.fail platform + | Http.Response.{ status = `OK; _ } -> Result.ok platform + | _ -> Result.error platform ;; let platform_to_string = function @@ -49,59 +40,67 @@ let platform_to_string = function | Linux -> "linux" ;; -let rec check_revision revision = +let rec check_revision env revision = let revision_str = string_of_int revision in - let* results = - Lwt.all - [ check_availability revision_str Linux - ; check_availability revision_str MacOS - ; check_availability revision_str MacOS_ARM - ; check_availability revision_str Win64 - ] + let results = + Eio.Fiber.List.map + (check_availability env revision_str) + [ Linux; MacOS; MacOS_ARM; Win64 ] in - flush stdout; print_int revision; - print_string ":"; + print_string ": "; let _available, not_available = results |> List.partition_map (function | Result.Ok platform -> - print_green (platform_to_string platform); + print_green (platform_to_string platform ^ " "); Either.left platform | Result.Error platform -> - print_red (platform_to_string platform); + print_red (platform_to_string platform ^ " "); Either.right platform) in - flush stdout; - print_endline ""; + Fmt.pr "@."; match not_available with - | [] -> Lwt.return revision - | _ -> check_revision (pred revision) + | [] -> revision + | _ -> check_revision env (pred revision) +;; + +let main env = + flush_all (); + print_newline (); + print_newline (); + let latestRevisions = + Eio.Fiber.List.map + (Client.get env ~host:"storage.googleapis.com") + [ "/chromium-browser-snapshots/Mac/LAST_CHANGE" + ; "/chromium-browser-snapshots/Mac_Arm/LAST_CHANGE" + ; "/chromium-browser-snapshots/Linux_x64/LAST_CHANGE" + ; "/chromium-browser-snapshots/Win_x64/LAST_CHANGE" + ] + in + let latestRevisions = + latestRevisions + |> Eio.Fiber.List.map (function + | ({ Http.Response.status = `OK; _ }, _) as r -> Client.read_fixed r + | response, _body -> + Format.fprintf + Format.err_formatter + "Latest version could not be checked:\n%a\n%!" + Http.Response.pp + response; + exit 1) + in + let matched_revision = + latestRevisions + |> List.map int_of_string + |> List.fold_left min Int.max_int + |> check_revision env + in + print_newline (); + print_green + (Printf.sprintf "Latest available revision across all platforms: %i" matched_revision); + flush_all (); + Fmt.pr "@." ;; -Lwt_main.run - (let uri = Uri.make ~scheme:"http" ~host:"storage.googleapis.com" ~port:80 in - let* latestRevisions = - Lwt.all - [ Client.get (uri ~path:"/chromium-browser-snapshots/Mac/LAST_CHANGE" ()) - ; Client.get (uri ~path:"/chromium-browser-snapshots/Mac_Arm/LAST_CHANGE" ()) - ; Client.get (uri ~path:"/chromium-browser-snapshots/Linux_x64/LAST_CHANGE" ()) - ; Client.get (uri ~path:"/chromium-browser-snapshots/Win_x64/LAST_CHANGE" ()) - ] - in - let* latestRevisions = - latestRevisions - |> Lwt_list.map_p (function - | { Response.status = `OK; _ }, body -> Cohttp_lwt.Body.to_string body - | response, _body -> - Format.fprintf - Format.err_formatter - "Latest version could not be checked:\n%a\n%!" - Response.pp_hum - response; - exit 1) - in - latestRevisions - |> List.map int_of_string - |> List.fold_left min Int.max_int - |> check_revision) +let () = Eio_main.run main diff --git a/bin/dune b/bin/dune index 7ae5f3c..90db913 100644 --- a/bin/dune +++ b/bin/dune @@ -20,4 +20,4 @@ (modules ChromiumVersion) (public_name chromium-version) (package chromium-version) - (libraries cohttp cohttp-lwt cohttp-lwt-unix fmt uri lwt lwt.unix)) + (libraries cohttp cohttp-eio http eio_main eio eio.core fmt)) diff --git a/chromium-version.opam b/chromium-version.opam index edc79d9..52b129d 100644 --- a/chromium-version.opam +++ b/chromium-version.opam @@ -15,9 +15,9 @@ depends: [ "cmdliner" "fmt" "cohttp" - "cohttp-lwt-unix" + "cohttp-eio" "fileutils" - "lwt" + "eio_main" "odoc" {with-doc} ] build: [ @@ -35,3 +35,7 @@ build: [ ] ] dev-repo: "git+https://github.com/eWert-Online/OSnap.git" +pin-depends: [ + [ "cohttp.6.0.0~alpha0" "git+https://github.com/mirage/ocaml-cohttp.git#master"] + [ "cohttp-eio.6.0.0~alpha0" "git+https://github.com/mirage/ocaml-cohttp.git#master"] +] \ No newline at end of file diff --git a/chromium-version.opam.locked b/chromium-version.opam.locked index 448c9bb..cc78da9 100644 --- a/chromium-version.opam.locked +++ b/chromium-version.opam.locked @@ -10,7 +10,6 @@ homepage: "https://github.com/eWert-Online/OSnap" bug-reports: "https://github.com/eWert-Online/OSnap/issues" depends: [ "angstrom" {= "0.15.0"} - "asn1-combinators" {= "0.2.6"} "astring" {= "0.8.5"} "base" {= "v0.15.1"} "base-bigarray" {= "base"} @@ -20,57 +19,45 @@ depends: [ "base-threads" {= "base"} "base-unix" {= "base"} "base64" {= "3.5.0"} + "bigarray-compat" {= "1.1.0"} "bigstringaf" {= "0.9.0"} - "bos" {= "0.2.1"} - "ca-certs" {= "0.2.3"} "camlp-streams" {= "5.0.1"} "chrome-trace" {= "3.6.1"} "cmdliner" {= "1.1.1"} "cohttp" {= "5.0.0"} - "cohttp-lwt" {= "5.0.0"} - "cohttp-lwt-unix" {= "5.0.0"} - "conduit" {= "6.1.0"} - "conduit-lwt" {= "6.1.0"} - "conduit-lwt-unix" {= "6.1.0"} - "conf-gmp" {= "4"} - "conf-gmp-powm-sec" {= "3"} + "cohttp-eio" {= "6.0.0~alpha0"} "conf-pkg-config" {= "2"} "cppo" {= "1.6.9"} "csexp" {= "1.5.1"} "cstruct" {= "6.1.1"} - "domain-name" {= "0.4.0"} + "ctypes" {= "0.20.1"} "dune" {= "3.6.1"} "dune-build-info" {= "3.6.1"} "dune-configurator" {= "3.6.1"} "dune-rpc" {= "3.6.1"} - "duration" {= "0.2.1"} "dyn" {= "3.6.1"} + "eio" {= "0.7"} + "eio_luv" {= "0.7"} + "eio_main" {= "0.7"} "either" {= "1.0.0"} - "eqaf" {= "0.9"} "fiber" {= "3.6.1"} "fileutils" {= "0.6.4"} "fix" {= "20220121"} "fmt" {= "0.9.0"} "fpath" {= "0.7.3"} - "gmap" {= "0.3.0"} - "ipaddr" {= "5.3.1"} - "ipaddr-sexp" {= "5.3.1"} + "hmap" {= "0.8.1"} + "http" {= "6.0.0~alpha0"} + "integers" {= "0.7.0"} "jsonm" {= "1.0.1"} "logs" {= "0.7.0"} + "luv" {= "0.5.11"} + "luv_unix" {= "0.5.0"} "lwt" {= "5.6.1"} - "macaddr" {= "5.3.1"} - "magic-mime" {= "1.3.0"} + "lwt-dllist" {= "1.0.1"} "menhir" {= "20220210"} "menhirLib" {= "20220210"} "menhirSdk" {= "20220210"} - "mirage-crypto" {= "0.10.7"} - "mirage-crypto-ec" {= "0.10.7"} - "mirage-crypto-pk" {= "0.10.7"} - "mirage-crypto-rng" {= "0.10.7"} - "mirage-no-solo5" {= "1"} - "mirage-no-xen" {= "1"} - "mtime" {= "2.0.0"} - "num" {= "1.4"} + "mtime" {= "1.4.0"} "ocaml" {= "5.0.0"} "ocaml-base-compiler" {= "5.0.0"} "ocaml-compiler-libs" {= "v0.12.4"} @@ -89,20 +76,18 @@ depends: [ "octavius" {= "1.2.2"} "odoc-parser" {= "2.0.0"} "omd" {= "1.3.2"} + "optint" {= "0.3.0"} "ordering" {= "3.6.1"} - "parsexp" {= "v0.15.0"} - "pbkdf" {= "1.2.0"} "pp" {= "1.1.2"} "ppx_derivers" {= "1.2.1"} "ppx_sexp_conv" {= "v0.15.1"} "ppx_yojson_conv_lib" {= "v0.15.0"} "ppxlib" {= "0.28.0"} + "psq" {= "0.2.1"} "ptime" {= "1.1.0"} "re" {= "1.10.4"} "result" {= "1.5"} - "rresult" {= "0.7.0"} "seq" {= "base"} - "sexplib" {= "v0.15.1"} "sexplib0" {= "v0.15.1"} "spawn" {= "v0.15.1"} "stdio" {= "v0.15.0"} @@ -116,10 +101,8 @@ depends: [ "uucp" {= "15.0.0"} "uuseg" {= "15.0.0"} "uutf" {= "1.0.3"} - "x509" {= "0.16.2"} "xdg" {= "3.6.1"} "yojson" {= "2.0.2"} - "zarith" {= "1.12"} ] build: [ ["dune" "subst"] {dev} @@ -135,4 +118,14 @@ build: [ "@doc" {with-doc} ] ] -dev-repo: "git+https://github.com/eWert-Online/OSnap.git" \ No newline at end of file +dev-repo: "git+https://github.com/eWert-Online/OSnap.git" +pin-depends: [ + [ + "cohttp.5.0.0" + "https://github.com/mirage/ocaml-cohttp/releases/download/v5.0.0/cohttp-5.0.0.tbz" + ] + [ + "cohttp-eio.6.0.0~alpha0" + "git+https://github.com/mirage/ocaml-cohttp.git#master" +] +] \ No newline at end of file diff --git a/chromium-version.opam.template b/chromium-version.opam.template new file mode 100644 index 0000000..9f44ba8 --- /dev/null +++ b/chromium-version.opam.template @@ -0,0 +1,4 @@ +pin-depends: [ + [ "cohttp.6.0.0~alpha0" "git+https://github.com/mirage/ocaml-cohttp.git#master"] + [ "cohttp-eio.6.0.0~alpha0" "git+https://github.com/mirage/ocaml-cohttp.git#master"] +] \ No newline at end of file diff --git a/dune-project b/dune-project index ce49f81..5259949 100644 --- a/dune-project +++ b/dune-project @@ -55,6 +55,6 @@ cmdliner fmt cohttp - cohttp-lwt-unix + cohttp-eio fileutils - lwt)) + eio_main)) diff --git a/lib/OSnap_Config/dune b/lib/OSnap_Config/dune index d0e495e..7191bc4 100644 --- a/lib/OSnap_Config/dune +++ b/lib/OSnap_Config/dune @@ -1,3 +1,3 @@ (library (name OSnap_Config) - (libraries OSnap_Response OSnap_Utils re fileutils yaml yojson)) + (libraries OSnap_Response OSnap_Utils re fileutils unix yaml yojson)) diff --git a/osnap.opam.locked b/osnap.opam.locked index b4d400e..7e0925e 100644 --- a/osnap.opam.locked +++ b/osnap.opam.locked @@ -80,7 +80,7 @@ depends: [ "mirage-crypto-rng" {= "0.10.7"} "mirage-no-solo5" {= "1"} "mirage-no-xen" {= "1"} - "mtime" {= "2.0.0"} + "mtime" {= "1.4.0"} "num" {= "1.4"} "ocaml" {= "5.0.0"} "ocaml-base-compiler" {= "5.0.0"} @@ -159,6 +159,10 @@ pin-depends: [ [ "cdp.dev" "git+https://github.com/eWert-Online/reason-cdp.git#ebb07093e93a27e302afde04296fbc4d22f83948" +] + [ + "cohttp.5.0.0" + "https://github.com/mirage/ocaml-cohttp/releases/download/v5.0.0/cohttp-5.0.0.tbz" ] ["libspng.dev" "git+https://github.com/eWert-Online/esy-libspng.git#opam"] [