diff --git a/doc/dune-files.rst b/doc/dune-files.rst index 265902ea737..68dc9f79bfd 100644 --- a/doc/dune-files.rst +++ b/doc/dune-files.rst @@ -22,7 +22,7 @@ Stanzas (rule (targets foo.ml) (deps generator/gen.exe) - (action (run ${<} -o ${@}))) + (action (run %{<} -o %{@}))) The following sections describe the available stanzas and their meaning. @@ -336,16 +336,16 @@ compilation mode binary kind extensions ---------------- ------------- ----------------- byte exe .bc and .bc.js native/best exe .exe -byte object .bc${ext_obj} -native/best object .exe${ext_obj} -byte shared_object .bc${ext_dll} -native/best shared_object ${ext_dll} +byte object .bc%{ext_obj} +native/best object .exe%{ext_obj} +byte shared_object .bc%{ext_dll} +native/best shared_object %{ext_dll} ================ ============= ================= -Where ``${ext_obj}`` and ``${ext_dll}`` are the extensions for object +Where ``%{ext_obj}`` and ``%{ext_dll}`` are the extensions for object and shared object files. Their value depends on the OS, for instance -on Unix ``${ext_obj}`` is usually ``.o`` and ``${ext_dll}`` is usually -``.so`` while on Windows ``${ext_obj}`` is ``.obj`` and ``${ext_dll}`` +on Unix ``%{ext_obj}`` is usually ``.o`` and ``%{ext_dll}`` is usually +``.so`` while on Windows ``%{ext_obj}`` is ``.obj`` and ``%{ext_dll}`` is ``.dll``. Note that when ``(byte exe)`` is specified but neither ``(best exe)`` @@ -459,7 +459,7 @@ For instance: (rule (targets b (deps a - (action (copy ${<} ${@}))))) + (action (copy %{<} %{@}))))) In this example it is obvious by inspecting the action what the dependencies and targets are. When this is the case you can use the @@ -483,7 +483,7 @@ stanza is rejected by dune: .. code:: scheme - (rule (copy a b.${read:file})) + (rule (copy a b.%{read:file})) ocamllex -------- @@ -495,7 +495,7 @@ ocamllex (rule (targets .ml) (deps .mll) - (action (chdir ${ROOT} (run ${bin:ocamllex} -q -o ${<})))) + (action (chdir %{root} (run %{bin:ocamllex} -q -o %{<})))) To use a different rule mode, use the long form: @@ -515,7 +515,7 @@ ocamlyacc (rule (targets .ml .mli) (deps .mly) - (action (chdir ${ROOT} (run ${bin:ocamlyacc} ${<})))) + (action (chdir %{root} (run %{bin:ocamlyacc} %{<})))) To use a different rule mode, use the long form: @@ -573,7 +573,7 @@ The typical use of the ``alias`` stanza is to define tests: (alias (name runtest) - (action (run ${exe:my-test-program.exe} blah))) + (action (run %{exe:my-test-program.exe} blah))) See the section about :ref:`running-tests` for details. @@ -825,18 +825,18 @@ Variables are expanded after the set language is interpreted. Variables expansion ------------------- -Some fields can contains variables of the form ``$(var)`` or ``${var}`` that are +Some fields can contains variables of the form ``$(var)`` or ``%{var}`` that are expanded by dune. Dune supports the following variables: -- ``ROOT`` is the relative path to the root of the build - context. Note that ``ROOT`` depends on the worksace - configuration. As such you shouldn't use ``ROOT`` to denote the - root of your project. Use ``SCOPE_ROOT`` instead for this purpose -- ``SCOPE_ROOT`` is the root of the current scope. It is typically +- ``root`` is the relative path to the root of the build + context. Note that ``root`` depends on the workspace + configuration. As such you shouldn't use ``root`` to denote the + root of your project. Use ``project_root`` instead for this purpose +- ``project_root`` is the root of the current scope. It is typically the toplevel directory of your project and as long as you have at - least one ``.opam`` file there, ``SCOPE_ROOT`` is + least one ``.opam`` file there, ``project_root`` is independent of the workspace configuration - ``CC`` is the C compiler command line (list made of the compiler name followed by its flags) that was used to compile OCaml in the @@ -844,13 +844,13 @@ Dune supports the following variables: - ``CXX`` is the C++ compiler command line being used in the current build context - ``ocaml_bin`` is the path where ``ocamlc`` lives -- ``OCAML`` is the ``ocaml`` binary -- ``OCAMLC`` is the ``ocamlc`` binary -- ``OCAMLOPT`` is the ``ocamlopt`` binary +- ``ocaml`` is the ``ocaml`` binary +- ``ocamlc`` is the ``ocamlc`` binary +- ``ocamlopt`` is the ``ocamlopt`` binary - ``ocaml_version`` is the version of the compiler used in the current build context - ``ocaml_where`` is the output of ``ocamlc -where`` -- ``ARCH_SIXTYFOUR`` is ``true`` if using a compiler targeting a +- ``arch_sixtyfour`` is ``true`` if using a compiler targeting a 64 bit architecture and ``false`` otherwise - ``null`` is ``/dev/null`` on Unix or ``nul`` on Windows - ``ext_obj``, ``ext_asm``, ``ext_lib``, ``ext_dll`` and ``ext_exe`` @@ -878,8 +878,8 @@ In addition, ``(action ...)`` fields support the following special variables: is installed by a package in the workspace (see `install`_ stanzas), the locally built binary will be used, otherwise it will be searched in the ``PATH`` of the current build context. Note that ``(run - ${bin:program} ...)`` and ``(run program ...)`` behave in the same - way. ``${bin:...}`` is only necessary when you are using ``(bash + %{bin:program} ...)`` and ``(run program ...)`` behave in the same + way. ``%{bin:...}`` is only necessary when you are using ``(bash ...)`` or ``(system ...)`` - ``lib::`` expands to a path to file ```` of library ````. If ```` is available @@ -906,10 +906,10 @@ In addition, ``(action ...)`` fields support the following special variables: - ``read-strings:`` expands to the list of lines in the given file, unescaped using OCaml lexical convention -The ``${:...}`` forms are what allows you to write custom rules that work +The ``%{:...}`` forms are what allows you to write custom rules that work transparently whether things are installed or not. -Note that aliases are ignored by both ``${<}`` and ``${^}``. +Note that aliases are ignored by both ``%{<}`` and ``%{^}``. The intent of this last form is to reliably read a list of strings generated by an OCaml program via: @@ -920,13 +920,13 @@ generated by an OCaml program via: #. Expansion of lists -Forms that expands to list of items, such as ``${CC}``, ``${^}``, -``${@}`` or ``${read-lines:...}``, are suitable to be used in, say, +Forms that expands to list of items, such as ``%{cc}``, ``%{^}``, +``%{@}`` or ``%{read-lines:...}``, are suitable to be used in, say, ``(run )``. For instance in: .. code:: scheme - (run foo ${^}) + (run foo %{^}) if there are two dependencies ``a`` and ``b``, the produced command will be equivalent to the shell command: @@ -940,7 +940,7 @@ you have to quote the variable as in: .. code:: scheme - (run foo "${^}") + (run foo "%{^}") which is equivalent to the following shell command: @@ -949,7 +949,7 @@ which is equivalent to the following shell command: $ foo "a b" (the items of the list are concatenated with space). -Note that, since ``${^}`` is a list of items, the first one may be +Note that, since ``%{^}`` is a list of items, the first one may be used as a program name, for instance: .. code:: scheme @@ -957,7 +957,7 @@ used as a program name, for instance: (rule (targets result.txt) (deps foo.exe (glob_files *.txt)) - (action (run ${^}))) + (action (run %{^}))) Here is another example: @@ -966,7 +966,7 @@ Here is another example: (rule (targets foo.exe) (deps foo.c) - (action (run ${CC} -o ${@} ${<} -lfoolib))) + (action (run %{cc} -o %{@} %{<} -lfoolib))) Library dependencies @@ -1052,10 +1052,10 @@ you had setup a rule for every file of the form: (rule (targets file.pp.ml) (deps file.ml) - (action (with-stdout-to ${@} (chdir ${ROOT} )))) + (action (with-stdout-to %{@} (chdir %{root} )))) The equivalent of a ``-pp `` option passed to the OCaml compiler is -``(system " ${<}")``. +``(system " %{<}")``. Preprocessing with ppx rewriters ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -1105,8 +1105,8 @@ For instance: .. code:: scheme (preprocess (per_module - (((action (run ./pp.sh X=1 ${<})) (foo bar))) - (((action (run ./pp.sh X=2 ${<})) (baz))))) + (((action (run ./pp.sh X=1 %{<})) (foo bar))) + (((action (run ./pp.sh X=2 %{<})) (baz))))) .. _deps-field: @@ -1231,7 +1231,7 @@ in ``src/foo/dune`` will be run from ``_build//src/foo``. The argument of ``(action ...)`` fields is a small DSL that is interpreted by dune directly and doesn't require an external shell. All atoms in the DSL support `Variables expansion`_. Moreover, you don't need to specify dependencies -explicitly for the special ``${:...}`` forms, these are recognized and +explicitly for the special ``%{:...}`` forms, these are recognized and automatically handled by dune. The DSL is currently quite limited, so if you want to do something complicated @@ -1289,15 +1289,15 @@ called ``copy-and-add-line-directive``. However, most of time one wants this behavior rather than a bare copy, so it was renamed to something shorter. -Note: expansion of the special ``${:...}`` is done relative to the current +Note: expansion of the special ``%{:...}`` is done relative to the current working directory of the part of the DSL being executed. So for instance if you have this action in a ``src/foo/dune``: .. code:: scheme - (action (chdir ../../.. (echo ${path:dune}))) + (action (chdir ../../.. (echo %{path:dune}))) -Then ``${path:dune}`` will expand to ``src/foo/dune``. When you run various +Then ``%{path:dune}`` will expand to ``src/foo/dune``. When you run various tools, they often use the filename given on the command line in error messages. As a result, if you execute the command from the original directory, it will only see the basename. @@ -1310,7 +1310,7 @@ To understand why this is important, let's consider this dune file living in (rule (targets blah.ml) (deps blah.mll) - (action (run ocamllex -o ${@} ${<}))) + (action (run ocamllex -o %{@} %{<}))) Here the command that will be executed is: @@ -1334,7 +1334,7 @@ of your project. What you should write instead is: (rule (targets blah.ml) (deps blah.mll) - (action (chdir ${ROOT} (run ocamllex -o ${@} ${<})))) + (action (chdir %{root} (run ocamllex -o %{@} %{<})))) Locks ----- @@ -1357,13 +1357,13 @@ same lock: (name runtest) (deps foo) (locks m) - (action (run test.exe ${<}))) + (action (run test.exe %{<}))) (alias (name runtest) (deps bar) (locks m) - (action (run test.exe ${<}))) + (action (run test.exe %{<}))) Dune will make sure that the executions of ``test.exe foo`` and ``test.exe bar`` are serialized. @@ -1383,7 +1383,7 @@ simply use an absolute filename: (name runtest) (deps foo) (locks /tcp-port/1042) - (action (run test.exe ${<}))) + (action (run test.exe %{<}))) .. _ocaml-syntax: diff --git a/doc/migration.rst b/doc/migration.rst index c6d4bd8924d..a50fd0cbf35 100644 --- a/doc/migration.rst +++ b/doc/migration.rst @@ -173,6 +173,14 @@ Jbuild Dune ``${path:file}`` ``%{dep:file}`` ``${SCOPE_ROOT}`` ``%{project_root}`` ``${findlib:..}`` ``%{lib:..}`` +``${CPP}`` ``%{cpp}`` +``${CC}`` ``%{cc}`` +``${CXX}`` ``%{cxx}`` +``${OCAML}`` ``%{ocaml}`` +``${OCAMLC}`` ``%{ocamlc}`` +``${OCAMLOPT}`` ``%{ocamlopt}`` +``${ARCH_SIXTYFOUR}`` ``%{arch_sixtyfour}`` +``${MAKE}`` ``%{make}`` ======================== ============ Removed Variables diff --git a/src/action.ml b/src/action.ml index fbf630644fd..6a7f86dc3ed 100644 --- a/src/action.ml +++ b/src/action.ml @@ -337,6 +337,9 @@ end let prog_and_args_of_values p ~dir = match p with | [] -> (Unresolved.Program.Search "", []) + | Value.Dir p :: _ -> + die "%s is a directory and cannot be used as an executable" + (Path.to_string_maybe_quoted p) | Value.Path p :: xs -> (This p, Value.L.to_strings ~dir xs) | String s :: xs -> (Unresolved.Program.of_string ~dir s, Value.L.to_strings ~dir xs) diff --git a/src/gen_rules.ml b/src/gen_rules.ml index e300704aa41..eee6291e6e8 100644 --- a/src/gen_rules.ml +++ b/src/gen_rules.ml @@ -201,7 +201,7 @@ module Gen(P : Install_rules.Params) = struct let copy_files_rules (def: Copy_files.t) ~src_dir ~dir ~scope = let loc = String_with_vars.loc def.glob in let glob_in_src = - let src_glob = SC.expand_vars sctx ~dir def.glob ~scope in + let src_glob = SC.expand_vars_string sctx ~dir def.glob ~scope in Path.relative src_dir src_glob ~error_loc:loc in (* The following condition is required for merlin to work. @@ -1042,7 +1042,7 @@ module Gen(P : Install_rules.Params) = struct | Copy_files { glob; _ } -> let src_dir = let loc = String_with_vars.loc glob in - let src_glob = SC.expand_vars sctx ~dir glob ~scope in + let src_glob = SC.expand_vars_string sctx ~dir glob ~scope in Path.parent_exn (Path.relative src_dir src_glob ~error_loc:loc) in Some diff --git a/src/jbuild.ml b/src/jbuild.ml index c5b8aabca3d..cfcd65bc4da 100644 --- a/src/jbuild.ml +++ b/src/jbuild.ml @@ -1238,7 +1238,7 @@ module Rule = struct ; action = (loc, Chdir - (S.virt_var __POS__ "ROOT", + (S.virt_var __POS__ "root", Run (S.virt_text __POS__ "ocamllex", [ S.virt_text __POS__ "-q" ; S.virt_text __POS__ "-o" @@ -1259,7 +1259,7 @@ module Rule = struct ; action = (loc, Chdir - (S.virt_var __POS__ "ROOT", + (S.virt_var __POS__ "root", Run (S.virt_text __POS__ "ocamlyacc", [S.virt_var __POS__ "first-dep"]))) ; mode diff --git a/src/menhir.ml b/src/menhir.ml index 0aa756cc474..d9222b875a1 100644 --- a/src/menhir.ml +++ b/src/menhir.ml @@ -61,7 +61,7 @@ module Run (P : PARAMS) = struct let sources ms = List.map ~f:source ms - (* Expand special variables, such as ${ROOT}, in the stanza's flags. *) + (* Expand special variables, such as %{root}, in the stanza's flags. *) let flags = SC.expand_and_eval_set diff --git a/src/pform.ml b/src/pform.ml new file mode 100644 index 00000000000..f975473bb2c --- /dev/null +++ b/src/pform.ml @@ -0,0 +1,185 @@ +open Import + +module Var = struct + type t = + | Values of Value.t list + | Project_root + | First_dep + | Deps + | Targets + + let to_value_no_deps_or_targets t ~scope = + match t with + | Values v -> Some v + | Project_root -> Some [Value.Dir (Scope.root scope)] + | First_dep + | Deps + | Targets -> None +end + +module Macro = struct + type t = + | Exe + | Dep + | Bin + | Lib + | Libexec + | Lib_available + | Version + | Read + | Read_strings + | Read_lines + | Path_no_dep +end + +type 'a t = + | No_info of 'a + | Since of 'a * Syntax.Version.t + | Deleted_in of 'a * Syntax.Version.t + | Renamed_in of Syntax.Version.t * string + +module Map = struct + type nonrec 'a t = 'a t String.Map.t + + let values v = No_info (Var.Values v) + let renamed_in ~new_name ~version = Renamed_in (version, new_name) + let deleted_in ~version kind = Deleted_in (kind, version) + let since ~version v = Since (v, version) + + let static_vars = + [ "first-dep", since ~version:(1, 0) Var.First_dep + ; "targets", since ~version:(1, 0) Var.Targets + ; "deps", since ~version:(1, 0) Var.Deps + ; "project_root", since ~version:(1, 0) Var.Project_root + + ; "<", renamed_in ~version:(1, 0) ~new_name:"first-dep" + ; "@", renamed_in ~version:(1, 0) ~new_name:"targets" + ; "^", renamed_in ~version:(1, 0) ~new_name:"deps" + ; "SCOPE_ROOT", renamed_in ~version:(1, 0) ~new_name:"project_root" + ] + + let macros = + let macro kind = No_info kind in + let open Macro in + [ "exe", macro Exe + ; "bin", macro Bin + ; "lib", macro Lib + ; "libexec", macro Libexec + ; "lib-available", macro Lib_available + ; "version", macro Version + ; "read", macro Read + ; "read-lines", macro Read_lines + ; "read-strings", macro Read_strings + + ; "dep", since ~version:(1, 0) Dep + + ; "path", renamed_in ~version:(1, 0) ~new_name:"dep" + ; "findlib", renamed_in ~version:(1, 0) ~new_name:"lib" + + ; "path-no-dep", deleted_in ~version:(1, 0) Path_no_dep + ] + |> String.Map.of_list_exn + + let create_vars ~(context : Context.t) ~cxx_flags = + let ocamlopt = + match context.ocamlopt with + | None -> Path.relative context.ocaml_bin "ocamlopt" + | Some p -> p + in + let string s = values [Value.String s] in + let path p = values [Value.Path p] in + let make = + match Bin.make with + | None -> string "make" + | Some p -> path p + in + let cflags = context.ocamlc_cflags in + let strings s = values (Value.L.strings s) in + let lowercased = + [ "cpp" , strings (context.c_compiler :: cflags @ ["-E"]) + ; "cc" , strings (context.c_compiler :: cflags) + ; "cxx" , strings (context.c_compiler :: cxx_flags) + ; "ocaml" , path context.ocaml + ; "ocamlc" , path context.ocamlc + ; "ocamlopt" , path ocamlopt + ; "arch_sixtyfour" , string (string_of_bool context.arch_sixtyfour) + ; "make" , make + ; "root" , values [Value.Dir context.build_dir] + ] in + let uppercased = + List.map lowercased ~f:(fun (k, _) -> + (String.uppercase k, renamed_in ~new_name:k ~version:(1, 0))) in + let vars = + [ "-verbose" , values [] + ; "pa_cpp" , strings (context.c_compiler :: cflags + @ ["-undef"; "-traditional"; + "-x"; "c"; "-E"]) + ; "ocaml_bin" , path context.ocaml_bin + ; "ocaml_version" , string context.version_string + ; "ocaml_where" , string (Path.to_string context.stdlib_dir) + ; "null" , string (Path.to_string Config.dev_null) + ; "ext_obj" , string context.ext_obj + ; "ext_asm" , string context.ext_asm + ; "ext_lib" , string context.ext_lib + ; "ext_dll" , string context.ext_dll + ; "ext_exe" , string context.ext_exe + ; "profile" , string context.profile + ] + in + let ocaml_config = + List.map (Ocaml_config.to_list context.ocaml_config) ~f:(fun (k, v) -> + ("ocaml-config:" ^ k, + match (v : Ocaml_config.Value.t) with + | Bool x -> string (string_of_bool x) + | Int x -> string (string_of_int x) + | String x -> string x + | Words x -> strings x + | Prog_and_args x -> strings (x.prog :: x.args))) + in + [ ocaml_config + ; static_vars + ; lowercased + ; uppercased + ; vars + ] + |> List.concat + |> String.Map.of_list_exn + + let static_vars = String.Map.of_list_exn static_vars + + let rec expand t ~syntax_version ~var = + let name = String_with_vars.Var.name var in + Option.bind (String.Map.find t name) ~f:(fun v -> + let what var = + String_with_vars.Var.to_string ( + if String_with_vars.Var.is_macro var then + String_with_vars.Var.with_payload var ~payload:(Some "..") + else + var) + in + match v with + | No_info v -> Some v + | Since (v, min_version) -> + if syntax_version >= min_version then + Some v + else + Syntax.Error.since (String_with_vars.Var.loc var) + Stanza.syntax min_version + ~what:(what var) + | Renamed_in (in_version, new_name) -> begin + if syntax_version >= in_version then + Syntax.Error.renamed_in (String_with_vars.Var.loc var) + Stanza.syntax syntax_version + ~what:(what var) + ~to_:(what (String_with_vars.Var.with_name var ~name:new_name)) + else + expand t ~syntax_version:in_version + ~var:(String_with_vars.Var.with_name var ~name:new_name) + end + | Deleted_in (v, in_version) -> + if syntax_version < in_version then + Some v + else + Syntax.Error.deleted_in (String_with_vars.Var.loc var) + Stanza.syntax syntax_version ~what:(what var)) +end diff --git a/src/pform.mli b/src/pform.mli new file mode 100644 index 00000000000..d36d3624125 --- /dev/null +++ b/src/pform.mli @@ -0,0 +1,48 @@ +module Var : sig + type t = + | Values of Value.t list + | Project_root + | First_dep + | Deps + | Targets + + val to_value_no_deps_or_targets : t -> scope:Scope.t -> Value.t list option +end + +module Macro : sig + type t = + | Exe + | Dep + | Bin + | Lib + | Libexec + | Lib_available + | Version + | Read + | Read_strings + | Read_lines + | Path_no_dep +end + +type 'a t = + | No_info of 'a + | Since of 'a * Syntax.Version.t + | Deleted_in of 'a * Syntax.Version.t + | Renamed_in of Syntax.Version.t * string + +module Map : sig + type 'a var + type 'a t + + val create_vars : context:Context.t -> cxx_flags:string list -> Var.t t + + val macros : Macro.t t + + val static_vars : Var.t t + + val expand + : 'a t + -> syntax_version:Syntax.Version.t + -> var:String_with_vars.Var.t + -> 'a option +end with type 'a var := 'a t diff --git a/src/preprocessing.ml b/src/preprocessing.ml index 18feab3ce1c..fad3f8cdab1 100644 --- a/src/preprocessing.ml +++ b/src/preprocessing.ml @@ -398,7 +398,7 @@ let get_ppx_driver sctx ~loc ~scope ~dir_kind pps = Ok (ppx_driver_exe sctx libs ~dir_kind, driver) let target_var = String_with_vars.virt_var __POS__ "targets" -let root_var = String_with_vars.virt_var __POS__ "ROOT" +let root_var = String_with_vars.virt_var __POS__ "root" let cookie_library_name lib_name = match lib_name with diff --git a/src/report_error.ml b/src/report_error.ml index 8e6dc01bd61..f19eaa7eeb1 100644 --- a/src/report_error.ml +++ b/src/report_error.ml @@ -75,7 +75,7 @@ let report_with_backtrace exn = Format.fprintf ppf "@{Internal error, please report upstream \ including the contents of _build/log.@}\n\ Description:%a\n" - (Usexp.pp Dune) sexp + Usexp.pp_quoted sexp } | Unix.Unix_error (err, func, fname) -> { p with pp = fun ppf -> diff --git a/src/stdune/hashtbl.ml b/src/stdune/hashtbl.ml index abadd237c5f..3e8c41e5499 100644 --- a/src/stdune/hashtbl.ml +++ b/src/stdune/hashtbl.ml @@ -37,6 +37,24 @@ module Make(H : Hashable.S) = struct fold t ~init ~f:(fun ~key ~data acc -> f key data acc) let fold t ~init ~f = foldi t ~init ~f:(fun _ x -> f x) end + + let of_list l = + let h = create (List.length l) in + let rec loop = function + | [] -> Result.Ok h + | (k, v) :: xs -> + begin match find h k with + | None -> add h k v; loop xs + | Some v' -> Error (k, v', v) + end + in + loop l + + let of_list_exn l = + match of_list l with + | Result.Ok h -> h + | Error (_, _, _) -> + Exn.code_error "Hashtbl.of_list_exn duplicate keys" [] end open MoreLabels.Hashtbl diff --git a/src/stdune/hashtbl_intf.ml b/src/stdune/hashtbl_intf.ml index 3d30d0e15a5..c09d8d27305 100644 --- a/src/stdune/hashtbl_intf.ml +++ b/src/stdune/hashtbl_intf.ml @@ -8,4 +8,6 @@ module type S = sig val fold : 'a t -> init:'b -> f:('a -> 'b -> 'b) -> 'b val foldi : 'a t -> init:'b -> f:(key -> 'a -> 'b -> 'b) -> 'b + + val of_list_exn : (key * 'a) list -> 'a t end diff --git a/src/stdune/string.ml b/src/stdune/string.ml index bc7e87f9431..3bb7f50ea71 100644 --- a/src/stdune/string.ml +++ b/src/stdune/string.ml @@ -16,6 +16,8 @@ let compare a b = Ordering.of_int (String.compare a b) module T = struct type t = StringLabels.t let compare = compare + let equal (x : t) (y : t) = x = y + let hash (s : t) = Hashtbl.hash s end let capitalize = capitalize_ascii @@ -201,6 +203,7 @@ let maybe_quoted s = module Set = Set.Make(T) module Map = Map.Make(T) +module Table = Hashtbl.Make(T) let enumerate_gen s = let s = " " ^ s ^ " " in diff --git a/src/stdune/string.mli b/src/stdune/string.mli index a2c9d9820d7..54818776170 100644 --- a/src/stdune/string.mli +++ b/src/stdune/string.mli @@ -53,3 +53,4 @@ val enumerate_or : string list -> string module Set : Set.S with type elt = t module Map : Map.S with type key = t +module Table : Hashtbl.S with type key = t diff --git a/src/string_with_vars.ml b/src/string_with_vars.ml index 7e99f400c4d..04aa239f06c 100644 --- a/src/string_with_vars.ml +++ b/src/string_with_vars.ml @@ -196,18 +196,34 @@ module Var = struct let loc (t : t) = t.loc type kind = - | Single of string - | Pair of string * string + | Var of string + | Macro of string * string let destruct { loc = _ ; name; payload; syntax = _ } = match payload with - | None -> Single name - | Some p -> Pair (name, p) + | None -> Var name + | Some p -> Macro (name, p) + + let name { name; _ } = name let full_name t = match destruct t with - | Single s -> s - | Pair (k, v) -> k ^ ":" ^ v + | Var s -> s + | Macro (k, v) -> k ^ ":" ^ v + + let to_string = string_of_var + + let pp fmt t = Format.pp_print_string fmt (to_string t) + + let sexp_of_t t = Sexp.atom (to_string t) + + let with_payload t ~payload = + { t with payload } + + let with_name t ~name = + { t with name } + + let is_macro t = Option.is_some t.payload end let partial_expand @@ -262,8 +278,8 @@ let expand t ~mode ~dir ~f = begin match var.syntax with | Percent -> begin match Var.destruct var with - | Single v -> Loc.fail var.loc "unknown variable %S" v - | Pair _ -> Loc.fail var.loc "unknown form %s" (string_of_var var) + | Var v -> Loc.fail var.loc "unknown variable %S" v + | Macro _ -> Loc.fail var.loc "unknown form %s" (string_of_var var) end | Dollar_brace | Dollar_paren -> Some [Value.String (string_of_var var)] diff --git a/src/string_with_vars.mli b/src/string_with_vars.mli index 649bbc8d237..ddb09575b4e 100644 --- a/src/string_with_vars.mli +++ b/src/string_with_vars.mli @@ -49,14 +49,27 @@ end module Var : sig type t + val pp : t Fmt.t + + val sexp_of_t : t -> Sexp.t + + val name : t -> string val loc : t -> Loc.t val full_name : t -> string type kind = - | Single of string - | Pair of string * string + | Var of string + | Macro of string * string val destruct : t -> kind + + val to_string : t -> string + + val with_name : t -> name:string -> t + + val with_payload : t -> payload:string option -> t + + val is_macro : t -> bool end val expand diff --git a/src/super_context.ml b/src/super_context.ml index fef59a01d7f..21b3fe090b8 100644 --- a/src/super_context.ml +++ b/src/super_context.ml @@ -45,7 +45,8 @@ type t = ; artifacts : Artifacts.t ; stanzas_to_consider_for_install : Installable.t list ; cxx_flags : string list - ; vars : Value.t list String.Map.t + ; vars : Pform.Var.t Pform.Map.t + ; macros : Pform.Macro.t Pform.Map.t ; chdir : (Action.t, Action.t) Build.t ; host : t option ; libs_by_package : (Package.t * Lib.Set.t) Package.Name.Map.t @@ -84,26 +85,34 @@ let installed_libs t = t.installed_libs let find_scope_by_dir t dir = Scope.DB.find_by_dir t.scopes dir let find_scope_by_name t name = Scope.DB.find_by_name t.scopes name -let expand_var_no_root t var = String.Map.find t.vars var - -let (expand_vars, expand_vars_path) = +let expand_vars t ~syntax_version ~var = + if String_with_vars.Var.is_macro var then + Loc.fail (String_with_vars.Var.loc var) + "macros of the form %%{name:..} cannot be expanded here" + else + Pform.Map.expand t.vars ~syntax_version ~var + +let expand_macro t ~syntax_version ~var = + if String_with_vars.Var.is_macro var then + Pform.Map.expand t.macros ~syntax_version ~var + else + Exn.code_error "expand_macro can't expand variables" + [ "var", String_with_vars.Var.sexp_of_t var ] + +let (expand_vars_string, 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 -> - match String_with_vars.Var.full_name v with - | "ROOT" -> Some [Value.Path t.context.build_dir] - | "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 - | None -> String.Map.find extra_vars var)) + String_with_vars.expand ~mode:Single ~dir s ~f:(fun var syntax_version -> + match expand_vars t ~syntax_version ~var with + | None -> + String.Map.find extra_vars (String_with_vars.Var.full_name var) + | Some v -> + begin match Pform.Var.to_value_no_deps_or_targets ~scope v with + | Some _ as v -> v + | None -> + Loc.fail (String_with_vars.Var.loc var) + "Variable %a is not allowed in this context" + String_with_vars.Var.pp var + end) in let expand_vars t ~scope ~dir ?extra_vars s = expand t ~scope ~dir ?extra_vars s @@ -117,7 +126,7 @@ let (expand_vars, expand_vars_path) = let expand_and_eval_set t ~scope ~dir ?extra_vars set ~standard = let open Build.O in - let f = expand_vars t ~scope ~dir ?extra_vars in + let f = expand_vars_string t ~scope ~dir ?extra_vars in let parse ~loc:_ s = s in let (syntax, files) = Ordered_set_lang.Unexpanded.files set ~f in match String.Set.to_list files with @@ -280,61 +289,7 @@ let create List.filter context.ocamlc_cflags ~f:(fun s -> not (String.is_prefix s ~prefix:"-std=")) in - let vars = - let ocamlopt = - match context.ocamlopt with - | None -> Path.relative context.ocaml_bin "ocamlopt" - | Some p -> p - in - let string s = [Value.String s] in - let path p = [Value.Path p] in - let make = - match Bin.make with - | None -> string "make" - | Some p -> path p - in - let cflags = context.ocamlc_cflags in - let strings = Value.L.strings in - let vars = - [ "-verbose" , [] - ; "CPP" , strings (context.c_compiler :: cflags @ ["-E"]) - ; "PA_CPP" , strings (context.c_compiler :: cflags - @ ["-undef"; "-traditional"; - "-x"; "c"; "-E"]) - ; "CC" , strings (context.c_compiler :: cflags) - ; "CXX" , strings (context.c_compiler :: cxx_flags) - ; "ocaml_bin" , path context.ocaml_bin - ; "OCAML" , path context.ocaml - ; "OCAMLC" , path context.ocamlc - ; "OCAMLOPT" , path ocamlopt - ; "ocaml_version" , string context.version_string - ; "ocaml_where" , string (Path.to_string context.stdlib_dir) - ; "ARCH_SIXTYFOUR" , string (string_of_bool context.arch_sixtyfour) - ; "MAKE" , make - ; "null" , string (Path.to_string Config.dev_null) - ; "ext_obj" , string context.ext_obj - ; "ext_asm" , string context.ext_asm - ; "ext_lib" , string context.ext_lib - ; "ext_dll" , string context.ext_dll - ; "ext_exe" , string context.ext_exe - ; "profile" , string context.profile - ] - in - let vars = - vars @ - List.map (Ocaml_config.to_list context.ocaml_config) ~f:(fun (k, v) -> - ("ocaml-config:" ^ k, - match (v : Ocaml_config.Value.t) with - | Bool x -> string (string_of_bool x) - | Int x -> string (string_of_int x) - | String x -> string x - | Words x -> strings x - | Prog_and_args x -> strings (x.prog :: x.args))) - in - match String.Map.of_list vars with - | Ok x -> x - | Error _ -> assert false - in + let vars = Pform.Map.create_vars ~context ~cxx_flags in let t = { context ; host @@ -349,6 +304,7 @@ let create ; artifacts ; cxx_flags ; vars + ; macros = Pform.Map.macros ; chdir = Build.arr (fun (action : Action.t) -> match action with | Chdir _ -> action @@ -528,7 +484,7 @@ module Deps = struct Build.source_tree ~dir:path ~file_tree:t.file_tree >>^ Path.Set.to_list | Package p -> - let pkg = Package.Name.of_string (expand_vars t ~scope ~dir p) in + let pkg = Package.Name.of_string (expand_vars_string t ~scope ~dir p) in Alias.dep (Alias.package_install ~context:t.context ~pkg) >>^ fun () -> [] | Universe -> @@ -636,40 +592,20 @@ module Action = struct ; ddeps = String.Map.empty } in - let expand var syntax_version = + let expand_form s 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) 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\ - Hint: Did you mean ${path:%s} instead?" - s - s - | Pair ("bin", s) -> begin + begin match expand_macro sctx ~syntax_version ~var with + | Some Pform.Macro.Exe -> Some (path_exp (map_exe (Path.relative dir s))) + | Some Dep -> Some (path_exp (Path.relative dir s)) + | Some Bin -> begin let sctx = host sctx in match Artifacts.binary (artifacts sctx) s with | Ok path -> Some (path_exp path) | Error e -> add_fail acc ({ fail = fun () -> Action.Prog.Not_found.raise e }) end - | Pair ("findlib", s) when syntax_version >= (1, 0) -> - Loc.fail - loc - "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 + | Some Lib -> begin let lib_dep, file = parse_lib_file ~loc s in add_lib_dep acc lib_dep dep_kind; match @@ -678,7 +614,7 @@ module Action = struct | Ok path -> Some (path_exp path) | Error fail -> add_fail acc fail end - | Pair ("libexec" , s) -> begin + | Some Libexec -> begin let sctx = host sctx in let lib_dep, file = parse_lib_file ~loc s in add_lib_dep acc lib_dep dep_kind; @@ -699,11 +635,13 @@ module Action = struct add_ddep acc ~key dep end end - | Pair ("lib-available", lib) -> - add_lib_dep acc lib Optional; - Some (str_exp (string_of_bool ( - Lib.DB.available (Scope.libs scope) lib))) - | Pair ("version", s) -> begin + | Some Lib_available -> begin + let lib = s in + add_lib_dep acc lib Optional; + Some (str_exp (string_of_bool ( + Lib.DB.available (Scope.libs scope) lib))) + end + | Some Version -> begin match Package.Name.Map.find (Scope.project scope).packages (Package.Name.of_string s) with | Some p -> @@ -718,7 +656,7 @@ module Action = struct Loc.fail loc "Package %S doesn't exist in the current project." s } end - | Pair ("read", s) -> begin + | Some Read -> begin let path = Path.relative dir s in let data = Build.contents path @@ -726,7 +664,7 @@ module Action = struct in add_ddep acc ~key data end - | Pair ("read-lines", s) -> begin + | Some Read_lines -> begin let path = Path.relative dir s in let data = Build.lines_of path @@ -734,7 +672,7 @@ module Action = struct in add_ddep acc ~key data end - | Pair ("read-strings", s) -> begin + | Some Read_strings -> begin let path = Path.relative dir s in let data = Build.strings path @@ -742,62 +680,46 @@ module Action = struct in add_ddep acc ~key data end - | _ -> - match expand_var_no_root sctx key with - | Some _ as x -> x - | None -> String.Map.find extra_vars key + | Some Path_no_dep -> Some [Value.Dir (Path.relative dir s)] + | None -> + Loc.fail (String_with_vars.Var.loc var) "Unknown form: %a" + String_with_vars.Var.pp var + end in - let targets loc name = - let var = - match name with - | "@" -> sprintf "${%s}" name - | "targets" -> sprintf "%%{%s}" name - | _ -> assert false + 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 res = + match String_with_vars.Var.destruct var with + | Macro (_, s) -> expand_form s var syntax_version + | Var var_name -> + begin match expand_vars sctx ~syntax_version ~var with + | None -> String.Map.find extra_vars key + | Some Targets -> + let var () = + match var_name with + | "@" -> sprintf "${%s}" var_name + | "targets" -> sprintf "%%{%s}" var_name + | _ -> assert false + in + begin 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.dirs l) (* XXX hack to signal no dep *) + end + | Some v -> Pform.Var.to_value_no_deps_or_targets v ~scope + end 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" -> - 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." - | _ -> - let exp = expand var syntax_version in - Option.iter exp ~f:(fun vs -> - acc.sdeps <- Path.Set.union (Path.Set.of_list - (Value.L.paths_only vs)) acc.sdeps; - ); - exp) + Option.iter res ~f:(fun v -> + acc.sdeps <- Path.Set.union + (Path.Set.of_list (Value.L.deps_only v)) acc.sdeps + ); + res in + let t = U.partial_expand t ~dir ~map_exe ~f:expand in (t, acc) let expand_step2 ~dir ~dynamic_expansions ~deps_written_by_user ~map_exe t = @@ -807,32 +729,20 @@ module Action = struct match String.Map.find dynamic_expansions key with | Some _ as opt -> opt | None -> - let first_dep () = - Some ( - match deps_written_by_user with + Pform.Map.expand Pform.Map.static_vars ~syntax_version ~var + |> Option.map ~f:(function + | Pform.Var.Deps -> (Value.L.paths deps_written_by_user) + | First_dep -> + begin 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 - | "<" -> - 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) + end + | _ -> + Exn.code_error "Unexpected variable in step2" + ["var", String_with_vars.Var.sexp_of_t var])) let run sctx ~loc ?(extra_vars=String.Map.empty) t ~dir ~dep_kind ~targets:targets_written_by_user ~scope diff --git a/src/super_context.mli b/src/super_context.mli index ae4bc5c3099..54dbe470b68 100644 --- a/src/super_context.mli +++ b/src/super_context.mli @@ -78,7 +78,7 @@ val dump_env : t -> dir:Path.t -> (unit, Sexp.t list) Build.t val find_scope_by_dir : t -> Path.t -> Scope.t val find_scope_by_name : t -> Dune_project.Name.t -> Scope.t -val expand_vars +val expand_vars_string : t -> scope:Scope.t -> dir:Path.t diff --git a/src/syntax.ml b/src/syntax.ml index 8a95138c31a..3e778dc2116 100644 --- a/src/syntax.ml +++ b/src/syntax.ml @@ -56,6 +56,21 @@ type t = ; supported_versions : Supported_versions.t } +module Error = struct + let since loc t ver ~what = + Loc.fail loc "%s is only available since version %s of %s" + what (Version.to_string ver) t.desc + + let renamed_in loc t ver ~what ~to_ = + Loc.fail loc "%s was renamed to '%s' in the %s version of %s" + what to_ (Version.to_string ver) t.desc + + let deleted_in loc t ver ~what = + Loc.fail loc "%s was deleted in version %s of %s" + what (Version.to_string ver) t.desc +end + + let create ~name ~desc supported_versions = { name ; desc @@ -112,9 +127,7 @@ let deleted_in t ver = return () else begin desc () >>= fun (loc, what) -> - Loc.fail loc - "%s was deleted in version %s of %s" what - (Version.to_string ver) t.desc + Error.deleted_in loc t ver ~what end let renamed_in t ver ~to_ = @@ -123,9 +136,7 @@ let renamed_in t ver ~to_ = return () else begin desc () >>= fun (loc, what) -> - Loc.fail loc - "%s was renamed to '%s' in the %s version of %s" what to_ - (Version.to_string ver) t.desc + Error.renamed_in loc t ver ~what ~to_ end let since t ver = @@ -134,7 +145,5 @@ let since t ver = return () else begin desc () >>= fun (loc, what) -> - Loc.fail loc - "%s is only available since version %s of %s" what - (Version.to_string ver) t.desc + Error.since loc t ver ~what end diff --git a/src/syntax.mli b/src/syntax.mli index 7faf305c00f..dd9c8e0bd8e 100644 --- a/src/syntax.mli +++ b/src/syntax.mli @@ -20,6 +20,14 @@ end type t +module Error : sig + val since : Loc.t -> t -> Version.t -> what:string -> _ + + val renamed_in : Loc.t -> t -> Version.t -> what:string -> to_:string -> _ + + val deleted_in : Loc.t -> t -> Version.t -> what:string -> _ +end + (** [create ~name ~desc supported_versions] defines a new syntax. [supported_version] is the list of the last minor version of each supported major version. [desc] is used to describe what diff --git a/src/usexp/usexp.ml b/src/usexp/usexp.ml index b687686e0ab..eb28b04a1ce 100644 --- a/src/usexp/usexp.ml +++ b/src/usexp/usexp.ml @@ -41,6 +41,18 @@ let rec pp syntax ppf = function Format.pp_close_box ppf () | Template t -> Template.pp syntax ppf t +let pp_quoted = + let rec loop = function + | Atom (A s) as t -> + if Atom.is_valid_dune s then + t + else + Quoted_string s + | List xs -> List (List.map ~f:loop xs) + | (Quoted_string _ | Template _) as t -> t + in + fun ppf t -> pp Dune ppf (loop t) + let pp_print_quoted_string ppf s = let syntax = Dune in if String.contains s '\n' then begin diff --git a/src/usexp/usexp.mli b/src/usexp/usexp.mli index bc0ad76886c..31810267cb3 100644 --- a/src/usexp/usexp.mli +++ b/src/usexp/usexp.mli @@ -76,6 +76,10 @@ val to_string : t -> syntax:syntax -> string (** Serialize a S-expression using indentation to improve readability *) val pp : syntax -> Format.formatter -> t -> unit +(** Serialization that never fails because it quotes atoms when necessary + TODO remove this once we have a proper sexp type *) +val pp_quoted : Format.formatter -> t -> unit + (** Same as [pp ~syntax:Dune], but split long strings. The formatter must have been prepared with [prepare_formatter]. *) val pp_split_strings : Format.formatter -> t -> unit diff --git a/src/value.ml b/src/value.ml index 9d8cf9fd6f4..f3dc587b86c 100644 --- a/src/value.ml +++ b/src/value.ml @@ -2,6 +2,7 @@ open Stdune type t = | String of string + | Dir of Path.t | Path of Path.t let string_of_path ~dir p = Path.reach ~from:dir p @@ -9,11 +10,13 @@ let string_of_path ~dir p = Path.reach ~from:dir p let to_string t ~dir = match t with | String s -> s + | Dir p | Path p -> string_of_path ~dir p let to_path ?error_loc t ~dir = match t with | String s -> Path.relative ?error_loc dir s + | Dir p | Path p -> p module L = struct @@ -23,12 +26,15 @@ module L = struct List.map ~f:(to_string ~dir) ts |> String.concat ~sep:" " - let paths_only = + let deps_only = List.filter_map ~f:(function + | Dir _ | String _ -> None | Path p -> Some p) let strings = List.map ~f:(fun x -> String x) let paths = List.map ~f:(fun x -> Path x) + + let dirs = List.map ~f:(fun x -> Dir x) end diff --git a/src/value.mli b/src/value.mli index d2a7b8453bb..ee7162dd63f 100644 --- a/src/value.mli +++ b/src/value.mli @@ -2,6 +2,7 @@ open Stdune type t = | String of string + | Dir of Path.t | Path of Path.t val to_string : t -> dir:Path.t -> string @@ -13,7 +14,9 @@ module L : sig val paths : Path.t list -> t list - val paths_only : t list -> Path.t list + val deps_only : t list -> Path.t list + + val dirs : Path.t list -> t list val concat : t list -> dir:Path.t -> string diff --git a/test/blackbox-tests/dune.inc b/test/blackbox-tests/dune.inc index 56093c94afd..bf0c54a11c3 100644 --- a/test/blackbox-tests/dune.inc +++ b/test/blackbox-tests/dune.inc @@ -88,6 +88,14 @@ test-cases/depend-on-the-universe (progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected))))) +(alias + (name dune-jbuild-var-case) + (deps (package dune) (source_tree test-cases/dune-jbuild-var-case)) + (action + (chdir + test-cases/dune-jbuild-var-case + (progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected))))) + (alias (name dune-ppx-driver-system) (deps (package dune) (source_tree test-cases/dune-ppx-driver-system)) @@ -362,6 +370,14 @@ test-cases/loop (progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected))))) +(alias + (name macro-expand-error) + (deps (package dune) (source_tree test-cases/macro-expand-error)) + (action + (chdir + test-cases/macro-expand-error + (progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected))))) + (alias (name menhir) (deps (package dune) (source_tree test-cases/menhir)) @@ -641,6 +657,7 @@ (alias cross-compilation) (alias custom-build-dir) (alias depend-on-the-universe) + (alias dune-jbuild-var-case) (alias dune-ppx-driver-system) (alias dune-project-edition) (alias env) @@ -673,6 +690,7 @@ (alias lib-available) (alias link-deps) (alias loop) + (alias macro-expand-error) (alias menhir) (alias merlin-tests) (alias meta-gen) @@ -718,6 +736,7 @@ (alias cross-compilation) (alias custom-build-dir) (alias depend-on-the-universe) + (alias dune-jbuild-var-case) (alias dune-ppx-driver-system) (alias dune-project-edition) (alias env) @@ -748,6 +767,7 @@ (alias lib-available) (alias link-deps) (alias loop) + (alias macro-expand-error) (alias merlin-tests) (alias meta-gen) (alias misc) diff --git a/test/blackbox-tests/test-cases/aliases/src/dune b/test/blackbox-tests/test-cases/aliases/src/dune index 20302805ffe..31951eebfb8 100644 --- a/test/blackbox-tests/test-cases/aliases/src/dune +++ b/test/blackbox-tests/test-cases/aliases/src/dune @@ -1,3 +1,3 @@ (alias (name x) - (action (chdir %{ROOT} (echo "running in .\n")))) + (action (chdir %{root} (echo "running in .\n")))) diff --git a/test/blackbox-tests/test-cases/aliases/src/foo/bar/dune b/test/blackbox-tests/test-cases/aliases/src/foo/bar/dune index 7ccf02de448..f0a2cb002cc 100644 --- a/test/blackbox-tests/test-cases/aliases/src/foo/bar/dune +++ b/test/blackbox-tests/test-cases/aliases/src/foo/bar/dune @@ -1,3 +1,3 @@ (alias (name x) - (action (chdir %{ROOT} (echo "running in bar\n")))) + (action (chdir %{root} (echo "running in bar\n")))) diff --git a/test/blackbox-tests/test-cases/aliases/src/foo/baz/dune b/test/blackbox-tests/test-cases/aliases/src/foo/baz/dune index ff87541b231..49318e33434 100644 --- a/test/blackbox-tests/test-cases/aliases/src/foo/baz/dune +++ b/test/blackbox-tests/test-cases/aliases/src/foo/baz/dune @@ -1,3 +1,3 @@ (alias (name x) - (action (chdir %{ROOT} (echo "running in baz\n")))) + (action (chdir %{root} (echo "running in baz\n")))) diff --git a/test/blackbox-tests/test-cases/dune-jbuild-var-case/dune-lower/dune b/test/blackbox-tests/test-cases/dune-jbuild-var-case/dune-lower/dune new file mode 100644 index 00000000000..343bdb8196d --- /dev/null +++ b/test/blackbox-tests/test-cases/dune-jbuild-var-case/dune-lower/dune @@ -0,0 +1,3 @@ +(alias + (name runtest) + (action (with-stdout-to %{null} (echo %{make})))) \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/dune-jbuild-var-case/dune-lower/dune-project b/test/blackbox-tests/test-cases/dune-jbuild-var-case/dune-lower/dune-project new file mode 100644 index 00000000000..b2559fa0581 --- /dev/null +++ b/test/blackbox-tests/test-cases/dune-jbuild-var-case/dune-lower/dune-project @@ -0,0 +1 @@ +(lang dune 1.0) \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/dune-jbuild-var-case/dune-upper/dune b/test/blackbox-tests/test-cases/dune-jbuild-var-case/dune-upper/dune new file mode 100644 index 00000000000..f6be7174cb0 --- /dev/null +++ b/test/blackbox-tests/test-cases/dune-jbuild-var-case/dune-upper/dune @@ -0,0 +1,3 @@ +(alias + (name runtest) + (action (with-stdout-to %{null} (echo %{MAKE})))) \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/dune-jbuild-var-case/dune-upper/dune-project b/test/blackbox-tests/test-cases/dune-jbuild-var-case/dune-upper/dune-project new file mode 100644 index 00000000000..b2559fa0581 --- /dev/null +++ b/test/blackbox-tests/test-cases/dune-jbuild-var-case/dune-upper/dune-project @@ -0,0 +1 @@ +(lang dune 1.0) \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/dune-jbuild-var-case/jbuilder-lower/jbuild b/test/blackbox-tests/test-cases/dune-jbuild-var-case/jbuilder-lower/jbuild new file mode 100644 index 00000000000..04a36be261e --- /dev/null +++ b/test/blackbox-tests/test-cases/dune-jbuild-var-case/jbuilder-lower/jbuild @@ -0,0 +1,3 @@ +(alias + ((name runtest) + (action (with-stdout-to ${null} (echo ${make}))))) diff --git a/test/blackbox-tests/test-cases/dune-jbuild-var-case/jbuilder-upper/jbuild b/test/blackbox-tests/test-cases/dune-jbuild-var-case/jbuilder-upper/jbuild new file mode 100644 index 00000000000..7132e12fb02 --- /dev/null +++ b/test/blackbox-tests/test-cases/dune-jbuild-var-case/jbuilder-upper/jbuild @@ -0,0 +1,3 @@ +(alias + ((name runtest) + (action (with-stdout-to ${null} (echo ${MAKE}))))) diff --git a/test/blackbox-tests/test-cases/dune-jbuild-var-case/run.t b/test/blackbox-tests/test-cases/dune-jbuild-var-case/run.t new file mode 100644 index 00000000000..766de35409a --- /dev/null +++ b/test/blackbox-tests/test-cases/dune-jbuild-var-case/run.t @@ -0,0 +1,18 @@ +All builtin variables are lower cased in Dune: + + $ dune runtest --root dune-lower + Entering directory 'dune-lower' + + $ dune runtest --root dune-upper + Entering directory 'dune-upper' + File "dune", line 3, characters 41-46: + Error: %{MAKE} was renamed to '%{make}' in the 1.0 version of the dune language + [1] + +jbuild files retain the the old names: + + $ dune runtest --root jbuilder-upper + Entering directory 'jbuilder-upper' + + $ dune runtest --root jbuilder-upper + Entering directory 'jbuilder-upper' diff --git a/test/blackbox-tests/test-cases/findlib-error/run.t b/test/blackbox-tests/test-cases/findlib-error/run.t index e704b5baea6..248caa52801 100644 --- a/test/blackbox-tests/test-cases/findlib-error/run.t +++ b/test/blackbox-tests/test-cases/findlib-error/run.t @@ -3,8 +3,7 @@ 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 in jbuild files, please use lib instead: - %{lib:pkg} in dune files + Error: %{findlib:..} was renamed to '%{lib:..}' in the 1.0 version of the dune language [1] But it must still be available in jbuild files diff --git a/test/blackbox-tests/test-cases/inline_tests/dune-file/dune b/test/blackbox-tests/test-cases/inline_tests/dune-file/dune index 6146b3dab09..8cde20c6ca2 100644 --- a/test/blackbox-tests/test-cases/inline_tests/dune-file/dune +++ b/test/blackbox-tests/test-cases/inline_tests/dune-file/dune @@ -12,7 +12,7 @@ (echo "\n") (echo "let () = print_int 43;;"))) (flags inline-test-runner %{library-name} - -source-tree-root %{ROOT} -diff-cmd -))) + -source-tree-root %{root} -diff-cmd -))) (library (name foo_tests) diff --git a/test/blackbox-tests/test-cases/inline_tests/run.t b/test/blackbox-tests/test-cases/inline_tests/run.t index d46693c77e6..dfad901ba57 100644 --- a/test/blackbox-tests/test-cases/inline_tests/run.t +++ b/test/blackbox-tests/test-cases/inline_tests/run.t @@ -30,7 +30,7 @@ (inline-test-runner %{library-name} -source-tree-root - %{ROOT} + %{root} -diff-cmd -)) (generate_runner diff --git a/test/blackbox-tests/test-cases/macro-expand-error/dune b/test/blackbox-tests/test-cases/macro-expand-error/dune new file mode 100644 index 00000000000..02ade1384d1 --- /dev/null +++ b/test/blackbox-tests/test-cases/macro-expand-error/dune @@ -0,0 +1 @@ +(copy_files %{read:x}/*) \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/macro-expand-error/run.t b/test/blackbox-tests/test-cases/macro-expand-error/run.t new file mode 100644 index 00000000000..832d5db88c8 --- /dev/null +++ b/test/blackbox-tests/test-cases/macro-expand-error/run.t @@ -0,0 +1,8 @@ +we're getting an acceptable error message when adding a macro form in an +inappropariate place: + + $ dune build + Info: creating file dune-project with this contents: (lang dune 1.0) + File "dune", line 1, characters 14-21: + Error: macros of the form %{name:..} cannot be expanded here + [1] diff --git a/test/blackbox-tests/test-cases/path-variables/run.t b/test/blackbox-tests/test-cases/path-variables/run.t index ccaca183f8a..56f4c48f1e6 100644 --- a/test/blackbox-tests/test-cases/path-variables/run.t +++ b/test/blackbox-tests/test-cases/path-variables/run.t @@ -8,7 +8,9 @@ In expands to a file name, and registers this as a dependency. $ dune build --root dune @test-dep Entering directory 'dune' - dynamic-contents + File "dune", line 13, characters 17-47: + Error: %{path:..} was renamed to '%{dep:..}' in the 1.0 version of the dune language + [1] %{path-no-dep:string} --------------------- @@ -18,7 +20,7 @@ This form does not exist, but displays an hint: $ dune build --root dune-invalid @test-path-no-dep Entering directory 'dune-invalid' File "dune", line 7, characters 17-54: - Error: The ${path-no-dep:...} syntax has been removed from dune. + Error: %{path-no-dep:..} was deleted in version 1.0 of the dune language [1] jbuild files @@ -51,6 +53,5 @@ 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. - Hint: Did you mean ${path:generated-file} instead? + Error: ${dep:..} is only available since version 1.0 of the dune language [1]