# HG changeset patch # User Rob Hoes # Date 1274793987 -3600 # Node ID 16c80b1f9915e5955a3978d687464e4a5c8def0d # Parent 5bd8f287caaea12af0043f104c5e9a61ccf79913 Generate API docs in JSON format Signed-off-by: Rob Hoes diff -r 5bd8f287caae -r 16c80b1f9915 .hgignore --- a/.hgignore +++ b/.hgignore @@ -104,6 +104,7 @@ stunnel-4.15/tools/stunnel.init zurich/java/com/xensource/autogen/*.java js/api.js +java ocaml/cdrommon/cdrommon ocaml/console/console ocaml/database/db_filter_lex.ml @@ -115,6 +116,9 @@ ocaml/db_process/xapi-db-process ocaml/db_process/xapi-db-upgrade-4.2 ocaml/doc/content +ocaml/doc/api +ocaml/doc/jsapi +ocaml/doc/components.js ocaml/events/event_listen ocaml/fdhelper/closeandexec ocaml/fdhelper/closeandexec_static diff -r 5bd8f287caae -r 16c80b1f9915 OMakeroot --- a/OMakeroot +++ b/OMakeroot @@ -96,6 +96,17 @@ OCamlDoc($(name), $(modules), "library") # +# Use Camlp4 +# +UseCamlp4(packs, files) = + OCAMLPACKS += $(packs) + OCAMLFINDFLAGS += -syntax camlp4o + $(addsuffix .cmx, $(files)): + $(addsuffix .o, $(files)): + $(addsuffix .cmi, $(files)): + $(addsuffix .cmo, $(files)): + +# # Include the OMakefile in this directory. # .SUBDIRS: . diff -r 5bd8f287caae -r 16c80b1f9915 ocaml/doc/OMakefile --- a/ocaml/doc/OMakefile +++ b/ocaml/doc/OMakefile @@ -2,7 +2,16 @@ BYTE_ENABLED = TRUE OCamlLibrary(odoc_json, odoc_json) +OCAML_LIBS += ../idl/datamodel +OCAMLINCLUDES += ../idl +OCamlProgram(jsapi, jsapi) + +.PHONY: doc +doc: jsapi + mkdir -p api + ./jsapi + .PHONY: clean clean: rm -f *~ *.cmi *.cmx *.cmo *.a *.cma *.cmxa *.run *.opt *.annot *.o - rm -rf components.js content + rm -rf components.js content jsapi diff -r 5bd8f287caae -r 16c80b1f9915 ocaml/doc/jsapi.ml --- /dev/null +++ b/ocaml/doc/jsapi.ml @@ -0,0 +1,27 @@ +(* + * Copyright (C) 2006-2009 Citrix Systems 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 _ = + let api = (* Datamodel_utils.add_implicit_messages *) (Datamodel.all_api) in + let objs = Dm_api.objects_of_api api in + let create_json obj = + let name = obj.Datamodel_types.name in + let s = Jsonrpc.to_string (Datamodel_types.rpc_of_obj obj) in + Unixext.write_string_to_file ("api/" ^ name ^ ".json") s; + name + in + let names = List.map create_json objs in + let class_list = String.concat ", " (List.map (fun s -> "'" ^ s ^ "'") names) in + Unixext.write_string_to_file "api/index.json" ("classes = [" ^ class_list ^ "]") + diff -r 5bd8f287caae -r 16c80b1f9915 ocaml/idl/OMakefile --- a/ocaml/idl/OMakefile +++ b/ocaml/idl/OMakefile @@ -8,6 +8,10 @@ OCAMLINCLUDES = ocaml_backend ../database OCAMLPACKS = xml-light2 sexpr log +CAMLP4_FILES = datamodel_types + +UseCamlp4(rpc-light.syntax, $(CAMLP4_FILES)) + # ----------------------------------------------------------------------- # Build datamodel library # ----------------------------------------------------------------------- diff -r 5bd8f287caae -r 16c80b1f9915 ocaml/idl/datamodel_types.ml --- a/ocaml/idl/datamodel_types.ml +++ b/ocaml/idl/datamodel_types.ml @@ -26,6 +26,12 @@ *) +module Date = struct + include Date + let iso8601_of_rpc rpc = Date.of_string (Rpc.string_of_rpc rpc) + let rpc_of_iso8601 date = Rpc.rpc_of_string (Date.to_string date) +end + (* useful constants for product vsn tracking *) let oss_since_303 = Some "3.0.3" let rel_george = "george" @@ -65,6 +71,7 @@ | Map of ty * ty | Ref of string | Record of string + with rpc type api_value = VString of string @@ -76,7 +83,8 @@ | VMap of (api_value*api_value) list | VSet of api_value list | VRef of string - + with rpc + (** Each database field has a qualifier associated with it: *) type qualifier = | RW @@ -88,13 +96,14 @@ | DynamicRO (** Read-only database field whose value is computed dynamically and not specified at the time of object construction. *) - + with rpc + (** Release keeps track of which versions of opensource/internal products fields and messages are included in *) type release = { opensource: string list; internal: string list; internal_deprecated_since: string option; (* first release we said it was deprecated *) -} +} with rpc (** Messages are tagged with one of these indicating whether the message was specified explicitly in the datamodel, or is one of the automatically @@ -136,7 +145,7 @@ msg_hide_from_docs: bool; msg_allowed_roles: string list option; msg_map_keys_roles: (string * (string list option)) list -} +} and field = { release: release; @@ -153,7 +162,7 @@ field_setter_roles: string list option; field_getter_roles: string list option; field_map_keys_roles: (string * (string list option)) list -} +} and error = { err_name: string; @@ -164,7 +173,7 @@ and mess = { mess_name: string; mess_doc: string; -} +} with rpc (** Getters and Setters will be generated for each field, depending on the qualifier. Namespaces allow fields to be grouped together (and this can get reflected in the XML @@ -173,11 +182,12 @@ type content = | Field of field (** An individual field *) | Namespace of string * content list (** A nice namespace for a group of fields *) - + with rpc + (* Note: there used be more than 2 persist_options -- that's why it isn't a bool. I figured even though there's only 2 now I may as well leave it as an enumeration type.. *) -type persist_option = PersistNothing | PersistEverything +type persist_option = PersistNothing | PersistEverything with rpc (* PersistEverything - all creates/writes persisted; PersistNothing - no creates/writes to this table persisted *) @@ -195,7 +205,10 @@ persist: persist_option; obj_release: release; in_database: bool (* If the object is in the database *) - } + } with rpc + +(* val rpc_of_obj : obj -> Rpc.t *) +(* let s = Jsonrpc.to_string (rpc_of_obj o) *) (** A relation binds two fields together *) type relation = (string * string) * (string * string)