From a317fb0606a781c862d01a331d1ac6f32edef89a Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Fri, 6 Jul 2018 13:42:24 +0700 Subject: [PATCH] Rename %{@} to %{targets} Signed-off-by: Rudi Grinberg --- doc/dune | 2 +- doc/quick-start.rst | 4 +- example/sample-projects/hello_world/test/dune | 2 +- .../sample-projects/with-configure-step/dune | 2 +- .../with-configure-step/src/dune | 2 +- src/jbuild.ml | 2 +- src/preprocessing.ml | 2 +- src/string_with_vars.ml | 2 +- src/super_context.ml | 27 +++++++++---- test/blackbox-tests/dune | 2 +- .../blackbox-tests/test-cases/copy_files/dune | 2 +- test/blackbox-tests/test-cases/github534/dune | 2 +- .../blackbox-tests/test-cases/output-obj/dune | 6 +-- .../test-cases/quoting/bad/dune | 2 +- .../test-cases/quoting/good/dune | 2 +- test/blackbox-tests/test-cases/quoting/run.t | 4 +- .../test-cases/redirections/dune | 6 +-- test/dune | 40 +++++++++---------- 18 files changed, 62 insertions(+), 49 deletions(-) diff --git a/doc/dune b/doc/dune index 657df0df..ed2babc1 100644 --- a/doc/dune +++ b/doc/dune @@ -21,7 +21,7 @@ (targets dune.inc.gen) (deps (package dune)) (action - (with-stdout-to %{@} + (with-stdout-to %{targets} (run bash %{dep:update-jbuild.sh})))) (alias diff --git a/doc/quick-start.rst b/doc/quick-start.rst index 5e8a30a7..c23af0d6 100644 --- a/doc/quick-start.rst +++ b/doc/quick-start.rst @@ -155,7 +155,7 @@ Write this in your ``dune`` file: (rule (targets foo.ml) (deps foo.cppo.ml ) - (action (run %{bin:cppo} %{<} -o %{@}))) + (action (run %{bin:cppo} %{<} -o %{targets}))) Defining a library with C stubs =============================== @@ -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 %{@}))) + (action (run %{<} -o %{targets}))) Defining tests ============== diff --git a/example/sample-projects/hello_world/test/dune b/example/sample-projects/hello_world/test/dune index 4d6083e6..ec69a4aa 100644 --- a/example/sample-projects/hello_world/test/dune +++ b/example/sample-projects/hello_world/test/dune @@ -1,6 +1,6 @@ (rule ((targets (hello_world.output)) - (action (with-stdout-to %{@} (run %{bin:hello_world}))))) + (action (with-stdout-to %{targets} (run %{bin:hello_world}))))) (alias ((name runtest) diff --git a/example/sample-projects/with-configure-step/dune b/example/sample-projects/with-configure-step/dune index 884ba33b..84fdf05e 100644 --- a/example/sample-projects/with-configure-step/dune +++ b/example/sample-projects/with-configure-step/dune @@ -2,7 +2,7 @@ ((fallback) (targets (config)) (deps (config.defaults)) - (action (copy %{<} %{@})))) + (action (copy %{<} %{targets})))) (rule ((targets (config.full)) diff --git a/example/sample-projects/with-configure-step/src/dune b/example/sample-projects/with-configure-step/src/dune index 73447673..ffcf4ef4 100644 --- a/example/sample-projects/with-configure-step/src/dune +++ b/example/sample-projects/with-configure-step/src/dune @@ -8,5 +8,5 @@ (rule ((targets (config.ml)) (deps (../config.full)) - (action (copy %{<} %{@})))) + (action (copy %{<} %{targets})))) diff --git a/src/jbuild.ml b/src/jbuild.ml index b554633d..95ddbd4f 100644 --- a/src/jbuild.ml +++ b/src/jbuild.ml @@ -1242,7 +1242,7 @@ module Rule = struct Run (S.virt_text __POS__ "ocamllex", [ S.virt_text __POS__ "-q" ; S.virt_text __POS__ "-o" - ; S.virt_var __POS__ "@" + ; S.virt_var __POS__ "targets" ; S.virt_var __POS__"<" ]))) ; mode diff --git a/src/preprocessing.ml b/src/preprocessing.ml index 33ca9f65..18feab3c 100644 --- a/src/preprocessing.ml +++ b/src/preprocessing.ml @@ -397,7 +397,7 @@ let get_ppx_driver sctx ~loc ~scope ~dir_kind pps = >>= fun libs -> Ok (ppx_driver_exe sctx libs ~dir_kind, driver) -let target_var = String_with_vars.virt_var __POS__ "@" +let target_var = String_with_vars.virt_var __POS__ "targets" let root_var = String_with_vars.virt_var __POS__ "ROOT" let cookie_library_name lib_name = diff --git a/src/string_with_vars.ml b/src/string_with_vars.ml index c7977649..7e99f400 100644 --- a/src/string_with_vars.ml +++ b/src/string_with_vars.ml @@ -126,7 +126,7 @@ let loc t = t.template.loc let syntax_version t = t.syntax_version -let virt_syntax = (0, 0) +let virt_syntax = (1, 0) let virt ?(quoted=false) pos s = let template = Jbuild.parse ~quoted ~loc:(Loc.of_pos pos) s in diff --git a/src/super_context.ml b/src/super_context.ml index 72a4498e..2a743cd2 100644 --- a/src/super_context.ml +++ b/src/super_context.ml @@ -747,6 +747,18 @@ module Action = struct | Some _ as x -> x | None -> String.Map.find extra_vars key in + let targets loc name = + let var = + match name with + | "@" -> sprintf "${%s}" name + | "targets" -> sprintf "%%{%s}" name + | _ -> assert false + in + match targets_written_by_user with + | Infer -> Loc.fail loc "You cannot use %s with inferred rules." var + | Alias -> Loc.fail loc "You cannot use %s in aliases." var + | Static l -> Some (Value.L.paths l) + in let t = U.partial_expand t ~dir ~map_exe ~f:(fun var syntax_version -> let var_name = String_with_vars.Var.full_name var in @@ -755,19 +767,20 @@ module Action = struct | "ROOT" -> Some (path_exp sctx.context.build_dir) | "SCOPE_ROOT" -> if syntax_version >= (1, 0) then - Loc.fail (String_with_vars.Var.loc var) + Loc.fail loc "Variable %%{SCOPE_ROOT} has been renamed to %%{project_root} \ in dune files" else Some (path_exp (Scope.root scope)) | "project_root" when syntax_version >= (1, 0) -> Some (path_exp (Scope.root scope)) - | "@" -> begin - match targets_written_by_user with - | Infer -> Loc.fail loc "You cannot use ${@} with inferred rules." - | Alias -> Loc.fail loc "You cannot use ${@} in aliases." - | Static l -> Some (Value.L.paths l) - end + | "@" -> + if syntax_version >= (1, 0) then + targets loc var_name + else + Loc.fail loc (* variable substitution to avoid ugly escaping *) + "Variable %s has been renamed to %%{targets} in dune files" "%{@}" + | "targets" when syntax_version >= (1, 0) -> targets loc var_name | _ -> match String_with_vars.Var.destruct var with | Pair ("path-no-dep", s) -> diff --git a/test/blackbox-tests/dune b/test/blackbox-tests/dune index 08b5483b..3cf4bfba 100644 --- a/test/blackbox-tests/dune +++ b/test/blackbox-tests/dune @@ -22,7 +22,7 @@ (rule (targets dune.inc.gen) (deps (source_tree test-cases)) - (action (with-stdout-to %{@} (run ./gen_tests.exe)))) + (action (with-stdout-to %{targets} (run ./gen_tests.exe)))) (alias (name runtest) diff --git a/test/blackbox-tests/test-cases/copy_files/dune b/test/blackbox-tests/test-cases/copy_files/dune index be51f201..f64183c3 100644 --- a/test/blackbox-tests/test-cases/copy_files/dune +++ b/test/blackbox-tests/test-cases/copy_files/dune @@ -3,7 +3,7 @@ (rule (targets dummy.ml) - (action (with-stdout-to %{@} (echo "")))) + (action (with-stdout-to %{targets} (echo "")))) (library (name foo) diff --git a/test/blackbox-tests/test-cases/github534/dune b/test/blackbox-tests/test-cases/github534/dune index e8c96ba4..baf332e0 100644 --- a/test/blackbox-tests/test-cases/github534/dune +++ b/test/blackbox-tests/test-cases/github534/dune @@ -6,5 +6,5 @@ (deps (glob_files optional.ml) (glob_files *optional.ml)) (action - (with-stdout-to %{@} + (with-stdout-to %{targets} (run echo "let () = print_endline \"Hello World\"")))) diff --git a/test/blackbox-tests/test-cases/output-obj/dune b/test/blackbox-tests/test-cases/output-obj/dune index f42c90f9..e0d292fb 100644 --- a/test/blackbox-tests/test-cases/output-obj/dune +++ b/test/blackbox-tests/test-cases/output-obj/dune @@ -21,19 +21,19 @@ (rule (targets static.exe) (deps test.exe%{ext_obj} static.c) - (action (run %{CC} -o %{@} -I %{ocaml_where} -I . %{^} + (action (run %{CC} -o %{targets} -I %{ocaml_where} -I . %{^} %{ocaml-config:native_c_libraries}))) (rule (targets static.bc) (deps test.bc%{ext_obj} static.c) - (action (run %{CC} -o %{@} -I %{ocaml_where} -I . %{^} + (action (run %{CC} -o %{targets} -I %{ocaml_where} -I . %{^} %{ocaml-config:bytecomp_c_libraries}))) (rule (targets dynamic.exe) (deps dynamic.c) - (action (run %{CC} -o %{@} %{<} %{ocaml-config:native_c_libraries}))) + (action (run %{CC} -o %{targets} %{<} %{ocaml-config:native_c_libraries}))) (alias (name runtest) diff --git a/test/blackbox-tests/test-cases/quoting/bad/dune b/test/blackbox-tests/test-cases/quoting/bad/dune index 498d90ab..8f436e6b 100644 --- a/test/blackbox-tests/test-cases/quoting/bad/dune +++ b/test/blackbox-tests/test-cases/quoting/bad/dune @@ -1,3 +1,3 @@ (rule (targets x y) - (action (with-stdout-to %{@} (echo foo)))) \ No newline at end of file + (action (with-stdout-to %{targets} (echo foo)))) \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/quoting/good/dune b/test/blackbox-tests/test-cases/quoting/good/dune index 9f4961cf..801d3a4c 100644 --- a/test/blackbox-tests/test-cases/quoting/good/dune +++ b/test/blackbox-tests/test-cases/quoting/good/dune @@ -1,3 +1,3 @@ (rule (targets s t) - (action (with-stdout-to "%{@}" (echo foo)))) \ No newline at end of file + (action (with-stdout-to "%{targets}" (echo foo)))) \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/quoting/run.t b/test/blackbox-tests/test-cases/quoting/run.t index 6a2f63e3..15890bbc 100644 --- a/test/blackbox-tests/test-cases/quoting/run.t +++ b/test/blackbox-tests/test-cases/quoting/run.t @@ -3,8 +3,8 @@ that ${@} is not quoted and doesn't contain exactly 1 element $ dune build --root bad x Entering directory 'bad' - File "dune", line 3, characters 27-29: - Error: Variable %{@} expands to 2 values, however a single value is expected here. Please quote this atom. + File "dune", line 3, characters 27-35: + Error: Variable %{targets} expands to 2 values, however a single value is expected here. Please quote this atom. [1] The targets should only be interpreted as a single path when quoted diff --git a/test/blackbox-tests/test-cases/redirections/dune b/test/blackbox-tests/test-cases/redirections/dune index d2facb4c..eed4e961 100644 --- a/test/blackbox-tests/test-cases/redirections/dune +++ b/test/blackbox-tests/test-cases/redirections/dune @@ -15,15 +15,15 @@ (rule (targets stdout.expected) - (action (with-stdout-to %{@} (echo "toto\n")))) + (action (with-stdout-to %{targets} (echo "toto\n")))) (rule (targets stderr.expected) - (action (with-stdout-to %{@} (echo "titi\n")))) + (action (with-stdout-to %{targets} (echo "titi\n")))) (rule (targets both.expected) - (action (with-stdout-to %{@} (echo "toto\ntiti\n")))) + (action (with-stdout-to %{targets} (echo "toto\ntiti\n")))) (alias (name runtest) diff --git a/test/dune b/test/dune index db9d8658..37c35a04 100644 --- a/test/dune +++ b/test/dune @@ -51,27 +51,27 @@ Printf.fprintf (open_out Sys.argv.(2)) \"%g\n%!\" (Sys.time ()) (executable (name incr) (libraries unix)) -(rule (targets 01.foo) (action (run ./incr.exe x %{@}))) -(rule (targets 02.foo) (action (run ./incr.exe x %{@}))) -(rule (targets 03.foo) (action (run ./incr.exe x %{@}))) -(rule (targets 04.foo) (action (run ./incr.exe x %{@}))) -(rule (targets 05.foo) (action (run ./incr.exe x %{@}))) -(rule (targets 06.foo) (action (run ./incr.exe x %{@}))) -(rule (targets 07.foo) (action (run ./incr.exe x %{@}))) -(rule (targets 08.foo) (action (run ./incr.exe x %{@}))) -(rule (targets 09.foo) (action (run ./incr.exe x %{@}))) -(rule (targets 10.foo) (action (run ./incr.exe x %{@}))) +(rule (targets 01.foo) (action (run ./incr.exe x %{targets}))) +(rule (targets 02.foo) (action (run ./incr.exe x %{targets}))) +(rule (targets 03.foo) (action (run ./incr.exe x %{targets}))) +(rule (targets 04.foo) (action (run ./incr.exe x %{targets}))) +(rule (targets 05.foo) (action (run ./incr.exe x %{targets}))) +(rule (targets 06.foo) (action (run ./incr.exe x %{targets}))) +(rule (targets 07.foo) (action (run ./incr.exe x %{targets}))) +(rule (targets 08.foo) (action (run ./incr.exe x %{targets}))) +(rule (targets 09.foo) (action (run ./incr.exe x %{targets}))) +(rule (targets 10.foo) (action (run ./incr.exe x %{targets}))) -(rule (targets 01.bar) (action (run ./incr.exe y %{@})) (locks m)) -(rule (targets 02.bar) (action (run ./incr.exe y %{@})) (locks m)) -(rule (targets 03.bar) (action (run ./incr.exe y %{@})) (locks m)) -(rule (targets 04.bar) (action (run ./incr.exe y %{@})) (locks m)) -(rule (targets 05.bar) (action (run ./incr.exe y %{@})) (locks m)) -(rule (targets 06.bar) (action (run ./incr.exe y %{@})) (locks m)) -(rule (targets 07.bar) (action (run ./incr.exe y %{@})) (locks m)) -(rule (targets 08.bar) (action (run ./incr.exe y %{@})) (locks m)) -(rule (targets 09.bar) (action (run ./incr.exe y %{@})) (locks m)) -(rule (targets 10.bar) (action (run ./incr.exe y %{@})) (locks m)) +(rule (targets 01.bar) (action (run ./incr.exe y %{targets})) (locks m)) +(rule (targets 02.bar) (action (run ./incr.exe y %{targets})) (locks m)) +(rule (targets 03.bar) (action (run ./incr.exe y %{targets})) (locks m)) +(rule (targets 04.bar) (action (run ./incr.exe y %{targets})) (locks m)) +(rule (targets 05.bar) (action (run ./incr.exe y %{targets})) (locks m)) +(rule (targets 06.bar) (action (run ./incr.exe y %{targets})) (locks m)) +(rule (targets 07.bar) (action (run ./incr.exe y %{targets})) (locks m)) +(rule (targets 08.bar) (action (run ./incr.exe y %{targets})) (locks m)) +(rule (targets 09.bar) (action (run ./incr.exe y %{targets})) (locks m)) +(rule (targets 10.bar) (action (run ./incr.exe y %{targets})) (locks m)) (alias (name runtest-no-deps)