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/migration.rst b/doc/migration.rst index cf968429..c6d4bd89 100644 --- a/doc/migration.rst +++ b/doc/migration.rst @@ -169,7 +169,7 @@ Jbuild Dune ======================== ============ ``${@}`` ``%{targets}`` ``${^}`` ``%{deps}`` -``${<}`` ``%{deps[0]}`` +``${<}`` ``%{first-dep}`` ``${path:file}`` ``%{dep:file}`` ``${SCOPE_ROOT}`` ``%{project_root}`` ``${findlib:..}`` ``%{lib:..}`` diff --git a/doc/quick-start.rst b/doc/quick-start.rst index 5e8a30a7..f9272534 100644 --- a/doc/quick-start.rst +++ b/doc/quick-start.rst @@ -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} %{first-dep}))) 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 ) - (action (run %{bin:cppo} %{<} -o %{@}))) + (action (run %{bin:cppo} %{first-dep} -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 %{first-dep} -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 %{@}))) + (action (run %{first-dep} -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 %{first-dep}))) And run the tests with: 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..60995c6d 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 %{first-dep} %{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..6b7bbe3d 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 %{first-dep} %{targets})))) diff --git a/src/jbuild.ml b/src/jbuild.ml index b554633d..c5b8aabc 100644 --- a/src/jbuild.ml +++ b/src/jbuild.ml @@ -1242,8 +1242,8 @@ 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__"<" + ; S.virt_var __POS__ "targets" + ; S.virt_var __POS__"first-dep" ]))) ; 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__ "first-dep"]))) ; mode ; locks = [] ; loc 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/stdune/int.ml b/src/stdune/int.ml index c11dc3da..d5c4a717 100644 --- a/src/stdune/int.ml +++ b/src/stdune/int.ml @@ -13,3 +13,9 @@ include T module Set = Set.Make(T) module Map = Map.Make(T) + +let of_string_exn s = + match int_of_string s with + | exception Failure _ -> + failwith (Printf.sprintf "of_string_exn: invalid int %S" s) + | s -> s diff --git a/src/stdune/int.mli b/src/stdune/int.mli index e9ff5063..62aeba20 100644 --- a/src/stdune/int.mli +++ b/src/stdune/int.mli @@ -3,3 +3,5 @@ val compare : t -> t -> Ordering.t module Set : Set.S with type elt = t module Map : Map.S with type key = t + +val of_string_exn : string -> t diff --git a/src/stdune/list.ml b/src/stdune/list.ml index 395119d6..2cc7655a 100644 --- a/src/stdune/list.ml +++ b/src/stdune/list.ml @@ -104,3 +104,9 @@ let rec assoc t x = | (k, v) :: t -> if x = k then Some v else assoc t x let singleton x = [x] + +let rec nth t i = + match t, i with + | [], _ -> None + | x :: _, 0 -> Some x + | _ :: xs, i -> nth xs (i - 1) diff --git a/src/stdune/list.mli b/src/stdune/list.mli index b19ace2b..3e310f4a 100644 --- a/src/stdune/list.mli +++ b/src/stdune/list.mli @@ -40,3 +40,5 @@ val compare : 'a t -> 'a t -> compare:('a -> 'a -> Ordering.t) -> Ordering.t val assoc : ('a * 'b) t -> 'a -> 'b option val singleton : 'a -> 'a t + +val nth : 'a t -> int -> 'a option 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 d7632d44..fef59a01 100644 --- a/src/super_context.ml +++ b/src/super_context.ml @@ -88,10 +88,18 @@ let expand_var_no_root t var = String.Map.find t.vars var let (expand_vars, expand_vars_path) = let expand t ~scope ~dir ?(extra_vars=String.Map.empty) s = - String_with_vars.expand ~mode:Single ~dir s ~f:(fun v _syntax_version -> + String_with_vars.expand ~mode:Single ~dir s ~f:(fun v syntax_version -> match String_with_vars.Var.full_name v with | "ROOT" -> Some [Value.Path t.context.build_dir] - | "SCOPE_ROOT" -> Some [Value.Path (Scope.root scope)] + | "SCOPE_ROOT" -> + if syntax_version >= (1, 0) then + Loc.fail (String_with_vars.Var.loc v) + "Variable %%{SCOPE_ROOT} has been renamed to %%{project_root} \ + in dune files" + else + Some [Value.Path (Scope.root scope)] + | "project_root" when syntax_version >= (1, 0) -> + Some [Value.Path (Scope.root scope)] | var -> (match expand_var_no_root t var with | Some _ as x -> x @@ -641,12 +649,12 @@ module Action = struct | 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\ - Hint: Did you mean ${path:%s} instead?" - s - s + Loc.fail + loc + "${dep:%s} is not supported in jbuild files.\n\ + Hint: Did you mean ${path:%s} instead?" + s + s | Pair ("bin", s) -> begin let sctx = host sctx in match Artifacts.binary (artifacts sctx) s with @@ -657,8 +665,8 @@ module Action = struct | Pair ("findlib", s) when syntax_version >= (1, 0) -> Loc.fail loc - "The findlib special variable is not supported anymore, please use lib instead:\n\ - %%{lib:%s}" + "The findlib special variable is not supported in jbuild files, \ + please use lib instead:\n%%{lib:%s} in dune files" s | Pair ("findlib", s) | Pair ("lib", s) -> begin @@ -739,28 +747,49 @@ 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 let loc = String_with_vars.Var.loc var in match var_name with | "ROOT" -> Some (path_exp sctx.context.build_dir) - | "SCOPE_ROOT" -> 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 + | "SCOPE_ROOT" -> + if syntax_version >= (1, 0) then + 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)) + | "@" -> + 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) -> - if syntax_version < (1, 0) then - Some (path_exp (Path.relative dir s)) - else - Loc.fail - loc - "The ${path-no-dep:...} syntax has been removed from dune." + if syntax_version < (1, 0) then + Some (path_exp (Path.relative dir s)) + else + Loc.fail + loc + "The ${path-no-dep:...} syntax has been removed from dune." | _ -> let exp = expand var syntax_version in Option.iter exp ~f:(fun vs -> @@ -772,23 +801,37 @@ module Action = struct (t, acc) let expand_step2 ~dir ~dynamic_expansions ~deps_written_by_user ~map_exe t = - U.Partial.expand t ~dir ~map_exe ~f:(fun var _syntax_version -> + U.Partial.expand t ~dir ~map_exe ~f:(fun var syntax_version -> let key = String_with_vars.Var.full_name var in let loc = String_with_vars.Var.loc var in match String.Map.find dynamic_expansions key with | Some _ as opt -> opt | None -> + let first_dep () = + Some ( + match deps_written_by_user with + | [] -> + Loc.warn loc "Variable '%s' used with no explicit \ + dependencies@." key; + [Value.String ""] + | 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]) - | "^" -> Some (Value.L.paths deps_written_by_user) + if syntax_version < (1, 0) then + first_dep () + else + Loc.fail loc "Variable '<' is renamed to 'first-dep' in dune files" + | "first-dep" when syntax_version >= (1, 0) -> first_dep () + | "^" -> + if syntax_version < (1, 0) then + Some (Value.L.paths deps_written_by_user) + else + Loc.fail loc + "Variable %%{^} has been renamed to %%{deps} in dune files" + | "deps" when syntax_version >= (1, 0) -> + Some (Value.L.paths deps_written_by_user) | _ -> None) let run sctx ~loc ?(extra_vars=String.Map.empty) @@ -800,8 +843,9 @@ module Action = struct | [] -> () | x :: _ -> let loc = String_with_vars.loc x in - Loc.warn loc "Aliases must not have targets, this target will be ignored.\n\ - This will become an error in the future."; + Loc.warn loc + "Aliases must not have targets, this target will be ignored.\n\ + This will become an error in the future."; end; let t, forms = expand_step1 sctx t ~dir ~dep_kind ~scope 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/dune.inc b/test/blackbox-tests/dune.inc index 3a339765..e7769aea 100644 --- a/test/blackbox-tests/dune.inc +++ b/test/blackbox-tests/dune.inc @@ -507,6 +507,14 @@ test-cases/private-public-overlap (progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected))))) +(alias + (name project-root) + (deps (package dune) (source_tree test-cases/project-root)) + (action + (chdir + test-cases/project-root + (progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected))))) + (alias (name promote) (deps (package dune) (source_tree test-cases/promote)) @@ -673,6 +681,7 @@ (alias path-variables) (alias ppx-rewriter) (alias private-public-overlap) + (alias project-root) (alias promote) (alias quoting) (alias redirections) @@ -740,6 +749,7 @@ (alias output-obj) (alias package-dep) (alias path-variables) + (alias project-root) (alias promote) (alias quoting) (alias redirections) 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/findlib-error/run.t b/test/blackbox-tests/test-cases/findlib-error/run.t index a46f6196..e704b5ba 100644 --- a/test/blackbox-tests/test-cases/findlib-error/run.t +++ b/test/blackbox-tests/test-cases/findlib-error/run.t @@ -3,8 +3,8 @@ We are dropping support for findlib in dune $ dune build --root in-dune target.txt Entering directory 'in-dune' File "dune", line 2, characters 25-37: - Error: The findlib special variable is not supported anymore, please use lib instead: - %{lib:pkg} + Error: The findlib special variable is not supported in jbuild files, please use lib instead: + %{lib:pkg} in dune files [1] But it must still be available in jbuild files diff --git a/test/blackbox-tests/test-cases/force-test/dune b/test/blackbox-tests/test-cases/force-test/dune index b82cbf03..51e83746 100644 --- a/test/blackbox-tests/test-cases/force-test/dune +++ b/test/blackbox-tests/test-cases/force-test/dune @@ -4,4 +4,4 @@ (alias (name runtest) (deps f.exe) - (action (run %{<}))) + (action (run %{first-dep}))) 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/github568/dune b/test/blackbox-tests/test-cases/github568/dune index 93ebd2fd..46bee013 100644 --- a/test/blackbox-tests/test-cases/github568/dune +++ b/test/blackbox-tests/test-cases/github568/dune @@ -8,7 +8,7 @@ (name runtest) (package lib1) (deps test1.exe) - (action (run %{<}))) + (action (run %{first-dep}))) (executable (name test1) @@ -25,7 +25,7 @@ (name runtest) (package lib2) (deps test2.exe) - (action (run %{<}))) + (action (run %{first-dep}))) (executable (name test2) diff --git a/test/blackbox-tests/test-cases/github660/explicit-interfaces/dune b/test/blackbox-tests/test-cases/github660/explicit-interfaces/dune index a6b2e734..7817f984 100644 --- a/test/blackbox-tests/test-cases/github660/explicit-interfaces/dune +++ b/test/blackbox-tests/test-cases/github660/explicit-interfaces/dune @@ -1,6 +1,6 @@ (alias (name runtest) (deps main.exe) - (action (run %{<}))) + (action (run %{first-dep}))) (executable (name main)) diff --git a/test/blackbox-tests/test-cases/github660/no-interfaces/dune b/test/blackbox-tests/test-cases/github660/no-interfaces/dune index a6b2e734..7817f984 100644 --- a/test/blackbox-tests/test-cases/github660/no-interfaces/dune +++ b/test/blackbox-tests/test-cases/github660/no-interfaces/dune @@ -1,6 +1,6 @@ (alias (name runtest) (deps main.exe) - (action (run %{<}))) + (action (run %{first-dep}))) (executable (name main)) diff --git a/test/blackbox-tests/test-cases/merlin-tests/dune b/test/blackbox-tests/test-cases/merlin-tests/dune index d413b523..ebbe84c5 100644 --- a/test/blackbox-tests/test-cases/merlin-tests/dune +++ b/test/blackbox-tests/test-cases/merlin-tests/dune @@ -1,4 +1,4 @@ (alias (name print-merlins) (deps lib/.merlin exe/.merlin) - (action (run ./sanitize-dot-merlin/sanitize_dot_merlin.exe %{^}))) + (action (run ./sanitize-dot-merlin/sanitize_dot_merlin.exe %{deps}))) diff --git a/test/blackbox-tests/test-cases/misc/blah/dune b/test/blackbox-tests/test-cases/misc/blah/dune index b7c3feae..a355e215 100644 --- a/test/blackbox-tests/test-cases/misc/blah/dune +++ b/test/blackbox-tests/test-cases/misc/blah/dune @@ -1,3 +1,3 @@ (alias (name runtest) - (deps %{SCOPE_ROOT}/023e1a58-4d08-11e7-a041-aa000008c8a6)) + (deps %{project_root}/023e1a58-4d08-11e7-a041-aa000008c8a6)) diff --git a/test/blackbox-tests/test-cases/misc/dune b/test/blackbox-tests/test-cases/misc/dune index 44ca475e..e20ad426 100644 --- a/test/blackbox-tests/test-cases/misc/dune +++ b/test/blackbox-tests/test-cases/misc/dune @@ -1,17 +1,17 @@ -;; Test for %{^} with globs in rules +;; Test for %{deps} with globs in rules (rule (targets result expected) (deps dune (glob_files *.txt)) (action (progn - (with-stdout-to result (echo %{^})) + (with-stdout-to result (echo %{deps})) (with-stdout-to expected (echo "dune a.txt b.txt c.txt"))))) (rule (targets result2 expected2) (deps (source_tree sub-tree)) (action (progn - (with-stdout-to result2 (echo %{^})) + (with-stdout-to result2 (echo %{deps})) (with-stdout-to expected2 (echo "sub-tree/a sub-tree/dir/b"))))) (alias @@ -31,7 +31,7 @@ (alias (name runtest) (deps dune dune-plop) - (action (run diff -u %{^}))) + (action (run diff -u %{deps}))) ;; For some tests in subdirs diff --git a/test/blackbox-tests/test-cases/output-obj/dune b/test/blackbox-tests/test-cases/output-obj/dune index f42c90f9..c4858bf5 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 . %{deps} %{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 . %{deps} %{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} %{first-dep} %{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 ./%{first-dep}))) (alias (name runtest) (deps test%{ext_dll}) - (action (run ./dynamic.exe ./%{<}))) + (action (run ./dynamic.exe ./%{first-dep}))) diff --git a/test/blackbox-tests/test-cases/project-root/dune b/test/blackbox-tests/test-cases/project-root/dune new file mode 100644 index 00000000..6b96a2c3 --- /dev/null +++ b/test/blackbox-tests/test-cases/project-root/dune @@ -0,0 +1,4 @@ +(alias + (name runtest) + (action (echo "From root: %{project_root}\n")) +) diff --git a/test/blackbox-tests/test-cases/project-root/dune-file/a/b/dune b/test/blackbox-tests/test-cases/project-root/dune-file/a/b/dune new file mode 100644 index 00000000..d5d1c23d --- /dev/null +++ b/test/blackbox-tests/test-cases/project-root/dune-file/a/b/dune @@ -0,0 +1,4 @@ +(alias + (name runtest) + (action (echo "From dune-file/a/b/: %{project_root}\n")) +) diff --git a/test/blackbox-tests/test-cases/project-root/dune-file/a/dune b/test/blackbox-tests/test-cases/project-root/dune-file/a/dune new file mode 100644 index 00000000..8c9f2086 --- /dev/null +++ b/test/blackbox-tests/test-cases/project-root/dune-file/a/dune @@ -0,0 +1,4 @@ +(alias + (name runtest) + (action (echo "From dune-file/a/: %{project_root}\n")) +) diff --git a/test/blackbox-tests/test-cases/project-root/dune-project b/test/blackbox-tests/test-cases/project-root/dune-project new file mode 100644 index 00000000..de4fc209 --- /dev/null +++ b/test/blackbox-tests/test-cases/project-root/dune-project @@ -0,0 +1 @@ +(lang dune 1.0) diff --git a/test/blackbox-tests/test-cases/project-root/jbuild-file/a/b/jbuild b/test/blackbox-tests/test-cases/project-root/jbuild-file/a/b/jbuild new file mode 100644 index 00000000..27bd88d3 --- /dev/null +++ b/test/blackbox-tests/test-cases/project-root/jbuild-file/a/b/jbuild @@ -0,0 +1,5 @@ +(alias + ((name runtest) + (action (echo "From jbuild/a/b/: ${SCOPE_ROOT}\n")) + ) + ) diff --git a/test/blackbox-tests/test-cases/project-root/jbuild-file/a/jbuild b/test/blackbox-tests/test-cases/project-root/jbuild-file/a/jbuild new file mode 100644 index 00000000..951834f6 --- /dev/null +++ b/test/blackbox-tests/test-cases/project-root/jbuild-file/a/jbuild @@ -0,0 +1,5 @@ +(alias + ((name runtest) + (action (echo "From jbuild/a/: ${SCOPE_ROOT}\n")) + ) + ) diff --git a/test/blackbox-tests/test-cases/project-root/run.t b/test/blackbox-tests/test-cases/project-root/run.t new file mode 100644 index 00000000..b73eef38 --- /dev/null +++ b/test/blackbox-tests/test-cases/project-root/run.t @@ -0,0 +1,9 @@ +%{SCOPE_ROOT} (or ${SCOPE_ROOT} in jbuild files) refers to the root of the +project. + + $ dune runtest + From dune-file/a/b/: ../../.. + From dune-file/a/: ../.. + From jbuild/a/b/: ../../.. + From jbuild/a/: ../.. + From root: . 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/reason/dune b/test/blackbox-tests/test-cases/reason/dune index 3aaf006d..e5dcdd49 100644 --- a/test/blackbox-tests/test-cases/reason/dune +++ b/test/blackbox-tests/test-cases/reason/dune @@ -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 %{first-dep})) (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 %{first-dep})) (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 %{first-dep}))) + (preprocess (action (run ./pp/reasononlypp.exe %{first-dep}))) (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 %{first-dep})))) 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/blackbox-tests/test-cases/select/dune b/test/blackbox-tests/test-cases/select/dune index b577aa3b..4e6a6b1f 100644 --- a/test/blackbox-tests/test-cases/select/dune +++ b/test/blackbox-tests/test-cases/select/dune @@ -11,4 +11,4 @@ (alias (name runtest) (deps main.exe) - (action (run %{<}))) + (action (run %{first-dep}))) 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) diff --git a/test/unit-tests/configurator/dune b/test/unit-tests/configurator/dune index 13f1fc96..1e259288 100644 --- a/test/unit-tests/configurator/dune +++ b/test/unit-tests/configurator/dune @@ -5,4 +5,4 @@ (alias (name runtest) (deps ./test_configurator.exe) - (action (run %{<}))) + (action (run %{first-dep}))) diff --git a/test/unit-tests/dune b/test/unit-tests/dune index b5355c99..7ee04560 100644 --- a/test/unit-tests/dune +++ b/test/unit-tests/dune @@ -19,71 +19,71 @@ (alias (name runtest) (deps tests.mlt - (glob_files %{SCOPE_ROOT}/src/.dune.objs/*.cmi) - (glob_files %{SCOPE_ROOT}/src/stdune/.stdune.objs/*.cmi) + (glob_files %{project_root}/src/.dune.objs/*.cmi) + (glob_files %{project_root}/src/stdune/.stdune.objs/*.cmi) (source_tree toolchain.d) (source_tree findlib-db)) - (action (chdir %{SCOPE_ROOT} + (action (chdir %{project_root} (progn - (run %{exe:expect_test.exe} %{<}) - (diff? %{<} %{<}.corrected))))) + (run %{exe:expect_test.exe} %{first-dep}) + (diff? %{first-dep} %{first-dep}.corrected))))) (alias (name runtest) (deps filename.mlt - (glob_files %{SCOPE_ROOT}/src/.dune.objs/*.cmi) - (glob_files %{SCOPE_ROOT}/src/stdune/.stdune.objs/*.cmi)) - (action (chdir %{SCOPE_ROOT} + (glob_files %{project_root}/src/.dune.objs/*.cmi) + (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} %{first-dep}) + (diff? %{first-dep} %{first-dep}.corrected))))) (alias (name runtest) (deps import_dot_map.mlt - (glob_files %{SCOPE_ROOT}/src/.dune.objs/*.cmi) - (glob_files %{SCOPE_ROOT}/src/stdune/.stdune.objs/*.cmi)) - (action (chdir %{SCOPE_ROOT} + (glob_files %{project_root}/src/.dune.objs/*.cmi) + (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} %{first-dep}) + (diff? %{first-dep} %{first-dep}.corrected))))) (alias (name runtest) (deps action.mlt - (glob_files %{SCOPE_ROOT}/src/.dune.objs/*.cmi) - (glob_files %{SCOPE_ROOT}/src/stdune/.stdune.objs/*.cmi)) - (action (chdir %{SCOPE_ROOT} + (glob_files %{project_root}/src/.dune.objs/*.cmi) + (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} %{first-dep}) + (diff? %{first-dep} %{first-dep}.corrected))))) (alias (name runtest) (deps path.mlt - (glob_files %{SCOPE_ROOT}/src/.dune.objs/*.cmi) - (glob_files %{SCOPE_ROOT}/src/stdune/.stdune.objs/*.cmi)) - (action (chdir %{SCOPE_ROOT} + (glob_files %{project_root}/src/.dune.objs/*.cmi) + (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} %{first-dep}) + (diff? %{first-dep} %{first-dep}.corrected))))) (alias (name runtest) (deps sexp.mlt - (glob_files %{SCOPE_ROOT}/src/.dune.objs/*.cmi) - (glob_files %{SCOPE_ROOT}/src/stdune/.stdune.objs/*.cmi)) - (action (chdir %{SCOPE_ROOT} + (glob_files %{project_root}/src/.dune.objs/*.cmi) + (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} %{first-dep}) + (diff? %{first-dep} %{first-dep}.corrected))))) (alias (name runtest) (deps jbuild.mlt - (glob_files %{SCOPE_ROOT}/src/.dune.objs/*.cmi) - (glob_files %{SCOPE_ROOT}/src/stdune/.stdune.objs/*.cmi)) - (action (chdir %{SCOPE_ROOT} + (glob_files %{project_root}/src/.dune.objs/*.cmi) + (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} %{first-dep}) + (diff? %{first-dep} %{first-dep}.corrected))))) diff --git a/test/unit-tests/ocaml-config/dune b/test/unit-tests/ocaml-config/dune index 05f8ec00..659d3aa3 100644 --- a/test/unit-tests/ocaml-config/dune +++ b/test/unit-tests/ocaml-config/dune @@ -5,4 +5,4 @@ (alias (name runtest) (deps ./gh637.exe) - (action (run %{<}))) + (action (run %{first-dep})))