Skip to content

Commit 3fc41ca

Browse files
committed
feat: Provide lib to compile grader helper libraries
and facility to link them during the `build` step. NOTE: the helper library is going to be included in every exercise. A lighter approach could be to keep loading it separately, e.g. after loading the cma/js file from a directory holding static content on the server (and removing the `.cma` from the compilation line in `precompile_exercise.ml`). This will probably fit well once we include such a mechanism for loading custom libraries as the prelude to exercises, the main difference being that the latter will also need the `cmi` files.
1 parent e768616 commit 3fc41ca

File tree

6 files changed

+26
-14
lines changed

6 files changed

+26
-14
lines changed

META.learn-ocaml.template

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package "test_lib" (
2+
directory = "test_lib"
3+
version = "0.13.2"
4+
description = "Learn-ocaml dependencies for automatic graders"
5+
requires = "compiler-libs"
6+
)

src/grader/dune

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -168,20 +168,19 @@
168168
)
169169

170170
;; cmis that are needed to precompile the graders for exercises
171-
;; FIXME: now we install the libs through dune, so use that ??
172171
(install
173-
(section share)
172+
(section lib)
174173
(package learn-ocaml)
175174
(files
176-
(../ppx-metaquot/.ty.objs/byte/ty.cmi as grading_cmis/ty.cmi)
177-
(../ppx-metaquot/.fun_ty.objs/byte/fun_ty.cmi as grading_cmis/fun_ty.cmi)
178-
;; (.exercise_init.objs/byte/exercise_init.cmi as grading_cmis/exercise_init.cmi)
179-
(.introspection_intf.objs/byte/introspection_intf.cmi as grading_cmis/introspection_intf.cmi)
180-
(.pre_test.objs/byte/learnocaml_internal.cmi as grading_cmis/learnocaml_internal.cmi)
181-
(.pre_test.objs/byte/pre_test.cmi as grading_cmis/pre_test.cmi)
182-
(.learnocaml_report.objs/byte/learnocaml_report.cmi as grading_cmis/learnocaml_report.cmi)
183-
(.pre_test.objs/byte/learnocaml_callback.cmi as grading_cmis/learnocaml_callback.cmi) ;;FIXME separate lib??
184-
(.testing_dyn.objs/byte/test_lib.cmi as grading_cmis/test_lib.cmi))
175+
(../ppx-metaquot/.ty.objs/byte/ty.cmi as test_lib/ty.cmi)
176+
(../ppx-metaquot/.fun_ty.objs/byte/fun_ty.cmi as test_lib/fun_ty.cmi)
177+
;; (.exercise_init.objs/byte/exercise_init.cmi as test_lib/exercise_init.cmi)
178+
(.introspection_intf.objs/byte/introspection_intf.cmi as test_lib/introspection_intf.cmi)
179+
(.pre_test.objs/byte/learnocaml_internal.cmi as test_lib/learnocaml_internal.cmi)
180+
(.pre_test.objs/byte/pre_test.cmi as test_lib/pre_test.cmi)
181+
(.learnocaml_report.objs/byte/learnocaml_report.cmi as test_lib/learnocaml_report.cmi)
182+
(.pre_test.objs/byte/learnocaml_callback.cmi as test_lib/learnocaml_callback.cmi) ;;FIXME separate lib??
183+
(.testing_dyn.objs/byte/test_lib.cmi as test_lib/test_lib.cmi))
185184
)
186185

187186

src/grader/learnocaml_internal.mli

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(* This interface is used to pre-compile modules for the toplevel, giving them
2+
access to specific toplevel functions. It should not be made accessible to
3+
the non-precompiled code running in the toplevel *)
4+
include Learnocaml_internal_intf.S

src/repo/learnocaml_precompile_exercise.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ open Lwt.Infix
66
let grading_cmis_dir, grading_ppx_dir =
77
let prefix = Filename.dirname (Filename.dirname (Sys.executable_name)) in
88
let ( / ) = Filename.concat in
9-
ref (prefix/"share"/"learn-ocaml"/"grading_cmis"),
9+
ref (prefix/"lib"/"learn-ocaml"/"test_lib"),
1010
ref (prefix/"lib"/"learn-ocaml"/"grading_ppx")
1111

1212
let run ?dir cmd args =
@@ -91,7 +91,7 @@ let precompile ~exercise_dir =
9191
~source:["test.ml"]
9292
~target:"test.cmo"
9393
>>= fun () ->
94-
ocamlc ~dir ["-a"]
94+
ocamlc ~dir (["-a"] @ grader_flags)
9595
~source:["test.cmo"]
9696
~target:"test.cma"
9797
>>= fun () ->

src/toplevel/dune

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
(library
1212
(name learnocaml_internal_intf)
13-
(public_name learn-ocaml.learnocaml_internal_intf)
1413
(wrapped false)
1514
(modules learnocaml_internal_intf)
1615
(modules_without_implementation learnocaml_internal_intf)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(* (hidden) interface of the module that will be pre-loaded in the toplevel *)
2+
module type S = sig
3+
val register_printer: string -> ('a -> 'b) -> unit
4+
end

0 commit comments

Comments
 (0)