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

feature(cinaps): runtime dependencies #6175

Merged
merged 1 commit into from
Oct 3, 2022
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
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
3.5.0 (unreleased)
------------------

- Add a `runtime_deps` field in the `cinaps` stanza to specify runtime
dependencies for running the cinaps preprocessing action (#6175, @rgrinberg)

- Shadow alias module `Foo__` when building a library `Foo` (#6126, @rgrinberg)

- Allow dune describe workspace to accept directories as arguments.
Expand Down
14 changes: 11 additions & 3 deletions src/dune_rules/cinaps.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type t =
; libraries : Lib_dep.t list
; preprocess : Preprocess.Without_instrumentation.t Preprocess.Per_module.t
; preprocessor_deps : Dep_conf.t list
; runtime_deps : Dep_conf.t list
}

let name = "cinaps"
Expand All @@ -14,7 +15,7 @@ type Stanza.t += T of t

let syntax =
Dune_lang.Syntax.create ~name ~desc:"the cinaps extension"
[ ((1, 0), `Since (1, 11)) ]
[ ((1, 0), `Since (1, 11)); ((1, 1), `Since (3, 5)) ]

let alias = Alias.make (Alias.Name.of_string name)

Expand All @@ -27,9 +28,12 @@ let decode =
and+ preprocess, preprocessor_deps = Dune_file.preprocess_fields
and+ libraries =
field "libraries" (Dune_file.Lib_deps.decode Executable) ~default:[]
and+ runtime_deps =
field ~default:[] "runtime_deps"
(Dune_lang.Syntax.since syntax (1, 1) >>> repeat Dep_conf.decode)
(* TODO use this field? *)
and+ _flags = Ocaml_flags.Spec.decode in
{ loc; files; libraries; preprocess; preprocessor_deps })
{ loc; files; libraries; preprocess; preprocessor_deps; runtime_deps })

let () =
let open Dune_lang.Decoder in
Expand Down Expand Up @@ -130,8 +134,12 @@ let gen_rules sctx t ~dir ~scope =
let open Action_builder.O in
let module A = Action in
let cinaps_exe = Path.build cinaps_exe in
let runtime_deps, sandbox =
Dep_conf_eval.unnamed ~expander t.runtime_deps
in
let* () = runtime_deps in
let+ () = Action_builder.path cinaps_exe in
Action.Full.make
Action.Full.make ~sandbox
@@ A.chdir (Path.build dir)
(A.progn
(A.run (Ok cinaps_exe) [ "-diff-cmd"; "-" ]
Expand Down
30 changes: 30 additions & 0 deletions test/blackbox-tests/test-cases/cinaps/runtime-deps.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Runtime dependencies for running cinaps

$ cat > dune-project <<EOF
> (lang dune 3.5)
> (using cinaps 1.1)
> EOF

$ cat > foo <<EOF
> hello world
> EOF

$ cat > dune <<EOF
> (cinaps
> (files *.ml)
> (runtime_deps foo))
> EOF

$ cat > test.ml <<EOF
> (*$ let f = open_in "foo" in print_endline (input_line f); close_in f *)
> (*$*)
> EOF

$ dune build @cinaps --auto-promote
File "test.ml", line 1, characters 0-0:
Error: Files _build/default/test.ml and
_build/default/test.ml.cinaps-corrected differ.
Promoting _build/default/test.ml.cinaps-corrected to test.ml.
[1]
$ cat test.ml
(*$ let f = open_in "foo" in print_endline (input_line f); close_in f *)hello world