Skip to content

Commit

Permalink
Rename path variables in dune files
Browse files Browse the repository at this point in the history
- `${path:file}` -> `%{dep:file}`
- `${path-no-dep:file}` -> `%{path:file}`

See #842

Signed-off-by: Etienne Millon <etienne@cryptosense.com>
  • Loading branch information
emillon committed Jul 2, 2018
1 parent 741d323 commit e0ad299
Show file tree
Hide file tree
Showing 15 changed files with 100 additions and 33 deletions.
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
6 changes: 3 additions & 3 deletions doc/dune-files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -828,10 +828,10 @@ 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>``
- ``path-no-dep:<path>`` is the same as ``path:<path>``, except that
- ``dep:<path>`` expands to ``<path>``
- ``path:<path>`` is the same as ``dep:<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``
``(chdir ${ROOT} (run foo --base ${path:bar}))`` in ``src/blah/jbuild``
will expand to ``(chdir ../.. (run foo --base src/blah/bar))`` where
``src/blah/bar`` doesn't have to be an existing or buildable file
- ``exe:<path>`` is the same as ``<path>``, except when cross-compiling, in
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}))))
17 changes: 14 additions & 3 deletions src/super_context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -631,9 +631,15 @@ 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 is_path_with_dep = function
| "path" when syntax_version < (1, 0) -> true
| "dep" when syntax_version >= (1, 0) -> true
| _ -> false
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 ("exe", s) -> Some (path_exp (map_exe (Path.relative dir s)))
| Pair (key, s) when is_path_with_dep key ->
Some (path_exp (Path.relative dir s) )
| Pair ("bin" , s) -> begin
let sctx = host sctx in
match Artifacts.binary (artifacts sctx) s with
Expand Down Expand Up @@ -730,6 +736,11 @@ module Action = struct
U.partial_expand t ~dir ~map_exe ~f:(fun var syntax_version ->
let var_name = String_with_vars.Var.full_name var in
let loc = String_with_vars.Var.loc var in
let is_path_without_dep = function
| "path-no-dep" when syntax_version < (1, 0) -> true
| "path" when syntax_version >= (1, 0) -> true
| _ -> false
in
match var_name with
| "ROOT" -> Some (path_exp sctx.context.build_dir)
| "SCOPE_ROOT" -> Some (path_exp (Scope.root scope))
Expand All @@ -741,7 +752,7 @@ module Action = struct
end
| _ ->
match String_with_vars.Var.destruct var with
| Pair ("path-no-dep", s) ->
| Pair (key, s) when is_path_without_dep key ->
Some (path_exp (Path.relative dir s))
| _ ->
let exp = expand var syntax_version in
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 @@ -473,6 +473,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 @@ -645,6 +653,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 @@ -711,6 +720,7 @@
(alias ocamldep-multi-stanzas)
(alias output-obj)
(alias package-dep)
(alias path-variables)
(alias promote)
(alias quoting)
(alias redirections)
Expand Down
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/aliases/src/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(alias
(name x)
(action (chdir %{ROOT} (echo "running in %{path-no-dep:.}\n"))))
(action (chdir %{ROOT} (echo "running in %{path:.}\n"))))
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/aliases/src/foo/bar/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(alias
(name x)
(action (chdir %{ROOT} (echo "running in %{path-no-dep:.}\n"))))
(action (chdir %{ROOT} (echo "running in %{path:.}\n"))))
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/aliases/src/foo/baz/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(alias
(name x)
(action (chdir %{ROOT} (echo "running in %{path-no-dep:.}\n"))))
(action (chdir %{ROOT} (echo "running in %{path:.}\n"))))
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
18 changes: 18 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,18 @@
;; path with dependency

(rule (write-file generated-file dynamic-contents))

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

;; path without dependency

(alias
(name test-path-without-dep)
(action
(chdir
sub-tree/dir
(progn
(echo "%{path:file-that-doesn't-exist}\n")
(echo "%{path:.}\n")))))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(lang dune 1.0)
18 changes: 18 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,18 @@
;; path with dependency

(rule (write-file generated-file dynamic-contents))

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

;; path without dependency

(alias
((name test-path-without-dep)
(action
(chdir
sub-tree/dir
(progn
(echo "${path-no-dep:file-that-doesn't-exist}\n")
(echo "${path-no-dep:.}\n"))))))
29 changes: 29 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,29 @@
In dune files, %{dep:string} expands to a file name, and registers this as a
dependency.

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

On the contrary, %{path:string} expands to a file name, but does
not register it as a dependency.

$ dune build --root dune @test-path-without-dep
Entering directory 'dune'
../../file-that-doesn't-exist
../..

In jbuild files, the legacy syntax is ${path:string} to register the
dependency:

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

and ${path-no-dep:string} to not include it.

$ dune build --root jbuild @test-path-without-dep
Entering directory 'jbuild'
../../file-that-doesn't-exist
../..

0 comments on commit e0ad299

Please sign in to comment.