diff --git a/ocaml/sdk-gen/go/dune b/ocaml/sdk-gen/go/dune index ed84911dedc..8b9b9f5ccc1 100644 --- a/ocaml/sdk-gen/go/dune +++ b/ocaml/sdk-gen/go/dune @@ -7,7 +7,6 @@ mustache xapi-datamodel gen_go_helper - go_file_headers ) ) @@ -22,15 +21,6 @@ ) ) -(library - (name go_file_headers) - (wrapped false) - (modules go_file_headers) - (libraries - mustache - ) -) - (rule (alias generate) (deps @@ -43,7 +33,7 @@ (test (name test_gen_go) (modules test_gen_go) - (libraries alcotest xapi-test-utils gen_go_helper go_file_headers) + (libraries alcotest xapi-test-utils gen_go_helper) (deps (source_tree test_data) (source_tree templates) diff --git a/ocaml/sdk-gen/go/gen_go_binding.ml b/ocaml/sdk-gen/go/gen_go_binding.ml index 47b21931b4c..1912c87e667 100644 --- a/ocaml/sdk-gen/go/gen_go_binding.ml +++ b/ocaml/sdk-gen/go/gen_go_binding.ml @@ -13,28 +13,21 @@ open Gen_go_helper -let render_header name = - let open Go_file_headers in - let header = - List.assoc name headers |> render_template "FileHeader.mustache" - in - header ^ "\n" - let render_api_messages_and_errors () = let obj = `O [ ("api_errors", `A Json.api_errors) ; ("api_messages", `A Json.api_messages) + ; ("modules", `Null) ] in - let messages_rendered = - render_header "api_errors" ^ render_template "APIErrors.mustache" obj ^ "\n" - in + let header = render_template "FileHeader.mustache" obj ^ "\n" in let error_rendered = - render_header "api_messages" - ^ render_template "APIMessages.mustache" obj - ^ "\n" + header ^ render_template "APIErrors.mustache" obj ^ "\n" + in + let messages_rendered = + header ^ render_template "APIMessages.mustache" obj ^ "\n" in generate_file error_rendered "api_errors.go" ; generate_file messages_rendered "api_messages.go" @@ -44,7 +37,7 @@ let main () = let objects = Json.xenapi objects in List.iter (fun (name, obj) -> - let header_rendered = render_header name in + let header_rendered = render_template "FileHeader.mustache" obj ^ "\n" in let enums_rendered = render_template "Enum.mustache" obj in let record_rendered = render_template "Record.mustache" obj in let rendered = header_rendered ^ enums_rendered ^ record_rendered in diff --git a/ocaml/sdk-gen/go/gen_go_helper.ml b/ocaml/sdk-gen/go/gen_go_helper.ml index 44b9ba7e830..2e0a8aeeb59 100644 --- a/ocaml/sdk-gen/go/gen_go_helper.ml +++ b/ocaml/sdk-gen/go/gen_go_helper.ml @@ -118,7 +118,10 @@ module Json = struct concated in List.fold_left - (fun (fields, enums) field -> + (fun (fields, enums, has_time_type) field -> + let is_time_type = + match field.ty with DateTime -> true | _ -> false + in let ty, e = string_of_ty_with_enums field.ty in ( `O [ @@ -128,9 +131,10 @@ module Json = struct ] :: fields , enums @ e + , if is_time_type then true else has_time_type ) ) - ([], []) fields + ([], [], false) fields let enums_from_result obj msg = match msg.msg_result with @@ -176,6 +180,23 @@ module Json = struct ) [] obj.messages + let get_modules messages has_time_type = + match messages with + | [] -> + `Null + | _ -> + let items = + match has_time_type with + | true -> + [ + `O [("name", `String "fmt"); ("sname", `Null)] + ; `O [("name", `String "time"); ("sname", `Null)] + ] + | false -> + [`O [("name", `String "fmt"); ("sname", `Null)]] + in + `O [("import", `Bool true); ("items", `A items)] + let xenapi objs = let enum_set = ref EnumSet.empty in let enum_dedup enums = @@ -192,7 +213,7 @@ module Json = struct in List.map (fun obj -> - let fields, enums1 = fields_of_obj_with_enums obj in + let fields, enums1, has_time_type = fields_of_obj_with_enums obj in let enums2 = enums_in_messages_of_obj obj in let enums = enum_dedup (enums1 @ enums2) in let event_snapshot = @@ -213,6 +234,7 @@ module Json = struct [] in let obj_name = snake_to_camel obj.name in + let modules = get_modules obj.messages has_time_type in let event_session_value = function | "event" -> [("event", `Bool true); ("session", `Null)] @@ -227,6 +249,7 @@ module Json = struct ; ("description", `String (String.trim obj.description)) ; ("fields", `A (event_snapshot @ fields)) ; ("enums", `A (List.map of_enum enums)) + ; ("modules", modules) ] in let assoc_list = event_session_value obj.name @ base_assoc_list in diff --git a/ocaml/sdk-gen/go/go_file_headers.ml b/ocaml/sdk-gen/go/go_file_headers.ml deleted file mode 100644 index 977c7a877d3..00000000000 --- a/ocaml/sdk-gen/go/go_file_headers.ml +++ /dev/null @@ -1,925 +0,0 @@ -(* Copyright (C) Cloud Software Group, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published - by the Free Software Foundation; version 2.1 only. with the special - exception on linking described in file LICENSE. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. -*) - -let headers : (string * Mustache.Json.t) list = - [ - ("api_errors", `O [("modules", `Null)]) - ; ("api_messages", `O [("modules", `Null)]) - ; ( "cluster_host" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ( "items" - , `A - [ - `O [("name", `String "fmt"); ("sname", `Null)] - ; `O [("name", `String "time"); ("sname", `Null)] - ] - ) - ] - ) - ] - ) - ; ( "feature" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "host_patch" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ( "items" - , `A - [ - `O [("name", `String "fmt"); ("sname", `Null)] - ; `O [("name", `String "time"); ("sname", `Null)] - ] - ) - ] - ) - ] - ) - ; ( "pbd" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "pool_update" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "repository" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "sr" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "vbd" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "vif_metrics" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ( "items" - , `A - [ - `O [("name", `String "fmt"); ("sname", `Null)] - ; `O [("name", `String "time"); ("sname", `Null)] - ] - ) - ] - ) - ] - ) - ; ( "vmss" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ( "items" - , `A - [ - `O [("name", `String "fmt"); ("sname", `Null)] - ; `O [("name", `String "time"); ("sname", `Null)] - ] - ) - ] - ) - ] - ) - ; ( "console" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "pci" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ("probe_result", `O [("modules", `Null)]) - ; ( "role" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ("sr_stat", `O [("modules", `Null)]) - ; ( "vbd_metrics" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ( "items" - , `A - [ - `O [("name", `String "fmt"); ("sname", `Null)] - ; `O [("name", `String "time"); ("sname", `Null)] - ] - ) - ] - ) - ] - ) - ; ( "vlan" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "vtpm" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "auth" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "convert" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ( "items" - , `A - [ - `O [("name", `String "fmt"); ("sname", `Null)] - ; `O [("name", `String "math"); ("sname", `Null)] - ; `O [("name", `String "reflect"); ("sname", `Null)] - ; `O [("name", `String "strconv"); ("sname", `Null)] - ; `O [("name", `String "time"); ("sname", `Null)] - ] - ) - ] - ) - ] - ) - ; ( "gpu_group" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "lvhd" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "pgpu" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "pusb" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "sdn_controller" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "subject" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "vdi" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ( "items" - , `A - [ - `O [("name", `String "fmt"); ("sname", `Null)] - ; `O [("name", `String "time"); ("sname", `Null)] - ] - ) - ] - ) - ] - ) - ; ( "vm_appliance" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "vusb" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "blob" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ( "items" - , `A - [ - `O [("name", `String "fmt"); ("sname", `Null)] - ; `O [("name", `String "time"); ("sname", `Null)] - ] - ) - ] - ) - ] - ) - ; ( "crashdump" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "host_cpu" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "message" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ( "items" - , `A - [ - `O [("name", `String "fmt"); ("sname", `Null)] - ; `O [("name", `String "time"); ("sname", `Null)] - ] - ) - ] - ) - ] - ) - ; ( "pif" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "pvs_cache_storage" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "secret" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "task" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ( "items" - , `A - [ - `O [("name", `String "fmt"); ("sname", `Null)] - ; `O [("name", `String "time"); ("sname", `Null)] - ] - ) - ] - ) - ] - ) - ; ("vdi_nbd_server_info", `O [("modules", `Null)]) - ; ( "vm" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ( "items" - , `A - [ - `O [("name", `String "fmt"); ("sname", `Null)] - ; `O [("name", `String "time"); ("sname", `Null)] - ] - ) - ] - ) - ] - ) - ; ( "bond" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ("data_source", `O [("modules", `Null)]) - ; ( "host_crashdump" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ( "items" - , `A - [ - `O [("name", `String "fmt"); ("sname", `Null)] - ; `O [("name", `String "time"); ("sname", `Null)] - ] - ) - ] - ) - ] - ) - ; ( "network" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "pif_metrics" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ( "items" - , `A - [ - `O [("name", `String "fmt"); ("sname", `Null)] - ; `O [("name", `String "time"); ("sname", `Null)] - ] - ) - ] - ) - ] - ) - ; ( "pvs_proxy" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "tunnel" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "vgpu" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "vm_guest_metrics" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ( "items" - , `A - [ - `O [("name", `String "fmt"); ("sname", `Null)] - ; `O [("name", `String "time"); ("sname", `Null)] - ] - ) - ] - ) - ] - ) - ; ( "certificate" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ( "items" - , `A - [ - `O [("name", `String "fmt"); ("sname", `Null)] - ; `O [("name", `String "time"); ("sname", `Null)] - ] - ) - ] - ) - ] - ) - ; ( "dr_task" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "host" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ( "items" - , `A - [ - `O [("name", `String "fmt"); ("sname", `Null)] - ; `O [("name", `String "time"); ("sname", `Null)] - ] - ) - ] - ) - ] - ) - ; ( "network_sriov" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "pool" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ( "items" - , `A - [ - `O [("name", `String "fmt"); ("sname", `Null)] - ; `O [("name", `String "time"); ("sname", `Null)] - ] - ) - ] - ) - ] - ) - ; ( "pvs_server" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "session" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ( "items" - , `A - [ - `O [("name", `String "fmt"); ("sname", `Null)] - ; `O [("name", `String "time"); ("sname", `Null)] - ] - ) - ] - ) - ] - ) - ; ( "usb_group" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "vgpu_type" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "vm_metrics" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ( "items" - , `A - [ - `O [("name", `String "fmt"); ("sname", `Null)] - ; `O [("name", `String "time"); ("sname", `Null)] - ] - ) - ] - ) - ] - ) - ; ( "cluster" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "event" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ( "items" - , `A - [ - `O [("name", `String "fmt"); ("sname", `Null)] - ; `O [("name", `String "time"); ("sname", `Null)] - ] - ) - ] - ) - ] - ) - ; ( "host_metrics" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ( "items" - , `A - [ - `O [("name", `String "fmt"); ("sname", `Null)] - ; `O [("name", `String "time"); ("sname", `Null)] - ] - ) - ] - ) - ] - ) - ; ( "observer" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "pool_patch" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "pvs_site" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "sm" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "user" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "vif" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ("items", `A [`O [("name", `String "fmt"); ("sname", `Null)]]) - ] - ) - ] - ) - ; ( "vmpp" - , `O - [ - ( "modules" - , `O - [ - ("import", `Bool true) - ; ( "items" - , `A - [ - `O [("name", `String "fmt"); ("sname", `Null)] - ; `O [("name", `String "time"); ("sname", `Null)] - ] - ) - ] - ) - ] - ) - ] diff --git a/ocaml/sdk-gen/go/test_gen_go.ml b/ocaml/sdk-gen/go/test_gen_go.ml index fa9ee5e9a49..c2eb2d0fd67 100644 --- a/ocaml/sdk-gen/go/test_gen_go.ml +++ b/ocaml/sdk-gen/go/test_gen_go.ml @@ -276,16 +276,11 @@ let generated_json_tests = `O [] in let jsons () = - let json = merge record enums in + let json = enums |> merge record |> merge header in let objects = Json.xenapi objects in check_true "Mustache.Json of records has right structure" @@ List.for_all (fun (_, obj) -> is_same_struct obj json) objects in - let headers () = - let open Go_file_headers in - check_true "Mustache.Json of headers has right structure" - @@ List.for_all (fun (_, h) -> is_same_struct h header) headers - in let errors_and_messages () = let errors = `O [("api_errors", `A Json.api_errors)] in let messages = `O [("api_messages", `A Json.api_messages)] in @@ -293,8 +288,7 @@ let generated_json_tests = @@ (is_same_struct errors api_errors && is_same_struct messages api_messages) in [ - ("headers", `Quick, headers) - ; ("jsons", `Quick, jsons) + ("jsons", `Quick, jsons) ; ("errors_and_messages", `Quick, errors_and_messages) ] diff --git a/quality-gate.sh b/quality-gate.sh index 2d055cab12f..8dc9260c3c5 100755 --- a/quality-gate.sh +++ b/quality-gate.sh @@ -25,7 +25,7 @@ verify-cert () { } mli-files () { - N=525 + N=524 # do not count ml files from the tests in ocaml/{tests/perftest/quicktest} MLIS=$(git ls-files -- '**/*.mli' | grep -vE "ocaml/tests|ocaml/perftest|ocaml/quicktest" | xargs -I {} sh -c "echo {} | cut -f 1 -d '.'" \;) MLS=$(git ls-files -- '**/*.ml' | grep -vE "ocaml/tests|ocaml/perftest|ocaml/quicktest" | xargs -I {} sh -c "echo {} | cut -f 1 -d '.'" \;)