Skip to content

Commit 64a22fc

Browse files
committed
Merge pull request #1264 from edgurgel/mix-rebar-scripts
Fix rebar config scripts evaluation
2 parents 160a825 + 07cd772 commit 64a22fc

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

lib/mix/lib/mix/rebar.ex

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,17 @@ defmodule Mix.Rebar do
128128
end
129129
end
130130

131-
defp eval_script(path, config) do
132-
script = Path.basename(path) |> binary_to_list
133-
case :file.script(path, eval_binds(CONFIG: config, SCRIPT: script)) do
131+
defp eval_script(script_path, config) do
132+
script = Path.basename(script_path) |> binary_to_list
133+
result = File.cd!(Path.dirname(script_path), fn ->
134+
:file.script(script, eval_binds(CONFIG: config, SCRIPT: script))
135+
end)
136+
case result do
134137
{ :ok, config } ->
135138
config
136139
{ :error, error } ->
137140
reason = :file.format_error(error)
138-
raise Mix.Error, message: "Error evaluating rebar config script #{path}: #{reason}"
141+
raise Mix.Error, message: "Error evaluating rebar config script #{script_path}: #{reason}"
139142
end
140143
end
141144

lib/mix/test/fixtures/rebar_dep_script/rebar.config

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{'dir', file:get_cwd()}].

lib/mix/test/mix/rebar_test.exs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ defmodule Mix.RebarTest do
2121
assert config[:SCRIPT] == 'rebar.config.script'
2222
end
2323

24+
test "execute rebar.config.script on dependecy directory" do
25+
path = MixTest.Case.fixture_path("rebar_dep_script")
26+
config = Mix.Rebar.load_config(path)
27+
assert config[:dir] == {:ok, binary_to_list(path)}
28+
end
29+
2430
test "rebar sub_dirs" do
2531
path = MixTest.Case.fixture_path("rebar_dep")
2632
assert Mix.Rebar.recur(path, fn _ -> File.cwd end)

0 commit comments

Comments
 (0)