From ec36262328f95168def0b76a8b1e25a8b5ac51af Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Loi=CC=88c=20Correnson?= <loic.correnson@cea.fr>
Date: Fri, 3 Feb 2023 21:59:11 +0100
Subject: [PATCH] [server] fixed documentation readme pages

---
 src/plugins/eva/api/general_requests.ml          |  1 -
 src/plugins/eva/api/values_request.ml            |  1 -
 src/plugins/metrics/metrics_pivot.ml             |  1 -
 src/plugins/server/{share => doc}/ast.md         |  0
 src/plugins/server/{share => doc}/kernel.md      |  0
 src/plugins/server/{share => doc}/project.md     |  0
 src/plugins/server/{share => doc}/server.md      |  0
 .../server/{share => doc}/server_batch.md        |  0
 .../server/{share => doc}/server_socket.md       |  0
 src/plugins/server/{share => doc}/server_zmq.md  |  0
 src/plugins/server/kernel_main.ml                |  6 ++++--
 src/plugins/server/package.ml                    |  4 ++--
 src/plugins/server/server_doc.ml                 | 16 +++++++++++-----
 src/plugins/studia/studia_request.ml             |  3 +--
 14 files changed, 18 insertions(+), 14 deletions(-)
 rename src/plugins/server/{share => doc}/ast.md (100%)
 rename src/plugins/server/{share => doc}/kernel.md (100%)
 rename src/plugins/server/{share => doc}/project.md (100%)
 rename src/plugins/server/{share => doc}/server.md (100%)
 rename src/plugins/server/{share => doc}/server_batch.md (100%)
 rename src/plugins/server/{share => doc}/server_socket.md (100%)
 rename src/plugins/server/{share => doc}/server_zmq.md (100%)

diff --git a/src/plugins/eva/api/general_requests.ml b/src/plugins/eva/api/general_requests.ml
index 75d3f5312fd..14a1586fe59 100644
--- a/src/plugins/eva/api/general_requests.ml
+++ b/src/plugins/eva/api/general_requests.ml
@@ -28,7 +28,6 @@ let package =
     ~plugin:"eva"
     ~name:"general"
     ~title:"Eva General Services"
-    ~readme:"eva.md"
     ()
 
 module ComputationState = struct
diff --git a/src/plugins/eva/api/values_request.ml b/src/plugins/eva/api/values_request.ml
index 72290c183f6..c672982553d 100644
--- a/src/plugins/eva/api/values_request.ml
+++ b/src/plugins/eva/api/values_request.ml
@@ -40,7 +40,6 @@ let package =
     ~plugin:"eva"
     ~name:"values"
     ~title:"Eva Values"
-    ~readme:"eva.md"
     ()
 
 type probe =
diff --git a/src/plugins/metrics/metrics_pivot.ml b/src/plugins/metrics/metrics_pivot.ml
index cf2e9e5cc1e..e10d16d41c0 100644
--- a/src/plugins/metrics/metrics_pivot.ml
+++ b/src/plugins/metrics/metrics_pivot.ml
@@ -503,7 +503,6 @@ let package =
     ~plugin:"pivot"
     ~name:"general"
     ~title:"Pivot Table Services"
-    ~readme:"pivot.md"
     ()
 
 module TableState = struct
diff --git a/src/plugins/server/share/ast.md b/src/plugins/server/doc/ast.md
similarity index 100%
rename from src/plugins/server/share/ast.md
rename to src/plugins/server/doc/ast.md
diff --git a/src/plugins/server/share/kernel.md b/src/plugins/server/doc/kernel.md
similarity index 100%
rename from src/plugins/server/share/kernel.md
rename to src/plugins/server/doc/kernel.md
diff --git a/src/plugins/server/share/project.md b/src/plugins/server/doc/project.md
similarity index 100%
rename from src/plugins/server/share/project.md
rename to src/plugins/server/doc/project.md
diff --git a/src/plugins/server/share/server.md b/src/plugins/server/doc/server.md
similarity index 100%
rename from src/plugins/server/share/server.md
rename to src/plugins/server/doc/server.md
diff --git a/src/plugins/server/share/server_batch.md b/src/plugins/server/doc/server_batch.md
similarity index 100%
rename from src/plugins/server/share/server_batch.md
rename to src/plugins/server/doc/server_batch.md
diff --git a/src/plugins/server/share/server_socket.md b/src/plugins/server/doc/server_socket.md
similarity index 100%
rename from src/plugins/server/share/server_socket.md
rename to src/plugins/server/doc/server_socket.md
diff --git a/src/plugins/server/share/server_zmq.md b/src/plugins/server/doc/server_zmq.md
similarity index 100%
rename from src/plugins/server/share/server_zmq.md
rename to src/plugins/server/doc/server_zmq.md
diff --git a/src/plugins/server/kernel_main.ml b/src/plugins/server/kernel_main.ml
index c94df8b12ab..aacea649733 100644
--- a/src/plugins/server/kernel_main.ml
+++ b/src/plugins/server/kernel_main.ml
@@ -29,8 +29,10 @@ module Senv = Server_parameters
 (* --- Frama-C Kernel Services                                            --- *)
 (* -------------------------------------------------------------------------- *)
 
-let package = Pkg.package ~name:"services"
-    ~title:"Kernel Services" ~readme:"kernel.md" ()
+let package = Pkg.package
+    ~name:"services"
+    ~title:"Kernel Services"
+    ~readme:"kernel.md" ()
 
 (* -------------------------------------------------------------------------- *)
 (* --- Config                                                             --- *)
diff --git a/src/plugins/server/package.ml b/src/plugins/server/package.ml
index 7ff0db41405..3655ac407f0 100644
--- a/src/plugins/server/package.ml
+++ b/src/plugins/server/package.ml
@@ -383,9 +383,9 @@ let resolve_readme ~plugin = function
     let file =
       match plugin with
       | Kernel ->
-        Printf.sprintf "%s/server/%s" (Fc_config.datadir:>string) readme
+        Printf.sprintf "src/plugins/server/doc/%s" readme
       | Plugin name ->
-        Printf.sprintf "%s/%s/server/%s" (Fc_config.datadir:>string) name readme
+        Printf.sprintf "src/plugins/%s/doc/%s" name readme
     in Some file
 
 (* -------------------------------------------------------------------------- *)
diff --git a/src/plugins/server/server_doc.ml b/src/plugins/server/server_doc.ml
index 70e09cf5f95..1169ad75c0d 100644
--- a/src/plugins/server/server_doc.ml
+++ b/src/plugins/server/server_doc.ml
@@ -99,7 +99,7 @@ let publish ~page ?name ?(index=[]) ~title
   page.sections <- section :: page.sections ; href
 
 let protocol ~title ~readme:filename =
-  let readme = Printf.sprintf "%s/server/%s" (Fc_config.datadir :> string) filename in
+  let readme = Printf.sprintf "src/plugins/server/doc/%s"  filename in
   ignore (page `Protocol ~title ~readme ~filename ())
 
 let () = protocol ~title:"Architecture" ~readme:"server.md"
@@ -111,7 +111,9 @@ let () = protocol ~title:"Architecture" ~readme:"server.md"
 let href_of_ident names id =
   let chapter = match id.plugin with
     | Kernel -> `Kernel | Plugin p -> `Plugin p in
-  let filename = String.concat "_" id.package ^ ".md" in
+  let filename =
+    if id.package = [] then "index.md" else
+      String.concat "_" id.package ^ ".md" in
   let page = snd @@ path_for chapter filename in
   let text = try IdMap.find id names with Not_found -> id.name in
   Md.link ~text:(Md.code text) ~page ~name:id.name ()
@@ -119,7 +121,9 @@ let href_of_ident names id =
 let page_of_package pkg =
   let chapter = match pkg.p_plugin with
     | Kernel -> `Kernel | Plugin p -> `Plugin p in
-  let filename = String.concat "_" pkg.p_package ^ ".md" in
+  let filename =
+    if pkg.p_package = [] then "index.md" else
+      String.concat "_" pkg.p_package ^ ".md" in
   try
     let _,path = path_for chapter filename in
     Pages.find path !pages
@@ -343,8 +347,10 @@ let dump ~root ?(meta=true) () =
            | Some file ->
              if Sys.file_exists file
              then Markdown.rawfile file @ page.descr
-             else (Senv.warning "Can not find %S file" file ;
-                   Markdown.section ~title page.descr)
+             else (
+               Senv.warning "Can not find %S file" file ;
+               Markdown.section ~title page.descr
+             )
          in
          let body = Markdown.subsections page.descr (build [] page.sections) in
          pp_one_page ~root ~page:path ~title (intro @ body) ;
diff --git a/src/plugins/studia/studia_request.ml b/src/plugins/studia/studia_request.ml
index 4bc6362c4e4..f657ba81880 100644
--- a/src/plugins/studia/studia_request.ml
+++ b/src/plugins/studia/studia_request.ml
@@ -24,8 +24,7 @@ open Server
 open Cil_types
 
 let package =
-  Package.package ~plugin:"studia" ~name:"studia" ~title:"Studia"
-    ~readme:"studia.md" ()
+  Package.package ~plugin:"studia" ~name:"studia" ~title:"Studia" ()
 
 type effects =
   { direct: stmt list;
-- 
GitLab