Skip to content

Commit

Permalink
Migrate to Dune (#11)
Browse files Browse the repository at this point in the history
* Migrate to Dune

* update travis file to opam 2

* 4.03.2 isn't a thing
  • Loading branch information
anmonteiro authored and ivg committed Dec 19, 2018
1 parent fb44bc7 commit 8ce657c
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 61 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
*.cmx
*.cmxs
*.cmxa
_build
.merlin
*.install

28 changes: 12 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
language: c
install: wget https://raw.githubusercontent.com/ocaml/ocaml-travisci-skeleton/master/.travis-opam.sh
script: bash -ex .travis-opam.sh
sudo: false
addons:
apt:
sources:
- avsm
packages:
- m4
- ocaml
- ocaml-base
- ocaml-base-nox
- ocaml-compiler-libs
- ocaml-native-compilers
- ocaml-nox

services:
- docker
install: wget https://raw.githubusercontent.com/ocaml/ocaml-travisci-skeleton/master/.travis-docker.sh
script: bash -ex ./.travis-docker.sh
env:
- FORK_USER=talex5 FORK_BRANCH=containers OPAMYES=true PACKAGE=lwt-parallel OCAML_VERSION=latest TESTS=true
global:
- PINS="lwt-parallel:."
matrix:
- PACKAGE="lwt-parallel" DISTRO="ubuntu-16.04" OCAML_VERSION="4.07.1"
- PACKAGE="lwt-parallel" DISTRO="ubuntu-16.04" OCAML_VERSION="4.06.0"
- PACKAGE="lwt-parallel" DISTRO="ubuntu-16.04" OCAML_VERSION="4.04.2"
- PACKAGE="lwt-parallel" DISTRO="ubuntu-16.04" OCAML_VERSION="4.03.0"
- PACKAGE="lwt-parallel" DISTRO="debian-unstable" OCAML_VERSION="4.07.1"
2 changes: 2 additions & 0 deletions dune-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(lang dune 1.6)
(name lwt-parallel)
12 changes: 0 additions & 12 deletions lib/META

This file was deleted.

5 changes: 5 additions & 0 deletions lib/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(library
(name parallel)
(public_name lwt-parallel)
(libraries lwt.unix logs.lwt)
(flags (:standard -w -9-27-32-34-38-39)))
4 changes: 0 additions & 4 deletions lib/lwt_parallel.mldylib

This file was deleted.

4 changes: 0 additions & 4 deletions lib/lwt_parallel.mllib

This file was deleted.

21 changes: 13 additions & 8 deletions lib/parallel.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
open Lwt
open Lwt_log
open Printf

exception Exited
Expand Down Expand Up @@ -47,7 +46,7 @@ end = struct
lock_p fd >>= fun () ->
try_bind f
(fun r -> unlock_p fd >>= fun () -> return r)
(fun exn -> unlock_p fd >>= fun () -> fail exn)
(fun exn -> unlock_p fd >>= fun () -> fail exn)

let with_lock m f =
Lwt_mutex.with_lock m.t_guard (fun () -> with_p_lock m.p_guard f)
Expand All @@ -64,6 +63,12 @@ let master = ref None

let pid = Unix.getpid ()

let error ~exn msg =
Logs_lwt.err (fun m -> m "%s: %s" msg (Printexc.to_string exn))

let ign_error ~exn msg =
error ~exn msg |> ignore

let rec reap n =
try
match Unix.waitpid [Unix.WNOHANG] (-1) with
Expand Down Expand Up @@ -119,13 +124,13 @@ let make_connection fd =
shutdown fd Unix.SHUTDOWN_RECEIVE;
return_unit
method close =
Lwt_io.close self#wo >>= fun () ->
Lwt_io.close self#wo >>= fun () ->
Lwt_io.close self#ro >>= fun () ->
Lwt_unix.close fd
end

let write_value fd v =
try_bind
try_bind
(fun () -> Lwt_io.write_value ~flags:[Marshal.Closures] fd v)
(fun () -> Lwt_io.flush fd)
(fun exn -> error ~exn "write_value failed")
Expand All @@ -142,15 +147,15 @@ let worker_thread exec =
| exn -> error ~exn "Process exited with") >>= fun () ->
return (push None) in
let send to_fd of_stream =
catch
catch
(fun () -> Lwt_stream.iter_s (write_value to_fd) of_stream)
(fun exn -> error ~exn "parallel write failed") in
let work fd =
let conn = make_connection fd in
let astream,apush = Lwt_stream.create () in
let bstream,bpush = Lwt_stream.create () in
let recv_t = recv conn#ro apush >>= fun () -> conn#read_finished in
let send_t = send conn#wo bstream >>= fun () -> conn#write_finished in
let send_t = send conn#wo bstream >>= fun () -> conn#write_finished in
let exec_t = exec (astream,bpush) in
async (fun () -> (recv_t <&> send_t) >>= fun () -> conn#close);
exec_t in
Expand Down Expand Up @@ -197,7 +202,7 @@ let init () =


let unlink_addr addr = match addr with
| Unix.ADDR_UNIX filename ->
| Unix.ADDR_UNIX filename ->
catch (fun () -> Lwt_unix.unlink filename)
(fun exn -> error ~exn "unlink failed")
| Unix.ADDR_INET _ -> return_unit
Expand All @@ -217,7 +222,7 @@ let open_connection addr =
let getfd = loop () >|= (fun fd -> `Socket fd) in
let timer = Lwt_unix.sleep 5. >>= fun () -> return `Timeout in

let fd = (getfd <?> timer) >>= function
let fd = (getfd <?> timer) >>= function
| `Socket fd -> return fd
| `Timeout ->
fail (Unix_error (ETIMEDOUT, "open_connection","timeout")) in
Expand Down
4 changes: 0 additions & 4 deletions lib/parallel.mldylib

This file was deleted.

4 changes: 0 additions & 4 deletions lib/parallel.mllib

This file was deleted.

15 changes: 6 additions & 9 deletions opam → lwt-parallel.opam
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
opam-version: "1.2"
opam-version: "2.0"
name: "lwt-parallel"
version: "master"
maintainer: "Ivan Gotovchits <[email protected]>"
authors: "Ivan Gotovchits <[email protected]>"
homepage: "https://github.com/ivg/parallel"
bug-reports: "https://github.com/ivg/parallel/issues"
dev-repo: "https://github.com/ivg/parallel.git"
dev-repo: "git+https://github.com/ivg/parallel.git"
license: "MIT"
build: [
["oasis" "setup"]
["./configure" "--prefix=%{prefix}%"]
[make]
["dune" "build" "-p" name "-j" jobs]
]
install: [make "install"]
remove: ["ocamlfind" "remove" "lwt-parallel"]
depends: [
"base-unix"
"lwt" {>= "2.7.0"}
"ocamlfind" {build}
"oasis" {build}
"dune" {build}
"logs"
]
synopsis: "Lwt-enabled parallel computing library"

0 comments on commit 8ce657c

Please sign in to comment.