Rename ROOT to root

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
Rudi Grinberg 2018-07-06 21:49:02 +07:00
parent a0a92d9adb
commit 54ff98b36d
10 changed files with 58 additions and 59 deletions

View File

@ -22,7 +22,7 @@ Stanzas
(rule (rule
(targets foo.ml) (targets foo.ml)
(deps generator/gen.exe) (deps generator/gen.exe)
(action (run ${<} -o ${@}))) (action (run %{<} -o %{@})))
The following sections describe the available stanzas and their meaning. 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 byte exe .bc and .bc.js
native/best exe .exe native/best exe .exe
byte object .bc${ext_obj} byte object .bc%{ext_obj}
native/best object .exe${ext_obj} native/best object .exe%{ext_obj}
byte shared_object .bc${ext_dll} byte shared_object .bc%{ext_dll}
native/best shared_object ${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 and shared object files. Their value depends on the OS, for instance
on Unix ``${ext_obj}`` is usually ``.o`` and ``${ext_dll}`` is usually on Unix ``%{ext_obj}`` is usually ``.o`` and ``%{ext_dll}`` is usually
``.so`` while on Windows ``${ext_obj}`` is ``.obj`` and ``${ext_dll}`` ``.so`` while on Windows ``%{ext_obj}`` is ``.obj`` and ``%{ext_dll}``
is ``.dll``. is ``.dll``.
Note that when ``(byte exe)`` is specified but neither ``(best exe)`` Note that when ``(byte exe)`` is specified but neither ``(best exe)``
@ -459,7 +459,7 @@ For instance:
(rule (rule
(targets b (targets b
(deps a (deps a
(action (copy ${<} ${@}))))) (action (copy %{<} %{@})))))
In this example it is obvious by inspecting the action what the 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 dependencies and targets are. When this is the case you can use the
@ -483,7 +483,7 @@ stanza is rejected by dune:
.. code:: scheme .. code:: scheme
(rule (copy a b.${read:file})) (rule (copy a b.%{read:file}))
ocamllex ocamllex
-------- --------
@ -495,7 +495,7 @@ ocamllex
(rule (rule
(targets <name>.ml) (targets <name>.ml)
(deps <name>.mll) (deps <name>.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: To use a different rule mode, use the long form:
@ -515,7 +515,7 @@ ocamlyacc
(rule (rule
(targets <name>.ml <name>.mli) (targets <name>.ml <name>.mli)
(deps <name>.mly) (deps <name>.mly)
(action (chdir ${ROOT} (run ${bin:ocamlyacc} ${<})))) (action (chdir %{root} (run %{bin:ocamlyacc} %{<}))))
To use a different rule mode, use the long form: 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 (alias
(name runtest) (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. See the section about :ref:`running-tests` for details.
@ -825,18 +825,18 @@ Variables are expanded after the set language is interpreted.
Variables expansion 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. expanded by dune.
Dune supports the following variables: Dune supports the following variables:
- ``ROOT`` is the relative path to the root of the build - ``root`` is the relative path to the root of the build
context. Note that ``ROOT`` depends on the worksace context. Note that ``root`` depends on the workspace
configuration. As such you shouldn't use ``ROOT`` to denote the configuration. As such you shouldn't use ``root`` to denote the
root of your project. Use ``SCOPE_ROOT`` instead for this purpose root of your project. Use ``project_root`` instead for this purpose
- ``SCOPE_ROOT`` is the root of the current scope. It is typically - ``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 the toplevel directory of your project and as long as you have at
least one ``<package>.opam`` file there, ``SCOPE_ROOT`` is least one ``<package>.opam`` file there, ``project_root`` is
independent of the workspace configuration independent of the workspace configuration
- ``CC`` is the C compiler command line (list made of the compiler - ``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 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 - ``CXX`` is the C++ compiler command line being used in the
current build context current build context
- ``ocaml_bin`` is the path where ``ocamlc`` lives - ``ocaml_bin`` is the path where ``ocamlc`` lives
- ``OCAML`` is the ``ocaml`` binary - ``ocaml`` is the ``ocaml`` binary
- ``OCAMLC`` is the ``ocamlc`` binary - ``ocamlc`` is the ``ocamlc`` binary
- ``OCAMLOPT`` is the ``ocamlopt`` binary - ``ocamlopt`` is the ``ocamlopt`` binary
- ``ocaml_version`` is the version of the compiler used in the - ``ocaml_version`` is the version of the compiler used in the
current build context current build context
- ``ocaml_where`` is the output of ``ocamlc -where`` - ``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 64 bit architecture and ``false`` otherwise
- ``null`` is ``/dev/null`` on Unix or ``nul`` on Windows - ``null`` is ``/dev/null`` on Unix or ``nul`` on Windows
- ``ext_obj``, ``ext_asm``, ``ext_lib``, ``ext_dll`` and ``ext_exe`` - ``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), is installed by a package in the workspace (see `install`_ stanzas),
the locally built binary will be used, otherwise it will be searched the locally built binary will be used, otherwise it will be searched
in the ``PATH`` of the current build context. Note that ``(run in the ``PATH`` of the current build context. Note that ``(run
${bin:program} ...)`` and ``(run program ...)`` behave in the same %{bin:program} ...)`` and ``(run program ...)`` behave in the same
way. ``${bin:...}`` is only necessary when you are using ``(bash way. ``%{bin:...}`` is only necessary when you are using ``(bash
...)`` or ``(system ...)`` ...)`` or ``(system ...)``
- ``lib:<public-library-name>:<file>`` expands to a path to file ``<file>`` of - ``lib:<public-library-name>:<file>`` expands to a path to file ``<file>`` of
library ``<public-library-name>``. If ``<public-library-name>`` is available library ``<public-library-name>``. If ``<public-library-name>`` is available
@ -906,10 +906,10 @@ In addition, ``(action ...)`` fields support the following special variables:
- ``read-strings:<path>`` expands to the list of lines in the given - ``read-strings:<path>`` expands to the list of lines in the given
file, unescaped using OCaml lexical convention file, unescaped using OCaml lexical convention
The ``${<kind>:...}`` forms are what allows you to write custom rules that work The ``%{<kind>:...}`` forms are what allows you to write custom rules that work
transparently whether things are installed or not. 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 The intent of this last form is to reliably read a list of strings
generated by an OCaml program via: generated by an OCaml program via:
@ -920,13 +920,13 @@ generated by an OCaml program via:
#. Expansion of lists #. Expansion of lists
Forms that expands to list of items, such as ``${CC}``, ``${^}``, Forms that expands to list of items, such as ``%{cc}``, ``%{^}``,
``${@}`` or ``${read-lines:...}``, are suitable to be used in, say, ``%{@}`` or ``%{read-lines:...}``, are suitable to be used in, say,
``(run <prog> <arguments>)``. For instance in: ``(run <prog> <arguments>)``. For instance in:
.. code:: scheme .. code:: scheme
(run foo ${^}) (run foo %{^})
if there are two dependencies ``a`` and ``b``, the produced command if there are two dependencies ``a`` and ``b``, the produced command
will be equivalent to the shell command: will be equivalent to the shell command:
@ -940,7 +940,7 @@ you have to quote the variable as in:
.. code:: scheme .. code:: scheme
(run foo "${^}") (run foo "%{^}")
which is equivalent to the following shell command: which is equivalent to the following shell command:
@ -949,7 +949,7 @@ which is equivalent to the following shell command:
$ foo "a b" $ foo "a b"
(the items of the list are concatenated with space). (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: used as a program name, for instance:
.. code:: scheme .. code:: scheme
@ -957,7 +957,7 @@ used as a program name, for instance:
(rule (rule
(targets result.txt) (targets result.txt)
(deps foo.exe (glob_files *.txt)) (deps foo.exe (glob_files *.txt))
(action (run ${^}))) (action (run %{^})))
Here is another example: Here is another example:
@ -966,7 +966,7 @@ Here is another example:
(rule (rule
(targets foo.exe) (targets foo.exe)
(deps foo.c) (deps foo.c)
(action (run ${CC} -o ${@} ${<} -lfoolib))) (action (run %{cc} -o %{@} %{<} -lfoolib)))
Library dependencies Library dependencies
@ -1052,10 +1052,10 @@ you had setup a rule for every file of the form:
(rule (rule
(targets file.pp.ml) (targets file.pp.ml)
(deps file.ml) (deps file.ml)
(action (with-stdout-to ${@} (chdir ${ROOT} <action>)))) (action (with-stdout-to %{@} (chdir %{root} <action>))))
The equivalent of a ``-pp <command>`` option passed to the OCaml compiler is The equivalent of a ``-pp <command>`` option passed to the OCaml compiler is
``(system "<command> ${<}")``. ``(system "<command> %{<}")``.
Preprocessing with ppx rewriters Preprocessing with ppx rewriters
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -1105,8 +1105,8 @@ For instance:
.. code:: scheme .. code:: scheme
(preprocess (per_module (preprocess (per_module
(((action (run ./pp.sh X=1 ${<})) (foo bar))) (((action (run ./pp.sh X=1 %{<})) (foo bar)))
(((action (run ./pp.sh X=2 ${<})) (baz))))) (((action (run ./pp.sh X=2 %{<})) (baz)))))
.. _deps-field: .. _deps-field:
@ -1231,7 +1231,7 @@ in ``src/foo/dune`` will be run from ``_build/<context>/src/foo``.
The argument of ``(action ...)`` fields is a small DSL that is interpreted by 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 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 support `Variables expansion`_. Moreover, you don't need to specify dependencies
explicitly for the special ``${<kind>:...}`` forms, these are recognized and explicitly for the special ``%{<kind>:...}`` forms, these are recognized and
automatically handled by dune. automatically handled by dune.
The DSL is currently quite limited, so if you want to do something complicated 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 wants this behavior rather than a bare copy, so it was renamed to
something shorter. something shorter.
Note: expansion of the special ``${<kind>:...}`` is done relative to the current Note: expansion of the special ``%{<kind>:...}`` is done relative to the current
working directory of the part of the DSL being executed. So for instance if you working directory of the part of the DSL being executed. So for instance if you
have this action in a ``src/foo/dune``: have this action in a ``src/foo/dune``:
.. code:: scheme .. 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. 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 As a result, if you execute the command from the original directory, it will
only see the basename. only see the basename.
@ -1310,7 +1310,7 @@ To understand why this is important, let's consider this dune file living in
(rule (rule
(targets blah.ml) (targets blah.ml)
(deps blah.mll) (deps blah.mll)
(action (run ocamllex -o ${@} ${<}))) (action (run ocamllex -o %{@} %{<})))
Here the command that will be executed is: Here the command that will be executed is:
@ -1334,7 +1334,7 @@ of your project. What you should write instead is:
(rule (rule
(targets blah.ml) (targets blah.ml)
(deps blah.mll) (deps blah.mll)
(action (chdir ${ROOT} (run ocamllex -o ${@} ${<})))) (action (chdir %{root} (run ocamllex -o %{@} %{<}))))
Locks Locks
----- -----
@ -1357,13 +1357,13 @@ same lock:
(name runtest) (name runtest)
(deps foo) (deps foo)
(locks m) (locks m)
(action (run test.exe ${<}))) (action (run test.exe %{<})))
(alias (alias
(name runtest) (name runtest)
(deps bar) (deps bar)
(locks m) (locks m)
(action (run test.exe ${<}))) (action (run test.exe %{<})))
Dune will make sure that the executions of ``test.exe foo`` and Dune will make sure that the executions of ``test.exe foo`` and
``test.exe bar`` are serialized. ``test.exe bar`` are serialized.
@ -1383,7 +1383,7 @@ simply use an absolute filename:
(name runtest) (name runtest)
(deps foo) (deps foo)
(locks /tcp-port/1042) (locks /tcp-port/1042)
(action (run test.exe ${<}))) (action (run test.exe %{<})))
.. _ocaml-syntax: .. _ocaml-syntax:

View File

@ -1238,7 +1238,7 @@ module Rule = struct
; action = ; action =
(loc, (loc,
Chdir Chdir
(S.virt_var __POS__ "ROOT", (S.virt_var __POS__ "root",
Run (S.virt_text __POS__ "ocamllex", Run (S.virt_text __POS__ "ocamllex",
[ S.virt_text __POS__ "-q" [ S.virt_text __POS__ "-q"
; S.virt_text __POS__ "-o" ; S.virt_text __POS__ "-o"
@ -1259,7 +1259,7 @@ module Rule = struct
; action = ; action =
(loc, (loc,
Chdir Chdir
(S.virt_var __POS__ "ROOT", (S.virt_var __POS__ "root",
Run (S.virt_text __POS__ "ocamlyacc", Run (S.virt_text __POS__ "ocamlyacc",
[S.virt_var __POS__ "first-dep"]))) [S.virt_var __POS__ "first-dep"])))
; mode ; mode

View File

@ -61,7 +61,7 @@ module Run (P : PARAMS) = struct
let sources ms = let sources ms =
List.map ~f:source 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 = let flags =
SC.expand_and_eval_set SC.expand_and_eval_set

View File

@ -398,7 +398,7 @@ let get_ppx_driver sctx ~loc ~scope ~dir_kind pps =
Ok (ppx_driver_exe sctx libs ~dir_kind, driver) Ok (ppx_driver_exe sctx libs ~dir_kind, driver)
let target_var = String_with_vars.virt_var __POS__ "targets" 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 = let cookie_library_name lib_name =
match lib_name with match lib_name with

View File

@ -104,7 +104,6 @@ let (expand_vars, expand_vars_path) =
let expand t ~scope ~dir ?(extra_vars=String.Map.empty) s = 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 match String_with_vars.Var.full_name v with
| "ROOT" -> Some [Value.Path t.context.build_dir]
| "SCOPE_ROOT" -> | "SCOPE_ROOT" ->
if syntax_version >= (1, 0) then if syntax_version >= (1, 0) then
Loc.fail (String_with_vars.Var.loc v) Loc.fail (String_with_vars.Var.loc v)
@ -320,6 +319,7 @@ let create
; "ocamlopt" , path ocamlopt ; "ocamlopt" , path ocamlopt
; "arch_sixtyfour" , string (string_of_bool context.arch_sixtyfour) ; "arch_sixtyfour" , string (string_of_bool context.arch_sixtyfour)
; "make" , make ; "make" , make
; "root" , [Value.Dir context.build_dir]
] in ] in
let vars = let vars =
lowercased lowercased
@ -787,7 +787,6 @@ module Action = struct
let var_name = String_with_vars.Var.full_name var in let var_name = String_with_vars.Var.full_name var in
let loc = String_with_vars.Var.loc var in let loc = String_with_vars.Var.loc var in
match var_name with match var_name with
| "ROOT" -> Some (path_exp sctx.context.build_dir)
| "SCOPE_ROOT" -> | "SCOPE_ROOT" ->
if syntax_version >= (1, 0) then if syntax_version >= (1, 0) then
Loc.fail loc Loc.fail loc

View File

@ -1,3 +1,3 @@
(alias (alias
(name x) (name x)
(action (chdir %{ROOT} (echo "running in .\n")))) (action (chdir %{root} (echo "running in .\n"))))

View File

@ -1,3 +1,3 @@
(alias (alias
(name x) (name x)
(action (chdir %{ROOT} (echo "running in bar\n")))) (action (chdir %{root} (echo "running in bar\n"))))

View File

@ -1,3 +1,3 @@
(alias (alias
(name x) (name x)
(action (chdir %{ROOT} (echo "running in baz\n")))) (action (chdir %{root} (echo "running in baz\n"))))

View File

@ -12,7 +12,7 @@
(echo "\n") (echo "\n")
(echo "let () = print_int 43;;"))) (echo "let () = print_int 43;;")))
(flags inline-test-runner %{library-name} (flags inline-test-runner %{library-name}
-source-tree-root %{ROOT} -diff-cmd -))) -source-tree-root %{root} -diff-cmd -)))
(library (library
(name foo_tests) (name foo_tests)

View File

@ -30,7 +30,7 @@
(inline-test-runner (inline-test-runner
%{library-name} %{library-name}
-source-tree-root -source-tree-root
%{ROOT} %{root}
-diff-cmd -diff-cmd
-)) -))
(generate_runner (generate_runner