diff --git a/CHANGES.md b/CHANGES.md index d12e9e75..b961f606 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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) ----------------------- diff --git a/doc/dune b/doc/dune index d65a7841..657df0df 100644 --- a/doc/dune +++ b/doc/dune @@ -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) diff --git a/doc/dune-files.rst b/doc/dune-files.rst index 26391c1b..b07bb7e3 100644 --- a/doc/dune-files.rst +++ b/doc/dune-files.rst @@ -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:`` expands to ```` +- ``dep:`` expands to ```` - ``path-no-dep:`` is the same as ``path:``, except that ```` is not considered as a dependency of the action. For instance ``(chdir ${ROOT} (run foo --base ${path-no-dep:bar}))`` in ``src/blah/jbuild`` diff --git a/example/sample-projects/hello_world/test/dune b/example/sample-projects/hello_world/test/dune index 192b315a..4d6083e6 100644 --- a/example/sample-projects/hello_world/test/dune +++ b/example/sample-projects/hello_world/test/dune @@ -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})))) diff --git a/example/sample-projects/with-configure-step/dune b/example/sample-projects/with-configure-step/dune index ead9dc07..884ba33b 100644 --- a/example/sample-projects/with-configure-step/dune +++ b/example/sample-projects/with-configure-step/dune @@ -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})))) diff --git a/src/super_context.ml b/src/super_context.ml index f769a995..c6273ae7 100644 --- a/src/super_context.ml +++ b/src/super_context.ml @@ -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) diff --git a/test/blackbox-tests/dune.inc b/test/blackbox-tests/dune.inc index efcea69d..46e6ed43 100644 --- a/test/blackbox-tests/dune.inc +++ b/test/blackbox-tests/dune.inc @@ -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)) @@ -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) @@ -721,6 +730,7 @@ (alias ocamldep-multi-stanzas) (alias output-obj) (alias package-dep) + (alias path-variables) (alias promote) (alias quoting) (alias redirections) diff --git a/test/blackbox-tests/test-cases/misc/dune b/test/blackbox-tests/test-cases/misc/dune index 5fcce8de..44ca475e 100644 --- a/test/blackbox-tests/test-cases/misc/dune +++ b/test/blackbox-tests/test-cases/misc/dune @@ -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 diff --git a/test/blackbox-tests/test-cases/misc/run.t b/test/blackbox-tests/test-cases/misc/run.t index 9ad4bc2d..4b02d83e 100644 --- a/test/blackbox-tests/test-cases/misc/run.t +++ b/test/blackbox-tests/test-cases/misc/run.t @@ -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 diff --git a/test/blackbox-tests/test-cases/path-variables/dune/dune b/test/blackbox-tests/test-cases/path-variables/dune/dune new file mode 100644 index 00000000..6d5c2c34 --- /dev/null +++ b/test/blackbox-tests/test-cases/path-variables/dune/dune @@ -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"))))) diff --git a/test/blackbox-tests/test-cases/path-variables/dune/dune-project b/test/blackbox-tests/test-cases/path-variables/dune/dune-project new file mode 100644 index 00000000..de4fc209 --- /dev/null +++ b/test/blackbox-tests/test-cases/path-variables/dune/dune-project @@ -0,0 +1 @@ +(lang dune 1.0) diff --git a/test/blackbox-tests/test-cases/path-variables/jbuild-invalid/jbuild b/test/blackbox-tests/test-cases/path-variables/jbuild-invalid/jbuild new file mode 100644 index 00000000..8d58e353 --- /dev/null +++ b/test/blackbox-tests/test-cases/path-variables/jbuild-invalid/jbuild @@ -0,0 +1,5 @@ +(rule (write-file generated-file dynamic-contents)) + +(alias + ((name test-dep) + (action (cat ${dep:generated-file})))) diff --git a/test/blackbox-tests/test-cases/path-variables/jbuild/jbuild b/test/blackbox-tests/test-cases/path-variables/jbuild/jbuild new file mode 100644 index 00000000..f81d5cfe --- /dev/null +++ b/test/blackbox-tests/test-cases/path-variables/jbuild/jbuild @@ -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")))))) diff --git a/test/blackbox-tests/test-cases/path-variables/run.t b/test/blackbox-tests/test-cases/path-variables/run.t new file mode 100644 index 00000000..69a6cad2 --- /dev/null +++ b/test/blackbox-tests/test-cases/path-variables/run.t @@ -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]