Skip to content

Commit

Permalink
Remove ppx_lwt dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
n-osborne committed Feb 20, 2025
1 parent 0427ec7 commit b9f9628
Show file tree
Hide file tree
Showing 38 changed files with 656 additions and 561 deletions.
1 change: 0 additions & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ The client-side code is compiled to JS using Ocsigen Js_of_ocaml or to Wasm usin
(js_of_ocaml-ppx_deriving_json (>= 5.5.0))
(js_of_ocaml-tyxml (>= 5.5.0))
lwt_log
(lwt_ppx (>= 1.2.3))
(tyxml (and (>= 4.6.0) (< 4.7.0)))
(ocsigenserver (and (>= 6.0.0) (< 7.0.0)))
(ipaddr (>= 2.1))
Expand Down
1 change: 0 additions & 1 deletion eliom.opam
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ depends: [
"js_of_ocaml-ppx_deriving_json" {>= "5.5.0"}
"js_of_ocaml-tyxml" {>= "5.5.0"}
"lwt_log"
"lwt_ppx" {>= "1.2.3"}
"tyxml" {>= "4.6.0" & < "4.7.0"}
"ocsigenserver" {>= "6.0.0" & < "7.0.0"}
"ipaddr" {>= "2.1"}
Expand Down
3 changes: 0 additions & 3 deletions pkg/distillery/templates/app.exe/dune
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
(wrapped false)
(preprocess
(pps
lwt_ppx
; pgocaml_ppx
js_of_ocaml-ppx_deriving_json
; ocsigen-i18n
Expand Down Expand Up @@ -40,7 +39,6 @@
(modules %%%MODULE_NAME%%%_main)
(preprocess
(pps
lwt_ppx
; pgocaml_ppx
js_of_ocaml-ppx_deriving_json
; ocsigen-i18n
Expand Down Expand Up @@ -92,7 +90,6 @@
(preprocess
(pps
js_of_ocaml-ppx
lwt_ppx
; ocsigen-i18n
; --
; --prefix
Expand Down
1 change: 0 additions & 1 deletion pkg/distillery/templates/app.exe/tools!dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
(name eliom_ppx_client)
(modes native)
(modules eliom_ppx_client)
(preprocess (pps lwt_ppx))
(libraries ocsigen-ppx-rpc eliom.ppx.client))

(rule
Expand Down
2 changes: 0 additions & 2 deletions pkg/distillery/templates/app.lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
(wrapped false)
(preprocess
(pps
lwt_ppx
; pgocaml_ppx
js_of_ocaml-ppx_deriving_json
; ocsigen-i18n
Expand Down Expand Up @@ -62,7 +61,6 @@
(preprocess
(pps
js_of_ocaml-ppx
lwt_ppx
; ocsigen-i18n
; --
; --prefix
Expand Down
1 change: 0 additions & 1 deletion pkg/distillery/templates/app.lib/tools!dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
(name eliom_ppx_client)
(modes native)
(modules eliom_ppx_client)
(preprocess (pps lwt_ppx))
(libraries ocsigen-ppx-rpc eliom.ppx.client))

(rule
Expand Down
4 changes: 2 additions & 2 deletions pkg/distillery/templates/basic.ppx/Makefile.options
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ SERVER_FILES := $(wildcard *.eliomi *.eliom)
CLIENT_FILES := $(wildcard *.eliomi *.eliom)

# OCamlfind packages for the server
SERVER_PACKAGES := lwt_ppx js_of_ocaml-ppx_deriving_json
SERVER_PACKAGES := js_of_ocaml-ppx_deriving_json
# OCamlfind packages for the client
CLIENT_PACKAGES := lwt_ppx js_of_ocaml-ppx js_of_ocaml-ppx_deriving_json
CLIENT_PACKAGES := js_of_ocaml-ppx js_of_ocaml-ppx_deriving_json

# Directory with files to be statically served
LOCAL_STATIC = static
Expand Down
7 changes: 3 additions & 4 deletions src/_tags
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ true:keep_locs
<lib/client/client.cma>:eliomstubs

<lib/type_dir/*.ml{,i}>:eliom_ppx,thread
<lib/type_dir/*.ml>:package(js_of_ocaml-ppx_deriving_json,lwt_ppx)
<lib/type_dir/*.ml>:package(js_of_ocaml-ppx_deriving_json)
<lib/type_dir/*.ml>:package(js_of_ocaml-ppx)

<lib/server/*.ml{,i}>:eliom_ppx
<lib/server/*.ml>:package(js_of_ocaml-ppx_deriving_json,lwt_ppx)
<lib/server/*.ml>:package(js_of_ocaml-ppx_deriving_json)
<lib/server/*.ml>:package(js_of_ocaml-ppx)

<lib/server/*.ml{,i}>:thread
Expand All @@ -22,7 +22,7 @@ true:keep_locs
<lib/*.eliom{,i}>:eliom_ppx

<lib/*.ml{,i}>:eliom_ppx
<lib/client/*.ml>:package(js_of_ocaml-ppx_deriving_json,lwt_ppx,js_of_ocaml-lwt.logger)
<lib/client/*.ml>:package(js_of_ocaml-ppx_deriving_json,js_of_ocaml-lwt.logger)
<lib/client/*.ml>:package(js_of_ocaml-ppx)

<lib/client/*.ml{,i}>: eliom_ppx
Expand All @@ -33,7 +33,6 @@ true:keep_locs

<lib/client/*.ml{,i}>:package(js_of_ocaml-ppx_deriving_json)

<lib/server/monitor/*.ml>:package(lwt_ppx)
<lib/server/monitor/*.ml{,i}>:thread
<lib/server/monitor/*.ml{,i}>:package(lwt,ocsigenserver,ocsipersist,tyxml)
<lib/server/monitor/*.ml{,i}>:I(src/lib/server)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/client/dune
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
eliom_shared_sigs
eliom_wrap)
(preprocess
(pps lwt_ppx js_of_ocaml-ppx js_of_ocaml-ppx_deriving_json))
(pps js_of_ocaml-ppx js_of_ocaml-ppx_deriving_json))
(library_flags
(:standard -linkall))
(libraries
Expand Down
38 changes: 21 additions & 17 deletions src/lib/client/eliommod_dom.ml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
open Lwt.Syntax

(* Ocsigen
* http://www.ocsigen.org
* Copyright (C) 2011 Pierre Chambart, Grégoire Henry
Expand Down Expand Up @@ -576,19 +578,21 @@ let rewrite_css_url ~prefix css pos =
let import_re = Regexp.regexp "@import\\s*"

let rec rewrite_css ~max (media, href, css) =
try%lwt
css >>= function
| None -> Lwt.return_nil
| Some css ->
if !Eliom_config.debug_timings
then Firebug.console ## (time (Js.string ("rewrite_CSS: " ^ href)));
let%lwt imports, css =
rewrite_css_import ~max ~prefix:(basedir href) ~media css 0
in
if !Eliom_config.debug_timings
then Firebug.console ## (timeEnd (Js.string ("rewrite_CSS: " ^ href)));
Lwt.return (imports @ [media, css])
with _ -> Lwt.return [media, Printf.sprintf "@import url(%s);" href]
Lwt.catch
(fun () ->
css >>= function
| None -> Lwt.return_nil
| Some css ->
if !Eliom_config.debug_timings
then Firebug.console ## (time (Js.string ("rewrite_CSS: " ^ href)));
let* imports, css =
rewrite_css_import ~max ~prefix:(basedir href) ~media css 0
in
if !Eliom_config.debug_timings
then
Firebug.console ## (timeEnd (Js.string ("rewrite_CSS: " ^ href)));
Lwt.return (imports @ [media, css]))
(fun _ -> Lwt.return [media, Printf.sprintf "@import url(%s);" href])

and rewrite_css_import ?(charset = "") ~max ~prefix ~media css pos =
match Regexp.search import_re css pos with
Expand All @@ -603,7 +607,7 @@ and rewrite_css_import ?(charset = "") ~max ~prefix ~media css pos =
let i = i + String.length (Regexp.matched_string res) in
let i, href = parse_url ~prefix css i in
let i, media' = parse_media css i in
let%lwt import =
let* import =
if max = 0
then
(* Maximum imbrication of @import reached, rewrite url. *)
Expand All @@ -623,7 +627,7 @@ and rewrite_css_import ?(charset = "") ~max ~prefix ~media css pos =
Eliom_request.http_get href [] Eliom_request.string_result
in
rewrite_css ~max:(max - 1) (media, href, css >|= snd)
and imports, css =
and* imports, css =
rewrite_css_import ~charset ~max ~prefix ~media css i
in
Lwt.return (import @ imports, css)
Expand All @@ -636,7 +640,7 @@ and rewrite_css_import ?(charset = "") ~max ~prefix ~media css pos =
let max_preload_depth = ref 4

let build_style (e, css) =
let%lwt css = rewrite_css ~max:!max_preload_depth css in
let* css = rewrite_css ~max:!max_preload_depth css in
(* lwt css = *)
Lwt_list.map_p
(fun (media, css) ->
Expand All @@ -663,7 +667,7 @@ let build_style (e, css) =
let preload_css (doc : Dom_html.element Js.t) =
if !Eliom_config.debug_timings
then Firebug.console ## (time (Js.string "preload_css (fetch+rewrite)"));
let%lwt css = Lwt_list.map_p build_style (fetch_linked_css (get_head doc)) in
let* css = Lwt_list.map_p build_style (fetch_linked_css (get_head doc)) in
let css = List.concat css in
List.iter
(fun (e, css) ->
Expand Down
50 changes: 29 additions & 21 deletions src/lib/eliom_bus.client.ml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
open Lwt.Syntax

(* Ocsigen
* http://www.ocsigen.org
* Copyright (C) 2010-2011
Expand Down Expand Up @@ -39,20 +41,22 @@ type ('a, 'b) t =
(* clone streams such that each clone of the original stream raise the same exceptions *)
let consume (t, u) s =
let t' =
try%lwt Lwt_stream.iter (fun _ -> ()) s
with e ->
(match Lwt.state t with Lwt.Sleep -> Lwt.wakeup_exn u e | _ -> ());
Lwt.fail e
Lwt.catch
(fun () -> Lwt_stream.iter (fun _ -> ()) s)
(fun e ->
(match Lwt.state t with Lwt.Sleep -> Lwt.wakeup_exn u e | _ -> ());
Lwt.fail e)
in
Lwt.choose [Lwt.bind t (fun _ -> Lwt.return_unit); t']

let clone_exn (t, u) s =
let s' = Lwt_stream.clone s in
Lwt_stream.from (fun () ->
try%lwt Lwt.choose [Lwt_stream.get s'; t]
with e ->
(match Lwt.state t with Lwt.Sleep -> Lwt.wakeup_exn u e | _ -> ());
Lwt.fail e)
Lwt.catch
(fun () -> Lwt.choose [Lwt_stream.get s'; t])
(fun e ->
(match Lwt.state t with Lwt.Sleep -> Lwt.wakeup_exn u e | _ -> ());
Lwt.fail e))

type ('a, 'att, 'co, 'ext, 'reg) callable_bus_service =
( unit
Expand All @@ -70,21 +74,25 @@ type ('a, 'att, 'co, 'ext, 'reg) callable_bus_service =

let create service channel waiter =
let write x =
try%lwt
let%lwt _ =
Eliom_client.call_service
~service:(service :> ('a, _, _, _, _) callable_bus_service)
() x
in
Lwt.return_unit
with Eliom_request.Failed_request 204 -> Lwt.return_unit
Lwt.catch
(fun () ->
let* _ =
Eliom_client.call_service
~service:(service :> ('a, _, _, _, _) callable_bus_service)
() x
in
Lwt.return_unit)
(function
| Eliom_request.Failed_request 204 -> Lwt.return_unit
| exc -> Lwt.reraise exc)
in
let error_h =
let t, u = Lwt.wait () in
( (try%lwt
let%lwt _ = t in
assert false
with e -> Lwt.fail e)
( Lwt.catch
(fun () ->
let* _ = t in
assert false)
(fun e -> Lwt.fail e)
, u )
in
let stream =
Expand All @@ -109,7 +117,7 @@ let create service channel waiter =
original channel (i.e. without message lost) is only available in
the first loading phase. *)
let _ =
let%lwt () = Eliom_client.wait_load_end () in
let* () = Eliom_client.wait_load_end () in
t.original_stream_available <- false;
Lwt.return_unit
in
Expand Down
4 changes: 3 additions & 1 deletion src/lib/eliom_bus.server.ml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
open Lwt.Syntax

(* Ocsigen
* http://www.ocsigen.org
* Copyright (C) 2010
Expand Down Expand Up @@ -92,7 +94,7 @@ let create_filtered ?scope ?name ?size ~filter typ =
(*The stream*)
let stream, push = Lwt_stream.create () in
let push x =
let%lwt y = filter x in
let* y = filter x in
push (Some y); Lwt.return_unit
in
let scope =
Expand Down
Loading

0 comments on commit b9f9628

Please sign in to comment.