Skip to content

Commit

Permalink
Update to dune, opam 2.0, sedlex 2.0 (#628)
Browse files Browse the repository at this point in the history
  • Loading branch information
smolkaj authored Mar 7, 2019
1 parent 35356d3 commit c8f3933
Show file tree
Hide file tree
Showing 25 changed files with 212 additions and 249 deletions.
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
INSTALL_ARGS := $(if $(PREFIX),--prefix $(PREFIX),)

build:
time -p jbuilder build @install
time -p dune build @install

install: build
jbuilder install $(INSTALL_ARGS)
dune install $(INSTALL_ARGS)

uninstall:
jbuilder uninstall $(INSTALL_ARGS)
dune uninstall $(INSTALL_ARGS)

reinstall: uninstall install

clean:
jbuilder clean
dune clean

doc:
jbuilder build @doc
dune build @doc

test:
jbuilder runtest
dune runtest

updatetest:
jbuilder runtest --auto-promote
dune runtest --auto-promote

all: build test doc

Expand Down
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,33 @@ You can build Frenetic-based network applications with:

### Installation

1. Install [OPAM](https://opam.ocaml.org/)
1. Install [OPAM](https://opam.ocaml.org/), version 2.0 or higher.

1. Switch to OCaml version 4.06.0 or greater:
2. Switch to OCaml version 4.06.0 or greater:
```
opam switch 4.06.0
```
```
3. Install [dune](https://dune.build/):
```
opam install dune
```
1. Install required OCaml dependencies. Note that JBuilder can compute the list of dependencies,
4. Install required OCaml dependencies. Note that dune can compute the list of dependencies,
```
jbuilder external-lib-deps --missing @install
dune external-lib-deps --missing @all
```
and you can install each using OPAM---for example:
```
opam install ocamlgraph
```
1. Build Frenetic
5. Build Frenetic
```
make && make install
```
1. (Optional) install [Mininet](http://mininet.org/)
6. (Optional) install [Mininet](http://mininet.org/)
### Hello World in SDN
Expand Down
Empty file added bench/dune
Empty file.
1 change: 0 additions & 1 deletion bench/jbuild

This file was deleted.

10 changes: 10 additions & 0 deletions bench/src/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(executable
(name benchmark)
(libraries core frenetic))

;; makes sure the executable is built in test mode

(alias
(name runtest)
(deps
(file benchmark.exe)))
12 changes: 0 additions & 12 deletions bench/src/jbuild

This file was deleted.

3 changes: 3 additions & 0 deletions dune-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(lang dune 1.0)
(name frenetic)
(using menhir 2.0)
4 changes: 4 additions & 0 deletions dune-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(lang dune 1.1)
(env
(dev (flags (:standard -warn-error "-6-9-27-32..34-37..39" -w -27-6-32-34-37-9-33-39)))
)
32 changes: 15 additions & 17 deletions frenetic.opam
Original file line number Diff line number Diff line change
@@ -1,43 +1,41 @@
opam-version: "1.2"
available: [ ocaml-version >= "4.05.0" ]
opam-version: "2.0"
version: "5.0.3"
synopsis: "The Frenetic Programming Language and Runtime System"
maintainer: "Steffen Smolka <[email protected]>"
authors: "Arjun Guha <[email protected]>, Nate Foster <[email protected]>, Steffen Smolka <[email protected]>"
homepage: "http://frenetic-lang.org"
bug-reports: "https://github.com/frenetic-lang/frenetic/issues"
dev-repo: "https://github.com/frenetic-lang/frenetic.git"

build: ["jbuilder" "build" "-p" name "-j" jobs]
build-doc: ["jbuilder" "build" "@doc" "-p" name "-j" jobs]
build-test: ["jbuilder" "runtest" "-p" name "-j" jobs]

dev-repo: "git+https://github.com/frenetic-lang/frenetic.git"
build: [
["dune" "subst"] {pinned}
["dune" "build" "-p" name "-j" jobs]
["dune" "runtest" "-p" name "-j" jobs] {with-test}
["dune" "build" "@doc" "-p" name "-j" jobs] {with-doc}
]
depends: [
"ocaml" {build & >= "4.05.0"}
"cppo"
"jbuilder" {>="1.0+beta13"}
"dune" {build & >= "1.0"}
"odoc"
#########################
"async" {>= "v0.11.0" & < "v0.12.0"}
"async_extended" {>= "v0.11.0" & < "v0.12.0"}
"base64" {>= "2.0.0"}
"base64" {>= "3.0.0"}
"cohttp"
"cohttp-async"
"core" {>= "v0.11.0" & < "v0.12.0"}
"cstruct" {>= "1.0.1"}
"cstruct-async"
"ipaddr" {>= "2.5.0"}
"menhir" {build}
"menhir"
"mparser"
"ocamlgraph" {>= "1.8.7"}
"open"
"ppxlib"
"ppx_compare"
"ppx_jane"
"ppx_cstruct"
"ppx_deriving" {>= "4.2"}
"ppx_driver"
"ppx_enumerate"
"ppx_fields_conv"
"ppx_sexp_conv"
"sedlex" {>= "1.99.4"}
"sedlex" {>= "2.0"}
"sexplib"
"tcpip"
"yojson" {>= "1.2.0"}
Expand Down
5 changes: 5 additions & 0 deletions src/exe/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(executables
(names main openflow)
(public_names frenetic frenetic.openflow)
(libraries core async async_extended frenetic)
(flags :standard -safe-string))
8 changes: 0 additions & 8 deletions src/exe/jbuild

This file was deleted.

9 changes: 9 additions & 0 deletions src/lib/async/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(library
(name frenetic_async)
(public_name frenetic.async)
(wrapped true)
(libraries async cohttp cohttp-async core cstruct cstruct-async
frenetic.kernel frenetic.netkat mparser mparser.re str)
(preprocess
(pps ppx_sexp_conv))
(flags :standard -safe-string))
24 changes: 0 additions & 24 deletions src/lib/async/jbuild

This file was deleted.

5 changes: 5 additions & 0 deletions src/lib/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(library
(name frenetic)
(public_name frenetic)
(wrapped true)
(libraries frenetic.netkat frenetic.async frenetic.kernel))
12 changes: 0 additions & 12 deletions src/lib/jbuild

This file was deleted.

2 changes: 1 addition & 1 deletion src/lib/kernel/Util.mli
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
open Core

(** Given a user-defined formatter and a type, make a string. This is a lot like sprintf, and encourages sharing the formatting code. *)
val make_string_of : (Format.formatter -> 'a -> 'b) -> 'a -> string
val make_string_of : (Format.formatter -> 'a -> unit) -> 'a -> string

(** register pretty printer for located exceptions Location.exception *)
val pp_exceptions : unit -> unit
Expand Down
9 changes: 9 additions & 0 deletions src/lib/kernel/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(library
(name frenetic_kernel)
(public_name frenetic.kernel)
(wrapped true)
(libraries core base64 cstruct ocamlgraph open tcpip yojson ipaddr sedlex
sexplib str menhirLib compiler-libs.common)
(preprocess
(pps ppx_cstruct ppx_deriving.std ppx_jane))
)
33 changes: 0 additions & 33 deletions src/lib/kernel/jbuild

This file was deleted.

7 changes: 4 additions & 3 deletions src/lib/netkat/Json.ml
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ let payload_from_json (json : json) : payload =
let open Yojson.Basic.Util in
match json |> member "type" |> to_string with
| "notbuffered" ->
let base64 = json |> member "data" |> to_string in
NotBuffered (Cstruct.of_string (B64.decode base64))
let base64 = json |> member "data" |> to_string in
NotBuffered (Cstruct.of_string (Base64.decode_exn base64))
| "buffered" ->
let bufferId = Int32.of_int_exn (json |> member "bufferid" |> to_int) in
(* TODO(arjun): Why does Buffered take a second argument. Won't it be ignored
Expand Down Expand Up @@ -369,7 +369,8 @@ let event_to_json (event : event) : json =
| PacketIn (pipe, sw_id, pt_id, payload, len, reason) ->
let buffer = Frenetic_kernel.OpenFlow.payload_bytes payload |>
Cstruct.to_string |>
B64.encode in
Base64.encode_exn
in
`Assoc [
("type", `String "packet_in");
("pipe", `String pipe);
Expand Down
42 changes: 23 additions & 19 deletions src/lib/netkat/LexBuffer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ type t = {
buf : Sedlexing.lexbuf;
mutable pos : Lexing.position;
mutable pos_mark : Lexing.position;
mutable last_char : int option;
mutable last_char_mark : int option;
mutable last_char : Uchar.t option;
mutable last_char_mark : Uchar.t option;
}

let of_sedlex ?(file="<n/a>") ?pos buf =
Expand All @@ -23,7 +23,7 @@ let of_sedlex ?(file="<n/a>") ?pos buf =
{ buf; pos; pos_mark = pos; last_char = None; last_char_mark = None; }

let of_ascii_string ?pos s =
of_sedlex ?pos Sedlexing.(Latin1.from_string s)
of_sedlex ?pos Sedlexing.(Latin1.from_string s)

let of_ascii_file file =
let chan = In_channel.create file in
Expand All @@ -50,28 +50,32 @@ let start lexbuf =
let next_loc lexbuf =
{ lexbuf.pos with pos_cnum = lexbuf.pos.pos_cnum + 1 }

let cr = Char.to_int '\r'
let cr = Uchar.of_char '\r'

(** next character *)
let next lexbuf =
let c = Sedlexing.next lexbuf.buf in
let pos = next_loc lexbuf in
(match Char.of_int c with
| Some '\r' ->
lexbuf.pos <- { pos with
pos_bol = pos.pos_cnum - 1;
pos_lnum = pos.pos_lnum + 1; }
| Some '\n' when not (lexbuf.last_char = Some cr) ->
lexbuf.pos <- { pos with
pos_bol = pos.pos_cnum - 1;
pos_lnum = pos.pos_lnum + 1; }
| Some '\n' -> ()
| _ -> lexbuf.pos <- pos);
lexbuf.last_char <- Some c;
c
Option.map (Sedlexing.next lexbuf.buf) ~f:(fun c ->
let pos = next_loc lexbuf in
begin match Uchar.to_char c with
| '\r' ->
lexbuf.pos <- { pos with
pos_bol = pos.pos_cnum - 1;
pos_lnum = pos.pos_lnum + 1; }
| '\n' when not (lexbuf.last_char = Some cr) ->
lexbuf.pos <- { pos with
pos_bol = pos.pos_cnum - 1;
pos_lnum = pos.pos_lnum + 1; }
| '\n' -> ()
| _ -> lexbuf.pos <- pos
| exception _ -> lexbuf.pos <- pos
end;
lexbuf.last_char <- Some c;
c
)

let raw lexbuf : int array =
Sedlexing.lexeme lexbuf.buf
|> Array.map ~f:Uchar.to_int

let ascii ?(skip=0) ?(drop=0) lexbuf : string =
let len = Sedlexing.(lexeme_length lexbuf.buf - skip - drop) in
Expand Down
2 changes: 1 addition & 1 deletion src/lib/netkat/Lexer.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ let token ~ppx ~loc_start buf =
| "var" -> VAR
| "in" -> IN
| '`', id -> METAID (ascii buf ~skip:1)
| _ -> illegal buf (Char.chr (next buf))
| _ -> illegal buf (next buf |> Base.Option.value_exn |> Uchar.to_char)

(** wrapper around `token` that records start and end locations *)
let loc_token ~ppx buf =
Expand Down
Loading

0 comments on commit c8f3933

Please sign in to comment.