Jbuilder to dune : what is first-dep

jbuilder
dune

#1

I am trying to convert my jbuild files to dune files. Following this documentation :

I changed my jbuild file for the tests to:

(executables
 (names test)
 (libraries GObject_introspection oUnit ctypes ctypes.foreign)
)

(alias
  (name    runtest)
  (deps    test.exe)
  (action  (run %{first-dep})))

When I run the test I have the following error:

dune runtest
File "tests/dune", line 9, characters 18-28:                                                                 
Error: Unknown variable "first-dep"

I tried to look in the documentation for more information on the first-dep but found nothing.

My dune version is 1.0.1.


#2

Does it works?

(alias
  (name    runtest)
  (deps    (:x test.exe))
  (action  (run %{x})))

#3

Yes, it works thanks!. I thought that first-dep was a default/generic variable name. This is not something obvious, the documentation is not finished I guess.


#4

Mind sending a pr to fix the docs here? %{first-dep} indeed used to be a built-in before we introduced the variable binding syntax. Now that there you can bind deps to your own names, there’s no need for this default name.


#5

I am working on it but I don’t see how to replace it here :

    (rule
     (targets foo.ml)
     (deps    foo.cppo.ml <other files that foo.ml includes>)
     (action  (run %{bin:cppo} %{first-dep} -o %{targets})))

and here:

    (preprocess (action (run %{bin:cppo} -V OCAML:%{ocaml_version} %{first-dep})))

#6

In the first instance, you should write your deps field as such:

(deps (:first-dep foo.cppo.ml) <other files that foo.ml includes>)

The second example is dealt with the new special variable for preprocessing: %{input-file}


#7

I filed https://github.com/ocaml/dune/issues/1063 to track this in the meantime.


#8

This should also work

(alias
  (name    runtest)
  (deps    test.exe)
  (action  (run %{deps})))

#9

Even shorter:

(alias
 (name runtest)
 (action (run ./test.exe))

But this is best:

(test (name test.exe))

:slight_smile: