From 32e165a8a2d551afbaed46c38671e61756ceb7f1 Mon Sep 17 00:00:00 2001 From: Luca Zhang Date: Tue, 9 Apr 2024 14:39:16 +0800 Subject: [PATCH] refactor: move `objects` from `Gen_go_helper` to `CommonFunctions` Signed-off-by: Luca Zhang --- ocaml/sdk-gen/common/CommonFunctions.ml | 18 ++++++++++++++++++ ocaml/sdk-gen/common/CommonFunctions.mli | 5 +++++ ocaml/sdk-gen/go/gen_go_binding.ml | 1 + ocaml/sdk-gen/go/gen_go_helper.ml | 18 ------------------ ocaml/sdk-gen/go/gen_go_helper.mli | 4 ---- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/ocaml/sdk-gen/common/CommonFunctions.ml b/ocaml/sdk-gen/common/CommonFunctions.ml index 12ef3420d31..74f022f4c05 100644 --- a/ocaml/sdk-gen/common/CommonFunctions.ml +++ b/ocaml/sdk-gen/common/CommonFunctions.ml @@ -4,6 +4,8 @@ open Printf open Datamodel_types +open Datamodel_utils +open Dm_api exception Unknown_wire_protocol @@ -328,3 +330,19 @@ let json_releases = , `Float (float_of_int (List.length unique_version_bumps)) ) ] + +let objects = + let api = Datamodel.all_api in + (* Add all implicit messages *) + let api = add_implicit_messages api in + (* Only include messages that are visible to a XenAPI client *) + let api = filter (fun _ -> true) (fun _ -> true) on_client_side api in + (* And only messages marked as not hidden from the docs, and non-internal fields *) + let api = + filter + (fun _ -> true) + (fun f -> not f.internal_only) + (fun m -> not m.msg_hide_from_docs) + api + in + objects_of_api api diff --git a/ocaml/sdk-gen/common/CommonFunctions.mli b/ocaml/sdk-gen/common/CommonFunctions.mli index 9a88b5cd5bd..4f787081dbb 100644 --- a/ocaml/sdk-gen/common/CommonFunctions.mli +++ b/ocaml/sdk-gen/common/CommonFunctions.mli @@ -1,3 +1,5 @@ +open Datamodel_types + (** Exception for unknown wire protocol. *) exception Unknown_wire_protocol @@ -129,3 +131,6 @@ val render_file : string * string -> Mustache.Json.t -> string -> string -> unit val json_releases : Mustache.Json.t (** JSON structure representing release information. *) + +val objects : obj list +(** Objects of api that generate SDKs. *) diff --git a/ocaml/sdk-gen/go/gen_go_binding.ml b/ocaml/sdk-gen/go/gen_go_binding.ml index 1912c87e667..a5b68c86825 100644 --- a/ocaml/sdk-gen/go/gen_go_binding.ml +++ b/ocaml/sdk-gen/go/gen_go_binding.ml @@ -11,6 +11,7 @@ GNU Lesser General Public License for more details. *) +open CommonFunctions open Gen_go_helper let render_api_messages_and_errors () = diff --git a/ocaml/sdk-gen/go/gen_go_helper.ml b/ocaml/sdk-gen/go/gen_go_helper.ml index 21a1f75581a..6fd9746f9bf 100644 --- a/ocaml/sdk-gen/go/gen_go_helper.ml +++ b/ocaml/sdk-gen/go/gen_go_helper.ml @@ -14,8 +14,6 @@ (* Generator of Go bindings from the datamodel *) open Datamodel_types -open Datamodel_utils -open Dm_api open CommonFunctions let dest_dir = "autogen" @@ -259,19 +257,3 @@ module Json = struct let api_errors = List.map (fun error -> `O [("name", `String error)]) !Api_errors.errors end - -let objects = - let api = Datamodel.all_api in - (* Add all implicit messages *) - let api = add_implicit_messages api in - (* Only include messages that are visible to a XenAPI client *) - let api = filter (fun _ -> true) (fun _ -> true) on_client_side api in - (* And only messages marked as not hidden from the docs, and non-internal fields *) - let api = - filter - (fun _ -> true) - (fun f -> not f.internal_only) - (fun m -> not m.msg_hide_from_docs) - api - in - objects_of_api api diff --git a/ocaml/sdk-gen/go/gen_go_helper.mli b/ocaml/sdk-gen/go/gen_go_helper.mli index f58fb079786..e624a99e0a9 100644 --- a/ocaml/sdk-gen/go/gen_go_helper.mli +++ b/ocaml/sdk-gen/go/gen_go_helper.mli @@ -11,14 +11,10 @@ GNU Lesser General Public License for more details. *) -open Datamodel_types - val ( // ) : string -> string -> string val snake_to_camel : string -> string -val objects : obj list - val render_template : string -> Mustache.Json.t -> string val generate_file : string -> string -> unit