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

Dune 2.7.0 integration #331

Merged
merged 9 commits into from
Oct 10, 2020
Merged
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ scripts:
WD=`pwd`
if [ ! -f node_modules/.bin/esy ]
then
npm install --no-save esy
npm install --no-save esy@0.6.4
export PATH="$WD/node_modules/.bin:$PATH"
else
mkdir -p _wrapped_esy
Expand Down
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
.PHONY : build
build :
dune build
dune build -p bisect_ppx

.PHONY : test
test : build
dune runtest --force --no-buffer -j 1
dune runtest -p bisect_ppx --force --no-buffer -j 1

SELF_COVERAGE := _self

Expand Down Expand Up @@ -105,8 +105,9 @@ EXPECTED_FILES := \
.PHONY : self-coverage-test
self-coverage-test :
cd $(SELF_COVERAGE) && rm -f bisect*.meta
cd $(SELF_COVERAGE) && dune build @install
cd $(SELF_COVERAGE) && dune runtest --force --no-buffer -j 1
cd $(SELF_COVERAGE) && dune build @install --instrument-with meta_bisect_ppx
cd $(SELF_COVERAGE) && \
dune runtest --force --no-buffer -j 1 --instrument-with meta_bisect_ppx
rm -rf _coverage
cd $(SELF_COVERAGE) && \
_build/install/default/bin/meta-bisect-ppx-report \
Expand Down
37 changes: 5 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,53 +56,26 @@ Refer to [**aantron/bisect-starter-dune**][dune-repo], which produces

```
depends: [
"bisect_ppx" {dev & >= "2.0.0"}
"bisect_ppx" {dev & >= "2.5.0"}
"dune" {>= "2.7.0"}
]
```

2. [Mark the code under test for preprocessing by
`bisect_ppx`](https://github.com/aantron/bisect-starter-dune/blob/master/dune#L4) in your `dune` file:
`bisect_ppx`](https://github.com/aantron/bisect-starter-dune/blob/master/dune) in your `dune` file:

```ocaml
(* -*- tuareg -*- *)

let preprocess =
match Sys.getenv "BISECT_ENABLE" with
| "yes" -> "(preprocess (pps bisect_ppx))"
| _ -> ""
| exception Not_found -> ""

let () = Jbuild_plugin.V1.send @@ {|

(library
(public_name my_lib)
|} ^ preprocess ^ {|)

|}
(instrumentation (backend bisect_ppx)))
```

This uses Dune's
[OCaml syntax](https://dune.readthedocs.io/en/stable/advanced-topics.html#ocaml-syntax)
to completely take `bisect_ppx` out as a dependency, except when the
environment variable `BISECT_ENABLE` is set to `yes`. This is so that you
can release your project without it depending on `bisect_ppx` for non-`dev`
builds.

After [ocaml/dune#57][dune-57], Dune will have a lighter-weight built-in
syntax for conditional preprocessing.

For now, the OCaml syntax can be understood as prepending a few lines of
OCaml code to a regular `dune` file, and then replacing the `preprocess`
stanza with `|} ^ preprocess ^ {|`. See
[here](https://github.com/aantron/bisect-starter-dune/commit/24ffb2153d3c42ff166c78a9f55095bd12f10f4e#diff-cabdb1014252d39ac018f447e7d5fbc2)
for a neat summary of the patch.

3. Build and run your test binary. In addition to testing your code, when
exiting, it will write one or more files with names like
`bisect0123456789.coverage`:

```
BISECT_ENABLE=yes dune runtest --force
dune runtest --instrument-with bisect_ppx --force
```

The `--force` flag forces all your tests to run, which is needed for an
Expand Down
2 changes: 1 addition & 1 deletion binaries.esy.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"dependencies": {
"ocaml": ">= 4.2.0",
"@opam/cmdliner": "^1.0.0",
"@opam/dune": "*",
"@opam/dune": "^2.7.0",
"@opam/ocaml-migrate-parsetree": "^1.7.0",
"@opam/ppx_tools_versioned": "^5.4.0"
},
Expand Down
2 changes: 1 addition & 1 deletion bisect_ppx.opam
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ maintainer: [
depends: [
"base-unix"
"cmdliner" {>= "1.0.0"}
"dune"
"dune" {>= "2.7.0"}
"ocaml" {>= "4.02.0"}
"ocaml-migrate-parsetree" {>= "1.7.0"}
"ppx_tools_versioned" {>= "5.4.0"}
Expand Down
4 changes: 3 additions & 1 deletion dune-project
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
(lang dune 1.0)
(lang dune 2.7)

(formatting disabled)
1 change: 1 addition & 0 deletions src/ppx/bucklescript/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
(executable
(modes byte exe)
(name ppx)
(libraries bisect_ppx ocaml-migrate-parsetree))
1 change: 1 addition & 0 deletions src/ppx/dune
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
(name bisect_ppx)
(public_name bisect_ppx)
(kind ppx_rewriter)
(instrumentation.backend (ppx bisect_ppx))
(synopsis "Code coverage for OCaml")
(ppx_runtime_libraries bisect_ppx.runtime)
(preprocess (pps ppx_tools_versioned.metaquot_411))
Expand Down
1 change: 1 addition & 0 deletions src/report/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(executable
(modes byte exe)
(name report)
(public_name bisect-ppx-report)
(package bisect_ppx)
Expand Down
2 changes: 1 addition & 1 deletion test/dune
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(ignored_subdirs (bucklescript))
(dirs (:standard \ bucklescript))
15 changes: 7 additions & 8 deletions test/self/bisect_ppx.diff
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,25 @@ diff -ru src/common/dune _self/bisect_ppx/src/common/dune
(library
(name bisect_common)
(public_name bisect_ppx.common)
+ (preprocess (pps meta_bisect_ppx))
+ (instrumentation (backend meta_bisect_ppx))
(synopsis "Bisect_ppx internal functions (internal)"))
diff -ru src/ppx/dune _self/bisect_ppx/src/ppx/dune
--- src/ppx/dune
+++ _self/bisect_ppx/src/ppx/dune
@@ -7,5 +7,5 @@
(kind ppx_rewriter)
@@ -9,4 +9,5 @@
(synopsis "Code coverage for OCaml")
(ppx_runtime_libraries bisect_ppx.runtime)
- (preprocess (pps ppx_tools_versioned.metaquot_410))
+ (preprocess (pps meta_bisect_ppx ppx_tools_versioned.metaquot_410))
(preprocess (pps ppx_tools_versioned.metaquot_411))
+ (instrumentation (backend meta_bisect_ppx))
(libraries bisect_ppx.common ocaml-migrate-parsetree ppx_tools_versioned str))
diff -ru src/report/dune _self/bisect_ppx/src/report/dune
--- src/report/dune
+++ _self/bisect_ppx/src/report/dune
@@ -2,6 +2,7 @@
@@ -3,6 +3,7 @@
(name report)
(public_name bisect-ppx-report)
(package bisect_ppx)
+ (preprocess (pps meta_bisect_ppx))
+ (instrumentation (backend meta_bisect_ppx))
(libraries bisect_ppx.common cmdliner unix))

(rule
Expand All @@ -35,5 +34,5 @@ diff -ru src/runtime/native/dune _self/bisect_ppx/src/runtime/native/dune
(name bisect)
(public_name bisect_ppx.runtime)
(synopsis "Bisect_ppx runtime library (internal)")
+ (preprocess (pps meta_bisect_ppx))
+ (instrumentation (backend meta_bisect_ppx))
(libraries bisect_ppx.common unix))
19 changes: 11 additions & 8 deletions test/self/meta_bisect_ppx.diff
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
diff -ru src/common/bisect_common.ml _self/meta_bisect_ppx/src/common/bisect_common.ml
--- src/common/bisect_common.ml
+++ _self/meta_bisect_ppx/src/common/bisect_common.ml
@@ -167,7 +167,7 @@
@@ -175,7 +175,7 @@
Random.self_init ()

let random_filename base_name =
Expand All @@ -23,7 +23,7 @@ diff -ru src/common/dune _self/meta_bisect_ppx/src/common/dune
diff -ru src/ppx/dune _self/meta_bisect_ppx/src/ppx/dune
--- src/ppx/dune
+++ _self/meta_bisect_ppx/src/ppx/dune
@@ -2,10 +2,10 @@
@@ -2,11 +2,11 @@
(ocamlyacc exclude_parser)

(library
Expand All @@ -32,25 +32,27 @@ diff -ru src/ppx/dune _self/meta_bisect_ppx/src/ppx/dune
+ (name meta_bisect_ppx)
+ (public_name meta_bisect_ppx)
(kind ppx_rewriter)
- (instrumentation.backend (ppx bisect_ppx))
+ (instrumentation.backend (ppx meta_bisect_ppx))
(synopsis "Code coverage for OCaml")
- (ppx_runtime_libraries bisect_ppx.runtime)
+ (ppx_runtime_libraries meta_bisect_ppx.runtime)
(preprocess (pps ppx_tools_versioned.metaquot_410))
(preprocess (pps ppx_tools_versioned.metaquot_411))
- (libraries bisect_ppx.common ocaml-migrate-parsetree ppx_tools_versioned str))
+ (libraries meta_bisect_ppx.common ocaml-migrate-parsetree ppx_tools_versioned str))
diff -ru src/ppx/instrument.ml _self/meta_bisect_ppx/src/ppx/instrument.ml
--- src/ppx/instrument.ml
+++ _self/meta_bisect_ppx/src/ppx/instrument.ml
@@ -54,7 +54,7 @@
module Ast_mapper_class = Ast_mapper_class_410
module Ast_mapper_class = Ast_mapper_class_411

(* From Bisect_ppx. *)
-module Common = Bisect_common
+module Common = Meta_bisect_common



@@ -907,7 +907,7 @@
@@ -905,7 +905,7 @@
let ___bisect_visit___ =
let point_definitions = [%e points_data] in
let `Staged cb =
Expand All @@ -74,8 +76,9 @@ diff -ru src/ppx/register.ml _self/meta_bisect_ppx/src/ppx/register.ml
diff -ru src/report/dune _self/meta_bisect_ppx/src/report/dune
--- src/report/dune
+++ _self/meta_bisect_ppx/src/report/dune
@@ -1,8 +1,8 @@
@@ -1,9 +1,9 @@
(executable
(modes byte exe)
(name report)
- (public_name bisect-ppx-report)
- (package bisect_ppx)
Expand Down Expand Up @@ -120,8 +123,8 @@ diff -ru src/report/report_html.ml _self/meta_bisect_ppx/src/report/report_html.
-module Common = Bisect_common
+module Common = Meta_bisect_common

let css_variables =
["unvisited_color", "#ffecec";
type theme = [
| `Light
diff -ru src/report/report.ml _self/meta_bisect_ppx/src/report/report.ml
--- src/report/report.ml
+++ _self/meta_bisect_ppx/src/report/report.ml
Expand Down
4 changes: 2 additions & 2 deletions test/unit/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(name test_main)
(libraries bisect_ppx.runtime compiler-libs.common ounit2))

(alias
(name runtest)
(rule
(alias runtest)
(deps (:tester test_main.exe) (source_tree fixtures))
(action (run %{tester} -runner processes -shards 6)))
13 changes: 13 additions & 0 deletions test/usage/dune-integration/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.PHONY : test
test : clean
dune exec ./source.exe
! test -f bisect*.coverage
dune clean
dune exec --instrument-with bisect_ppx ./source.exe
ls -l _build
test -f bisect*.coverage

.PHONY : clean
clean :
dune clean
rm -f bisect*.coverage
3 changes: 3 additions & 0 deletions test/usage/dune-integration/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(executable
(name source)
(instrumentation (backend bisect_ppx)))
1 change: 1 addition & 0 deletions test/usage/dune-integration/dune-project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(lang dune 2.7)
Empty file.
1 change: 1 addition & 0 deletions test/usage/dune-integration/source.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let () = ()