From bcebafae6a13ab61a58b11774c5b97c5b86651eb Mon Sep 17 00:00:00 2001 From: Simmo Saan Date: Fri, 21 Jun 2024 14:06:13 +0300 Subject: [PATCH 1/3] Replace ppx_yojson_conv with ppx_deriving_yojson This matches with Goblint itself. --- dune-project | 2 +- goblint-http-server/api.ml | 5 ++--- goblint-http-server/dune | 2 +- goblint-http-server/goblint_http.ml | 10 ++++------ goblint-http-server/json.ml | 4 ++-- gobview.opam | 2 +- gobview.opam.locked | 4 ---- 7 files changed, 11 insertions(+), 18 deletions(-) diff --git a/dune-project b/dune-project index 060a067..b75c004 100644 --- a/dune-project +++ b/dune-project @@ -35,7 +35,7 @@ lwt lwt_ppx yojson - ppx_yojson_conv ; TODO: switch to ppx_deriving_yojson like Goblint itself + ppx_deriving_yojson conduit-lwt-unix jsoo-react js_of_ocaml-lwt diff --git a/goblint-http-server/api.ml b/goblint-http-server/api.ml index c651b7e..c270d9b 100644 --- a/goblint-http-server/api.ml +++ b/goblint-http-server/api.ml @@ -1,6 +1,5 @@ open Batteries open State -open Ppx_yojson_conv_lib.Yojson_conv.Primitives module type Request = sig val name: string @@ -8,8 +7,8 @@ module type Request = sig type body type response - val body_of_yojson: Yojson.Safe.t -> body - val yojson_of_response: response -> Yojson.Safe.t + val body_of_yojson: Yojson.Safe.t -> (body, string) result + val response_to_yojson: response -> Yojson.Safe.t val process: State.t -> body -> response Lwt.t end diff --git a/goblint-http-server/dune b/goblint-http-server/dune index 55f78c1..96d95fd 100644 --- a/goblint-http-server/dune +++ b/goblint-http-server/dune @@ -14,4 +14,4 @@ yojson uri) (preprocess - (pps lwt_ppx ppx_yojson_conv))) + (pps lwt_ppx ppx_deriving_yojson))) diff --git a/goblint-http-server/goblint_http.ml b/goblint-http-server/goblint_http.ml index f053274..58232f1 100644 --- a/goblint-http-server/goblint_http.ml +++ b/goblint-http-server/goblint_http.ml @@ -3,8 +3,6 @@ open Cohttp_lwt open Cohttp_lwt_unix open Lwt.Infix -module Yojson_conv = Ppx_yojson_conv_lib.Yojson_conv - let docroot = ref "run" let distroot = ref "gobview/_dist" let index = ref "index.html" @@ -35,13 +33,13 @@ let process state name body = | exception Yojson.Json_error err -> Server.respond_error ~status:`Bad_request ~body:err () | json -> match R.body_of_yojson json with - | exception Yojson_conv.Of_yojson_error (exn, _) -> - Server.respond_error ~status:`Bad_request ~body:(Printexc.to_string exn) () - | body -> + | Error msg -> + Server.respond_error ~status:`Bad_request ~body:msg () + | Ok body -> Lwt.catch (fun () -> R.process state body - >|= R.yojson_of_response + >|= R.response_to_yojson >|= Yojson.Safe.to_string >>= fun body -> Server.respond_string ~status:`OK ~body ()) (fun exn -> Server.respond_error ~status:`Bad_request ~body:(Printexc.to_string exn) ()) diff --git a/goblint-http-server/json.ml b/goblint-http-server/json.ml index f06d205..94d0179 100644 --- a/goblint-http-server/json.ml +++ b/goblint-http-server/json.ml @@ -1,4 +1,4 @@ type t = Yojson.Safe.t -let t_of_yojson x = x -let yojson_of_t x = x +let of_yojson x = Ok x +let to_yojson x = x diff --git a/gobview.opam b/gobview.opam index 572ba40..0ca617c 100644 --- a/gobview.opam +++ b/gobview.opam @@ -24,7 +24,7 @@ depends: [ "lwt" "lwt_ppx" "yojson" - "ppx_yojson_conv" + "ppx_deriving_yojson" "conduit-lwt-unix" "jsoo-react" "js_of_ocaml-lwt" diff --git a/gobview.opam.locked b/gobview.opam.locked index 7b0baf5..2ab89fd 100644 --- a/gobview.opam.locked +++ b/gobview.opam.locked @@ -94,7 +94,6 @@ depends: [ "ocamlbuild" {= "0.14.3"} "ocamlfind" {= "1.9.6"} "ocplib-endian" {= "1.2"} - "octavius" {= "1.2.2"} "odoc" {= "2.4.2" & with-doc} "odoc-parser" {= "2.4.2" & with-doc} "ojs" {= "1.1.2"} @@ -103,10 +102,7 @@ depends: [ "ppx_derivers" {= "1.2.1"} "ppx_deriving" {= "6.0.2"} "ppx_deriving_yojson" {= "3.8.0"} - "ppx_js_style" {= "v0.16.0"} "ppx_sexp_conv" {= "v0.16.0"} - "ppx_yojson_conv" {= "v0.16.0"} - "ppx_yojson_conv_lib" {= "v0.16.0"} "ppxlib" {= "0.32.1"} "ptime" {= "1.1.0"} "re" {= "1.11.0"} From 3c6a3362e52487882a2c1cbc03b1b9f643f86a65 Mon Sep 17 00:00:00 2001 From: Simmo Saan Date: Fri, 21 Jun 2024 14:16:28 +0300 Subject: [PATCH 2/3] Generate less yojson converters --- goblint-http-server/api.ml | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/goblint-http-server/api.ml b/goblint-http-server/api.ml index c270d9b..1a72a3d 100644 --- a/goblint-http-server/api.ml +++ b/goblint-http-server/api.ml @@ -4,11 +4,8 @@ open State module type Request = sig val name: string - type body - type response - - val body_of_yojson: Yojson.Safe.t -> (body, string) result - val response_to_yojson: response -> Yojson.Safe.t + type body [@@deriving of_yojson] + type response [@@deriving to_yojson] val process: State.t -> body -> response Lwt.t end @@ -19,22 +16,22 @@ let register (module R : Request) = Hashtbl.add registry R.name (module R : Requ module Ping = struct let name = "ping" - type body = unit [@@deriving yojson] - type response = unit [@@deriving yojson] + type body = unit [@@deriving of_yojson] + type response = unit [@@deriving to_yojson] let process state () = Goblint.ping state.goblint end module Config = struct let name = "config" - type body = string * Json.t [@@deriving yojson] - type response = unit [@@deriving yojson] + type body = string * Json.t [@@deriving of_yojson] + type response = unit [@@deriving to_yojson] let process state (conf, json) = Goblint.config state.goblint conf json end module Analyze = struct let name = "analyze" - type body = [`All | `Functions of string list] option [@@deriving yojson] - type response = unit [@@deriving yojson] + type body = [`All | `Functions of string list] option [@@deriving of_yojson] + type response = unit [@@deriving to_yojson] let process state reanalyze = let%lwt save_run = Goblint.analyze state.goblint ?reanalyze in state.save_run <- Some save_run; From e3795aeeba84431d05efbc616a1cca145ffcaea8 Mon Sep 17 00:00:00 2001 From: Simmo Saan Date: Fri, 21 Jun 2024 14:24:59 +0300 Subject: [PATCH 3/3] Remove Json module --- goblint-http-server/api.ml | 2 +- goblint-http-server/json.ml | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) delete mode 100644 goblint-http-server/json.ml diff --git a/goblint-http-server/api.ml b/goblint-http-server/api.ml index 1a72a3d..e015314 100644 --- a/goblint-http-server/api.ml +++ b/goblint-http-server/api.ml @@ -23,7 +23,7 @@ end module Config = struct let name = "config" - type body = string * Json.t [@@deriving of_yojson] + type body = string * Yojson.Safe.t [@@deriving of_yojson] type response = unit [@@deriving to_yojson] let process state (conf, json) = Goblint.config state.goblint conf json end diff --git a/goblint-http-server/json.ml b/goblint-http-server/json.ml deleted file mode 100644 index 94d0179..0000000 --- a/goblint-http-server/json.ml +++ /dev/null @@ -1,4 +0,0 @@ -type t = Yojson.Safe.t - -let of_yojson x = Ok x -let to_yojson x = x