diff --git a/.gitignore b/.gitignore index 9721e08b..2a052037 100644 --- a/.gitignore +++ b/.gitignore @@ -49,4 +49,5 @@ examples/static_serve_override examples/uppercase_middleware lib_test/routes *.merlin -*.install \ No newline at end of file +*.install +_opam diff --git a/.travis.yml b/.travis.yml index 4926b329..5ce88cfb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +1,34 @@ language: c -sudo: false +install: wget https://raw.githubusercontent.com/ocaml/ocaml-ci-scripts/master/.travis-docker.sh +script: bash -ex .travis-docker.sh services: - - docker -install: wget https://raw.githubusercontent.com/ocaml/ocaml-travisci-skeleton/master/.travis-docker.sh -script: bash -ex ./.travis-docker.sh +- docker env: global: - EXTRA_REMOTES="https://github.com/mirage/mirage-dev.git" - PINS="opium_kernel:. opium:." matrix: - - PACKAGE="opium_kernel" DISTRO="ubuntu-16.04" OCAML_VERSION="4.04.2" - - PACKAGE="opium" DISTRO="ubuntu-16.04" OCAML_VERSION="4.04.2" - - PACKAGE="opium_kernel" DISTRO="alpine" OCAML_VERSION="4.03.0" - - PACKAGE="opium" DISTRO="alpine" OCAML_VERSION="4.03.0" - - PACKAGE="opium_kernel" DISTRO="debian-unstable" OCAML_VERSION="4.03.0" - - PACKAGE="opium" DISTRO="debian-unstable" OCAML_VERSION="4.03.0" + - PACKAGE="opium_kernel" DISTRO="ubuntu-18.04" OCAML_VERSION="4.04" + - PACKAGE="opium" DISTRO="ubuntu-18.04" OCAML_VERSION="4.04" + - PACKAGE="opium_kernel" DISTRO="ubuntu-18.04" OCAML_VERSION="4.05" + - PACKAGE="opium" DISTRO="ubuntu-18.04" OCAML_VERSION="4.05" + - PACKAGE="opium_kernel" DISTRO="ubuntu-18.04" OCAML_VERSION="4.06" + - PACKAGE="opium" DISTRO="ubuntu-18.04" OCAML_VERSION="4.06" + - PACKAGE="opium_kernel" DISTRO="ubuntu-18.04" OCAML_VERSION="4.07" + - PACKAGE="opium" DISTRO="ubuntu-18.04" OCAML_VERSION="4.07" + - PACKAGE="opium_kernel" DISTRO="ubuntu-16.04" OCAML_VERSION="4.04" + - PACKAGE="opium" DISTRO="ubuntu-16.04" OCAML_VERSION="4.04" + - PACKAGE="opium_kernel" DISTRO="ubuntu-16.04" OCAML_VERSION="4.05" + - PACKAGE="opium" DISTRO="ubuntu-16.04" OCAML_VERSION="4.05" + - PACKAGE="opium_kernel" DISTRO="ubuntu-16.04" OCAML_VERSION="4.06" + - PACKAGE="opium" DISTRO="ubuntu-16.04" OCAML_VERSION="4.06" + - PACKAGE="opium_kernel" DISTRO="ubuntu-16.04" OCAML_VERSION="4.07" + - PACKAGE="opium" DISTRO="ubuntu-16.04" OCAML_VERSION="4.07" + - PACKAGE="opium_kernel" DISTRO="alpine" OCAML_VERSION="4.04" + - PACKAGE="opium" DISTRO="alpine" OCAML_VERSION="4.04" + - PACKAGE="opium_kernel" DISTRO="alpine" OCAML_VERSION="4.05" + - PACKAGE="opium" DISTRO="alpine" OCAML_VERSION="4.05" + - PACKAGE="opium_kernel" DISTRO="alpine" OCAML_VERSION="4.06" + - PACKAGE="opium" DISTRO="alpine" OCAML_VERSION="4.06" + - PACKAGE="opium_kernel" DISTRO="alpine" OCAML_VERSION="4.07" + - PACKAGE="opium" DISTRO="alpine" OCAML_VERSION="4.07" diff --git a/Makefile b/Makefile index 41c9fff4..964e4f84 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,12 @@ .DEFAULT_GOAL: all -JBUILDER ?= jbuilder +JBUILDER ?= dune all: - @$(JBUILDER) build --dev @install @DEFAULT + @$(JBUILDER) build @install @DEFAULT check: - @$(JBUILDER) runtest --dev + @$(JBUILDER) runtest test: check @@ -19,4 +19,4 @@ clean: .PHONY: all clean check test all-supported-ocaml-versions: - $(JBUILDER) runtest --dev --workspace jbuild-workspace.dev + $(JBUILDER) runtest --workspace dune-workspace.dev diff --git a/dune-project b/dune-project new file mode 100644 index 00000000..673b3e24 --- /dev/null +++ b/dune-project @@ -0,0 +1,2 @@ +(lang dune 1.5) +(name opium) diff --git a/dune-workspace.dev b/dune-workspace.dev new file mode 100644 index 00000000..a6cd0322 --- /dev/null +++ b/dune-workspace.dev @@ -0,0 +1,6 @@ +(lang dune 1.5) + +;; This file is used by `make all-supported-ocaml-versions` +(context (opam (switch 4.04.2))) +(context (opam (switch 4.05.0))) +(context (opam (switch 4.06.0))) diff --git a/examples/dune b/examples/dune new file mode 100644 index 00000000..33cb54c9 --- /dev/null +++ b/examples/dune @@ -0,0 +1,15 @@ +(executables + (libraries re ezjsonm opium) + (preprocess + (pps ppx_sexp_conv) + ) + (flags + (:standard -safe-string) + ) + (names auth_middleware exit_hook_example hello_world_basic hello_world_html hello_world middleware_ua read_json_body sample static_serve_override uppercase_middleware) +) + +(alias + (name DEFAULT) + (deps auth_middleware.exe exit_hook_example.exe hello_world_basic.exe hello_world_html.exe hello_world.exe middleware_ua.exe read_json_body.exe sample.exe static_serve_override.exe uppercase_middleware.exe) +) diff --git a/examples/jbuild b/examples/jbuild deleted file mode 100644 index 0c91879d..00000000 --- a/examples/jbuild +++ /dev/null @@ -1,31 +0,0 @@ -(jbuild_version 1) - -(executables - ((libraries (re ezjsonm opium)) - (preprocess (pps (ppx_sexp_conv))) - (flags (:standard -safe-string)) - (names - (auth_middleware - exit_hook_example - hello_world_basic - hello_world_html - hello_world - middleware_ua - read_json_body - sample - static_serve_override - uppercase_middleware)))) - -(alias - ((name DEFAULT) - (deps - (auth_middleware.exe - exit_hook_example.exe - hello_world_basic.exe - hello_world_html.exe - hello_world.exe - middleware_ua.exe - read_json_body.exe - sample.exe - static_serve_override.exe - uppercase_middleware.exe)))) diff --git a/lib_test/dune b/lib_test/dune new file mode 100644 index 00000000..fe573bbc --- /dev/null +++ b/lib_test/dune @@ -0,0 +1,8 @@ +(test + (name routes) + (libraries alcotest opium) + (package opium) + (flags + (:standard -safe-string) + ) +) diff --git a/lib_test/jbuild b/lib_test/jbuild deleted file mode 100644 index 929f26d8..00000000 --- a/lib_test/jbuild +++ /dev/null @@ -1,12 +0,0 @@ -(jbuild_version 1) - -(executables - ((libraries (alcotest opium)) - (flags (:standard -safe-string)) - (names (routes)))) - -(alias - ((name runtest) - (package opium) - (deps (routes.exe)) - (action (run ${<})))) diff --git a/opium.opam b/opium.opam index 2fdb7099..ccf32fb5 100644 --- a/opium.opam +++ b/opium.opam @@ -1,33 +1,40 @@ -opam-version: "1.2" +opam-version: "2.0" maintainer: "rudi.grinberg@gmail.com" authors: ["Rudi Grinberg"] license: "MIT" homepage: "https://github.com/rgrinberg/opium" bug-reports: "https://github.com/rgrinberg/opium/issues" -dev-repo: "https://github.com/rgrinberg/opium.git" +dev-repo: "git+https://github.com/rgrinberg/opium.git" +synopsis: "Sinatra like web toolkit based on Lwt + Cohttp" +description: """ +Opium is a minimalistic library for quickly binding functions to http routes. Its features include (but not limited to): + + Middleware system for app independent components + A simple router for matching urls and parsing parameters + Request/Response pretty printing for easier debugging +""" build: [ - ["jbuilder" "subst" "-n" name] {pinned} - ["jbuilder" "build" "-p" name "-j" jobs] + ["dune" "subst"] {pinned} + ["dune" "build" "-p" name "-j" jobs] + ["dune" "runtest" "-p" name "-j" jobs] {with-test} ] -build-test: [["jbuilder" "runtest" "-p" name "-j" jobs]] depends: [ - "jbuilder" {build} + "ocaml" {>= "4.04.1"} + "dune" {build} "opium_kernel" "cohttp-lwt-unix" {>= "0.99.0"} "base-unix" "lwt" - "lwt_log" + "logs" "cmdliner" "ppx_fields_conv" {>= "v0.9.0"} "ppx_sexp_conv" {>= "v0.9.0"} "re" {>= "1.3.0"} "magic-mime" "stringext" - "alcotest" {test} - "cow" {test & >= "0.10.0"} + "alcotest" {with-test} + "cow" {with-test & >= "0.10.0"} ] - -available: [ocaml-version >= "4.02.3"] diff --git a/opium/debug.ml b/opium/debug.ml index 2c8bc7c1..dce165ce 100644 --- a/opium/debug.ml +++ b/opium/debug.ml @@ -3,6 +3,8 @@ open Opium_kernel.Rock let exn_ e = Logs.err (fun f -> f "%s" (Printexc.to_string e)) +let log_src = Logs.Src.create "opium.server" + let format_error req _exn = Printf.sprintf " @@ -24,6 +26,6 @@ let trace = let filter handler req = handler req >|= fun response -> let code = response |> Response.code |> Cohttp.Code.code_of_status in - Lwt_log.ign_debug_f "Responded with %d" code; + Logs.debug ~src:log_src (fun m -> m "Responded with %d" code); response in Middleware.create ~name:"Trace" ~filter diff --git a/opium/dune b/opium/dune new file mode 100644 index 00000000..3b9ab31a --- /dev/null +++ b/opium/dune @@ -0,0 +1,10 @@ +(library + (public_name opium) + (flags + (:standard -safe-string) + ) + (preprocess + (pps ppx_sexp_conv ppx_fields_conv) + ) + (libraries opium_kernel cmdliner cohttp-lwt-unix magic-mime logs stringext) +) diff --git a/opium/jbuild b/opium/jbuild deleted file mode 100644 index 3f1e810c..00000000 --- a/opium/jbuild +++ /dev/null @@ -1,15 +0,0 @@ -(jbuild_version 1) - -(library - ((name opium) - (public_name opium) - (flags (:standard -safe-string)) - (preprocess (pps (ppx_sexp_conv ppx_fields_conv))) - (libraries - (opium_kernel - lwt_log - cmdliner - cohttp-lwt-unix - magic-mime - logs - stringext)))) diff --git a/opium_kernel.opam b/opium_kernel.opam index c4c5607f..3706ac59 100644 --- a/opium_kernel.opam +++ b/opium_kernel.opam @@ -1,20 +1,25 @@ -opam-version: "1.2" +opam-version: "2.0" maintainer: "rudi.grinberg@gmail.com" authors: ["Rudi Grinberg"] license: "MIT" homepage: "https://github.com/rgrinberg/opium" bug-reports: "https://github.com/rgrinberg/opium/issues" -dev-repo: "https://github.com/rgrinberg/opium.git" +dev-repo: "git+https://github.com/rgrinberg/opium.git" +synopsis: "Sinatra like web toolkit based on Lwt + Cohttp" +description: """ +Opium_kernel is the Unix indpendent core of Opium. Useful for extremely portable environments such as mirage. +""" build: [ - ["jbuilder" "subst" "-n" name] {pinned} - ["jbuilder" "build" "-p" name "-j" jobs] + ["dune" "subst"] {pinned} + ["dune" "build" "-p" name "-j" jobs] + ["dune" "runtest" "-p" name "-j" jobs] {with-test} ] -build-test: [["jbuilder" "runtest" "-p" name "-j" jobs]] depends: [ - "jbuilder" {build} + "ocaml" {>= "4.04.1"} + "dune" {build} "hmap" "cohttp" {>= "0.99.0"} "cohttp-lwt" {>= "0.99.0"} @@ -26,8 +31,6 @@ depends: [ "ppx_fields_conv" {>= "v0.9.0"} "ppx_sexp_conv" {>= "v0.9.0"} "re" {>= "1.3.0"} - "alcotest" {test} - "cow" {test & >= "0.10.0"} + "alcotest" {with-test} + "cow" {with-test & >= "0.10.0"} ] - -available: [ocaml-version >= "4.02.3"] \ No newline at end of file diff --git a/opium_kernel/dune b/opium_kernel/dune new file mode 100644 index 00000000..a0020979 --- /dev/null +++ b/opium_kernel/dune @@ -0,0 +1,10 @@ +(library + (public_name opium_kernel) + (flags + (:standard -safe-string) + ) + (preprocess + (pps ppx_sexp_conv ppx_fields_conv) + ) + (libraries hmap cohttp-lwt ezjsonm) +) diff --git a/opium_kernel/jbuild b/opium_kernel/jbuild deleted file mode 100644 index 726a032f..00000000 --- a/opium_kernel/jbuild +++ /dev/null @@ -1,11 +0,0 @@ -(jbuild_version 1) - -(library - ((name opium_kernel) - (public_name opium_kernel) - (flags (:standard -safe-string)) - (preprocess (pps (ppx_sexp_conv ppx_fields_conv))) - (libraries - (hmap - cohttp-lwt - ezjsonm))))