Rename %{<} to %{deps[0]} and implement %{deps[i]}

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
Rudi Grinberg 2018-07-06 14:42:14 +07:00
parent 97fba5537d
commit 204b21f4fb
16 changed files with 57 additions and 49 deletions

View File

@ -136,7 +136,7 @@ Add this field to your ``library`` or ``executable`` stanzas:
.. code:: scheme
(preprocess (action (run %{bin:cppo} -V OCAML:%{ocaml_version} %{<})))
(preprocess (action (run %{bin:cppo} -V OCAML:%{ocaml_version} %{deps[0]})))
Additionally, if you are include a ``config.h`` file, you need to
declare the dependency to this file via:
@ -155,7 +155,7 @@ Write this in your ``dune`` file:
(rule
(targets foo.ml)
(deps foo.cppo.ml <other files that foo.ml includes>)
(action (run %{bin:cppo} %{<} -o %{targets})))
(action (run %{bin:cppo} %{deps[0]} -o %{targets})))
Defining a library with C stubs
===============================
@ -193,7 +193,7 @@ compilation and link flags. Write this ``dune`` file:
(rule
(targets c_flags.sexp c_library_flags.sexp)
(deps config/discover.exe)
(action (run %{<} -ocamlc %{OCAMLC})))
(action (run %{deps[0]} -ocamlc %{OCAMLC})))
Then create a ``config`` subdirectory and write this ``dune`` file:
@ -241,7 +241,7 @@ To generate a file ``foo.ml`` using a program from another directory:
(rule
(targets foo.ml)
(deps ../generator/gen.exe)
(action (run %{<} -o %{targets})))
(action (run %{deps[0]} -o %{targets})))
Defining tests
==============
@ -253,7 +253,7 @@ Write this in your ``dune`` file:
(alias
(name runtest)
(deps my-test-program.exe)
(action (run %{<})))
(action (run %{deps[0]})))
And run the tests with:

View File

@ -2,7 +2,7 @@
((fallback)
(targets (config))
(deps (config.defaults))
(action (copy %{<} %{targets}))))
(action (copy %{deps[0]} %{targets}))))
(rule
((targets (config.full))

View File

@ -8,5 +8,5 @@
(rule
((targets (config.ml))
(deps (../config.full))
(action (copy %{<} %{targets}))))
(action (copy %{deps[0]} %{targets}))))

View File

@ -11,7 +11,7 @@
which_program)
(synopsis "Internal Dune library, do not use!"))
(ocamllex meta_lexer glob_lexer dune_lexer)
(ocamllex meta_lexer glob_lexer dune_lexer dune_vars)
(rule
(targets setup.ml)

View File

@ -1243,7 +1243,7 @@ module Rule = struct
[ S.virt_text __POS__ "-q"
; S.virt_text __POS__ "-o"
; S.virt_var __POS__ "targets"
; S.virt_var __POS__"<"
; S.virt_var __POS__"deps[0]"
])))
; mode
; locks = []
@ -1261,7 +1261,7 @@ module Rule = struct
Chdir
(S.virt_var __POS__ "ROOT",
Run (S.virt_text __POS__ "ocamlyacc",
[S.virt_var __POS__ "<"])))
[S.virt_var __POS__ "deps[0]"])))
; mode
; locks = []
; loc

View File

@ -807,16 +807,20 @@ module Action = struct
match String.Map.find dynamic_expansions key with
| Some _ as opt -> opt
| None ->
let dep i =
match List.nth deps_written_by_user i with
| None ->
Loc.warn loc "Variable '%s' used with no explicit \
dependencies@." key;
[Value.String ""]
| Some v -> [Path v]
in
match key with
| "<" ->
Some
(match deps_written_by_user with
| [] ->
Loc.warn loc "Variable '<' used with no explicit \
dependencies@.";
[Value.String ""]
| dep :: _ ->
[Path dep])
if syntax_version < (1, 0) then
Some (dep 0)
else
Loc.fail loc "Variable '<' is renamed to 'deps[0]' in dune"
| "^" ->
if syntax_version < (1, 0) then
Some (Value.L.paths deps_written_by_user)
@ -824,7 +828,11 @@ module Action = struct
Loc.fail loc "Variable %%{^} has been renamed to %%{deps}"
| "deps" when syntax_version >= (1, 0) ->
Some (Value.L.paths deps_written_by_user)
| _ -> None)
| _ ->
if syntax_version < (1, 0) then
None
else
Option.map (Dune_vars.deps key) ~f:dep)
let run sctx ~loc ?(extra_vars=String.Map.empty)
t ~dir ~dep_kind ~targets:targets_written_by_user ~scope

View File

@ -4,4 +4,4 @@
(alias
(name runtest)
(deps f.exe)
(action (run %{<})))
(action (run %{deps[0]})))

View File

@ -8,7 +8,7 @@
(name runtest)
(package lib1)
(deps test1.exe)
(action (run %{<})))
(action (run %{deps[0]})))
(executable
(name test1)
@ -25,7 +25,7 @@
(name runtest)
(package lib2)
(deps test2.exe)
(action (run %{<})))
(action (run %{deps[0]})))
(executable
(name test2)

View File

@ -1,6 +1,6 @@
(alias
(name runtest)
(deps main.exe)
(action (run %{<})))
(action (run %{deps[0]})))
(executable (name main))

View File

@ -1,6 +1,6 @@
(alias
(name runtest)
(deps main.exe)
(action (run %{<})))
(action (run %{deps[0]})))
(executable (name main))

View File

@ -33,7 +33,7 @@
(rule
(targets dynamic.exe)
(deps dynamic.c)
(action (run %{CC} -o %{targets} %{<} %{ocaml-config:native_c_libraries})))
(action (run %{CC} -o %{targets} %{deps[0]} %{ocaml-config:native_c_libraries})))
(alias
(name runtest)
@ -48,9 +48,9 @@
(alias
(name runtest)
(deps test.bc%{ext_dll})
(action (run ./dynamic.exe ./%{<})))
(action (run ./dynamic.exe ./%{deps[0]})))
(alias
(name runtest)
(deps test%{ext_dll})
(action (run ./dynamic.exe ./%{<})))
(action (run ./dynamic.exe ./%{deps[0]})))

View File

@ -8,18 +8,18 @@
(lint
(per_module
((pps (reasonppx (-lint true))) (hello cppome))
((action (run ./pp/reasononlypp.exe -lint %{<})) (foo bar pped))))
((action (run ./pp/reasononlypp.exe -lint %{deps[0]})) (foo bar pped))))
(preprocess
(per_module
((pps (reasonppx)) (foo))
((pps (reasonppx (-lint false))) (hello))
((action (run ./pp/reasononlypp.exe %{<})) (cppome))))))
((action (run ./pp/reasononlypp.exe %{deps[0]})) (cppome))))))
(executable
((name rbin)
(modules rbin)
(lint (action (run ./pp/reasononlypp.exe -lint %{<})))
(preprocess (action (run ./pp/reasononlypp.exe %{<})))
(lint (action (run ./pp/reasononlypp.exe -lint %{deps[0]})))
(preprocess (action (run ./pp/reasononlypp.exe %{deps[0]})))
(libraries (rlib))))
;; we want to make sure that .rei files are present
@ -31,4 +31,4 @@
(alias
((name runtest)
(deps (rbin.exe))
(action (run %{<}))))
(action (run %{deps[0]}))))

View File

@ -11,4 +11,4 @@
(alias
(name runtest)
(deps main.exe)
(action (run %{<})))
(action (run %{deps[0]})))

View File

@ -5,4 +5,4 @@
(alias
(name runtest)
(deps ./test_configurator.exe)
(action (run %{<})))
(action (run %{deps[0]})))

View File

@ -25,8 +25,8 @@
(source_tree findlib-db))
(action (chdir %{project_root}
(progn
(run %{exe:expect_test.exe} %{<})
(diff? %{<} %{<}.corrected)))))
(run %{exe:expect_test.exe} %{deps[0]})
(diff? %{deps[0]} %{deps[0]}.corrected)))))
(alias
(name runtest)
@ -35,8 +35,8 @@
(glob_files %{project_root}/src/stdune/.stdune.objs/*.cmi))
(action (chdir %{project_root}
(progn
(run %{exe:expect_test.exe} %{<})
(diff? %{<} %{<}.corrected)))))
(run %{exe:expect_test.exe} %{deps[0]})
(diff? %{deps[0]} %{deps[0]}.corrected)))))
(alias
(name runtest)
@ -45,8 +45,8 @@
(glob_files %{project_root}/src/stdune/.stdune.objs/*.cmi))
(action (chdir %{project_root}
(progn
(run %{exe:expect_test.exe} %{<})
(diff? %{<} %{<}.corrected)))))
(run %{exe:expect_test.exe} %{deps[0]})
(diff? %{deps[0]} %{deps[0]}.corrected)))))
(alias
(name runtest)
@ -55,8 +55,8 @@
(glob_files %{project_root}/src/stdune/.stdune.objs/*.cmi))
(action (chdir %{project_root}
(progn
(run %{exe:expect_test.exe} %{<})
(diff? %{<} %{<}.corrected)))))
(run %{exe:expect_test.exe} %{deps[0]})
(diff? %{deps[0]} %{deps[0]}.corrected)))))
(alias
(name runtest)
@ -65,8 +65,8 @@
(glob_files %{project_root}/src/stdune/.stdune.objs/*.cmi))
(action (chdir %{project_root}
(progn
(run %{exe:expect_test.exe} %{<})
(diff? %{<} %{<}.corrected)))))
(run %{exe:expect_test.exe} %{deps[0]})
(diff? %{deps[0]} %{deps[0]}.corrected)))))
(alias
(name runtest)
@ -75,8 +75,8 @@
(glob_files %{project_root}/src/stdune/.stdune.objs/*.cmi))
(action (chdir %{project_root}
(progn
(run %{exe:expect_test.exe} %{<})
(diff? %{<} %{<}.corrected)))))
(run %{exe:expect_test.exe} %{deps[0]})
(diff? %{deps[0]} %{deps[0]}.corrected)))))
(alias
(name runtest)
@ -85,5 +85,5 @@
(glob_files %{project_root}/src/stdune/.stdune.objs/*.cmi))
(action (chdir %{project_root}
(progn
(run %{exe:expect_test.exe} %{<})
(diff? %{<} %{<}.corrected)))))
(run %{exe:expect_test.exe} %{deps[0]})
(diff? %{deps[0]} %{deps[0]}.corrected)))))

View File

@ -5,4 +5,4 @@
(alias
(name runtest)
(deps ./gh637.exe)
(action (run %{<})))
(action (run %{deps[0]})))