Skip to content

Commit

Permalink
Merge pull request #572 from ocsigen/ppx
Browse files Browse the repository at this point in the history
Completely switch to PPX
  • Loading branch information
balat authored Jan 20, 2020
2 parents 05da8a6 + d1afaed commit fe23316
Show file tree
Hide file tree
Showing 6 changed files with 3,586 additions and 684 deletions.
15 changes: 9 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ all: byte $(OPT_RULE)
byte:: $(LIBDIR)/${PKG_NAME}.server.cma $(LIBDIR)/${PKG_NAME}.client.cma
opt:: $(LIBDIR)/${PKG_NAME}.server.cmxs

rebuild-os-db:
[ ! -z "$(PGHOST)" ] || exit 1
(echo '(* GENERATED CODE, DO NOT EDIT! *)'; \
`ocamlfind query -format "%d/ppx.exe" pgocaml_ppx` \
src/os_db.ppx.ml ) > src/os_db.ml

##----------------------------------------------------------------------
## Aux

Expand Down Expand Up @@ -87,22 +93,22 @@ $(LIBDIR)/$(PKG_NAME).server.cmxa: $(call objs,$(ELIOM_SERVER_DIR),cmx,$(SERVER_
$(ELIOMOPT) -ppx -shared -linkall -o $@ $(GENERATE_DEBUG) $<

${ELIOM_SERVER_DIR}/%_db.cmi: %_db.mli
${ELIOMC} -c ${SERVER_DB_INC} ${SERVER_INC_DIRS} $(GENERATE_DEBUG) $<
${ELIOMC} -ppx -c ${SERVER_DB_INC} ${SERVER_INC_DIRS} $(GENERATE_DEBUG) $<
${ELIOM_SERVER_DIR}/%.cmi: %.mli
${ELIOMC} -ppx -c ${SERVER_INC} ${SERVER_INC_DIRS} $(GENERATE_DEBUG) $<

${ELIOM_SERVER_DIR}/%.cmi: %.eliomi
${ELIOMC} -ppx -c ${SERVER_INC} ${SERVER_INC_DIRS} $(GENERATE_DEBUG) $<

${ELIOM_SERVER_DIR}/%_db.cmo: %_db.ml
${ELIOMC} -c ${SERVER_DB_INC} ${SERVER_INC_DIRS} $(GENERATE_DEBUG) $<
${ELIOMC} -ppx -c ${SERVER_DB_INC} ${SERVER_INC_DIRS} $(GENERATE_DEBUG) $<
${ELIOM_SERVER_DIR}/%.cmo: %.ml
${ELIOMC} -ppx -c ${SERVER_INC} ${SERVER_INC_DIRS} $(GENERATE_DEBUG) $<
${ELIOM_SERVER_DIR}/%.cmo: %.eliom
${ELIOMC} -ppx -c ${SERVER_INC} ${SERVER_INC_DIRS} $(GENERATE_DEBUG) $<

${ELIOM_SERVER_DIR}/%_db.cmx: %_db.ml
${ELIOMOPT} -c ${SERVER_DB_INC} ${SERVER_INC_DIRS} $(GENERATE_DEBUG) $<
${ELIOMOPT} -ppx -c ${SERVER_DB_INC} ${SERVER_INC_DIRS} $(GENERATE_DEBUG) $<
${ELIOM_SERVER_DIR}/%.cmx: %.ml
${ELIOMOPT} -ppx -c ${SERVER_INC} ${SERVER_INC_DIRS} $(GENERATE_DEBUG) $<
${ELIOM_SERVER_DIR}/%.cmx: %.eliom
Expand Down Expand Up @@ -187,9 +193,6 @@ endif
.depend: $(patsubst %,$(DEPSDIR)/%.server,$(SERVER_FILES)) $(patsubst %,$(DEPSDIR)/%.client,$(CLIENT_FILES))
cat $^ > $@

$(DEPSDIR)/%_db.ml.server: %_db.ml | $(DEPSDIR)
$(ELIOMDEP) -server $(SERVER_DB_INC) $(SERVER_DEP_DIRS) $< > $@

$(DEPSDIR)/%.server: % | $(DEPSDIR)
$(ELIOMDEP) -server -ppx $(SERVER_INC) $(SERVER_DEP_DIRS) $< > $@

Expand Down
6 changes: 3 additions & 3 deletions Makefile.options
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ PKG_VERS := 1.1.0
PKG_DESC := Skeleton for building your own Eliom application

# Source files for the server
SERVER_FILES := $(wildcard \
SERVER_FILES := $(filter-out %.ppx.ml,$(wildcard \
src/*.ml* \
src/*.eliom* \
src/view/*.eliom* \
)
))
# Source files for the client
CLIENT_FILES := $(wildcard \
src/*.eliom* \
Expand Down Expand Up @@ -58,7 +58,7 @@ SERVER_PACKAGES := lwt_ppx js_of_ocaml-ppx.deriving calendar safepass \
ocsigen-toolkit.server yojson re.str cohttp-lwt-unix \
netstring

SERVER_DB_PACKAGES := pgocaml macaque.syntax \
SERVER_DB_PACKAGES := lwt_ppx pgocaml pgocaml_ppx \
calendar safepass resource-pooling

# OCamlfind packages for the client
Expand Down
4 changes: 1 addition & 3 deletions opam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
opam-version: "2.0"
name: "ocsigen-start"
version: "2.14.0"
version: "2.15.0"
authors: "dev@ocsigen.org"
maintainer: "dev@ocsigen.org"
synopsis: "An Eliom application skeleton ready to use to build your own application with users, (pre)registration, notifications, etc"
Expand All @@ -15,7 +15,6 @@ depends: [
"ocaml" {>= "4.06.1"}
"pgocaml" {>= "4.0"}
"pgocaml_ppx" {>= "4.0"}
"macaque" {>= "0.7.4"}
"safepass" {>= "3.0"}
"ocsigen-i18n" {>= "3.1.0"}
"eliom" {>= "6.4.0"}
Expand All @@ -28,7 +27,6 @@ depends: [
"cohttp-lwt-unix"
"conf-npm" {>= "1"}
"ocamlnet"
"lwt_camlp4"
]
depexts: [
["imagemagick" "ruby-sass" "postgresql" "postgresql-common"] {os-family = "debian"}
Expand Down
28 changes: 14 additions & 14 deletions src/os_core_db.ml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ let dispose db =
Lwt.catch (fun () -> PGOCaml.close db) (fun _ -> Lwt.return_unit)

let connect () =
lwt h =
let%lwt h =
Lwt_PGOCaml.connect
?host:!host_r
?port:!port_r
Expand All @@ -65,20 +65,20 @@ let connect () =
in
match !init_r with
| Some init ->
lwt () =
try_lwt
let%lwt () =
try%lwt
init h
with exn ->
lwt () = dispose h in
let%lwt () = dispose h in
Lwt.fail exn
in
Lwt.return h
| None ->
Lwt.return h

let validate db =
try_lwt
lwt () = Lwt_PGOCaml.ping db in
try%lwt
let%lwt () = Lwt_PGOCaml.ping db in
Lwt.return_true
with _ ->
Lwt.return_false
Expand All @@ -105,25 +105,25 @@ let connection_pool () = !pool

let use_pool f =
Resource_pool.use !pool @@ fun db ->
try_lwt
try%lwt
f db
with
| Lwt_PGOCaml.Error msg as e ->
Lwt_log.ign_error_f ~section "postgresql protocol error: %s" msg;
lwt () = Lwt_PGOCaml.close db in Lwt.fail e
let%lwt () = Lwt_PGOCaml.close db in Lwt.fail e
| Lwt.Canceled as e ->
Lwt_log.ign_error ~section "thread canceled";
lwt () = PGOCaml.close db in Lwt.fail e
let%lwt () = PGOCaml.close db in Lwt.fail e

let transaction_block db f =
try_lwt
try%lwt
Lwt_PGOCaml.begin_work db >>= fun _ ->
lwt r = f () in
lwt () = Lwt_PGOCaml.commit db in
let%lwt r = f () in
let%lwt () = Lwt_PGOCaml.commit db in
Lwt.return r
with e ->
lwt () =
try_lwt
let%lwt () =
try%lwt
Lwt_PGOCaml.rollback db
with Lwt_PGOCaml.PostgreSQL_Error _ ->
(* If the rollback fails, for instance due to a timeout,
Expand Down
Loading

0 comments on commit fe23316

Please sign in to comment.