Skip to content

Commit da45fde

Browse files
author
José Valim
committed
Use in_project in deps.compile (tks @ericmj)
1 parent 4df1149 commit da45fde

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

lib/mix/lib/mix/project.ex

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,21 @@ defmodule Mix.Project do
176176
the current working directory and loading the given project
177177
into the project stack.
178178
"""
179-
def in_project(app, app_path, post_config // [], fun) do
179+
def in_project(app, app_path, post_config // [], fun)
180+
181+
def in_project(app, ".", post_config, fun) do
182+
cached = load_project(app, post_config)
183+
result = try do
184+
fun.(cached)
185+
after
186+
Mix.Project.pop
187+
end
188+
result
189+
end
190+
191+
def in_project(app, app_path, post_config, fun) do
180192
File.cd! app_path, fn ->
181-
cached = load_project(app, post_config)
182-
result = try do
183-
fun.(cached)
184-
after
185-
Mix.Project.pop
186-
end
187-
result
193+
in_project(app, ".", post_config, fun)
188194
end
189195
end
190196

@@ -210,22 +216,22 @@ defmodule Mix.Project do
210216
# mixfile cache and pushes the project to the project stack.
211217
defp load_project(app, post_config) do
212218
if cached = Mix.Server.call({ :mixfile_cache, app }) do
213-
Mix.Project.post_config(post_config)
214-
Mix.Project.push(cached)
219+
post_config(post_config)
220+
push(cached)
215221
cached
216222
else
217-
old_proj = Mix.Project.get
223+
old_proj = get
218224

219225
if File.regular?("mix.exs") do
220-
Mix.Project.post_config(post_config)
226+
post_config(post_config)
221227
Code.load_file "mix.exs"
222228
end
223229

224-
new_proj = Mix.Project.get
230+
new_proj = get
225231

226232
if old_proj == new_proj do
227233
new_proj = nil
228-
Mix.Project.push new_proj
234+
push new_proj
229235
end
230236

231237
Mix.Server.cast({ :mixfile_cache, app, new_proj })

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,24 +83,23 @@ defmodule Mix.Tasks.Deps.Compile do
8383
:ok
8484
end
8585

86-
defp do_mix(Mix.Dep[app: app, opts: opts, project: project], config) do
86+
defp do_mix(Mix.Dep[app: app, opts: opts], config) do
8787
env = opts[:env] || :prod
8888
old_env = Mix.env
8989
old_tasks = Mix.Task.clear
9090

9191
try do
9292
Mix.env(env)
93-
Mix.Project.post_config(config)
94-
Mix.Project.push project
95-
Mix.Task.run "compile", ["--no-deps"]
93+
Mix.Project.in_project(app, ".", config, fn _ ->
94+
Mix.Task.run "compile", ["--no-deps"]
95+
end)
9696
catch
9797
kind, reason ->
9898
Mix.shell.error "could not compile dependency #{app}, mix compile failed. " <>
9999
"In case you want to recompile this dependency, please run: mix deps.compile #{app}"
100100
:erlang.raise(kind, reason, System.stacktrace)
101101
after
102102
Mix.env(old_env)
103-
Mix.Project.pop
104103
Mix.Task.set_tasks(old_tasks)
105104
end
106105
end

0 commit comments

Comments
 (0)