[Libguestfs] [PATCH 1/4] generator: add always-available optgroups

Pino Toscano ptoscano at redhat.com
Wed May 21 13:15:36 UTC 2014


Support the possibility to have optional groups always enabled (e.g.
because they were present in the past, and they need to be kept for
users).
Add and use few helper optgroups-related functions to deal also with
them.
---
 generator/daemon.ml    | 24 ++++++++++++++++++++----
 generator/optgroups.ml | 22 ++++++++++++++++++++++
 2 files changed, 42 insertions(+), 4 deletions(-)

diff --git a/generator/daemon.ml b/generator/daemon.ml
index 548982b..ca748d2 100644
--- a/generator/daemon.ml
+++ b/generator/daemon.ml
@@ -713,11 +713,27 @@ and generate_daemon_optgroups_c () =
   pr "#include \"optgroups.h\"\n";
   pr "\n";
 
+  if optgroups_retired <> [] then (
+    pr "static int\n";
+    pr "dummy_available (void)\n";
+    pr "{\n";
+    pr "  return 1;\n";
+    pr "}\n";
+    pr "\n";
+
+    List.iter (
+      fun group ->
+        pr "#define optgroup_%s_available dummy_available\n" group;
+    ) optgroups_retired;
+
+    pr "\n";
+  );
+
   pr "struct optgroup optgroups[] = {\n";
   List.iter (
-    fun (group, _) ->
+    fun group ->
       pr "  { \"%s\", optgroup_%s_available },\n" group group
-  ) optgroups;
+  ) optgroups_names_all;
   pr "  { NULL, NULL }\n";
   pr "};\n"
 
@@ -729,9 +745,9 @@ and generate_daemon_optgroups_h () =
   pr "\n";
 
   List.iter (
-    fun (group, _) ->
+    fun group ->
       pr "extern int optgroup_%s_available (void);\n" group
-  ) optgroups;
+  ) optgroups_names;
 
   pr "\n";
 
diff --git a/generator/optgroups.ml b/generator/optgroups.ml
index 2a348e7..1c7f45e 100644
--- a/generator/optgroups.ml
+++ b/generator/optgroups.ml
@@ -19,8 +19,16 @@
 (* Please read generator/README first. *)
 
 open Types
+open Utils
 open Actions
 
+(* The list of optional groups which need to be in the daemon as always
+ * available.  These are "retired" as they no longer appear in the
+ * list of functions.
+ *)
+let optgroups_retired = [
+]
+
 (* Create list of optional groups. *)
 let optgroups =
   let h = Hashtbl.create 13 in
@@ -42,3 +50,17 @@ let optgroups =
         group, fns
     ) groups in
   List.sort (fun x y -> compare (fst x) (fst y)) groups
+
+let optgroups_names =
+  fst (List.split optgroups)
+
+let optgroups_names_all =
+  List.sort compare (optgroups_names @ optgroups_retired)
+
+let () =
+  let file = "generator/optgroups.ml" in
+  List.iter (
+    fun x ->
+      if List.mem x optgroups_names then
+        failwithf "%s: optgroups_retired list contains optgroup with functions (%s)" file x
+  ) optgroups_retired
-- 
1.9.0




More information about the Libguestfs mailing list