Skip to content

Commit b659ecf

Browse files
author
José Valim
committed
Remove pre-copying of dev dependencies
The current code was copying manifests but they got recent access times which caused bugs. Also, a dependency can have different results depending on each dependencies are available and which are not, so simply copying the compiled dep can lead to weird errors.
1 parent c240a49 commit b659ecf

File tree

3 files changed

+8
-93
lines changed

3 files changed

+8
-93
lines changed

lib/elixir/lib/module/locals_tracker.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
defmodule Module.LocalsTracker do
3535
@moduledoc false
3636

37-
@timeout 30_000
38-
@behavior :gen_server
37+
@timeout 30_000
38+
@behaviour :gen_server
3939

4040
@type ref :: pid | module
4141
@type name :: atom

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

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ defmodule Mix.Tasks.Deps.Compile do
5858
not nil?(opts[:compile]) ->
5959
do_compile dep
6060
mix?(dep) ->
61-
do_mix dep, config
61+
do_mix dep
6262
rebar?(dep) ->
6363
do_rebar dep, config
6464
make?(dep) ->
@@ -84,17 +84,8 @@ defmodule Mix.Tasks.Deps.Compile do
8484
:ok
8585
end
8686

87-
defp do_mix(Mix.Dep[app: app] = dep, config) do
87+
defp do_mix(dep) do
8888
Mix.Deps.in_dependency dep, fn _ ->
89-
case dev_compilation(app, config) do
90-
{ source, target } ->
91-
File.rm_rf!(target)
92-
File.mkdir_p!(target)
93-
File.cp_r!(source, Path.dirname(target))
94-
false ->
95-
:ok
96-
end
97-
9889
try do
9990
res = Mix.Task.run("compile", ["--no-deps"])
10091
:ok in List.wrap(res)
@@ -109,21 +100,6 @@ defmodule Mix.Tasks.Deps.Compile do
109100
end
110101
end
111102

112-
# In case we have build per environments and the dependency was already
113-
# compiled for development and the target is stale compared to the
114-
# development (source) one, we simply copy the source to target and do
115-
# the compilation on top of it.
116-
defp dev_compilation(app, config) do
117-
if config[:build_per_environment] do
118-
source = config[:build_path] |> Path.dirname |> Path.join("dev/lib/#{app}")
119-
target = Mix.Project.manifest_path
120-
source != target && Mix.Deps.Lock.mix_env(source) == to_string(Mix.env) &&
121-
not Mix.Utils.stale?([target], [source]) && { source, target }
122-
else
123-
false
124-
end
125-
end
126-
127103
defp do_rebar(Mix.Dep[app: app] = dep, config) do
128104
do_command dep, rebar_cmd(app), "compile skip_deps=true deps_dir=#{inspect config[:deps_path]}"
129105
end
@@ -143,7 +119,7 @@ defmodule Mix.Tasks.Deps.Compile do
143119
end
144120

145121
Mix.Task.run "local.rebar", []
146-
Mix.Rebar.local_rebar_cmd || raise Mix.Error, message: "rebar instalation failed"
122+
Mix.Rebar.local_rebar_cmd || raise Mix.Error, message: "rebar installation failed"
147123
end
148124

149125
defp do_make(dep) do

lib/mix/test/mix/tasks/deps_test.exs

Lines changed: 3 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ defmodule Mix.Tasks.DepsTest do
2727
end
2828
end
2929

30-
defmodule PerEnvironemtDepsApp do
30+
defmodule PerEnvironmentDepsApp do
3131
def project do
3232
[ app: :sample, version: "0.1.0", build_per_environment: true,
3333
deps: [
@@ -154,7 +154,7 @@ defmodule Mix.Tasks.DepsTest do
154154
end
155155

156156
test "compiles and prunes builds per environment" do
157-
Mix.Project.push PerEnvironemtDepsApp
157+
Mix.Project.push PerEnvironmentDepsApp
158158

159159
in_fixture "deps_status", fn ->
160160
Mix.Tasks.Deps.Compile.run []
@@ -167,75 +167,14 @@ defmodule Mix.Tasks.DepsTest do
167167

168168
Mix.ProjectStack.post_config [deps: []]
169169
Mix.Project.pop
170-
Mix.Project.push PerEnvironemtDepsApp
170+
Mix.Project.push PerEnvironmentDepsApp
171171

172172
Mix.Tasks.Deps.Check.run []
173173
refute File.exists?("_build/dev/lib/ok/ebin/ok.app")
174174
assert File.exists?("_build/dev/lib/sample/ebin/sample.app")
175175
end
176176
end
177177

178-
test "copies dev dependency when building per environment" do
179-
Mix.Project.push PerEnvironemtDepsApp
180-
181-
in_fixture "deps_status", fn ->
182-
File.mkdir_p!("deps/ok/lib")
183-
File.write!("deps/ok/lib/empty.ex", "")
184-
185-
Mix.Tasks.Deps.Compile.run []
186-
assert File.exists?("_build/dev/lib/ok/ebin/ok.app")
187-
assert_received { :mix_shell, :info, ["Generated ok.app"] }
188-
189-
Mix.Task.clear
190-
Mix.env(:test)
191-
Mix.Project.pop
192-
Mix.Project.push PerEnvironemtDepsApp
193-
194-
Mix.Tasks.Deps.Compile.run []
195-
assert File.exists?("_build/test/lib/ok/ebin/ok.app")
196-
assert File.read!("_build/test/lib/ok/priv/sample") == "SAMPLE"
197-
# We don't get a message becaused we copied the contents over
198-
refute_received { :mix_shell, :info, ["Generated ok.app"] }
199-
end
200-
end
201-
202-
test "does not choke when another environment is compiled first than dev" do
203-
Mix.Project.push PerEnvironemtDepsApp
204-
Mix.env(:test)
205-
206-
in_fixture "deps_status", fn ->
207-
File.mkdir_p!("deps/ok/lib")
208-
File.write!("deps/ok/lib/empty.ex", "")
209-
210-
Mix.Tasks.Deps.Compile.run []
211-
assert File.exists?("_build/test/lib/ok/ebin/ok.app")
212-
assert File.read!("_build/test/lib/ok/priv/sample") == "SAMPLE"
213-
assert_received { :mix_shell, :info, ["Generated ok.app"] }
214-
end
215-
end
216-
217-
test "does not copy if environments do not match" do
218-
Mix.ProjectStack.post_config(deps: [{ :ok, "0.1.0", path: "deps/ok", env: Mix.env }])
219-
Mix.Project.push PerEnvironemtDepsApp
220-
221-
in_fixture "deps_status", fn ->
222-
File.mkdir_p!("deps/ok/lib")
223-
File.write!("deps/ok/lib/empty.ex", "")
224-
225-
Mix.Tasks.Deps.Compile.run []
226-
assert File.exists?("_build/dev/lib/ok/ebin/ok.app")
227-
assert_received { :mix_shell, :info, ["Generated ok.app"] }
228-
229-
Mix.Task.clear
230-
Mix.env(:test)
231-
Mix.Project.pop
232-
Mix.Project.push PerEnvironemtDepsApp
233-
234-
Mix.Tasks.Deps.Compile.run []
235-
assert_received { :mix_shell, :info, ["Generated ok.app"] }
236-
end
237-
end
238-
239178
test "unlocks all deps" do
240179
Mix.Project.push DepsApp
241180
in_fixture "no_mixfile", fn ->

0 commit comments

Comments
 (0)