From 10bdab4dc6d6be94d6a81b4232e01b5f5324f09d Mon Sep 17 00:00:00 2001 From: Nicolas Berthier Date: Fri, 8 Nov 2013 15:46:31 +0100 Subject: [PATCH] Exclusively use ocamlfind; source documentation generation. - Stripped portions of `myocamlbuild{,_config}.ml' that seem useless when `-use-ocamlfind' is passed to ocamlbuild. - Added some code in `myocamlbuild_config.ml' to be able to generate documentation by merging interface and implementation files. --- .gitignore | 1 + compiler/Makefile | 7 +++ compiler/_tags | 12 ++-- compiler/heptagon/parsing/_tags | 2 +- compiler/main/heptc.ml | 2 - compiler/minils/ctrl-n/_tags | 1 + compiler/myocamlbuild.ml | 1 - compiler/myocamlbuild_config.ml | 101 ++++++++++---------------------- config.in | 2 +- heptc | 2 +- 10 files changed, 48 insertions(+), 83 deletions(-) create mode 100644 compiler/minils/ctrl-n/_tags diff --git a/.gitignore b/.gitignore index f22f710..9c10944 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,4 @@ test/_check_builds lib/java/.classpath /test/async/build/* /test/image_filters/java/* +compiler/doc.odocl diff --git a/compiler/Makefile b/compiler/Makefile index 9527ab7..d8888d3 100644 --- a/compiler/Makefile +++ b/compiler/Makefile @@ -47,3 +47,10 @@ endif clean: $(OCAMLBUILD) -clean + +.PHONY: doc +doc: + find _build -regex '.*.cmi?' -printf '%f\n' \ + | sed -e '/ocamlbuild/ d; s/\(.*\)\.cmi$$/\u\1/' \ + | sort > doc.odocl; + $(OCAMLBUILD) doc.docdir/index.html diff --git a/compiler/_tags b/compiler/_tags index 2023b06..bb54261 100644 --- a/compiler/_tags +++ b/compiler/_tags @@ -1,8 +1,8 @@ or or or or
or :include -<**/*.ml>: debug, dtypes, pkg_ocamlgraph -: camlp4of, use_camlp4 -true:use_menhir -<**/*.{byte,native}>: use_unix, use_str, debug, custom, pkg_menhirLib, pkg_ocamlgraph +<**/*.ml>: debug, dtypes, package(ocamlgraph) +: camlp4of, package(camlp4) +true: use_menhir -
: pkg_lablgtk2, thread -
: pkg_lablgtk2, thread +<**/*.{byte,native}>: package(unix), package(str), debug, custom +<**/heptc.{byte,native}>: package(menhirLib), package(ocamlgraph) +
: package(lablgtk2), thread diff --git a/compiler/heptagon/parsing/_tags b/compiler/heptagon/parsing/_tags index c484f20..5bbadcf 100644 --- a/compiler/heptagon/parsing/_tags +++ b/compiler/heptagon/parsing/_tags @@ -1 +1 @@ -: pkg_menhirLib \ No newline at end of file +: package(menhirLib) diff --git a/compiler/main/heptc.ml b/compiler/main/heptc.ml index 369e6e7..4a7648f 100644 --- a/compiler/main/heptc.ml +++ b/compiler/main/heptc.ml @@ -29,8 +29,6 @@ open Misc -open Modules -open Location open Compiler_utils open Compiler_options diff --git a/compiler/minils/ctrl-n/_tags b/compiler/minils/ctrl-n/_tags new file mode 100644 index 0000000..0c17139 --- /dev/null +++ b/compiler/minils/ctrl-n/_tags @@ -0,0 +1 @@ +<*.mli>: doc_use_interf_n_implem, merge(A) diff --git a/compiler/myocamlbuild.ml b/compiler/myocamlbuild.ml index 775f69c..61636e6 100644 --- a/compiler/myocamlbuild.ml +++ b/compiler/myocamlbuild.ml @@ -31,7 +31,6 @@ open Ocamlbuild_plugin.Options open Myocamlbuild_config let df = function - | Before_options -> ocamlfind_before_options () | After_rules -> ocamlfind_after_rules (); diff --git a/compiler/myocamlbuild_config.ml b/compiler/myocamlbuild_config.ml index e63553b..7420a02 100644 --- a/compiler/myocamlbuild_config.ml +++ b/compiler/myocamlbuild_config.ml @@ -28,85 +28,44 @@ (***********************************************************************) open Ocamlbuild_plugin -(* these functions are not really officially exported *) -let run_and_read = Ocamlbuild_pack.My_unix.run_and_read -let blank_sep_strings = Ocamlbuild_pack.Lexers.blank_sep_strings - -let split s ch = - let x = ref [] in - let rec go s = - let pos = String.index s ch in - x := (String.before s pos)::!x; - go (String.after s (pos + 1)) - in - try - go s - with Not_found -> !x - -let split_nl s = split s '\n' - -let before_space s = - try - String.before s (String.index s ' ') - with Not_found -> s - -(* this lists all supported packages *) -let find_packages () = - List.map before_space (split_nl & run_and_read "ocamlfind list") - (* this is supposed to list available syntaxes, but I don't know how to do it. *) let find_syntaxes () = ["camlp4o"; "camlp4r"] -(* ocamlfind command *) -let ocamlfind x = S[A"ocamlfind"; x] - let ocamlfind_query pkg = let cmd = Printf.sprintf "ocamlfind query %s" (Filename.quote pkg) in Ocamlbuild_pack.My_unix.run_and_open cmd (fun ic -> input_line ic) -let ocamlfind_before_options () = - (* by using Before_options one let command line options have an higher priority *) - (* on the contrary using After_options will guarantee to have the higher priority *) - - (* override default commands by ocamlfind ones *) - Options.ocamlc := ocamlfind & A"ocamlc"; - Options.ocamlopt := ocamlfind & A"ocamlopt"; - Options.ocamldep := ocamlfind & A"ocamldep"; - Options.ocamldoc := ocamlfind & A"ocamldoc"; - Options.ocamlmktop := ocamlfind & A"ocamlmktop" - let ocamlfind_after_rules () = - (* When one link an OCaml library/binary/package, one should use -linkpkg *) - flag ["ocaml"; "link"; "program"] & A"-linkpkg"; - (* For each ocamlfind package one inject the -package option when - * compiling, computing dependencies, generating documentation and - * linking. *) - List.iter begin fun pkg -> - flag ["ocaml"; "compile"; "pkg_"^pkg] & S[A"-package"; A pkg]; - flag ["ocaml"; "ocamldep"; "pkg_"^pkg] & S[A"-package"; A pkg]; - flag ["ocaml"; "doc"; "pkg_"^pkg] & S[A"-package"; A pkg]; - flag ["ocaml"; "link"; "pkg_"^pkg] & S[A"-package"; A pkg]; - flag ["ocaml"; "infer_interface"; "pkg_"^pkg] & S[A"-package"; A pkg]; - end (find_packages ()); + (* Like -package but for extensions syntax. Morover -syntax is useless + * when linking. *) + List.iter begin fun syntax -> + flag ["ocaml"; "compile"; "syntax_"^syntax] & S[A"-syntax"; A syntax]; + flag ["ocaml"; "ocamldep"; "syntax_"^syntax] & S[A"-syntax"; A syntax]; + flag ["ocaml"; "doc"; "syntax_"^syntax] & S[A"-syntax"; A syntax]; + flag ["ocaml"; "infer_interface"; "syntax_"^syntax] & S[A"-syntax"; A syntax]; + end (find_syntaxes ()); - (* Like -package but for extensions syntax. Morover -syntax is useless - * when linking. *) - List.iter begin fun syntax -> - flag ["ocaml"; "compile"; "syntax_"^syntax] & S[A"-syntax"; A syntax]; - flag ["ocaml"; "ocamldep"; "syntax_"^syntax] & S[A"-syntax"; A syntax]; - flag ["ocaml"; "doc"; "syntax_"^syntax] & S[A"-syntax"; A syntax]; - flag ["ocaml"; "infer_interface"; "syntax_"^syntax] & S[A"-syntax"; A syntax]; - end (find_syntaxes ()); + (* Use both ml and mli files to build documentation: *) + rule "ocaml: ml & mli -> odoc" + ~insert:`top + ~tags:["ocaml"; "doc"; "doc_use_interf_n_implem"] + ~prod:"%.odoc" + (* "%.cmo" so that cmis of ml dependencies are already built: *) + ~deps:["%.ml"; "%.mli"; "%.cmo"] + begin fun env build -> + let mli = env "%.mli" and ml = env "%.ml" and odoc = env "%.odoc" in + let tags = + (Tags.union (tags_of_pathname mli) (tags_of_pathname ml)) + ++"doc_use_interf_n_implem"++"ocaml"++"doc" in + let include_dirs = Pathname.include_dirs_of (Pathname.dirname ml) in + let include_flags = + List.fold_right (fun p acc -> A"-I" :: A p :: acc) include_dirs [] in + Cmd (S [!Options.ocamldoc; A"-dump"; Px odoc; + T (tags++"doc"++"pp"); S (include_flags); + A"-intf"; P mli; A"-impl"; P ml]) + end; - (* The default "thread" tag is not compatible with ocamlfind. - Indeed, the default rules add the "threads.cma" or "threads.cmxa" - options when using this tag. When using the "-linkpkg" option with - ocamlfind, this module will then be added twice on the command line. - - To solve this, one approach is to add the "-thread" option when using - the "threads" package using the previous plugin. - *) - flag ["ocaml"; "pkg_threads"; "compile"] (S[A "-thread"]); - flag ["ocaml"; "pkg_threads"; "link"] (S[A "-thread"]); - flag ["ocaml"; "pkg_threads"; "infer_interface"] (S[A "-thread"]) + (* Specifying merge options. *) + pflag ["ocaml"; "doc"; "doc_use_interf_n_implem"] "merge" + (fun s -> S[A"-m"; A s]); diff --git a/config.in b/config.in index 4d84aa0..09f6119 100644 --- a/config.in +++ b/config.in @@ -16,7 +16,7 @@ INSTALL_BINDIR=$(bindir) INSTALL_LIBDIR=$(libdir)/heptagon STDLIB_DIR=@stdlib_dir@ -OCAMLBUILD=STDLIB=$(STDLIB_DIR) @OCAMLBUILD@ +OCAMLBUILD=STDLIB=$(STDLIB_DIR) @OCAMLBUILD@ -use-ocamlfind TARGET=byte ENABLE_SIMULATOR=@enable_simulator@ diff --git a/heptc b/heptc index 16904e6..73f5aea 100755 --- a/heptc +++ b/heptc @@ -33,7 +33,7 @@ then HEPTC=$HEPTC_DEBUG else pushd "$COMPILER_DIR" > /dev/null - ocamlbuild -j 0 "$COMPILER" + ocamlbuild -use-ocamlfind -j 0 "$COMPILER" popd > /dev/null fi fi