Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jbuilder #64

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
*.annot
*.cmo
*.cma
*.cmi
*.a
*.o
*.so
*.cmx
*.cmxs
*.cmxa
README.git
_build/
tools/
Ipython_json_*
.merlin
*.install
iocaml.log
.*.swp
*~
Expand Down
79 changes: 8 additions & 71 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,77 +1,14 @@
# new makefile - the build is about to get more complex.
JBUILDER ?= jbuilder

all: top
all:
$(JBUILDER) build

json:
atdgen -t Ipython_json.atd
atdgen -j Ipython_json.atd
tests:
$(JBUILDER) runtest

stub:
ocamlfind c iocaml_zmq_stubs.c

lib: json stub
# compile log (first so we can use it in the zmq code)
ocamlfind c -c -g log.mli log.ml
# iocaml_zmq (which requires preprocessing)
ocamlfind c -c -g \
-syntax camlp4o -package lwt.unix,lwt.syntax,ctypes.foreign \
iocaml_zmq.mli iocaml_zmq.ml
# rest of the library
ocamlfind c -c -g \
-package yojson,atdgen,compiler-libs \
Ipython_json_t.mli Ipython_json_j.mli base64.mli \
Ipython_json_t.ml Ipython_json_j.ml base64.ml
ocamlfind ocamlmklib -o iocaml_lib \
-l zmq \
-package ctypes.foreign,lwt.unix,yojson \
iocaml_zmq_stubs.o \
log.cmo Ipython_json_t.cmo Ipython_json_j.cmo iocaml_zmq.cmo base64.cmo

OCP_INDEX_INC=`ocamlfind query ocp-index.lib -predicates byte -format "%d"`
OCP_INDEX_ARCHIVE=`ocamlfind query ocp-index.lib -predicates byte -format "%a"`

HAS_OCP = $(shell if ocamlfind query ocp-index.lib >/dev/null 2>&1; then echo 1; else echo 0; fi)
ifeq ($(HAS_OCP),1)
TOP_PKG=threads,uuidm,lwt.unix,ctypes.foreign,yojson,atdgen,ocp-indent.lib,compiler-libs
TOP_SRC = \
message.mli sockets.mli completion.mli exec.mli iocaml.mli \
message.ml sockets.ml completion.ml exec.ml iocaml.ml
TOP_OBJ = message.cmo sockets.cmo completion.cmo exec.cmo iocaml.cmo
TOP_OCP = -I $(OCP_INDEX_INC) $(OCP_INDEX_INC)/$(OCP_INDEX_ARCHIVE)
else
TOP_PKG=threads,uuidm,lwt.unix,ctypes.foreign,yojson,atdgen,compiler-libs
TOP_SRC = \
message.mli sockets.mli exec.mli iocaml.mli \
message.ml sockets.ml exec.ml iocaml.ml
TOP_OBJ = message.cmo sockets.cmo exec.cmo iocaml.cmo
TOP_OCP =
endif

top: lib
ocamlfind c -c -g -thread \
-syntax camlp4o -package optcomp -ppopt "-let has_ocp=$(HAS_OCP)" \
-package $(TOP_PKG) \
$(TOP_OCP) $(TOP_SRC)
ocamlfind ocamlmktop -g -thread -linkpkg \
-o iocaml.top \
-package $(TOP_PKG) $(TOP_OCP) \
iocaml_lib.cma $(TOP_OBJ) iocaml_main.ml

BINDIR=`opam config var bin`

install: top
ocamlfind install iocaml-kernel META *.cmi *.cmo *.cma *.so *.a *.o
cp iocaml.top $(BINDIR)/iocaml.top

uninstall:
ocamlfind remove iocaml-kernel
rm -f $(BINDIR)/iocaml.top

reinstall:
-$(MAKE) uninstall
$(MAKE) install
check: tests

clean:
rm *.cmi *.cmo *.cma *.so *.a *.o iocaml.top

$(JBUILDER) clean

.PHONY: all tests clean check
17 changes: 0 additions & 17 deletions _tags

This file was deleted.

6 changes: 3 additions & 3 deletions exec.ml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
type ('a,'b) status = Ok of 'a | Error of 'b

let get_error_loc = function
#if ocaml_version > (4,0)
#if OCAML_VERSION > (4, 0, 0)
| Syntaxerr.Error(x) -> Some(Syntaxerr.location_of_error x)
#endif
| Lexer.Error(_, loc)
#if ocaml_version < (4,1)
#if OCAML_VERSION < (4, 1, 0)
| Typecore.Error(loc, _)
| Typetexp.Error(loc, _)
| Typeclass.Error(loc, _)
Expand All @@ -31,7 +31,7 @@ let run_cell_lb execution_count lb =
Errors.report_error formatter exn;
(match get_error_loc exn with
| Some(loc) ->
#if ocaml_version < (4,2)
#if OCAML_VERSION < (4, 2, 0)
ignore (Location.highlight_locations formatter loc Location.none);
#else
ignore (Location.highlight_locations formatter [loc]);
Expand Down
29 changes: 29 additions & 0 deletions iocaml-kernel.opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
opam-version: "1.2"
maintainer: "Andy Ray <[email protected]>"
authors: "Andy Ray <[email protected]>"
homepage: "https://github.com/andrewray/iocaml"
dev-repo: "git+https://github.com/andrewray/iocaml.git"
bug-reports: "https://github.com/andrewray/iocaml/issues"
depends: [
"jbuilder" {build & >= "1.0+beta10"}
"cppo" {build}
"conf-zmq" {build}
"uuidm"
"yojson"
"atdgen"
"ctypes" {>= "0.3"}
"ctypes-foreign"
"base-unix"
"lwt" {>= "2.4"}
]
depopts: ["ocp-index"]
conflicts: [
"ocp-index" {< "1.0.1"}
]

build: [
["jbuilder" "build" "-p" name "-j" jobs]
]
build-test: [
["jbuilder" "runtest" "-p" name "-j" jobs]
]
26 changes: 4 additions & 22 deletions iocaml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -335,23 +335,9 @@ module Shell = struct
let handle_invalid_message () =
raise (Failure "Invalid message on shell socket")

let complete_request index socket msg x =
#if has_ocp=1
if !completion then
let reply = Completion.complete index x in
send_h socket msg (Complete_reply reply)
else
#endif
()

let object_info_request index socket msg x =
#if has_ocp=1
if !object_info then
let reply = Completion.info index x in
send_h socket msg (Object_info_reply reply)
else
#endif
()
let complete_request = Iocaml_complete.complete_request !completion

let object_info_request = Iocaml_complete.object_info_request !object_info

let connect_request socket msg = ()
let history_request socket msg x = ()
Expand Down Expand Up @@ -452,11 +438,7 @@ let send_flush () =
Pervasives.flush stderr;
ignore (send_iopub Shell.Iopub_flush)

#if has_ocp=1
let index = Completion.init ()
#else
let index = ()
#endif
let index = Iocaml_complete.index

let suppress_stdout b = ignore (send_iopub (Shell.Iopub_suppress_stdout b))
let suppress_stderr b = ignore (send_iopub (Shell.Iopub_suppress_stderr b))
Expand Down
7 changes: 1 addition & 6 deletions iocaml.mli
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,7 @@ val suppress_compiler : bool -> unit
(** suppress all output (except mime messages) *)
val suppress_all : bool -> unit

(** ocp-index *)
#if has_ocp = 1
val index : LibIndex.t
#else
val index : unit
#endif
val index : Iocaml_complete.index

type cell_context

Expand Down
7 changes: 7 additions & 0 deletions iocaml_no_ocp.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type index = unit

let complete_request _completion _socket _msg _index _x = ()

let object_info_request _object_info _index _socket _msg _x = ()

let index = ()
17 changes: 17 additions & 0 deletions iocaml_ocp.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
type index = LibIndex.t

let complete_request completion index socket msg x =
if completion then
let reply = Completion.complete index x in
Message.send_h socket msg (Complete_reply reply)
else
()

let object_info_request object_info index socket msg x =
if object_info then
let reply = Completion.info index x in
Message.send_h socket msg (Object_info_reply reply)
else
()

let index = Completion.init ()
17 changes: 6 additions & 11 deletions iocaml_zmq.ml
Original file line number Diff line number Diff line change
Expand Up @@ -379,17 +379,12 @@ module Lwt_zmq = struct
)
in
let rec idle_loop () =
try_lwt
Lwt.wrap1 f s.socket
with
| Unix.Unix_error ( Unix.EAGAIN, _, _) -> begin
try_lwt
io_loop ()
with
| Break_event_loop -> idle_loop ()
end
| Unix.Unix_error (Unix.EINTR, _, _) ->
idle_loop ()
Lwt.catch (fun () -> Lwt.wrap1 f s.socket)
(function
| Unix.Unix_error ( Unix.EAGAIN, _, _) ->
Lwt.catch io_loop (function Break_event_loop -> idle_loop())
| Unix.Unix_error (Unix.EINTR, _, _) ->
idle_loop ())
in
idle_loop ()

Expand Down
29 changes: 29 additions & 0 deletions jbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
(jbuild_version 1)

(rule
((targets (Ipython_json_t.ml Ipython_json_t.mli))
(deps (Ipython_json.atd))
(action (run atdgen -t ${<}))))

(rule
((targets (Ipython_json_j.ml Ipython_json_j.mli))
(deps (Ipython_json.atd))
(action (run atdgen -j ${<}))))

(library
((name iocaml_kernel)
(public_name iocaml-kernel)
(wrapped false)

(preprocess
(per_module
((action (run ${bin:cppo} -V OCAML:${ocaml_version} ${<})) (exec))))
(libraries
(atdgen
(select iocaml_complete.ml from
(ocp-index.lib -> iocaml_ocp.ml)
(-> iocaml_no_ocp.ml))
lwt.unix
yojson
ctypes.foreign
uuidm))))