Opam: fix some dependencies and add some scripts/opam-*.sh.

Installation:

   `./scripts/opam-pin.sh && opam install tezos-node tezos-client`

Upgrade installed packages after a `git pull` (opam2 only):

   `./scripts/opam-upgrade.sh`

Remove and cleanup every from the opam repo:

   `./scripts/opam-unpin.sh`
This commit is contained in:
Grégoire Henry 2017-12-06 19:51:49 +01:00 committed by Grégoire
parent 2471232766
commit d2708740c8
45 changed files with 308 additions and 116 deletions

View File

@ -6,6 +6,8 @@ tezos-node
tezos-protocol-compiler
tezos-client
scripts/opam-test-all.sh.DONE
**/.merlin
**/*~

2
.gitignore vendored
View File

@ -6,6 +6,8 @@
/tezos-protocol-compiler
/tezos-client
/scripts/opam-test-all.sh.DONE
.merlin
*~

View File

@ -10,6 +10,9 @@ depends: [
"ocamlfind" { build }
"jbuilder" { build & >= "1.0+beta15" }
"tezos-base"
"tezos-embedded-client-genesis"
"tezos-embedded-client-alpha"
"tezos-client-base"
]
build: [
[ "jbuilder" "build" "-p" name "-j" jobs ]

View File

@ -12,7 +12,8 @@
tezos-embedded-protocol-genesis
tezos-embedded-protocol-demo
tezos-embedded-protocol-alpha
cmdliner))
cmdliner
ssl))
(flags (:standard -w -9+27-30-32-40@8
-safe-string
-open Tezos_base__TzPervasives

View File

@ -14,6 +14,7 @@ depends: [
"tezos-embedded-protocol-demo"
"tezos-embedded-protocol-alpha"
"cmdliner"
"ssl"
]
build: [
[ "jbuilder" "build" "-p" name "-j" jobs ]

View File

@ -9,14 +9,14 @@ license: "unreleased"
depends: [
"ocamlfind" { build }
"jbuilder" { build & >= "1.0+beta15" }
"base-bigarray"
"tezos-stdlib"
"tezos-stdlib-lwt"
"tezos-crypto"
"tezos-data-encoding"
"tezos-error-monad"
"ezjsonm"
"ezjsonm" { >= "0.5.0" }
"calendar"
"mtime" { >= "1.0.0" }
]
build: [
[ "jbuilder" "build" "-p" name "-j" jobs ]

View File

@ -201,7 +201,7 @@ class type rpc_sig = object
RPC.meth ->
string list ->
Data_encoding.json ->
('a * Cohttp.Code.status_code * Cohttp_lwt_body.t)
('a * Cohttp.Code.status_code * Cohttp_lwt.Body.t)
Error_monad.tzresult Lwt.t
method parse_answer :
(unit, 'b, 'c, 'd) RPC.service ->
@ -220,7 +220,7 @@ class rpc config = object (self)
RPC.meth ->
string list ->
Data_encoding.json ->
(a * Cohttp.Code.status_code * Cohttp_lwt_body.t)
(a * Cohttp.Code.status_code * Cohttp_lwt.Body.t)
Error_monad.tzresult Lwt.t =
fun log_request meth service json ->
let scheme = if config.tls then "https" else "http" in
@ -229,7 +229,7 @@ class rpc config = object (self)
Uri.make ~scheme ~host:config.host ~port:config.port ~path () in
let reqbody = Data_encoding_ezjsonm.to_string json in
Lwt.catch begin fun () ->
let body = Cohttp_lwt_body.of_string reqbody in
let body = Cohttp_lwt.Body.of_string reqbody in
Cohttp_lwt_unix.Client.call
(meth :> Cohttp.Code.meth) ~body uri >>= fun (code, ansbody) ->
log_request uri json >>= fun reqid ->
@ -249,7 +249,7 @@ class rpc config = object (self)
meth service json >>=? fun (reqid, code, ansbody) ->
match code with
| #Cohttp.Code.success_status ->
let ansbody = Cohttp_lwt_body.to_stream ansbody in
let ansbody = Cohttp_lwt.Body.to_stream ansbody in
let json_st = Data_encoding_ezjsonm.from_stream ansbody in
let parsed_st, push = Lwt_stream.create () in
let rec loop () =
@ -271,7 +271,7 @@ class rpc config = object (self)
Lwt.async loop ;
return parsed_st
| err ->
Cohttp_lwt_body.to_string ansbody >>= fun ansbody ->
Cohttp_lwt.Body.to_string ansbody >>= fun ansbody ->
logger.log_error reqid code ansbody >>= fun () ->
fail config (Request_failed (service, err))
@ -293,7 +293,7 @@ class rpc config = object (self)
let Logger logger = config.logger in
self#make_request logger.log_request
meth service json >>=? fun (reqid, code, ansbody) ->
Cohttp_lwt_body.to_string ansbody >>= fun ansbody ->
Cohttp_lwt.Body.to_string ansbody >>= fun ansbody ->
match code with
| #Cohttp.Code.success_status -> begin
if ansbody = "" then
@ -331,7 +331,7 @@ let make_request config log_request meth service json =
Uri.make ~scheme ~host:config.host ~port:config.port ~path () in
let reqbody = Data_encoding_ezjsonm.to_string json in
Lwt.catch begin fun () ->
let body = Cohttp_lwt_body.of_string reqbody in
let body = Cohttp_lwt.Body.of_string reqbody in
Cohttp_lwt_unix.Client.call
(meth :> Cohttp.Code.meth)
~body uri >>= fun (code, ansbody) ->

View File

@ -39,7 +39,7 @@ class type rpc_sig = object
RPC.meth ->
string list ->
Data_encoding.json ->
('a * Cohttp.Code.status_code * Cohttp_lwt_body.t)
('a * Cohttp.Code.status_code * Cohttp_lwt.Body.t)
Error_monad.tzresult Lwt.t
method parse_answer :
(unit, 'b, 'c, 'd) RPC.service ->

View File

@ -9,9 +9,13 @@ license: "unreleased"
depends: [
"ocamlfind" { build }
"jbuilder" { build & >= "1.0+beta15" }
"base-bigarray"
"tezos-base"
"lwt"
"tezos-stdlib"
"tezos-stdlib-lwt"
"tezos-data-encoding"
"tezos-error-monad"
"nocrypto"
"sodium"
"zarith"
]
build: [
[ "jbuilder" "build" "-p" name "-j" jobs ]

View File

@ -9,7 +9,6 @@ license: "unreleased"
depends: [
"ocamlfind" { build }
"jbuilder" { build & >= "1.0+beta15" }
"base-bigarray"
"tezos-stdlib"
"ocplib-json-typed"
"ocplib-endian"

View File

@ -11,7 +11,7 @@ depends: [
"jbuilder" { build & >= "1.0+beta15" }
"tezos-base"
"tezos-embedded-protocol-alpha"
"tezos-embedded-protocol-alpha.raw"
"tezos-node-services"
"tezos-client-base"
]
build: [

View File

@ -11,9 +11,8 @@ depends: [
"jbuilder" { build & >= "1.0+beta15" }
"tezos-base"
"tezos-embedded-protocol-genesis"
"tezos-embedded-protocol-genesis.raw"
"tezos-embedded-protocol-alpha.environment"
"tezos-embedded-protocol-alpha.raw"
"tezos-embedded-protocol-alpha"
"tezos-node-services"
"tezos-client-base"
]
build: [

View File

@ -9,11 +9,14 @@ license: "unreleased"
depends: [
"ocamlfind" { build }
"jbuilder" { build & >= "1.0+beta15" }
"base-bigarray"
"tezos-base"
"uutf"
"tezos-protocol-compiler"
"tezos-node-updater"
"tezos-node-shell"
]
build: [
[ "rm" "jbuild" "src/jbuild" ]
[ "cp" "%{tezos-protocol-compiler:share}%/jbuild_embedded_protocol_template" "src/jbuild" ]
[ "sed" "-i" "s/let predefined_version = None/let predefined_version = Some \"alpha\"/" "src/jbuild" ]
[ "jbuilder" "build" "-p" name "-j" jobs ]
]
build-test: [

View File

@ -9,11 +9,12 @@ license: "unreleased"
depends: [
"ocamlfind" { build }
"jbuilder" { build & >= "1.0+beta15" }
"base-bigarray"
"tezos-base"
"uutf"
"tezos-protocol-compiler"
]
build: [
[ "rm" "jbuild" "src/jbuild" ]
[ "cp" "%{tezos-protocol-compiler:share}%/jbuild_protocol_template" "jbuild" ]
[ "sed" "-i" "s/let predefined_version = None/let predefined_version = Some \"alpha\"/" "jbuild" ]
[ "jbuilder" "build" "-p" name "-j" jobs ]
]
build-test: [

View File

@ -9,11 +9,14 @@ license: "unreleased"
depends: [
"ocamlfind" { build }
"jbuilder" { build & >= "1.0+beta15" }
"base-bigarray"
"tezos-base"
"uutf"
"tezos-protocol-compiler"
"tezos-node-updater"
"tezos-node-shell"
]
build: [
[ "rm" "jbuild" "src/jbuild" ]
[ "cp" "%{tezos-protocol-compiler:share}%/jbuild_embedded_protocol_template" "src/jbuild" ]
[ "sed" "-i" "s/let predefined_version = None/let predefined_version = Some \"demo\"/" "src/jbuild" ]
[ "jbuilder" "build" "-p" name "-j" jobs ]
]
build-test: [

View File

@ -9,11 +9,12 @@ license: "unreleased"
depends: [
"ocamlfind" { build }
"jbuilder" { build & >= "1.0+beta15" }
"base-bigarray"
"tezos-base"
"uutf"
"tezos-protocol-compiler"
]
build: [
[ "rm" "jbuild" "src/jbuild" ]
[ "cp" "%{tezos-protocol-compiler:share}%/jbuild_protocol_template" "jbuild" ]
[ "sed" "-i" "s/let predefined_version = None/let predefined_version = Some \"demo\"/" "jbuild" ]
[ "jbuilder" "build" "-p" name "-j" jobs ]
]
build-test: [

View File

@ -9,11 +9,14 @@ license: "unreleased"
depends: [
"ocamlfind" { build }
"jbuilder" { build & >= "1.0+beta15" }
"base-bigarray"
"tezos-base"
"uutf"
"tezos-protocol-compiler"
"tezos-node-updater"
"tezos-node-shell"
]
build: [
[ "rm" "jbuild" "src/jbuild" ]
[ "cp" "%{tezos-protocol-compiler:share}%/jbuild_embedded_protocol_template" "src/jbuild" ]
[ "sed" "-i" "s/let predefined_version = None/let predefined_version = Some \"genesis\"/" "src/jbuild" ]
[ "jbuilder" "build" "-p" name "-j" jobs ]
]
build-test: [

View File

@ -9,11 +9,12 @@ license: "unreleased"
depends: [
"ocamlfind" { build }
"jbuilder" { build & >= "1.0+beta15" }
"base-bigarray"
"tezos-base"
"uutf"
"tezos-protocol-compiler"
]
build: [
[ "rm" "jbuild" "src/jbuild" ]
[ "cp" "%{tezos-protocol-compiler:share}%/jbuild_protocol_template" "jbuild" ]
[ "sed" "-i" "s/let predefined_version = None/let predefined_version = Some \"genesis\"/" "jbuild" ]
[ "jbuilder" "build" "-p" name "-j" jobs ]
]
build-test: [

View File

@ -9,9 +9,9 @@ license: "unreleased"
depends: [
"ocamlfind" { build }
"jbuilder" { build & >= "1.0+beta15" }
"base-bigarray"
"tezos-stdlib"
"tezos-data-encoding"
"lwt"
]
build: [
[ "jbuilder" "build" "-p" name "-j" jobs ]

View File

@ -9,7 +9,6 @@ license: "unreleased"
depends: [
"ocamlfind" { build }
"jbuilder" { build & >= "1.0+beta15" }
"base-bigarray"
"tezos-base"
"uutf"
]

View File

@ -9,8 +9,9 @@ license: "unreleased"
depends: [
"ocamlfind" { build }
"jbuilder" { build & >= "1.0+beta15" }
"base-bigarray"
"mtime.clock.os"
"tezos-base"
"tezos-node-services"
"ocplib-resto-directory"
"ocplib-resto-cohttp"
]
build: [

View File

@ -9,9 +9,8 @@ license: "unreleased"
depends: [
"ocamlfind" { build }
"jbuilder" { build & >= "1.0+beta15" }
"base-bigarray"
"mtime.clock.os"
"ocplib-resto-cohttp"
"tezos-base"
"tezos-node-p2p-base"
]
build: [
[ "jbuilder" "build" "-p" name "-j" jobs ]

View File

@ -9,9 +9,7 @@ license: "unreleased"
depends: [
"ocamlfind" { build }
"jbuilder" { build & >= "1.0+beta15" }
"base-bigarray"
"mtime.clock.os"
"ocplib-resto-cohttp"
"tezos-base"
]
build: [
[ "jbuilder" "build" "-p" name "-j" jobs ]

View File

@ -9,9 +9,9 @@ license: "unreleased"
depends: [
"ocamlfind" { build }
"jbuilder" { build & >= "1.0+beta15" }
"base-bigarray"
"mtime.clock.os"
"ocplib-resto-cohttp"
"tezos-base"
"tezos-node-p2p-base"
"ocplib-resto"
]
build: [
[ "jbuilder" "build" "-p" name "-j" jobs ]

View File

@ -9,12 +9,12 @@ license: "unreleased"
depends: [
"ocamlfind" { build }
"jbuilder" { build & >= "1.0+beta15" }
"base-bigarray"
"tezos-base"
"tezos-micheline"
"tezos-protocol-compiler"
"tezos-node-net"
"tezos-node-db"
"tezos-storage"
"tezos-node-services"
"tezos-node-p2p-base"
"tezos-node-p2p"
"tezos-node-updater"
]
build: [
[ "jbuilder" "build" "-p" name "-j" jobs ]

View File

@ -9,9 +9,13 @@ license: "unreleased"
depends: [
"ocamlfind" { build }
"jbuilder" { build & >= "1.0+beta15" }
"base-bigarray"
"tezos-base"
"uutf"
"tezos-micheline"
"tezos-protocol-compiler"
"tezos-storage"
"tezos-node-services"
"tezos-node-p2p-base"
"tezos-node-http"
]
build: [
[ "jbuilder" "build" "-p" name "-j" jobs ]

View File

@ -3,12 +3,17 @@
let prefix = "lib_embedded_protocol_"
let dirname = Filename.basename @@ Filename.dirname @@ Sys.getcwd ()
let predefined_version = None (* to be substituted in opam packages *)
let version =
let x = String.length prefix in
let n = String.length dirname in
if not (n >= x && String.sub dirname 0 x = prefix) then
failwith "unexpected directory name" ;
String.sub dirname x (n - x)
match predefined_version with
| Some version -> version
| None ->
let x = String.length prefix in
let n = String.length dirname in
if not (n >= x && String.sub dirname 0 x = prefix) then
failwith "unexpected directory name" ;
String.sub dirname x (n - x)
let () = Format.kasprintf Jbuild_plugin.V1.send {|
(jbuild_version 1)

View File

@ -12,12 +12,22 @@
let prefix = "lib_embedded_protocol_"
let dirname = Filename.basename @@ Sys.getcwd ()
let predefined_version = None (* to be substituted in opam packages *)
let version =
let x = String.length prefix in
let n = String.length dirname in
if not (n >= x && String.sub dirname 0 x = prefix) then
failwith "unexpected directory name" ;
String.sub dirname x (n - x)
match predefined_version with
| Some version -> version
| None ->
let x = String.length prefix in
let n = String.length dirname in
if not (n >= x && String.sub dirname 0 x = prefix) then
failwith "unexpected directory name" ;
String.sub dirname x (n - x)
let path =
match predefined_version with
| None -> "lib_embedded_protocol_" ^ version
| Some _ -> "."
let () = Format.kasprintf Jbuild_plugin.V1.send {|
@ -38,8 +48,7 @@ let () = Format.kasprintf Jbuild_plugin.V1.send {|
(library
((name tezos_protocol_%s)
(public_name tezos-protocol-%s)
(library_flags (:standard -linkall
lib_embedded_protocol_%s/tezos_protocol_%s.cmx))
(library_flags (:standard -linkall %s/tezos_protocol_%s.cmx))
(wrapped false)
(modes (native))
(modules (Tezos_protocol_%s_dummy))))
@ -55,4 +64,5 @@ let () = Format.kasprintf Jbuild_plugin.V1.send {|
|}
version version version version version version version version
version version version version
path
version version version

View File

@ -9,14 +9,12 @@ license: "unreleased"
depends: [
"ocamlfind" { build }
"jbuilder" { build & >= "1.0+beta15" }
"base-unix"
"tezos-base"
"tezos-protocol-environment-sigs"
"compiler-libs"
"compiler-libs.optcomp"
"lwt.unix"
"lwt"
"ocplib-endian"
"ocplib-ocamlres"
"unix"
"ocp-ocamlres" { >= "dev" }
]
build: [
[ "jbuilder" "build" "-p" name "-j" jobs ]

View File

@ -9,9 +9,8 @@ license: "unreleased"
depends: [
"ocamlfind" { build }
"jbuilder" { build & >= "1.0+beta15" }
"base-bigarray"
"cstruct"
"ocplib-endian.bigstring"
"ocplib-endian"
"stringext"
]
build: [

View File

@ -9,12 +9,11 @@ license: "unreleased"
depends: [
"ocamlfind" { build }
"jbuilder" { build & >= "1.0+beta15" }
"base-bigarray"
"tezos-stdlib"
"tezos-data-encoding"
"tezos-error-monad"
"lwt.unix"
"ipaddr.unix"
"lwt" { >= "3.0.0" }
"ipaddr"
]
build: [
[ "jbuilder" "build" "-p" name "-j" jobs ]

View File

@ -9,10 +9,9 @@ license: "unreleased"
depends: [
"ocamlfind" { build }
"jbuilder" { build & >= "1.0+beta15" }
"base-bigarray"
"tezos-base"
"leveldb"
"irmin-unix"
"irmin-leveldb"
]
build: [
[ "jbuilder" "build" "-p" name "-j" jobs ]

21
scripts/opam-pin.sh Executable file
View File

@ -0,0 +1,21 @@
#! /bin/sh
set -e
script_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)/")"
src_dir="$(dirname "$script_dir")"
opams=$(find "$src_dir" -name tezos-deps.opam -prune -or -name \*.opam -print)
export OPAMYES=yes
packages=
for opam in $opams; do
dir=$(dirname $opam)
file=$(basename $opam)
package=${file%.opam}
packages="$packages $package"
opam pin add --no-action $package $dir
done
packages=$(opam list --short --all --sort $packages)

20
scripts/opam-remove.sh Executable file
View File

@ -0,0 +1,20 @@
#! /bin/sh
set -e
script_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)/")"
src_dir="$(dirname "$script_dir")"
opams=$(find "$src_dir" -name \*.opam)
packages=
for opam in $opams; do
dir=$(dirname $opam)
file=$(basename $opam)
package=${file%.opam}
packages="$packages $package"
done
installed=$(opam list --short --installed $packages)
opam remove $installed

74
scripts/opam-test-all.sh Executable file
View File

@ -0,0 +1,74 @@
#! /bin/sh
set -e
script_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)/")"
src_dir="$(dirname "$script_dir")"
cd "$src_dir"
cleanup () {
set +e
if [ -f LOG ]; then
echo "failed."
echo
cat LOG
rm LOG
echo
exit 1
fi
}
trap cleanup EXIT INT
silent () {
"$@" > LOG 2>&1
rm LOG
}
requested_packages="$@"
export OPAMYES=yes
echo -n "Cleanup state and pin packages..."
silent ./scripts/opam-unpin.sh
silent . ./scripts/opam-pin.sh
echo " OK."
if ! [ -z "$requested_packages" ]; then
packages="$requested_packages"
fi
okfile="$0.DONE"
touch $okfile
ok=$(cat "$okfile")
ignore() {
for i in $ok; do
if [ $i = $1 ]; then return 0; fi
done
return 1
}
for package in $packages; do
if ignore $package; then
echo "Ignoring: $package."
continue
fi
echo -n "Installing: $package..."
silent opam install $package
echo " OK."
echo -n "Removing: $package..."
silent opam remove -a $package
echo " OK."
echo $package >> "$okfile"
done
echo
echo "Successfully installed the following packages: "
echo
cat $okfile | sed 's/^/- /'
rm $okfile

11
scripts/opam-unpin.sh Executable file
View File

@ -0,0 +1,11 @@
#! /bin/sh
set -e
script_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)/")"
src_dir="$(dirname "$script_dir")"
. "$script_dir"/opam-remove.sh
opam pin remove $packages

35
scripts/opam-upgrade.sh Executable file
View File

@ -0,0 +1,35 @@
#! /bin/sh
set -e
script_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)/")"
src_dir="$(dirname "$script_dir")"
cd "$src_dir"
cleanup () {
set +e
if [ -f LOG ]; then
echo "Failure"
echo
cat LOG
echo
exit 1
fi
}
trap cleanup EXIT INT
silent () {
"$@" > LOG 2>&1
rm LOG
}
echo "Updating package description..."
silent . ./scripts/opam-pin.sh
upgradables=$(opam list --short --installed $packages)
if [ -z "$upgradables" ]; then
echo "No previously installed package. Nothing to do."
exit 1
fi
opam upgrade $upgradables

View File

@ -13,13 +13,10 @@ depends: [
"base-threads"
"conf-libev"
"calendar"
"cohttp" { >= "0.21" }
"cohttp" { >= "1.0.0" }
"conduit"
"ezjsonm" { >= "0.5.0" }
"git"
"git-unix"
"irmin" { >= "1.3" }
"irmin-unix" { >= "1.3" }
"lwt" { >= "3.0.0" }
"lwt_ssl"
"menhir"

View File

@ -15,7 +15,7 @@ build-test: ["jbuilder" "runtest" "-p" name]
depends: [
"jbuilder" {build & >= "1.0+beta10"}
"irmin" {>= "1.2.0"}
"irmin" {>= "1.3.0"}
"leveldb" {>= "1.1.1"}
]

View File

@ -3,4 +3,4 @@
(library
((name irmin_leveldb)
(public_name irmin-leveldb)
(libraries (irmin leveldb git))))
(libraries (irmin leveldb))))

View File

@ -19,6 +19,6 @@ build-test: [
depends: [
"ocamlfind" {build}
"jbuilder" {build}
"ocplib-ezresto"
"ocplib-resto-directory"
"ocplib-ezresto" {= "dev" }
"ocplib-resto-directory" {= "dev" }
]

View File

@ -19,6 +19,6 @@ build-test: [
depends: [
"ocamlfind" {build}
"jbuilder" {build}
"ocplib-resto"
"ocplib-resto-json"
"ocplib-resto" {= "dev" }
"ocplib-resto-json" {= "dev" }
]

View File

@ -19,6 +19,6 @@ build-test: [
depends: [
"ocamlfind" {build}
"jbuilder" {build}
"ocplib-resto-directory"
"cohttp-lwt-unix"
"ocplib-resto-directory" {= "dev" }
"cohttp-lwt-unix" { >= "1.0.0" }
]

View File

@ -215,10 +215,10 @@ module Make (Encoding : Resto.ENCODING)(Log : LOGGING) = struct
end >>=? fun query ->
let output = output_media_type.construct s.types.output
and error = function
| None -> Cohttp_lwt_body.empty, Transfer.Fixed 0L
| None -> Cohttp_lwt.Body.empty, Transfer.Fixed 0L
| Some e ->
let s = output_media_type.construct s.types.error e in
Cohttp_lwt_body.of_string s,
Cohttp_lwt.Body.of_string s,
Transfer.Fixed (Int64.of_int (String.length s)) in
let headers = Header.init () in
let headers =
@ -228,7 +228,7 @@ module Make (Encoding : Resto.ENCODING)(Log : LOGGING) = struct
| Service.No_input ->
s.handler query () >>= Lwt.return_ok
| Service.Input input ->
Cohttp_lwt_body.to_string body >>= fun body ->
Cohttp_lwt.Body.to_string body >>= fun body ->
match
input_media_type.destruct input body
with
@ -243,13 +243,13 @@ module Make (Encoding : Resto.ENCODING)(Log : LOGGING) = struct
Transfer.Fixed (Int64.of_int (String.length body)) in
Lwt.return_ok
(Response.make ~status:`OK ~encoding ~headers (),
Cohttp_lwt_body.of_string body)
Cohttp_lwt.Body.of_string body)
| `OkStream o ->
let body = create_stream server con output o in
let encoding = Transfer.Chunked in
Lwt.return_ok
(Response.make ~status:`OK ~encoding ~headers (),
Cohttp_lwt_body.of_stream body)
Cohttp_lwt.Body.of_stream body)
| `Created s ->
let headers = Header.init () in
let headers =
@ -258,11 +258,11 @@ module Make (Encoding : Resto.ENCODING)(Log : LOGGING) = struct
| Some s -> Header.add headers "location" s in
Lwt.return_ok
(Response.make ~status:`Created ~headers (),
Cohttp_lwt_body.empty)
Cohttp_lwt.Body.empty)
| `No_content ->
Lwt.return_ok
(Response.make ~status:`No_content (),
Cohttp_lwt_body.empty)
Cohttp_lwt.Body.empty)
| `Unauthorized e ->
let body, encoding = error e in
let status = `Unauthorized in
@ -322,7 +322,7 @@ module Make (Encoding : Resto.ENCODING)(Log : LOGGING) = struct
let headers = Cors.add_headers headers server.cors origin_header in
Lwt.return_ok
(Response.make ~flush:true ~status:`OK ~headers (),
Cohttp_lwt_body.empty)
Cohttp_lwt.Body.empty)
| _ ->
Lwt.return_error `Not_implemented
end >>= function
@ -330,7 +330,7 @@ module Make (Encoding : Resto.ENCODING)(Log : LOGGING) = struct
| Error `Not_implemented ->
Lwt.return
(Response.make ~status:`Not_implemented (),
Cohttp_lwt_body.empty)
Cohttp_lwt.Body.empty)
| Error `Method_not_allowed methods ->
let headers = Header.init () in
let headers =
@ -338,14 +338,14 @@ module Make (Encoding : Resto.ENCODING)(Log : LOGGING) = struct
(List.map Resto.string_of_meth methods) in
Lwt.return
(Response.make ~status:`Method_not_allowed ~headers (),
Cohttp_lwt_body.empty)
Cohttp_lwt.Body.empty)
| Error `Cannot_parse_path (context, arg, value) ->
let headers = Header.init () in
let headers =
Header.add headers "content-type" "text/plain" in
Lwt.return
(Response.make ~status:`Bad_request ~headers (),
Format.kasprintf Cohttp_lwt_body.of_string
Format.kasprintf Cohttp_lwt.Body.of_string
"Failed to parsed an argument in path. After \"%s\", \
the value \"%s\" is not acceptable for type \"%s\""
(String.concat "/" context) value arg.name)
@ -355,7 +355,7 @@ module Make (Encoding : Resto.ENCODING)(Log : LOGGING) = struct
Header.add headers "content-type" "text/plain" in
Lwt.return
(Response.make ~status:`Bad_request ~headers (),
Format.kasprintf Cohttp_lwt_body.of_string
Format.kasprintf Cohttp_lwt.Body.of_string
"Failed to parse the request body: %s" s)
| Error `Cannot_parse_query s ->
let headers = Header.init () in
@ -363,7 +363,7 @@ module Make (Encoding : Resto.ENCODING)(Log : LOGGING) = struct
Header.add headers "content-type" "text/plain" in
Lwt.return
(Response.make ~status:`Bad_request ~headers (),
Format.kasprintf Cohttp_lwt_body.of_string
Format.kasprintf Cohttp_lwt.Body.of_string
"Failed to parse the query string: %s" s)
| Error `Not_acceptable ->
let accepted_encoding =
@ -372,15 +372,15 @@ module Make (Encoding : Resto.ENCODING)(Log : LOGGING) = struct
server.media_types) in
Lwt.return
(Response.make ~status:`Not_acceptable (),
Cohttp_lwt_body.of_string accepted_encoding)
Cohttp_lwt.Body.of_string accepted_encoding)
| Error `Unsupported_media_type _ ->
Lwt.return
(Response.make ~status:`Unsupported_media_type (),
Cohttp_lwt_body.empty)
Cohttp_lwt.Body.empty)
| Error `Not_found ->
Lwt.return
(Response.make ~status:`Not_found (),
Cohttp_lwt_body.empty)
Cohttp_lwt.Body.empty)
(* Promise a running RPC server. *)
@ -402,9 +402,8 @@ module Make (Encoding : Resto.ENCODING)(Log : LOGGING) = struct
stopper ;
worker = Lwt.return_unit ;
} in
let open Cohttp_lwt_unix in
Conduit_lwt_unix.init ~src:host () >>= fun ctx ->
let ctx = Cohttp_lwt_unix_net.init ~ctx () in
let ctx = Cohttp_lwt_unix.Net.init ~ctx () in
server.worker <- begin
let conn_closed (_, con) =
log_info "connection closed %s" (Connection.to_string con) ;
@ -426,12 +425,12 @@ module Make (Encoding : Resto.ENCODING)(Log : LOGGING) = struct
let headers =
Header.add headers "content-type" "text/ocaml.exception" in
let status = `Internal_server_error in
let body = Cohttp_lwt_body.of_string (Printexc.to_string exn) in
let body = Cohttp_lwt.Body.of_string (Printexc.to_string exn) in
Lwt.return (Response.make ~status ~headers (), body)
end
in
Server.create ~stop ~ctx ~mode ~on_exn
(Server.make ~callback ~conn_closed ())
Cohttp_lwt_unix.Server.create ~stop ~ctx ~mode ~on_exn
(Cohttp_lwt_unix.Server.make ~callback ~conn_closed ())
end ;
Lwt.return server

View File

@ -19,6 +19,7 @@ build-test: [
depends: [
"ocamlfind" {build}
"jbuilder" {build}
"ocplib-resto"
"ocplib-resto" {= "dev" }
"ocplib-json-typed" { >= "0.4" }
"ocplib-endian" ## for `ocplib-json-typed.bson` to be built
]