ocsigen / eliom

Multi-tier framework for programming web and mobile applications in OCaml.
http://eliom.org
Other
306 stars 53 forks source link

Ocamlbuild plugin not including clientside-fragments placed in serverside-code #403

Open rand00 opened 8 years ago

rand00 commented 8 years ago

When having the main ".eliom" module reference a server-side value from another ".eliom" module (not referencing any client-side values); client-side fragments contained in server-side values in the referenced module will not get linked in the resulting js file. The problem doesn't happen with the makefile template from the distillery as one explicitly declares the client-side files.

A not so pretty fix is making a top-level client value in the referenced module and referring to it in the main module. I havn't found a fix where one explicitly declares files to be included client-side by the plugin - is this possible?

foo.eliom:

(*... excluded beginning of file ...*)

let%client bar = ""
let v () = body [
  div [C.node [%client (pcdata "foo")]]
]

main.eliom:

(*... excluded beginning of file ...*)

(*-> we need this line to make ocamlbuild include fragment from Foo.v thunk*)
let%client _ = Foo.bar

let () =
  Main_app.register
    ~service:main_service
    (fun () () ->
       Lwt.return
         (Eliom_tools.F.html
            ~title
            @@ Foo.v ()
         ))
rand00 commented 8 years ago

Just to clarify the proof of the module Bar not getting linked in, the following is the output of diff between the ocamlbuild log files for respectively the cases where the toplevel client-side value is referenced, and the case where there is only referenced a client-side fragment inside server-value:

$ diff _log-client-value _log-fragment 
36,39d35
< # Target: src/client/bar.ml.depends, tags: { extension:ml, file:src/client/bar.ml, include, ocaml, ocamldep, package(eliom.client), package(eliom.ppx.client), package(lwt.ppx), quiet, traverse }
< ocamlfind ocamldep -package eliom.client -package lwt.ppx -package eliom.ppx.client -ppxopt 'eliom.ppx.client,-type src/type/bar.inferred.mli_eliom' -modules src/client/bar.ml > src/client/bar.ml.depends
< # Target: src/client/bar.cmo, tags: { byte, compile, extension:cmo, extension:ml, file:src/client/bar.cmo, file:src/client/bar.ml, implem, include, ocaml, package(eliom.client), package(eliom.ppx.client), package(lwt.ppx), quiet, traverse }
< ocamlfind ocamlc -c -package eliom.client -package lwt.ppx -package eliom.ppx.client -ppxopt 'eliom.ppx.client,-type src/type/bar.inferred.mli_eliom' -I src -I src/client -I experiments -o src/client/bar.cmo src/client/bar.ml
43c39
< ocamlfind ocamlc -linkpkg -package eliom.client -package lwt.ppx src/client/bar.cmo src/client/rand7plan0.cmo -o src/client/rand7plan0.byte
---
> ocamlfind ocamlc -linkpkg -package eliom.client -package lwt.ppx src/client/rand7plan0.cmo -o src/client/rand7plan0.byte