Skip to content

Commit

Permalink
ocamlformat the whole project
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Rochel committed Feb 11, 2022
1 parent 1fed6fa commit c7a6d46
Show file tree
Hide file tree
Showing 180 changed files with 21,394 additions and 22,641 deletions.
32 changes: 32 additions & 0 deletions .ocamlformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version=0.19.0
break-cases = fit
break-collection-expressions = fit-or-vertical
break-fun-decl = wrap
break-fun-sig = wrap
break-infix = wrap
break-infix-before-func = false
break-sequences = false
break-separators = before
break-string-literals = never
break-struct = force
cases-matching-exp-indent = compact
doc-comments = after-when-possible
dock-collection-brackets = false
indicate-multiline-delimiters = no
infix-precedence = indent
let-and = compact
let-binding-spacing = compact
module-item-spacing = compact
parens-tuple = multi-line-only
parens-tuple-patterns = multi-line-only
sequence-style = terminator
sequence-blank-line = compact
single-case = compact
type-decl = compact
if-then-else = keyword-first
field-space = loose
space-around-arrays = false
space-around-records = false
space-around-lists = false
space-around-variants = false
ocp-indent-compat = true
107 changes: 58 additions & 49 deletions build/build.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
open Ocamlbuild_plugin
module Pack = Ocamlbuild_pack

let best = if Sys.command "command -v ocamlopt > /dev/null" = 0 then "native" else "byte"
let best =
if Sys.command "command -v ocamlopt > /dev/null" = 0 then "native" else "byte"

module Conf = struct
let server_dir = "server"
Expand All @@ -10,63 +11,71 @@ module Conf = struct
end

module Intern = struct

let with_eliom_ppx = Some begin function
| `Client -> "src/ppx/ppx_eliom_client_ex." ^ best
| `Server -> "src/ppx/ppx_eliom_server_ex." ^ best
end
let with_eliom_ppx =
Some
(function
| `Client -> "src/ppx/ppx_eliom_client_ex." ^ best
| `Server -> "src/ppx/ppx_eliom_server_ex." ^ best)

let with_package = function
| "eliom.ppx.type" -> "pkg_ppx_eliom_types"
| "eliom.ppx.client"
| "eliom.ppx.server"
| "eliom.syntax.predef"
| "eliom.client"
| "eliom.server" -> (* do noting in this case *) "pkg_dummy"
| "eliom.ppx.client" | "eliom.ppx.server" | "eliom.syntax.predef"
| "eliom.client" | "eliom.server" ->
(* do noting in this case *) "pkg_dummy"
| _ -> assert false
end

module Eliom_plugin = Ocamlbuild_eliom.MakeIntern(Intern)(Conf)

let _ = dispatch (fun x ->
Eliom_plugin.dispatcher x;
match x with
| After_rules ->
Doc.init ();

let link source dest =
rule (Printf.sprintf "%s -> %s" source dest) ~dep:source ~prod:dest
(fun env _ -> Cmd (S [A"ln"; A"-f";P (env source); P (env dest)])) in

(* add I pflag *)
pflag [ "ocaml"; "compile"] "I" (fun x -> S[A"-I"; A x]);
pflag [ "ocaml"; "infer_interface"] "I" (fun x -> S[A"-I"; A x]);
pflag [ "ocaml"; "doc"] "I" (fun x -> S[A"-I"; A x]);
module Eliom_plugin = Ocamlbuild_eliom.MakeIntern (Intern) (Conf)

(* add syntax extension *)
let add_syntax name path =
let bytes_dep = Findlib.(link_flags_byte [query "bytes"]) in
(* hack : not dep when "compile" to avoid the extension syntax to be link with binaries *)
(* the dep with ocamldep make sure the extension syntax is compiled before *)
flag ["ocaml";"compile";"pkg_"^name] (S [A "-ppx" ;P (path ^ name ^ "_ex." ^ best) ]);
flag_and_dep ["ocaml";"ocamldep";"pkg_"^name] (S [A "-ppx" ;P (path ^ name ^ "_ex." ^ best) ]);
flag_and_dep ["ocaml";"infer_interface";"pkg_"^name] (S [A "-ppx" ;P (path ^ name ^ "_ex." ^ best) ]);
flag_and_dep ["doc";"pkg_"^name] (S [A "-ppx" ;P (path ^ name ^ "_ex." ^ best) ]) in

add_syntax "ppx_eliom_utils" "src/ppx/";
add_syntax "ppx_eliom_types" "src/ppx/";

(* link executable aliases *)
let link_exec f t =
link (Printf.sprintf "src/tools/%s.byte" f) (Printf.sprintf "src/tools/%s.byte" t);
link (Printf.sprintf "src/tools/%s.native" f) (Printf.sprintf "src/tools/%s.native" t);
in
List.iter (link_exec "eliomc") [ "eliomopt";"eliomcp";"js_of_eliom"];
link_exec "distillery" "eliom-distillery";
| _ -> ())
let _ =
dispatch (fun x ->
Eliom_plugin.dispatcher x;
match x with
| After_rules ->
Doc.init ();
let link source dest =
rule (Printf.sprintf "%s -> %s" source dest) ~dep:source ~prod:dest
(fun env _ ->
Cmd (S [A "ln"; A "-f"; P (env source); P (env dest)]))
in
(* add I pflag *)
pflag ["ocaml"; "compile"] "I" (fun x -> S [A "-I"; A x]);
pflag ["ocaml"; "infer_interface"] "I" (fun x -> S [A "-I"; A x]);
pflag ["ocaml"; "doc"] "I" (fun x -> S [A "-I"; A x]);
(* add syntax extension *)
let add_syntax name path =
let bytes_dep = Findlib.(link_flags_byte [query "bytes"]) in
(* hack : not dep when "compile" to avoid the extension syntax to be link with binaries *)
(* the dep with ocamldep make sure the extension syntax is compiled before *)
flag
["ocaml"; "compile"; "pkg_" ^ name]
(S [A "-ppx"; P (path ^ name ^ "_ex." ^ best)]);
flag_and_dep
["ocaml"; "ocamldep"; "pkg_" ^ name]
(S [A "-ppx"; P (path ^ name ^ "_ex." ^ best)]);
flag_and_dep
["ocaml"; "infer_interface"; "pkg_" ^ name]
(S [A "-ppx"; P (path ^ name ^ "_ex." ^ best)]);
flag_and_dep ["doc"; "pkg_" ^ name]
(S [A "-ppx"; P (path ^ name ^ "_ex." ^ best)])
in
add_syntax "ppx_eliom_utils" "src/ppx/";
add_syntax "ppx_eliom_types" "src/ppx/";
(* link executable aliases *)
let link_exec f t =
link
(Printf.sprintf "src/tools/%s.byte" f)
(Printf.sprintf "src/tools/%s.byte" t);
link
(Printf.sprintf "src/tools/%s.native" f)
(Printf.sprintf "src/tools/%s.native" t)
in
List.iter (link_exec "eliomc") ["eliomopt"; "eliomcp"; "js_of_eliom"];
link_exec "distillery" "eliom-distillery"
| _ -> ())

let _ =
Options.make_links:=false;
Options.make_links := false;
Options.plugin := false;
Options.use_ocamlfind := true;
Ocamlbuild_unix_plugin.setup ();
Expand Down
40 changes: 19 additions & 21 deletions build/doc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,37 @@ let ocamldoc_man tags deps docout docdir =
let init_wikidoc () =
try
let wikidoc_dir =
let base = Ocamlbuild_pack.My_unix.run_and_read "ocamlfind query wikidoc" in
let base =
Ocamlbuild_pack.My_unix.run_and_read "ocamlfind query wikidoc"
in
String.sub base 0 (String.length base - 1)
in

Ocamlbuild_pack.Rule.rule
"ocamldoc: document ocaml project odocl & *odoc -> wikidocdir"
~insert:`top
~prod:"%.wikidocdir/index.wiki"
~stamp:"%.wikidocdir/wiki.stamp"
~dep:"%.odocl"
~insert:`top ~prod:"%.wikidocdir/index.wiki"
~stamp:"%.wikidocdir/wiki.stamp" ~dep:"%.odocl"
(Ocamlbuild_pack.Ocaml_tools.document_ocaml_project
~ocamldoc:ocamldoc_wiki
"%.odocl" "%.wikidocdir/index.wiki" "%.wikidocdir");
flag ["wikidoc"] & S[A"-colorize-code";A"-i";A wikidoc_dir;A"-g";A"odoc_wiki.cma"];
pflag ["wikidoc"] "subproject" (fun sub -> S [A"-passopt";A "-subproject"; A sub])

with Failure e -> () (* Silently fail if the package wikidoc isn't available *)
~ocamldoc:ocamldoc_wiki "%.odocl" "%.wikidocdir/index.wiki"
"%.wikidocdir");
flag ["wikidoc"]
& S [A "-colorize-code"; A "-i"; A wikidoc_dir; A "-g"; A "odoc_wiki.cma"];
pflag ["wikidoc"] "subproject" (fun sub ->
S [A "-passopt"; A "-subproject"; A sub])
with Failure e -> ()
(* Silently fail if the package wikidoc isn't available *)

let init_mandoc () =
Ocamlbuild_pack.Rule.rule
"ocamldoc: document ocaml project odocl & *odoc -> mandocdir"
~insert:`top
~prod:"%.mandocdir/man.%(ext)"
~stamp:"%.mandocdir/man.%(ext).stamp"
"ocamldoc: document ocaml project odocl & *odoc -> mandocdir" ~insert:`top
~prod:"%.mandocdir/man.%(ext)" ~stamp:"%.mandocdir/man.%(ext).stamp"
~dep:"%.odocl"
(Ocamlbuild_pack.Ocaml_tools.document_ocaml_project
~ocamldoc:ocamldoc_man
(Ocamlbuild_pack.Ocaml_tools.document_ocaml_project ~ocamldoc:ocamldoc_man
"%.odocl" "%.mandocdir/man.%(ext)" "%.mandocdir");
pflag ["apiref"] "man_ext" (fun ext -> S[A"-man-mini";A "-man-section"; A ext; A"-man-suffix";A ext])

pflag ["apiref"] "man_ext" (fun ext ->
S [A "-man-mini"; A "-man-section"; A ext; A "-man-suffix"; A ext])

let init () =
init_wikidoc ();
init_mandoc ();
(* ocamldoc intro *)
pflag_and_dep ["doc"] "with_intro" (fun f -> S [A "-intro"; P f]);
pflag_and_dep ["doc"] "with_intro" (fun f -> S [A "-intro"; P f])
Loading

0 comments on commit c7a6d46

Please sign in to comment.