Skip to content

Commit 60dcd14

Browse files
committed
Fix Rebar3 env var with spaces (#13303)
1 parent 8344e21 commit 60dcd14

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

lib/mix/lib/mix/rebar.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ defmodule Mix.Rebar do
3636
@doc """
3737
Returns the path to the available `rebar` command.
3838
"""
39-
# TODO: Remove on Elixir v1.18 because phx_new and other installers rely on it.
39+
# TODO: Remove on Elixir v1.20 because phx_new and other installers rely on it.
4040
def rebar_cmd(:rebar) do
4141
Mix.shell().error("[warning] :rebar is no longer supported in Mix, falling back to :rebar3")
4242
rebar_cmd(:rebar3)
@@ -218,7 +218,7 @@ defmodule Mix.Rebar do
218218
defp wrap_cmd(rebar) do
219219
cond do
220220
not match?({:win32, _}, :os.type()) ->
221-
rebar
221+
String.replace(rebar, " ", "\\ ")
222222

223223
String.ends_with?(rebar, ".cmd") ->
224224
"\"#{String.replace(rebar, "/", "\\")}\""

lib/mix/lib/mix/tasks/deps.compile.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ defmodule Mix.Tasks.Deps.Compile do
207207
{"TERM", "dumb"}
208208
]
209209

210-
cmd = "#{escape_path(rebar_cmd(dep))} bare compile --paths #{escape_path(lib_path)}"
210+
cmd = "#{rebar_cmd(dep)} bare compile --paths #{escape_path(lib_path)}"
211211
do_command(dep, config, cmd, false, env)
212212

213213
# Check if we have any new symlinks after compilation

lib/mix/test/mix/rebar_test.exs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ defmodule Mix.RebarTest do
219219
# We run only on Unix because Windows has a hard time
220220
# removing the Rebar executable after executed.
221221
@tag :unix
222-
test "applies variables from :system_env option when compiling dependencies" do
222+
test "applies variables from :system_env option on config/compilation" do
223223
in_tmp("applies variables from system_env", fn ->
224224
Mix.Project.push(RebarAsDepWithEnv)
225225

@@ -233,6 +233,27 @@ defmodule Mix.RebarTest do
233233
end)
234234
end
235235

236+
# We run only on Unix because Windows has a hard time
237+
# removing the Rebar executable after executed.
238+
@tag :unix
239+
test "gets and compiles dependencies with MIX_REBAR3 with spaces" do
240+
in_tmp("rebar3 env with spaces", fn ->
241+
File.cp!(Mix.Rebar.local_rebar_path(:rebar3), "rebar3")
242+
System.put_env("MIX_REBAR3", Path.absname("rebar3"))
243+
assert Mix.Rebar.rebar_cmd(:rebar3) =~ " "
244+
245+
Mix.Project.push(RebarAsDep)
246+
Mix.Tasks.Deps.Get.run([])
247+
assert_received {:mix_shell, :info, ["* Getting git_rebar " <> _]}
248+
249+
Mix.Tasks.Deps.Compile.run([])
250+
assert_received {:mix_shell, :run, ["===> Compiling git_rebar\n"]}
251+
assert_received {:mix_shell, :run, ["===> Compiling rebar_dep\n"]}
252+
end)
253+
after
254+
System.delete_env("MIX_REBAR3")
255+
end
256+
236257
test "gets and compiles dependencies with Mix" do
237258
in_tmp("get and compile dependencies with Mix", fn ->
238259
Mix.Project.push(RebarAsDep)

0 commit comments

Comments
 (0)