Repository: mransan/ocaml-protoc
Pull request #202 (2023-08-20 22:50:39)

some refactors
- doc and warnings
- fix typo; remove dead odoc file; improve cmdline argument parsing
- remove dead files, add .mli, close files in codegen



Patch:
diff --git a/.gitignore b/.gitignore
index addd45e..3170801 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,7 +6,6 @@
 *.sw*
 _build
 
-ocaml-protoc
 ocaml_protoc.byte
 ocaml_protoc.native
 
diff --git a/.merlin b/.merlin
deleted file mode 100644
index bb7eccc..0000000
--- a/.merlin
+++ /dev/null
@@ -1,25 +0,0 @@
-S src/
-S src/compilerlib/
-S src/compilerlib/ocaml
-S src/runtime
-
-B _build/src/
-B _build/src/compilerlib/
-B _build/src/compilerlib/ocaml
-B _build/src/runtime
-
-PKG ppx_deriving_protobuf.runtime
-
-####{BSB GENERATED: NO EDIT
-FLG -ppx /Users/maximeransan/Documents/git/ocaml-protoc.git/node_modules/bs-platform/lib/bsppx.exe
-S /Users/maximeransan/Documents/git/ocaml-protoc.git/node_modules/bs-platform/lib/ocaml
-B /Users/maximeransan/Documents/git/ocaml-protoc.git/node_modules/bs-platform/lib/ocaml
-FLG -nostdlib
-FLG -w -30-40+6+7+27+32..39+44+45+101
-S src/runtime-bs/src
-B lib/bs/src/runtime-bs/src
-S src/tests/bs
-B lib/bs/src/tests/bs
-S src/runtime/
-B lib/bs/src/runtime/
-####BSB GENERATED: NO EDIT}
diff --git a/benchs/benchs.ml b/benchs/benchs.ml
index ee3dbff..5c09778 100644
--- a/benchs/benchs.ml
+++ b/benchs/benchs.ml
@@ -554,7 +554,7 @@ module Nested = struct
     *)
 
     let int64_as_varint = varint
-    let int_as_varint i e = (varint [@inlined]) (Int64.of_int i) e
+    let int_as_varint i e = varint (Int64.of_int i) e
 
     let[@inline] key k pk f e =
       let pk' =
diff --git a/src/compilerlib/compilerlib.odocl b/src/compilerlib/compilerlib.odocl
deleted file mode 100644
index 4f205ec..0000000
--- a/src/compilerlib/compilerlib.odocl
+++ /dev/null
@@ -1,33 +0,0 @@
-Pb_exception
-Pb_location
-Pb_logger
-Pb_util
-Pb_field_type
-Pb_option
-
-Pb_parsing
-Pb_parsing_parse_tree
-Pb_parsing_util
-
-Pb_typing
-Pb_typing_graph
-Pb_typing_recursion
-Pb_typing_resolution
-Pb_typing_type_tree
-Pb_typing_util
-Pb_typing_validation
-
-Pb_codegen_backend
-Pb_codegen_util
-Pb_codegen_formatting
-Pb_codegen_sig
-Pb_codegen_ocaml_type
-Pb_codegen_types
-Pb_codegen_default
-Pb_codegen_encode_binary
-Pb_codegen_decode_binary 
-Pb_codegen_encode_yojson
-Pb_codegen_decode_yojson   
-Pb_codegen_encode_bs
-Pb_codegen_decode_bs   
-Pb_codegen_pp
diff --git a/src/compilerlib/dune b/src/compilerlib/dune
index a64b5c5..9613d44 100644
--- a/src/compilerlib/dune
+++ b/src/compilerlib/dune
@@ -5,6 +5,7 @@
 (library
  (name ocaml_protoc_compiler_lib)
  (public_name ocaml-protoc.compiler-lib)
+ (synopsis "Compiler library for ocaml-protoc, to turn .proto files into OCaml code")
  (wrapped true)
  (modules pb_codegen_backend pb_codegen_decode_binary pb_codegen_decode_bs
    pb_codegen_decode_yojson pb_codegen_default pb_codegen_encode_binary
diff --git a/src/compilerlib/pb_codegen_backend.ml b/src/compilerlib/pb_codegen_backend.ml
index 8705b45..a64c6d3 100644
--- a/src/compilerlib/pb_codegen_backend.ml
+++ b/src/compilerlib/pb_codegen_backend.ml
@@ -209,31 +209,31 @@ let compile_field_type ~unsigned_tag all_types file_options field_options
     file_name field_type =
   let ocaml_type =
     match Pb_option.get field_options "ocaml_type" with
-    | Some (Pb_option.Constant_litteral "int_t") -> `Int_t
+    | Some (Pb_option.Constant_literal "int_t") -> `Int_t
     | _ -> `None
   in
 
   let int32_type =
     match Pb_option.get file_options "int32_type" with
-    | Some (Pb_option.Constant_litteral "int_t") -> Ot.(Ft_basic_type Bt_int)
+    | Some (Pb_option.Constant_literal "int_t") -> Ot.(Ft_basic_type Bt_int)
     | _ -> Ot.(Ft_basic_type Bt_int32)
   in
 
   let uint32_type =
     match Pb_option.get file_options "int32_type" with
-    | Some (Pb_option.Constant_litteral "int_t") -> Ot.(Ft_basic_type Bt_int)
+    | Some (Pb_option.Constant_literal "int_t") -> Ot.(Ft_basic_type Bt_int)
     | _ -> Ot.(Ft_basic_type Bt_uint32)
   in
 
   let int64_type =
     match Pb_option.get file_options "int64_type" with
-    | Some (Pb_option.Constant_litteral "int_t") -> Ot.(Ft_basic_type Bt_int)
+    | Some (Pb_option.Constant_literal "int_t") -> Ot.(Ft_basic_type Bt_int)
     | _ -> Ot.(Ft_basic_type Bt_int64)
   in
 
   let uint64_type =
     match Pb_option.get file_options "int64_type" with
-    | Some (Pb_option.Constant_litteral "int_t") -> Ot.(Ft_basic_type Bt_int)
+    | Some (Pb_option.Constant_literal "int_t") -> Ot.(Ft_basic_type Bt_int)
     | _ -> Ot.(Ft_basic_type Bt_uint64)
   in
 
@@ -292,7 +292,7 @@ let is_mutable ?field_name field_options =
 let ocaml_container field_options =
   match Pb_option.get field_options "ocaml_container" with
   | None -> None
-  | Some (Pb_option.Constant_litteral container_name) -> Some container_name
+  | Some (Pb_option.Constant_literal container_name) -> Some container_name
   | Some _ -> None
 
 let variant_of_oneof ?include_oneof_name ~outer_message_names ~unsigned_tag
diff --git a/src/compilerlib/pb_codegen_sig.ml b/src/compilerlib/pb_codegen_sig.ml
index cedc579..d140422 100644
--- a/src/compilerlib/pb_codegen_sig.ml
+++ b/src/compilerlib/pb_codegen_sig.ml
@@ -4,12 +4,14 @@ module type S = sig
     Pb_codegen_ocaml_type.type_ ->
     Pb_codegen_formatting.scope ->
     bool
+  (** Generate a signature file (.mli) *)
 
   val gen_struct :
     ?and_:unit ->
     Pb_codegen_ocaml_type.type_ ->
     Pb_codegen_formatting.scope ->
     bool
+  (** Generate the implementation (.ml) *)
 
   val ocamldoc_title : string
   val file_suffix : string
diff --git a/src/compilerlib/pb_codegen_util.ml b/src/compilerlib/pb_codegen_util.ml
index 20814ce..964e53b 100644
--- a/src/compilerlib/pb_codegen_util.ml
+++ b/src/compilerlib/pb_codegen_util.ml
@@ -1,6 +1,5 @@
 module Ot = Pb_codegen_ocaml_type
 
-(** [sp x] same as sprintf but prefixed with new line *)
 let sp x = Printf.sprintf x
 
 let let_decl_of_and = function
diff --git a/src/compilerlib/pb_logger.mli b/src/compilerlib/pb_logger.mli
index 495e7ba..135b881 100644
--- a/src/compilerlib/pb_logger.mli
+++ b/src/compilerlib/pb_logger.mli
@@ -27,21 +27,21 @@
  *)
 
 val setup_from_out_channel : out_channel -> unit
-(** [setup_from_out_channel oc] will configure the logger to print all 
-    logging statement to [oc]. 
+(** [setup_from_out_channel oc] will configure the logger to print all
+    logging statement to [oc].
 
-    Function can be called multiple times, each call will disable (override) the 
+    Function can be called multiple times, each call will disable (override) the
     previously setup out channel
  *)
 
 val log : ('a, out_channel, unit) format -> 'a
-(** [log format x y ] same as [Printf.printf] except that the message will 
+(** [log format x y ] same as [Printf.printf] except that the message will
     get printed to the previously setup [out_channel] in the
     [setup_from_out_channel] function. 
  *)
 
 val endline : string -> unit
-(** [endline format x y ] same as [Pervasives.print_endline] except that the message will 
+(** [endline str] same as [Stdlib.print_endline str] except that the message will
     get printed to the previously setup [out_channel] in the
-    [setup_from_out_channel] function. 
+    [setup_from_out_channel] function.
  *)
diff --git a/src/compilerlib/pb_option.ml b/src/compilerlib/pb_option.ml
index d1ff42d..d7f3f08 100644
--- a/src/compilerlib/pb_option.ml
+++ b/src/compilerlib/pb_option.ml
@@ -3,7 +3,7 @@ type constant =
   | Constant_bool of bool
   | Constant_int of int
   | Constant_float of float
-  | Constant_litteral of string
+  | Constant_literal of string
 
 type option_name = string
 type t = option_name * constant
diff --git a/src/compilerlib/pb_option.mli b/src/compilerlib/pb_option.mli
index d0f21f9..26686b7 100644
--- a/src/compilerlib/pb_option.mli
+++ b/src/compilerlib/pb_option.mli
@@ -1,14 +1,14 @@
 (** Protobuf File/Message/Field options *)
 
-(** Protobuf constance
-    
+(** Protobuf constant
+
     As defined in: {{:https://goo.gl/FzpQY2} Protobuf Language Spec}. *)
 type constant =
   | Constant_string of string
   | Constant_bool of bool
   | Constant_int of int
   | Constant_float of float
-  | Constant_litteral of string
+  | Constant_literal of string
 
 type option_name = string
 (** Option identifier *)
diff --git a/src/compilerlib/pb_parsing_parser.mly b/src/compilerlib/pb_parsing_parser.mly
index 17dbae3..32b21d5 100644
--- a/src/compilerlib/pb_parsing_parser.mly
+++ b/src/compilerlib/pb_parsing_parser.mly
@@ -373,7 +373,7 @@ constant :
     match (snd $1) with
     | "true"   -> Pb_option.Constant_bool true
     | "false"  -> Pb_option.Constant_bool false
-    | litteral -> Pb_option.Constant_litteral litteral
+    | str -> Pb_option.Constant_literal str
   }
   | T_string     { Pb_option.Constant_string $1 };
 
diff --git a/src/compilerlib/pb_typing_resolution.ml b/src/compilerlib/pb_typing_resolution.ml
index cd22251..2e5b6bc 100644
--- a/src/compilerlib/pb_typing_resolution.ml
+++ b/src/compilerlib/pb_typing_resolution.ml
@@ -197,7 +197,7 @@ let resolve_builtin_type_field_default field_name builtin_type field_default =
 let resolve_enum_field_default field_name type_ field_default =
   match field_default with
   | None -> None
-  | Some (Pb_option.Constant_litteral default_enum_value as constant) ->
+  | Some (Pb_option.Constant_literal default_enum_value as constant) ->
     let { Tt.spec; _ } = type_ in
     (match spec with
     | Tt.Message _ ->
diff --git a/src/compilerlib/pb_util.ml b/src/compilerlib/pb_util.ml
index 65451ce..25f9e26 100644
--- a/src/compilerlib/pb_util.ml
+++ b/src/compilerlib/pb_util.ml
@@ -100,6 +100,15 @@ let read_file file_name =
   close_in ic;
   Bytes.sub_string b 0 !offset
 
+let protect ~finally f =
+  try
+    let x = f () in
+    finally ();
+    x
+  with e ->
+    finally ();
+    raise e
+
 module List = struct
   let rec pop_last = function
     | [] -> failwith "Invalid argument [] for pop_last"
diff --git a/src/compilerlib/pb_util.mli b/src/compilerlib/pb_util.mli
index c16a9b1..e1d0208 100644
--- a/src/compilerlib/pb_util.mli
+++ b/src/compilerlib/pb_util.mli
@@ -65,6 +65,7 @@ end
 (* Option *)
 
 val read_file : string -> string
+val protect : finally:(unit -> unit) -> (unit -> 'a) -> 'a
 
 module List : sig
   val pop_last : 'a list -> 'a list
diff --git a/src/include/ocaml-protoc/.gitignore b/src/include/ocaml-protoc/.gitignore
new file mode 100644
index 0000000..2d4ce60
--- /dev/null
+++ b/src/include/ocaml-protoc/.gitignore
@@ -0,0 +1,1 @@
+ocamloptions.pb.*
diff --git a/src/ocaml-protoc/ocaml_protoc_cmdline.ml b/src/ocaml-protoc/ocaml_protoc_cmdline.ml
index 1acc400..ae7d1c6 100644
--- a/src/ocaml-protoc/ocaml_protoc_cmdline.ml
+++ b/src/ocaml-protoc/ocaml_protoc_cmdline.ml
@@ -23,14 +23,14 @@
 
 *)
 
-(* [ocaml-protoc] provides the ability to override all the custom
- *
- * protobuf file options defined in
- * src/include/ocaml-protoc/ocamloptions.proto as command line arguments.
- *
- * This module implements the bridge functionality between the 2
- * mechanism; command line options are converted to file options and
- * appended there.
+(** [ocaml-protoc] provides the ability to override all the custom
+  
+   protobuf file options defined in
+   [src/include/ocaml-protoc/ocamloptions.proto] as command line arguments.
+  
+   This module implements the bridge functionality between the 2
+   mechanism; command line options are converted to file options and
+   appended there.
  *)
 module File_options = struct
   type t = {
@@ -39,8 +39,10 @@ module File_options = struct
     mutable ocaml_file_ppx: string option;
     mutable ocaml_all_types_ppx: string option;
   }
-  (* all file options supported... this needs to be kept in sync with
-   * src/include/ocaml-protoc/ocamloptions.proto *)
+  (** all file options supported. *)
+
+  (* NOTE: this needs to be kept in sync with
+     src/include/ocaml-protoc/ocamloptions.proto *)
 
   let make () =
     {
@@ -50,7 +52,7 @@ module File_options = struct
       ocaml_all_types_ppx = None;
     }
 
-  (* Compute the command line arguments for be used with the Arg module.  *)
+  (** Compute the command line arguments for be used with the Arg module.  *)
   let cmd_line_args t =
     [
       ( "-int32_type",
@@ -58,19 +60,19 @@ module File_options = struct
           (function
           | "int_t" -> t.int32_type <- Some "int_t"
           | x -> failwith @@ Printf.sprintf "Invalid int32_type value %s" x),
-        "int32_type file option" );
+        " int32_type file option" );
       ( "-int64_type",
         Arg.String
           (function
           | "int_t" -> t.int64_type <- Some "int_t"
           | x -> failwith @@ Printf.sprintf "Invalid int64_type value %s" x),
-        "int64_type file option" );
+        " int64_type file option" );
       ( "-ocaml_file_ppx",
         Arg.String (fun s -> t.ocaml_file_ppx <- Some s),
-        "ocaml_file_ppx file option" );
+        " ocaml_file_ppx file option" );
       ( "-ocaml_all_types_ppx",
         Arg.String (fun s -> t.ocaml_all_types_ppx <- Some s),
-        "ocaml_all_types_ppx file option" );
+        " ocaml_all_types_ppx file option" );
     ]
 
   (** Converts the command line values to Parse Tree file options
@@ -86,30 +88,30 @@ module File_options = struct
         Pb_option.add options option_name option_value
     in
     Pb_option.empty
-    |> map int32_type (fun s -> "int32_type", Pb_option.Constant_litteral s)
-    |> map int64_type (fun s -> "int64_type", Pb_option.Constant_litteral s)
+    |> map int32_type (fun s -> "int32_type", Pb_option.Constant_literal s)
+    |> map int64_type (fun s -> "int64_type", Pb_option.Constant_literal s)
     |> map ocaml_file_ppx (fun s ->
            "ocaml_file_ppx", Pb_option.Constant_string s)
     |> map ocaml_all_types_ppx (fun s ->
            "ocaml_all_types_ppx", Pb_option.Constant_string s)
 end
 
-(* Command line argument for the ocaml-protoc *)
+(** Command line argument for the ocaml-protoc *)
 module Cmdline = struct
   type t = {
-    mutable ml_out: string; (* output directory *)
+    mutable ml_out: string;  (** output directory *)
     mutable proto_file_name: string;
-        (* proto file name as given on the cmd line *)
+        (** proto file name as given on the cmd line *)
     mutable include_dirs: string list;
-        (* include directories given with -I argument *)
-    binary: bool ref; (* whether binary encoding is enabled *)
-    yojson: bool ref; (* whether yojson encoding is enabled *)
-    bs: bool ref; (* whether BuckleScript encoding is enabled *)
-    pp: bool ref; (* whether pretty printing is enabled *)
+        (** include directories given with -I argument *)
+    binary: bool ref;  (** whether binary encoding is enabled *)
+    yojson: bool ref;  (** whether yojson encoding is enabled *)
+    bs: bool ref;  (** whether BuckleScript encoding is enabled *)
+    pp: bool ref;  (** whether pretty printing is enabled *)
     mutable cmd_line_file_options: File_options.t;
-        (* file options override from the cmd line *)
+        (** file options override from the cmd line *)
     unsigned_tag: bool ref;
-        (* if true, unsigned int32/64s will be generated with a polymorphic
+        (** if true, unsigned int32/64s will be generated with a polymorphic
            variant [`unsigned int32/64], otherwise will be emitted as
            immediate [int32/int64]. *)
   }
@@ -129,17 +131,17 @@ module Cmdline = struct
 
   let cmd_line_args t =
     [
-      "-yojson", Arg.Set t.yojson, "generate yojson encoding";
-      "-bs", Arg.Set t.bs, "generate BuckleScript encoding";
-      "-binary", Arg.Set t.binary, "generate binary encoding";
-      "-pp", Arg.Set t.pp, "generate pretty print functions";
+      "-yojson", Arg.Set t.yojson, " generate yojson encoding";
+      "-bs", Arg.Set t.bs, " generate BuckleScript encoding";
+      "-binary", Arg.Set t.binary, " generate binary encoding";
+      "-pp", Arg.Set t.pp, " generate pretty print functions";
       ( "-I",
         Arg.String (fun s -> t.include_dirs <- s :: t.include_dirs),
-        "include directories" );
-      "-ml_out", Arg.String (fun s -> t.ml_out <- s), "output directory";
+        " include directories" );
+      "-ml_out", Arg.String (fun s -> t.ml_out <- s), " output directory";
       ( "-unsigned",
         Arg.Set t.unsigned_tag,
-        "tag uint32 and uint64 types with `unsigned" );
+        " tag uint32 and uint64 types with `unsigned" );
     ]
     @ File_options.cmd_line_args t.cmd_line_file_options
 
@@ -162,7 +164,7 @@ module Cmdline = struct
   let parse () =
     let args = make () in
     let anon_fun = anon_fun args in
-    let cmd_line_args = cmd_line_args args in
+    let cmd_line_args = cmd_line_args args |> Arg.align in
     Arg.parse cmd_line_args anon_fun usage;
     validate args;
     args
diff --git a/src/ocaml-protoc/ocaml_protoc_generation.ml b/src/ocaml-protoc/ocaml_protoc_generation.ml
index 133aec7..aaad4a9 100644
--- a/src/ocaml-protoc/ocaml_protoc_generation.ml
+++ b/src/ocaml-protoc/ocaml_protoc_generation.ml
@@ -31,7 +31,8 @@ module Cmdline = Ocaml_protoc_cmdline.Cmdline
 
 type codegen_f = ?and_:unit -> Ot.type_ -> F.scope -> bool
 
-let generate_for_all_types ocaml_types sc (f : codegen_f) ocamldoc_title =
+let generate_for_all_types ocaml_types sc (f : codegen_f) ocamldoc_title : unit
+    =
   (match ocamldoc_title with
   | None -> ()
   | Some ocamldoc_title ->
@@ -57,7 +58,7 @@ let generate_for_all_types ocaml_types sc (f : codegen_f) ocamldoc_title =
       ())
     ocaml_types
 
-let open_files cmdline file_suffix =
+let open_files cmdline file_suffix f =
   let { Cmdline.ml_out; Cmdline.proto_file_name; _ } = cmdline in
 
   let out_file_name =
@@ -72,9 +73,16 @@ let open_files cmdline file_suffix =
   Printf.printf "Generating %s.mli\n%!" out_file_name;
   Printf.printf "Generating %s.ml\n%!" out_file_name;
 
-  open_out @@ out_file_name ^ ".mli", open_out @@ out_file_name ^ ".ml"
+  let oc_mli = open_out @@ out_file_name ^ ".mli" in
+  let oc_ml = open_out @@ out_file_name ^ ".ml" in
 
-let generate_type_and_default ocaml_types proto_file_options cmdline =
+  Pb_util.protect
+    ~finally:(fun () ->
+      close_out oc_mli;
+      close_out oc_ml)
+    (fun () -> f (oc_mli, oc_ml))
+
+let generate_type_and_default ocaml_types proto_file_options cmdline : unit =
   let file_suffix = "types" in
 
   let print_ppx sc =
@@ -105,11 +113,11 @@ let generate_type_and_default ocaml_types proto_file_options cmdline =
   generate_for_all_types ocaml_types mli_sc Pb_codegen_default.gen_sig
     (Some Pb_codegen_default.ocamldoc_title);
 
-  let sig_oc, struct_oc = open_files cmdline file_suffix in
+  open_files cmdline file_suffix @@ fun (sig_oc, struct_oc) ->
   output_string struct_oc (F.print ml_sc);
   output_string sig_oc (F.print mli_sc)
 
-let generate_mutable_records gen_file_suffix ocaml_types sc =
+let generate_mutable_records gen_file_suffix ocaml_types (sc : F.scope) : unit =
   let ocaml_types = List.flatten ocaml_types in
   List.iter
     (fun { Ot.spec; module_prefix; _ } ->
@@ -148,11 +156,11 @@ let generate_yojson ocaml_types cmdline =
   generate_for_all_types ocaml_types mli_sc Pb_codegen_decode_yojson.gen_sig
     (Some Pb_codegen_decode_yojson.ocamldoc_title);
 
-  let sig_oc, struct_oc = open_files cmdline file_suffix in
+  open_files cmdline file_suffix @@ fun (sig_oc, struct_oc) ->
   output_string struct_oc (F.print ml_sc);
   output_string sig_oc (F.print mli_sc)
 
-let generate_bs ocaml_types cmdline =
+let generate_bs ocaml_types cmdline : unit =
   let file_suffix = "bs" in
 
   (* .ml file *)
@@ -175,7 +183,7 @@ let generate_bs ocaml_types cmdline =
   generate_for_all_types ocaml_types mli_sc Pb_codegen_decode_bs.gen_sig
     (Some Pb_codegen_decode_bs.ocamldoc_title);
 
-  let sig_oc, struct_oc = open_files cmdline file_suffix in
+  open_files cmdline file_suffix @@ fun (sig_oc, struct_oc) ->
   output_string struct_oc (F.print ml_sc);
   output_string sig_oc (F.print mli_sc)
 
@@ -204,7 +212,7 @@ let generate_binary ocaml_types cmdline =
   generate_for_all_types ocaml_types mli_sc Pb_codegen_decode_binary.gen_sig
     (Some Pb_codegen_decode_binary.ocamldoc_title);
 
-  let sig_oc, struct_oc = open_files cmdline file_suffix in
+  open_files cmdline file_suffix @@ fun (sig_oc, struct_oc) ->
   output_string struct_oc (F.print ml_sc);
   output_string sig_oc (F.print mli_sc)
 
@@ -226,18 +234,14 @@ let generate_pp ocaml_types cmdline =
   generate_for_all_types ocaml_types mli_sc Pb_codegen_pp.gen_sig
     (Some Pb_codegen_pp.ocamldoc_title);
 
-  let sig_oc, struct_oc = open_files cmdline file_suffix in
+  open_files cmdline file_suffix @@ fun (sig_oc, struct_oc) ->
   output_string struct_oc (F.print ml_sc);
   output_string sig_oc (F.print mli_sc)
 
-let generate_code ocaml_types proto_file_options cmdline =
+let generate_code ocaml_types proto_file_options cmdline : unit =
   generate_type_and_default ocaml_types proto_file_options cmdline;
-
   if !(cmdline.Cmdline.yojson) then generate_yojson ocaml_types cmdline;
-
   if !(cmdline.Cmdline.binary) then generate_binary ocaml_types cmdline;
-
   if !(cmdline.Cmdline.pp) then generate_pp ocaml_types cmdline;
-
   if !(cmdline.Cmdline.bs) then generate_bs ocaml_types cmdline;
   ()
diff --git a/src/ocaml-protoc/ocaml_protoc_generation.mli b/src/ocaml-protoc/ocaml_protoc_generation.mli
new file mode 100644
index 0000000..3e1f7cc
--- /dev/null
+++ b/src/ocaml-protoc/ocaml_protoc_generation.mli
@@ -0,0 +1,6 @@
+(** Main entrypoint for code generation *)
+
+module Ot = Pb_codegen_ocaml_type
+module Cmdline = Ocaml_protoc_cmdline.Cmdline
+
+val generate_code : Ot.type_ list list -> Pb_option.set -> Cmdline.t -> unit


Test patch:
diff --git a/src/tests/benchmark/ocaml_test_runner.mli b/src/tests/benchmark/ocaml_test_runner.mli
index eb9734b..ece44a4 100644
--- a/src/tests/benchmark/ocaml_test_runner.mli
+++ b/src/tests/benchmark/ocaml_test_runner.mli
@@ -39,4 +39,4 @@ end
 
 (** [Make(T)] returns a module which can execute a test request for type [T.t] 
  *)
-module Make (T : T_sig) : Runner_sig
+module Make (_ : T_sig) : Runner_sig
diff --git a/src/tests/integration-tests/test_proto3_optional.ml b/src/tests/integration-tests/test_proto3_optional.ml
index 6e81c25..bfe4686 100644
--- a/src/tests/integration-tests/test_proto3_optional.ml
+++ b/src/tests/integration-tests/test_proto3_optional.ml
@@ -1,5 +1,4 @@
 open Test_proto3_optional_types
-open Test_proto3_optional_pp
 module Pb = Test_proto3_optional_pb
 
 let foo1 : foo = { x = 1l; y = None; name = Some "hello" }
diff --git a/src/tests/unit-tests/parse_field_options.ml b/src/tests/unit-tests/parse_field_options.ml
index 68873b7..d4ca8e7 100644
--- a/src/tests/unit-tests/parse_field_options.ml
+++ b/src/tests/unit-tests/parse_field_options.ml
@@ -45,7 +45,7 @@ let () =
     parse Pb_parsing_parser.field_options_ "[(ocaml_type) = int]"
   in
   assert (
-    Some (Pb_option.Constant_litteral "int")
+    Some (Pb_option.Constant_literal "int")
     = Pb_option.get field_options "ocaml_type")
 
 let () = print_endline "Parse Field Options ... Ok"