Skip to content

Commit

Permalink
Rename path to dep in dune files
Browse files Browse the repository at this point in the history
See #842

Signed-off-by: Etienne Millon <etienne@cryptosense.com>
  • Loading branch information
emillon committed Jul 3, 2018
1 parent e6a5ef9 commit c580abf
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 28 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ next

- Add the `lib_root` and `libexec_root` install sections (#947, @diml)

- Rename `path:file` to `dep:file` (#944, @emillon)

1.0+beta20 (10/04/2018)
-----------------------

Expand Down
2 changes: 1 addition & 1 deletion doc/dune
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
(deps (package dune))
(action
(with-stdout-to %{@}
(run bash %{path:update-jbuild.sh}))))
(run bash %{dep:update-jbuild.sh}))))

(alias
(name runtest)
Expand Down
2 changes: 1 addition & 1 deletion doc/dune-files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ In addition, ``(action ...)`` fields support the following special variables:
- ``<`` expands to the first dependency, or the empty string if there are no
dependencies
- ``^`` expands to the list of dependencies, separated by spaces
- ``path:<path>`` expands to ``<path>``
- ``dep:<path>`` expands to ``<path>``
- ``path-no-dep:<path>`` is the same as ``path:<path>``, except that
``<path>`` is not considered as a dependency of the action. For instance
``(chdir ${ROOT} (run foo --base ${path-no-dep:bar}))`` in ``src/blah/jbuild``
Expand Down
2 changes: 1 addition & 1 deletion example/sample-projects/hello_world/test/dune
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

(alias
((name runtest)
(action (run diff -uw %{path:hello_world.expected} %{path:hello_world.output}))))
(action (run diff -uw %{dep:hello_world.expected} %{dep:hello_world.output}))))
2 changes: 1 addition & 1 deletion example/sample-projects/with-configure-step/dune
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
(rule
((targets (config.full))
(deps (config_common.ml config))
(action (run %{OCAML} %{path:real_configure.ml}))))
(action (run %{OCAML} %{dep:real_configure.ml}))))
19 changes: 16 additions & 3 deletions src/super_context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -631,10 +631,23 @@ module Action = struct
let expand var syntax_version =
let loc = String_with_vars.Var.loc var in
let key = String_with_vars.Var.full_name var in
let path_with_dep s =
Some (path_exp (Path.relative dir s) )
in
match String_with_vars.Var.destruct var with
| Pair ("exe" , s) -> Some (path_exp (map_exe (Path.relative dir s)))
| Pair ("path" , s) -> Some (path_exp (Path.relative dir s) )
| Pair ("bin" , s) -> begin
| Pair ("exe", s) -> Some (path_exp (map_exe (Path.relative dir s)))
| Pair ("path", s) when syntax_version < (1, 0) ->
path_with_dep s
| Pair ("dep", s) when syntax_version >= (1, 0) ->
path_with_dep s
| Pair ("dep", s) ->
Loc.fail
loc
"${dep:%s} is not supported in jbuild files.\n\
Did you mean: ${path:%s}"
s
s
| Pair ("bin", s) -> begin
let sctx = host sctx in
match Artifacts.binary (artifacts sctx) s with
| Ok path -> Some (path_exp path)
Expand Down
10 changes: 10 additions & 0 deletions test/blackbox-tests/dune.inc
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,14 @@
test-cases/package-dep
(progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected)))))

(alias
(name path-variables)
(deps (package dune) (source_tree test-cases/path-variables))
(action
(chdir
test-cases/path-variables
(progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected)))))

(alias
(name ppx-rewriter)
(deps (package dune) (source_tree test-cases/ppx-rewriter))
Expand Down Expand Up @@ -654,6 +662,7 @@
(alias odoc-unique-mlds)
(alias output-obj)
(alias package-dep)
(alias path-variables)
(alias ppx-rewriter)
(alias private-public-overlap)
(alias promote)
Expand Down Expand Up @@ -721,6 +730,7 @@
(alias ocamldep-multi-stanzas)
(alias output-obj)
(alias package-dep)
(alias path-variables)
(alias promote)
(alias quoting)
(alias redirections)
Expand Down
19 changes: 0 additions & 19 deletions test/blackbox-tests/test-cases/misc/dune
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,6 @@

(rule (with-stdout-to 023e1a58-4d08-11e7-a041-aa000008c8a6 (echo "plop")))

;; Test for %{path-no-dep}

(rule
(progn
(with-stdout-to pnd-result
(chdir sub-tree/dir
(progn
(echo "%{path-no-dep:file-that-doesn't-exist}\n")
(echo "%{path-no-dep:.}\n"))))
(with-stdout-to pnd-expected
(progn
(echo "../../file-that-doesn't-exist\n")
(echo "../..\n")))))

(alias
(name runtest)
(deps pnd-result pnd-expected)
(action (run diff -u %{^})))

;; Test for globs

(alias
Expand Down
3 changes: 1 addition & 2 deletions test/blackbox-tests/test-cases/misc/run.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
$ dune runtest --display short
File "dune", line 63, characters 19-42:
File "dune", line 44, characters 19-42:
Warning: Directory dir-that-doesnt-exist doesn't exist.
diff alias runtest
diff alias runtest
diff alias runtest
diff alias runtest
23 changes: 23 additions & 0 deletions test/blackbox-tests/test-cases/path-variables/dune/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(rule (write-file generated-file dynamic-contents))

(alias
(name test-dep)
(action (cat %{dep:generated-file})))

(alias
(name test-path)
(action
(chdir
sub-tree/dir
(progn
(echo "%{path:file-that-does-not-exist}\n")
(echo "%{path:.}\n")))))

(alias
(name test-path-no-dep)
(action
(chdir
sub-tree/dir
(progn
(echo "%{path-no-dep:file-that-does-not-exist}\n")
(echo "%{path-no-dep:.}\n")))))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(lang dune 1.0)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(rule (write-file generated-file dynamic-contents))

(alias
((name test-dep)
(action (cat ${dep:generated-file}))))
14 changes: 14 additions & 0 deletions test/blackbox-tests/test-cases/path-variables/jbuild/jbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(rule (write-file generated-file dynamic-contents))

(alias
((name test-path)
(action (cat ${path:generated-file}))))

(alias
((name test-path-no-dep)
(action
(chdir
sub-tree/dir
(progn
(echo "${path-no-dep:file-that-does-not-exist}\n")
(echo "${path-no-dep:.}\n"))))))
55 changes: 55 additions & 0 deletions test/blackbox-tests/test-cases/path-variables/run.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
dune files
==========

%{dep:string}
-------------

In expands to a file name, and registers this as a dependency.

$ dune build --root dune @test-dep
Entering directory 'dune'
dynamic-contents

%{path-no-dep:string}
---------------------

It expands to a file name, but does not register it as a dependency.

$ dune build --root dune @test-path-no-dep
Entering directory 'dune'
../../file-that-does-not-exist
../..

jbuild files
============

${path:string}
--------------

This registers the dependency:

$ dune build --root jbuild @test-path
Entering directory 'jbuild'
dynamic-contents

${path-no-dep:string}
---------------------

This does not:

$ dune build --root jbuild @test-path-no-dep
Entering directory 'jbuild'
../../file-that-does-not-exist
../..

${dep:string}
--------------

This form does not exist, but displays an hint:

$ dune build --root jbuild-invalid @test-dep
Entering directory 'jbuild-invalid'
File "jbuild", line 5, characters 16-37:
Error: ${dep:generated-file} is not supported in jbuild files.
Did you mean: ${path:generated-file}
[1]

0 comments on commit c580abf

Please sign in to comment.