diff --git a/doc/usage.rst b/doc/usage.rst index b5ee0d0270b..58e5b11dd94 100644 --- a/doc/usage.rst +++ b/doc/usage.rst @@ -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` diff --git a/src/context.ml b/src/context.ml index f6ee5a4f736..1cd73ffe696 100644 --- a/src/context.ml +++ b/src/context.ml @@ -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 @@ -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 @@ -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 = _ } -> diff --git a/test/blackbox-tests/test-cases/workspace-paths/bin/dune b/test/blackbox-tests/test-cases/workspace-paths/bin/dune index 6cb22929627..75f54cbed6b 100644 --- a/test/blackbox-tests/test-cases/workspace-paths/bin/dune +++ b/test/blackbox-tests/test-cases/workspace-paths/bin/dune @@ -1,3 +1,3 @@ (executable (name hello) - (promote (until-clean))) +) diff --git a/test/blackbox-tests/test-cases/workspace-paths/bin/hello.exe b/test/blackbox-tests/test-cases/workspace-paths/bin/hello.exe deleted file mode 100755 index 0a86f6b4eb5..00000000000 Binary files a/test/blackbox-tests/test-cases/workspace-paths/bin/hello.exe and /dev/null differ diff --git a/test/blackbox-tests/test-cases/workspace-paths/run.t b/test/blackbox-tests/test-cases/workspace-paths/run.t index 438ed74958f..933ab89b08e 100644 --- a/test/blackbox-tests/test-cases/workspace-paths/run.t +++ b/test/blackbox-tests/test-cases/workspace-paths/run.t @@ -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 <