Skip to content

Commit

Permalink
Restore documentation generation and full tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rleonid committed Oct 31, 2016
1 parent 78108da commit fbae00d
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 77 deletions.
5 changes: 0 additions & 5 deletions .ocamlinit
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
(* Need to list all of the sub directories so that Utop
knows where to look. *)
(*
#directory "_lite_build/src/lib" ;;
#load_rec "oml_lite.cma" ;;
print_endline "Loaded Oml_lite" ;;
*)

#directory "_build/src";;
#load_rec "oml.cma";;
Expand Down
27 changes: 19 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
TEST_BUILD_DIR="_test_build"
COVERED_TEST_BUILD_DIR="_covered_test_build"
DOC_BUILD_DIR="_doc_build"

.PHONY: all clean test build setup doc
.PHONY: all clean test build full setup doc

default: FORCE
@echo "available targets:"
@echo " build compiles Oml_lite and Oml if possible"
@echo " build compiles Oml"
@echo " full compiles Omlf"
@echo " test runs unit tests"
@echo " doc generates ocamldoc documentations"
@echo " clean deletes all produced files"
Expand All @@ -25,10 +27,15 @@ setup-test:
#### Building

build:
ocaml pkg/pkg.ml build --with-lacaml false --with-lbfgs false --with-ocephes false

full:
ocaml pkg/pkg.ml build

clean:
ocaml pkg/pkg.ml clean
ocaml pkg/pkg.ml clean --build-dir $(TEST_BUILD_DIR)
ocaml pkg/pkg.ml clean --build-dir $(COVERED_TEST_BUILD_DIR)
ocaml pkg/pkg.ml clean --build-dir $(DOC_BUILD_DIR)

#### Testing

Expand Down Expand Up @@ -58,14 +65,18 @@ clean_reports:

#### Documentation

oml.odocl:
cp src/lib/oml.mlpack oml.odocl
#oml.odocl:
# cp src/lib/oml.mlpack oml.odocl

# including the cmi as build targets triggers all of the including logic
# to get saner documentation.
doc:
$(OCAMLBUILD) -build-dir $(DOC_BUILD_DIR) \
$(foreach package, $(PACKAGES),-package $(package)) \
$(foreach sd, $(SOURCE_DIRS), -I src/lib$(sd)) -I src/lib oml.cmi doc.docdir/index.html
ocamlbuild -classic-display -use-ocamlfind -plugin-tag 'package(str)' -no-links -build-dir $(DOC_BUILD_DIR) -docflags '-colorize-code,-charset,utf-8' doc/api.docdir/index.html

# topkg doc --build-dir $(DOC_BUILD_DIR)
#
# $(OCAMLBUILD) -build-dir $(DOC_BUILD_DIR) \
# $(foreach package, $(PACKAGES),-package $(package)) \
# $(foreach sd, $(SOURCE_DIRS), -I src/lib$(sd)) -I src/lib oml.cmi doc.docdir/index.html

FORCE:
4 changes: 2 additions & 2 deletions _tags
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ true: safe_string, annot, bin_annot, principal, warn(A-42-44-48-50)
<src-full/**> : package(lacaml), package(ocephes), package(lbfgs)
<src/**/*.mlj> : package(kaputt)
<src-full/**/*.mlj> : package(kaputt)
<src-full/cls/*.mlj> : package(dsfo)
<test/**> : package(kaputt)
<test/**> : package(kaputt), package(lacaml), package(ocephes), package(lbfgs)

"_build": -traverse
"_test_build": -traverse
"_covered_test_build": -traverse
"_doc_build": -traverse
1 change: 1 addition & 0 deletions doc/api.odocl
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Oml
Oml_full
91 changes: 51 additions & 40 deletions myocamlbuild.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ let target_with_extension ext =
let is_test_target () =
List.exists (function
| "oml_test.native"
| "oml_lite_test.native" -> true
| "omlf_test.native" -> true
| s when (Filename.basename s = "oml_test.native"
|| Filename.basename s = "oml_lite_test.native") -> true
|| Filename.basename s = "omlf_test.native") -> true
| _ -> false)
!Options.targets

let is_doc_target () =
target_with_extension "html"

let add_ml_and_mlt_and_depends () =
rule "concat ml and mlt files, and build dependencies"
~insert:`top
Expand Down Expand Up @@ -107,8 +110,7 @@ let add_compile_mlj_to_byte_rule () =
Ocaml_compiler.prepare_compile build mlj;
Cmd ( S [ !Options.ocamlc; A"-c"; Ocaml_arch.forpack_flags_of_pathname mlj
; T tags
; (*!Options.ocaml_ppflags tags
; *) Ocaml_utils.ocaml_include_flags mlj
; Ocaml_utils.ocaml_include_flags mlj
; A "-o"; Px cmo
; A "-impl"; P mlj])
end
Expand Down Expand Up @@ -136,8 +138,7 @@ let add_compile_mlj_to_native_rule () =
Ocaml_compiler.prepare_link cmx cmi ["cmx"; "cmi"] build;
Cmd ( S [ !Options.ocamlopt; A"-c"; Ocaml_arch.forpack_flags_of_pathname mlj
; T tags
; (*!Options.ocaml_ppflags tags
; *) Ocaml_utils.ocaml_include_flags mlj
; Ocaml_utils.ocaml_include_flags mlj
; A "-o"; Px cmx (* FIXME ocamlopt bug -o cannot be after the input file *)
; A "-impl"; P mlj])
end
Expand Down Expand Up @@ -165,7 +166,6 @@ let to_mli_assoc =
List.map (fun s ->
String.capitalize_ascii (Filename.chop_extension (Filename.basename s)), s)

(*
let imto_regex =
Str.regexp "include module type of \\([A-Z][a-zA-Z_]+\\)"

Expand All @@ -181,6 +181,7 @@ let rec include_includes modassoc mli =
let ap = Str.match_end () in
try
let file = List.assoc md modassoc in
Printf.printf "inserting %s for %s ----\n" file md;
let bef = String.sub ff pos (np - pos) in
let ic =
if not (Sys.file_exists file) then begin
Expand All @@ -194,6 +195,7 @@ let rec include_includes modassoc mli =
close_in ic;
loop ap (incf :: bef :: acc)
with Not_found -> (* Missing module in modassoc *)
Printf.printf "didn't find %s \n" md;
let bef = String.sub ff pos (ap - pos - 1) in
loop (ap - 1) (bef :: acc)
with Not_found ->
Expand All @@ -205,7 +207,6 @@ let rec include_includes modassoc mli =
let oc = open_out mli in
List.iter (output_string oc) (List.rev lst);
close_out oc
*)

let () =
let additional_rules =
Expand All @@ -217,30 +218,31 @@ let () =
| Before_rules -> ()
| After_rules ->
begin
let regular_source_dirs =
[ "src" (* For the Online stuff that hasn't been packaged. *)
; "src/util"
; "src/unc"
; "src/stats"
; "src/cls"
; "src/rgr"
; "src/uns"
]
in
let full_source_dirs =
[ "src-full"
; "src-full/unc"
; "src-full/stats"
; "src-full/cls"
; "src-full/rgr"
; "src-full/uns"
]
in

if is_test_target () then begin
add_ml_and_mlt_and_depends ();
(*add_lite_ml_and_mlt_and_depends (); *)
add_compile_mlj_to_native_rule ();
add_compile_mlj_to_byte_rule ();
let regular_source_dirs =
[ "src" (* For the Online stuff that hasn't been packaged. *)
; "src/util"
; "src/unc"
; "src/stats"
; "src/cls"
; "src/rgr"
; "src/uns"
]
in
let full_source_dirs =
[ "src-full/unc"
; "src-full/stats"
; "src-full/cls"
; "src-full/rgr"
; "src-full/uns"
]
in

Pathname.define_context "test" regular_source_dirs;
Pathname.define_context "test" full_source_dirs;
List.iter (fun dir -> Pathname.define_context dir [ "test"])
Expand All @@ -258,22 +260,31 @@ let () =
(Ocaml_compiler.byte_compile_ocaml_implem "%.ml" "%.cmo");
*)

(* For documentation.
if target_with_extension "html" then begin
Options.make_links := true;
Pathname.define_context "src/lib"
[ "src/lib"; "src/lib/util"; "src/lib/unc"; "src/lib/stats"
; "src/lib/cls"; "src/lib/rgr"; "src/lib/uns"];
Pathname.define_context "src/lib/cls" ["src/lib/util"; ];
Pathname.define_context "src/lib/rgr" ["src/lib/util"; "src/lib/stats"];
if is_doc_target () then begin
Pathname.define_context "src" regular_source_dirs;
Pathname.define_context "src-full" full_source_dirs;

(* Since ocamldoc doesn't work very well with
"include module type of ___" directives, we'll preprocess the
mli files to manually insert the relevant signature. *)
mli files to manually insert the relevant signature.
1. Get all the mli's.
2. Before compiling them, scan for "include m... sig"
3. If we find this pattern and we have a signature file.
3a. Recurse!
4. Manually insert it into the mli.
*)
let mla =
(all_mli_files "src"
@ all_mli_files "src-full")
|> to_mli_assoc
|> fun l ->
("Oml_cls_intf", "src/cls/oml_cls_intf.ml") ::
("Oml_intf", "src-full/rgr/omlf_intf.ml") ::
l
in
Printf.printf "We have these files:\n%!";
List.iter (fun (m,f) -> Printf.printf "%s\t\t%s\n%!" m f) mla;

let mla = all_mli_files "src" |> to_mli_assoc in
(*Printf.printf "We have these files:\n%!";
List.iter (fun (m,f) -> Printf.printf "%s\t\t%s\n%!" m f) mla; *)
rule "For documentation ocaml: mli -> cmi"
~insert:`top
~deps:[ "%.mli"; "%.mli.depends" ]
Expand All @@ -283,7 +294,7 @@ let () =
include_includes mla mli;
Ocaml_compiler.compile_ocaml_interf "%.mli" "%.cmi" env build
end;
end *)
end
end
in
dispatch additional_rules
22 changes: 12 additions & 10 deletions pkg/pkg.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@
#require "topkg"
open Topkg

let lacaml = Conf.with_pkg ~default:false "lacaml"
let lbfgs = Conf.with_pkg ~default:false "lbfgs"
let ocephes = Conf.with_pkg ~default:false "ocephes"
let lacaml = Conf.with_pkg "lacaml"
let lbfgs = Conf.with_pkg "lbfgs"
let ocephes = Conf.with_pkg "ocephes"
let kaputt = Conf.with_pkg "kaputt"
let bisect_ppx = Conf.with_pkg "bisect_ppx"
let coverage = Conf.with_pkg ~default:false "coverage"
let documentation = Conf.with_pkg ~default:false "documentation"

let () =
let build =
let cmd c os fpaths =
let scmd =
if Conf.value c coverage
then Cmd.((Pkg.build_cmd c os) % "-package" % "bisect_ppx" %% of_list fpaths)
else Cmd.(Pkg.build_cmd c os %% of_list fpaths)
Cmd.(Pkg.build_cmd c os
%% (of_list ["-plugin-tag"; "package(str)"]) (* Cause of Str in myocamlbuild.ml *)
%% on (Conf.value c coverage) (of_list ["-package"; "bisect_ppx"])
%% on (Conf.pkg_name c = "omltest") (of_list [ "-package"; "dsfo"
; "-package"; "kaputt"
])
%% of_list fpaths)
in
OS.Cmd.run scmd
in
Expand All @@ -36,9 +41,6 @@ let () =
let kaputt = Conf.value c kaputt in
(* TODO: Add dsfo! *)
let full = full && kaputt in
Ok [ Pkg.mllib ~api:["Oml"] "src/oml.mllib"
; Pkg.mllib ~cond:full ~api:["Oml_full"] "src-full/oml_full.mllib"
; Pkg.test "test/oml_test"
]
Ok [ Pkg.test (if full then "test/omlf_test" else "test/oml_test") ]
| other ->
R.error_msgf "Unrecognized package name: %s" other
18 changes: 9 additions & 9 deletions test/omlf_modules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@
driver: oml_test.ml. *)

(* Uncategorized. *)
module Svd = Svd
module Omlf_svd = Omlf_svd

(* Statistics. *)
module Oml_functions = Oml_functions
module Distributions = Distributions
module Hypothesis_test = Hypothesis_test
module Omlf_functions = Omlf_functions
module Omlf_distributions = Omlf_distributions
module Omlf_hypothesis_test = Omlf_hypothesis_test

(* Classification. *)
module Logistic_regression = Logistic_regression
module Oml_naive_bayes = Oml_naive_bayes
module Omlf_logistic_regression = Omlf_logistic_regression
module Omlf_naive_bayes = Omlf_naive_bayes

(* Regression. *)
module Multivariate = Multivariate
module Tikhonov = Tikhonov
module Omlf_multivariate = Omlf_multivariate
module Omlf_tikhonov = Omlf_tikhonov

(* Unsupervised. *)
module Pca = Pca
module Omlf_pca = Omlf_pca
2 changes: 1 addition & 1 deletion test/omlf_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

open Test_utils

module Oml_lite_modules = Oml_lite_modules
module Oml_modules = Oml_modules
module Omlf_modules = Omlf_modules

let () =
if Array.length Sys.argv > 1 then
Expand Down
2 changes: 1 addition & 1 deletion test/test_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ module Test = struct
let launch_tests () =
TestMap.bindings !test_holder
|> List.sort ~cmp:compare
|> fun l -> Printf.printf "%d\n" (List.length l); l
|> fun l -> Printf.printf "Testing %d groups.\n" (List.length l); l
|> List.iter ~f:(fun (group, tests) ->
Printf.printf "--%s--\n%!" group;
List.rev tests |> run_tests)
Expand Down
2 changes: 1 addition & 1 deletion tools/travis_ci_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ echo Installing C and Fortran deps
opam install ocephes lacaml lbfgs

echo Compiling with C/Fortran deps
make build
make full

echo Install bisect ppx and ocveralls for coverage reporting
opam install bisect_ppx ocveralls
Expand Down

0 comments on commit fbae00d

Please sign in to comment.