Skip to content

Commit

Permalink
Relative paths in (paths are absolutized inside the build directory
Browse files Browse the repository at this point in the history
Signed-off-by: François Bobot <francois.bobot@cea.fr>
  • Loading branch information
bobot committed Aug 2, 2019
1 parent bd5492c commit 86ee8f4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion doc/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ context or can be the description of an opam switch, as follows:
``PATH``-like variables in this context. These variables are passed as part of
the environment to any program launched by ``dune``. For each variable, the
value is specified using the :ref:`ordered-set-language`. Relative paths are
interpreted with respect to the workspace root, see :ref:`finding-root`.
interpreted with respect to the context build directory.


If environment variables, such as ``PATH``, are modified in the `dune-workspace`
Expand Down
14 changes: 11 additions & 3 deletions src/context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ let create ~(kind : Kind.t) ~path ~env ~env_nodes ~name ~merlin ~targets
in
native :: List.filter_opt others

let extend_paths t ~env =
let extend_paths t ~env ~build_dir =
let module Eval =
Ordered_set_lang.Make(String)
(struct
Expand All @@ -549,7 +549,13 @@ let extend_paths t ~env =
in
let vars =
let to_absolute_filename s =
Path.of_string s |> Path.to_absolute_filename in
if Filename.is_relative s then
Path.Build.relative build_dir s
|> Path.build
|> Path.to_absolute_filename
else
s
in
let sep = String.make 1 Bin.path_sep in
let env = Env.Map.of_list_exn t in
let f l = String.concat ~sep (List.map ~f:to_absolute_filename l) in
Expand Down Expand Up @@ -650,7 +656,9 @@ let instantiate_context env (workspace : Workspace.t)
(Env_nodes.extra_env
~profile:(Workspace.Context.profile context) env_nodes)
in
let env = extend_paths ~env (Workspace.Context.paths context) in
let build_dir =
Path.Build.relative Path.Build.root (Workspace.Context.name context) in
let env = extend_paths ~env ~build_dir (Workspace.Context.paths context) in
match context with
| Default { targets; name; host_context = _; profile; env = _
; toolchain ; paths = _; loc = _ } ->
Expand Down
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/workspace-paths/bin/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(executable
(name hello)
(promote (until-clean)))
)
Binary file not shown.
6 changes: 4 additions & 2 deletions test/blackbox-tests/test-cases/workspace-paths/run.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
$ dune build
$ dune build bin/hello.exe

$ dune build @default
hello alias default
Hello: $TESTCASE_ROOT/a:/c
Hello: $TESTCASE_ROOT/_build/default/a:/c

$ mkdir sub
$ cat > sub/dune-workspace <<EOF
Expand Down

0 comments on commit 86ee8f4

Please sign in to comment.