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

Record instrumentation backends in dune-package #3735

Merged
merged 1 commit into from
Aug 25, 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
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Unreleased
the object file, as long as they are the same after parsing. (#3739, fixes
#3736, @rgrinberg)

- Record instrumentation backends in dune-package files. This makes it possible
to use instrumentation backends defined in installed libraries (eg via OPAM).
(#3735, @nojb)

2.7.0 (13/08/2020)
------------------

Expand Down
7 changes: 6 additions & 1 deletion src/dune/dune_package.ml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ module Lib = struct
in
let jsoo_runtime = Lib_info.jsoo_runtime info in
let virtual_ = Option.is_some (Lib_info.virtual_ info) in
let instrumentation_backend = Lib_info.instrumentation_backend info in
record_fields
@@ [ field "name" Lib_name.encode name
; field "kind" Lib_kind.encode kind
Expand All @@ -82,6 +83,8 @@ module Lib = struct
; field_o "modules" Modules.encode modules
; field_o "special_builtin_support"
Lib_info.Special_builtin_support.encode special_builtin_support
; field_o "instrumentation.backend" (no_loc Lib_name.encode)
instrumentation_backend
]
@ ( Sub_system_name.Map.to_list sub_systems
|> List.map ~f:(fun (name, info) ->
Expand Down Expand Up @@ -145,6 +148,8 @@ module Lib = struct
field_o "special_builtin_support"
( Dune_lang.Syntax.since Stanza.syntax (1, 10)
>>> Lib_info.Special_builtin_support.decode )
and+ instrumentation_backend =
field_o "instrumentation.backend" (located Lib_name.decode)
in
let modes = Mode.Dict.Set.of_list modes in
let info : Path.t Lib_info.t =
Expand Down Expand Up @@ -176,7 +181,7 @@ module Lib = struct
~jsoo_runtime ~jsoo_archive ~preprocess ~enabled ~virtual_deps
~dune_version ~virtual_ ~implements ~default_implementation ~modes
~wrapped ~special_builtin_support ~exit_module:None
~instrumentation_backend:None
~instrumentation_backend
in
{ info; main_module_name; modules })

Expand Down
27 changes: 26 additions & 1 deletion test/blackbox-tests/test-cases/instrumentation.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Dune!" at the beginning of the module.
> (modules main)
> (libraries mylib)
> (instrumentation (backend hello)))
>
> (library
> (name mylib)
> (modules mylib)
Expand Down Expand Up @@ -106,3 +105,29 @@ Per-context setting takes precedence over per-workspace setting.
$ dune build

$ _build/coverage/main.exe

Next, we check the backend can be used when it is installed.

$ dune build ppx/hello.install
$ dune install hello --prefix _install 2>/dev/null
$ grep instrumentation.backend _install/lib/hello/dune-package
(instrumentation.backend hello.ppx))
$ mkdir -p installed
$ cat >installed/dune-workspace <<EOF
> (lang dune 2.7)
> (instrument_with hello)
> EOF
$ cat >installed/dune-project <<EOF
> (lang dune 2.7)
> EOF
$ cat >installed/dune <<EOF
> (executable
> (name main)
> (instrumentation (backend hello)))
> EOF
$ cat >installed/main.ml <<EOF
> EOF
$ OCAMLPATH=$PWD/_install/lib dune build --root installed
Entering directory 'installed'
$ installed/_build/default/main.exe
Hello, Dune!