Skip to content

Commit

Permalink
Merge pull request #85 from anmonteiro/anmonteiro/dune-and-prepare-fo…
Browse files Browse the repository at this point in the history
…r-new-release

Upgrade from JBuilder to Dune and document building and testing instructions
  • Loading branch information
gasche committed Dec 11, 2018
2 parents 82bc0b8 + 1c82f34 commit acde30c
Show file tree
Hide file tree
Showing 16 changed files with 198 additions and 109 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
_build
*.install
pkg/META
.merlin
19 changes: 10 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
language: c
sudo: required
install: wget https://raw.githubusercontent.com/ocaml/ocaml-ci-scripts/master/.travis-opam.sh
script: bash -ex .travis-opam.sh
sudo: false
services:
- docker
install: wget https://raw.githubusercontent.com/ocaml/ocaml-travisci-skeleton/master/.travis-docker.sh
script: bash -ex ./.travis-docker.sh
env:
global:
- TESTS=true
- PINS="ppx_deriving_yojson:."
matrix:
- OCAML_VERSION=4.04 PACKAGE="ppx_deriving_yojson"
- OCAML_VERSION=4.05 PACKAGE="ppx_deriving_yojson"
- OCAML_VERSION=4.06 PACKAGE="ppx_deriving_yojson"
os:
- linux
- PACKAGE="ppx_deriving_yojson" DISTRO="ubuntu-16.04" OCAML_VERSION="4.07"
- PACKAGE="ppx_deriving_yojson" DISTRO="ubuntu-16.04" OCAML_VERSION="4.06"
- PACKAGE="ppx_deriving_yojson" DISTRO="ubuntu-16.04" OCAML_VERSION="4.05"
- PACKAGE="ppx_deriving_yojson" DISTRO="ubuntu-16.04" OCAML_VERSION="4.04"
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
Changelog
=========

Unreleased
---

* Add `let _ = to_yojson / of_yojson` to generated code to avoid warnings when
they aren't used
(#68)
@stevebleazard
* Fix bug where doing [@@deriving of_yojson] causes an unused rec warning
(#68)
@stevebleazard
* Add generated `ty_of_yojson_exn` to raise an exception rather than return an
error
(#57, #68)
@stevebleazard
* Port `ppx_deriving_yojson` to `dune`
(#69, #85)
@rgrinberg, @anmonteiro
* Added deriver option `fields` to generate a `Yojson_meta` module containing
all JSON key names.
(#70)
@stevebleazard
* Remove cppo that included support for versions no longer supported by
`ppx_deriving_yojson`
(#75)
@rgrinberg

3.1
---

Expand Down
57 changes: 57 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Contributing to `ppx_deriving_yojson`

## Setting up

This document assumes you have [OPAM](https://opam.ocaml.org/) installed.

### Installing

To start building this project you will need to install the packages it depends
on. To do so, run the following command:

```shell
$ opam install . --deps-only -t
```

## Developing

### Building & Testing

This project uses [dune](http://dune.build/) as its build system. The
[Makefile](./Makefile) in this repo provides shorter commands over the `dune`
commands.

#### Building

To build the project, run `make` or `make build`.

### Running Tests

`make test` will build and run the tests in the current OPAM switch.

### Cleaning up

`make clean` can be used to clean up the build artifacts.

## Cutting a release

### Testing for a release

Before cutting a release, it is useful to test this project against all the
supported OCaml versions. `make all-supported-ocaml-versions` will do just that,
but requires some setting up beforehand. The instructions are as follows:

1. The [`dune-workspace.dev`](./dune-workspace.dev) defines all the OPAM
switches that will be tested when running `make
all-supported-ocaml-versions`. Make sure you have switches for all those
OCaml version, with the appropriate names (e.g., for the build context that
`(context (opam (switch 4.07.1)))` defines, make sure you have a switch named
`4.07.1`. To find out which OPAM switches you have, run `opam switch list`).
2. For every OPAM switch listed in the Dune workspace file, switch into it and
run the installation command at the top of this document.
3. Finally, you can now run `make all-supported-ocaml-versions`, which will
build and test this project against all those OCaml versions.

### Making a release

- WIP
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
build:
jbuilder build
dune build

test:
jbuilder runtest
dune runtest

doc:
jbuilder build @doc
dune build @doc

clean:
jbuilder clean
dune clean

.PHONY: build test doc clean

Expand All @@ -23,7 +23,7 @@ release:
opam publish submit $(NAME_VERSION)
rm -rf $(NAME_VERSION)

.PHONY: gh-pages release all-supported-ocaml-versions
.PHONY: release all-supported-ocaml-versions

all-supported-ocaml-versions:
jbuilder build @install @runtest --workspace jbuild-workspace.dev
dune build @install @runtest --workspace dune-workspace.dev
4 changes: 0 additions & 4 deletions descr

This file was deleted.

1 change: 1 addition & 0 deletions dune-project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(lang dune 1.2)
6 changes: 6 additions & 0 deletions dune-workspace.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(lang dune 1.2)
;; 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.1)))
(context (opam (switch 4.07.1)))
4 changes: 0 additions & 4 deletions jbuild-workspace.dev

This file was deleted.

21 changes: 13 additions & 8 deletions ppx_deriving_yojson.opam
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
opam-version: "1.2"
version: "3.1"
opam-version: "2.0"
maintainer: "whitequark <whitequark@whitequark.org>"
authors: [ "whitequark <whitequark@whitequark.org>" ]
license: "MIT"
homepage: "https://github.com/ocaml-ppx/ppx_deriving_yojson"
doc: "http://ocaml-ppx.github.io/ppx_deriving_yojson"
bug-reports: "https://github.com/ocaml-ppx/ppx_deriving_yojson/issues"
dev-repo: "git://github.com/ocaml-ppx/ppx_deriving_yojson.git"
tags: [ "syntax" "json" ]
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] {with-test}
]
build-test: [["jbuilder" "runtest" "-p" name "-j" jobs]]
depends: [
"ocaml" {>= "4.04.0"}
"yojson"
"result"
"ppx_deriving" {>= "4.0" & < "5.0"}
"ppx_tools" {build}
"ppxfind" {build}
"jbuilder" {build}
"dune" {build}
"cppo" {build}
"ounit" {test}
"ounit" {with-test}
]
synopsis:
"JSON codec generator for OCaml"
description: """
ppx_deriving_yojson is a ppx_deriving plugin that provides
a JSON codec generator.
"""
23 changes: 23 additions & 0 deletions src/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(rule
(deps ppx_deriving_yojson.cppo.ml)
(targets ppx_deriving_yojson.ml)
(action (run %{bin:cppo} -V OCAML:%{ocaml_version} %{deps} -o %{targets})))

(library
(name ppx_deriving_yojson_runtime)
(public_name ppx_deriving_yojson.runtime)
(synopsis "Runtime components of [@@deriving yojson]")
(modules ppx_deriving_yojson_runtime)
(libraries ppx_deriving.runtime result))

(library
(name ppx_deriving_yojson)
(public_name ppx_deriving_yojson)
(synopsis "[@@deriving yojson]")
(libraries ppx_deriving.api)
(preprocess
(action (run ppxfind -legacy ppx_tools.metaquot --as-pp %{input-file})))
(ppx_runtime_libraries ppx_deriving_yojson_runtime yojson)
(modules ppx_deriving_yojson)
(kind ppx_deriver)
(flags (:standard -w -9)))
21 changes: 0 additions & 21 deletions src/jbuild

This file was deleted.

25 changes: 12 additions & 13 deletions src/ppx_deriving_yojson.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
Rtag({ txt = label }, attrs, has_empty, args)
#endif


open Longident
open Location
open Asttypes
Expand Down Expand Up @@ -226,7 +225,7 @@ and desu_expr_of_typ ~path typ =
let wrap_runtime decls =
Ppx_deriving.sanitize ~module_:(Lident "Ppx_deriving_yojson_runtime") decls

let ser_type_of_decl ~options ~path type_decl =
let ser_type_of_decl ~options ~path:_ type_decl =
ignore (parse_options options);
let typ = Ppx_deriving.core_type_of_type_decl type_decl in
let polymorphize = Ppx_deriving.poly_arrow_of_type_decl
Expand All @@ -235,7 +234,7 @@ let ser_type_of_decl ~options ~path type_decl =

let ser_str_of_record varname labels =
let fields =
labels |> List.mapi (fun i { pld_name = { txt = name }; pld_type; pld_attributes } ->
labels |> List.mapi (fun _i { pld_name = { txt = name }; pld_type; pld_attributes } ->
let field = Exp.field (evar varname) (mknoloc (Lident name)) in
let result = [%expr [%e str (attr_key name pld_attributes)],
[%e ser_expr_of_typ pld_type] [%e field]] in
Expand Down Expand Up @@ -264,7 +263,7 @@ let ser_str_of_type ~options ~path ({ ptype_loc = loc } as type_decl) =
(`PrefixSuffix ("M", "to_yojson")) type_decl
in
match type_decl.ptype_manifest with
| Some ({ ptyp_desc = Ptyp_constr ({ txt = lid }, args) } as manifest) ->
| Some ({ ptyp_desc = Ptyp_constr ({ txt = lid }, _args) } as manifest) ->
let ser = ser_expr_of_typ manifest in
let lid = Ppx_deriving.mangle_lid (`PrefixSuffix ("M", "to_yojson")) lid in
let orig_mod = Mod.ident (mknoloc lid) in
Expand Down Expand Up @@ -356,7 +355,7 @@ let ser_str_of_type ~options ~path ({ ptype_loc = loc } as type_decl) =
[Str.value Nonrecursive [Vb.mk [%expr [%e pvar "_"]] [%expr [%e evar var_s]]] ]
)

let ser_str_of_type_ext ~options ~path ({ ptyext_path = { loc }} as type_ext) =
let ser_str_of_type_ext ~options ~path:_ ({ ptyext_path = { loc }} as type_ext) =
ignore (parse_options options);
let serializer =
let pats =
Expand Down Expand Up @@ -409,7 +408,7 @@ let ser_str_of_type_ext ~options ~path ({ ptyext_path = { loc }} as type_ext) =

let error_or typ = [%type: [%t typ] Ppx_deriving_yojson_runtime.error_or]

let desu_type_of_decl_poly ~options ~path type_decl type_ =
let desu_type_of_decl_poly ~options ~path:_ type_decl type_ =
ignore (parse_options options);
let polymorphize = Ppx_deriving.poly_arrow_of_type_decl
(fun var -> [%type: Yojson.Safe.json -> [%t error_or var]]) type_decl in
Expand Down Expand Up @@ -473,7 +472,7 @@ let desu_str_of_type ~options ~path ({ ptype_loc = loc } as type_decl) =
(`PrefixSuffix ("M", "of_yojson")) type_decl
in
match type_decl.ptype_manifest with
| Some ({ ptyp_desc = Ptyp_constr ({ txt = lid }, args) } as manifest) ->
| Some ({ ptyp_desc = Ptyp_constr ({ txt = lid }, _args) } as manifest) ->
let desu = desu_expr_of_typ ~path manifest in
let lid = Ppx_deriving.mangle_lid (`PrefixSuffix ("M", "of_yojson")) lid in
let orig_mod = Mod.ident (mknoloc lid) in
Expand Down Expand Up @@ -647,7 +646,7 @@ let ser_sig_of_type ~options ~path type_decl =
| _ -> [to_yojson]


let ser_sig_of_type_ext ~options ~path type_ext = []
let ser_sig_of_type_ext ~options:_ ~path:_ _type_ext = []

let desu_sig_of_type ~options ~path type_decl =
let of_yojson =
Expand Down Expand Up @@ -687,17 +686,17 @@ let desu_sig_of_type ~options ~path type_decl =
[mod_; of_yojson]
| _ -> [of_yojson; of_yojson_exn]

let desu_sig_of_type_ext ~options ~path type_ext = []
let desu_sig_of_type_ext ~options:_ ~path:_ _type_ext = []

let yojson_str_fields ~options ~path ({ ptype_loc = loc } as type_decl) =
let yojson_str_fields ~options ~path:_ type_decl =
let (_, want_meta) = parse_options options in
match want_meta, type_decl.ptype_kind with
| false, _ | true, Ptype_open -> []
| true, kind ->
match kind, type_decl.ptype_manifest with
| Ptype_record labels, _ ->
let fields =
labels |> List.map (fun { pld_name = { txt = name }; pld_type; pld_attributes } ->
labels |> List.map (fun { pld_name = { txt = name }; pld_attributes } ->
[%expr [%e str (attr_key name pld_attributes)]])
in
let flist = List.fold_right (fun n acc -> [%expr [%e n] :: [%e acc]])
Expand All @@ -712,7 +711,7 @@ let yojson_str_fields ~options ~path ({ ptype_loc = loc } as type_decl) =
]
| _ -> []

let yojson_sig_fields ~options ~path ({ ptype_loc = loc } as type_decl) =
let yojson_sig_fields ~options ~path:_ type_decl =
let (_, want_meta) = parse_options options in
match want_meta, type_decl.ptype_kind with
| false, _ | true, Ptype_open -> []
Expand Down Expand Up @@ -806,4 +805,4 @@ let () =
~type_decl_sig:(on_sig_decls sig_of_type_of_yojson)
~type_ext_sig:desu_sig_of_type_ext
()
))
))
15 changes: 15 additions & 0 deletions src_test/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(rule
(deps test_ppx_yojson.cppo.ml)
(targets test_ppx_yojson.ml)
(action (run %{bin:cppo} -V OCAML:%{ocaml_version} %{deps} -o %{targets})))

(executable
(name test_ppx_yojson)
(libraries oUnit result)
(preprocess (pps ppx_deriving.show ppx_deriving_yojson))
(flags (:standard -w -9-39-27-34-37)))

(alias
(name runtest)
(deps test_ppx_yojson.exe)
(action (run %{deps})))
16 changes: 0 additions & 16 deletions src_test/jbuild

This file was deleted.

0 comments on commit acde30c

Please sign in to comment.