From 2b6240c3530fc74beb17810ef8b67d6435fe79ce Mon Sep 17 00:00:00 2001
From: Virgile Prevosto <virgile.prevosto@m4x.org>
Date: Tue, 21 Feb 2023 20:11:34 +0100
Subject: [PATCH] [machdep] stick to ppx_deriving_yojson for now

ppx_yojson_conv is advertised as its successor, but it looks less documented, with
a not so convenient interface (exception instead of result type), and MdR would be
painful to convert (and I don't think we want to have two ppx for generating json
serializer/deserializers)
---
 src/dune                                | 4 ++--
 src/kernel_services/ast_queries/file.ml | 9 ++++-----
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/src/dune b/src/dune
index 22a59fed114..30b7a156d88 100644
--- a/src/dune
+++ b/src/dune
@@ -37,7 +37,7 @@
           (echo "  - dune-site.plugins:" %{lib-available:dune-site.plugins} "\n")
           (echo "  - ppx_import:" %{lib-available:ppx_import} "\n")
           (echo "  - ppx_deriving.eq:" %{lib-available:ppx_deriving.eq} "\n")
-          (echo "  - ppx_yojson_conv:" %{lib-available:ppx_yojson_conv} "\n")
+          (echo "  - ppx_deriving_yojson:" %{lib-available:ppx_deriving_yojson} "\n")
   )
   )
 )
@@ -49,7 +49,7 @@
   (flags :standard -w -9)
   (libraries frama-c.init str unix zarith ocamlgraph dynlink bytes yojson menhirLib dune-site dune-site.plugins)
   (instrumentation (backend landmarks))
-  (preprocess (staged_pps ppx_import ppx_deriving.eq ppx_yojson_conv))
+  (preprocess (staged_pps ppx_import ppx_deriving.eq ppx_deriving_yojson))
 )
 
 (generate_sites_module (module config_data) (sites frama-c) (plugins (frama-c plugins) (frama-c plugins_gui)))
diff --git a/src/kernel_services/ast_queries/file.ml b/src/kernel_services/ast_queries/file.ml
index 3d5b1476a12..54a324407c6 100644
--- a/src/kernel_services/ast_queries/file.ml
+++ b/src/kernel_services/ast_queries/file.ml
@@ -368,8 +368,6 @@ let set_machdep () =
 
 let () = Cmdline.run_after_configuring_stage set_machdep
 
-open Ppx_yojson_conv_lib.Yojson_conv.Primitives
-
 type mach = [%import: Cil_types.mach] [@@deriving of_yojson]
 
 (* Local to this module. Use Cil.theMachine.theMachine outside *)
@@ -382,11 +380,12 @@ let get_machdep () =
       if is_default_machdep m then default_machdep_file m
       else Filepath.Normalized.of_string ~existence:Must_exist m
     in
-    try
+    match
       mach_of_yojson (Yojson.Safe.from_file (file:>string))
     with
-      Ppx_yojson_conv_lib.Yojson_conv.Of_yojson_error(exn,_) ->
-      Kernel.fatal "Error during machdep parsing: %s" (Printexc.to_string exn)
+    | Ok machdep -> machdep
+    | Error s ->
+      Kernel.fatal "Error during machdep parsing: %s" s
 
 let list_available_machdeps () =
   CustomMachdeps.fold (fun m _ acc -> m :: acc) (default_machdeps ())
-- 
GitLab