Jbuilder warning, aliases must not have targets

Hi, I’ve been trying to make a jbuild file for tests (alcotest), but before running them I want to copy one file into the same directory with the tests.exe. I described an executable part in the jbuild, and below an alias to run tests with “jbuilder build @_build/default/src/runtest”. The alias part looks like

(alias
 ((name runtest)
  (deps (tests.exe))
  (action
    (progn
      (copy path/file1.txt file2.txt)
      (run ${<})))
 )
)

Everything works fine, but there is a warning saying “Warning: Aliases must not have targets, this target will be ignored. This will become an error in the future.”. It points out to the file2.txt. How it can be fixed?

you can setup the copy rule on the side:

(alias
 ((name runtest)
  (deps (tests.exe))
  (action (run ${<})))

(rule (copy path/file1.txt file2.txt))

(Note that you should probably specify file2.txt as a dependency of running tests.exe).

A few users have been bitten by this, maybe we should just allow it.

Hi. This solution worked fine with jbuilder, but once I updated to dune the build process fails with “Error: path outside the workspace:”. I’ve updated all parts to dune according to https://dune.readthedocs.io/en/latest/migration.html.
Is there a way to add to the workspace the whole project folder or maybe only path/file1.txt? “path/file1.txt” is located in the root folder of the project.

@alrev, could you provide the dune file that causes this error?

(executables
  (names project1 tests)
    (libraries
      core_kernel
      core
      async
      alcotest-async)
  (preprocess (pps ppx_jane))
  (modes native)
  (modules project1 module1 module2 tests)
)

(alias
 (name runtest)
  (deps tests.exe test_file.txt)
  (action (run ./tests.exe))
)

(rule (copy ../../../test_data/test_file.txt test_file.txt))

The folder structure is
project1
project1/project1.opam
project1/src
project1/test_data

I want to copy somehow files from “test_data” folder to the “_build/default/src/” before running “tests.exe”. Maybe there is a better approach? Thanks for the help.

Can you try:

(rule (copy ../test_data/test_file.txt test_file.txt))

? Source files are automatically copied from the source tree to the _build/default directory on demand, and only dune itself is allowed to do that.

1 Like

It works.
By having 3 “…” in the ../../../test_data/test_file.txt I thought we go back to the root project folder out of the _build/default/src, which worked somehow with jbuilder. Now I see the test_data folder in the _build/default.
Thanks for the explanation.

It indeed used to work with jbuilder, however in Dune we added the possibility to change the build directory (via a command line option or environment variable) so we made such paths forbidden.