Skip to content

Commit 0addc22

Browse files
author
José Valim
committed
Improve coverage for builds and rebar integration
1 parent c345e51 commit 0addc22

File tree

8 files changed

+58
-14
lines changed

8 files changed

+58
-14
lines changed

lib/mix/lib/mix/project.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ defmodule Mix.Project do
253253
target = Path.join(app, "ebin")
254254

255255
cond do
256-
opts[:symlink_ebin?] ->
256+
opts[:symlink_ebin] ->
257257
Mix.Utils.symlink_or_copy(source, target)
258258
match?({ :ok, _ }, :file.read_link(target)) ->
259259
File.rm_rf!(target)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ defmodule Mix.Tasks.Deps.Compile do
163163
defp build_structure(dest, build, config) do
164164
File.cd! dest, fn ->
165165
config = Keyword.put(config, :app_path, build)
166-
Mix.Project.build_structure(config, symlink_ebin?: true)
166+
Mix.Project.build_structure(config, symlink_ebin: true)
167167
end
168168
end
169169
end

lib/mix/lib/mix/utils.ex

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -320,21 +320,25 @@ defmodule Mix.Utils do
320320
"""
321321
def symlink_or_copy(source, target) do
322322
if File.exists?(source) do
323-
case :file.make_symlink(source, target) do
324-
:ok -> :ok
325-
{ :error, :eexist } ->
326-
case :file.read_link(target) do
327-
{ :ok, _ } -> :ok
328-
{ :error, _ } -> do_copy(source, target)
329-
end
330-
{ :error, _ } -> do_copy(source, target)
323+
source_list = String.to_char_list!(source)
324+
case :file.read_link(target) do
325+
{ :ok, ^source_list } -> :ok
326+
{ :error, :enoent } ->
327+
do_symlink_or_copy(source, target)
328+
{ :error, _ } ->
329+
File.rm_rf!(target)
330+
do_symlink_or_copy(source, target)
331331
end
332+
else
333+
{ :error, :enoent }
332334
end
333335
end
334336

335-
defp do_copy(source, target) do
336-
File.rm_rf!(target)
337-
File.cp_r!(source, Path.join(target, "."))
337+
defp do_symlink_or_copy(source, target) do
338+
case :file.make_symlink(source, target) do
339+
:ok -> :ok
340+
{ :error, _ } -> File.cp_r!(source, Path.join(target, "."))
341+
end
338342
end
339343

340344
@doc """

lib/mix/test/fixtures/rebar_dep/apps/another/rebar.config

Lines changed: 0 additions & 1 deletion
This file was deleted.

lib/mix/test/fixtures/rebar_dep/ebin/.gitkeep

Whitespace-only changes.

lib/mix/test/mix/project_test.exs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,26 @@ defmodule Mix.ProjectTest do
7676
Mix.Project.get!
7777
end
7878
end
79+
80+
test "builds the project structure" do
81+
in_fixture "archive", fn ->
82+
config = [app_path: "_build/archive"]
83+
assert Mix.Project.build_structure(config) == :ok
84+
assert File.dir?("_build/archive/ebin")
85+
assert :file.read_link("_build/archive/priv") == { :ok, Path.expand('priv') }
86+
end
87+
end
88+
89+
test "builds the project structure with ebin symlink" do
90+
in_fixture "archive", fn ->
91+
config = [app_path: "_build/archive"]
92+
assert Mix.Project.build_structure(config, symlink_ebin: true) == :ok
93+
assert :file.read_link("_build/archive/ebin") == { :ok, Path.expand('ebin') }
94+
assert :file.read_link("_build/archive/priv") == { :ok, Path.expand('priv') }
95+
96+
assert Mix.Project.build_structure(config) == :ok
97+
assert File.dir?("_build/archive/ebin")
98+
assert :file.read_link("_build/archive/priv") == { :ok, Path.expand('priv') }
99+
end
100+
end
79101
end

lib/mix/test/mix/rebar_test.exs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,14 @@ defmodule Mix.RebarTest do
7676
assert_received { :mix_shell, :info, ["* Compiling git_rebar"] }
7777
assert_received { :mix_shell, :info, ["* Compiling rebar_dep"] }
7878
assert :git_rebar.any_function == :ok
79+
assert :rebar_dep.any_function == :ok
7980

8081
load_paths = Mix.Deps.loaded
8182
|> Enum.map(&Mix.Deps.load_paths(&1))
8283
|> Enum.concat
8384

85+
assert File.exists?("_build/lib/rebar_dep/ebin/rebar_dep.beam")
86+
assert File.exists?("_build/lib/git_rebar/ebin/git_rebar.beam")
8487
assert Enum.any?(load_paths, &String.ends_with?(&1, "git_rebar/ebin"))
8588
assert Enum.any?(load_paths, &String.ends_with?(&1, "rebar_dep/ebin"))
8689
end

lib/mix/test/mix/utils_test.exs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,20 @@ defmodule Mix.UtilsTest do
7777
time = { { 2000, 1, 1 }, { 0, 0, 0 } }
7878
assert Mix.Utils.extract_stale([{ "hello", time }], [__FILE__]) == []
7979
end
80+
81+
test :symlink_or_copy do
82+
in_fixture "archive", fn ->
83+
File.mkdir_p!("_build/archive")
84+
assert Mix.Utils.symlink_or_copy(Path.expand("ebin"), "_build/archive/ebin") == :ok
85+
assert :file.read_link("_build/archive/ebin") == { :ok, Path.expand('ebin') }
86+
end
87+
end
88+
89+
test :symlink_or_copy_removes_previous_directories do
90+
in_fixture "archive", fn ->
91+
File.mkdir_p!("_build/archive/ebin")
92+
assert Mix.Utils.symlink_or_copy(Path.expand("ebin"), "_build/archive/ebin") == :ok
93+
assert :file.read_link("_build/archive/ebin") == { :ok, Path.expand('ebin') }
94+
end
95+
end
8096
end

0 commit comments

Comments
 (0)