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 | 26 ++++++++++++++++++++++++++
2 files changed, 46 insertions(+), 4 deletions(-)
diff --git a/generator/daemon.ml b/generator/daemon.ml
index 548982b..65d910a 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_available <> [] 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_available;
+
+ 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_all;
pr "\n";
diff --git a/generator/optgroups.ml b/generator/optgroups.ml
index 2a348e7..a08f9c3 100644
--- a/generator/optgroups.ml
+++ b/generator/optgroups.ml
@@ -21,6 +21,18 @@
open Types
open Actions
+(* The list of optional groups which need to be in the daemon as always
+ * available.
+ *
+ * NOTE: if a optional group listed here has functions using it, then its
+ * presence here will be ignored (thus being handled as usual). This way,
+ * there is no need to remove groups from this list, once they have been
+ * added (as it means at some point they had no more functions using them,
+ * but libguestfs ought to provide them to the user.
+ *)
+let internal_optgroups_available = [
+]
+
(* Create list of optional groups. *)
let optgroups =
let h = Hashtbl.create 13 in
@@ -42,3 +54,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_available =
+ let groups =
+ List.filter (
+ fun group ->
+ List.mem group optgroups_names <> true
+ ) internal_optgroups_available in
+ List.sort compare groups
+
+let optgroups_names_all =
+ List.sort compare (optgroups_names @ optgroups_available)
--
1.9.0