Skip to content

Commit c80e52e

Browse files
author
José Valim
committed
Merge pull request #1198 from ericmj/patch-1194
Dont run deps tasks recursively when they are started non-recursively
2 parents 2768232 + 520415b commit c80e52e

File tree

3 files changed

+50
-22
lines changed

3 files changed

+50
-22
lines changed

lib/mix/lib/mix/project.ex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ defmodule Mix.Project do
3131
defined.
3232
"""
3333

34+
alias Mix.Server.Project
35+
3436
@doc false
3537
defmacro __using__(_) do
3638
quote do
@@ -85,7 +87,7 @@ defmodule Mix.Project do
8587
"""
8688
def get do
8789
case Mix.Server.call(:projects) do
88-
[{ h, _ }|_] -> h
90+
[Project[name: project]|_] -> project
8991
_ -> nil
9092
end
9193
end
@@ -103,7 +105,7 @@ defmodule Mix.Project do
103105
"""
104106
def config do
105107
case Mix.Server.call(:projects) do
106-
[{ h, config }|_] when h != nil -> config
108+
[Project[name: name, config: config]|_] when name != nil -> config
107109
_ -> default_config
108110
end
109111
end

lib/mix/lib/mix/server.ex

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ defmodule Mix.Server do
55
use GenServer.Behaviour
66

77
defrecord Config, tasks: Ordset.new, projects: [], mixfile: [],
8-
shell: Mix.Shell.IO, scm: Ordset.new, env: nil, post_config: [],
9-
io_done: false
8+
shell: Mix.Shell.IO, scm: Ordset.new, env: nil, post_config: []
9+
10+
defrecord Project, name: nil, config: nil, rec_enabled?: true, io_done: false
1011

1112
def start_link(env) do
1213
:gen_server.start_link({ :local, __MODULE__ }, __MODULE__, env, [])
@@ -56,8 +57,8 @@ defmodule Mix.Server do
5657

5758
def handle_call(:pop_project, _from, config) do
5859
case config.projects do
59-
[{ project, _ }|tail] ->
60-
{ :reply, project, config.projects(tail).io_done(false) }
60+
[ Project[name: project] | tail ] ->
61+
{ :reply, project, config.projects(tail) }
6162
_ ->
6263
{ :reply, nil, config }
6364
end
@@ -67,15 +68,25 @@ defmodule Mix.Server do
6768
{ :reply, config.mixfile[app], config }
6869
end
6970

70-
def handle_call(:io_done, _from, config) do
71-
{ :reply, config.io_done, config.io_done(true) }
72-
end
73-
7471
def handle_call(:output_app?, _from, config) do
7572
# Check that we haven't already outputted app and that we are part of an
7673
# umbrella project
77-
output = not config.io_done and not umbrella?(config) and in_umbrella?(config)
78-
{ :reply, output, config.io_done(true) }
74+
case config.projects do
75+
[ project | tail ] ->
76+
output = not project.io_done and not umbrella?(config) and in_umbrella?(config)
77+
{ :reply, output, config.projects([project.io_done(true)|tail]) }
78+
_ ->
79+
{ :reply, false, config }
80+
end
81+
end
82+
83+
def handle_call(:recursive_enabled?, _from, config) do
84+
case config.projects do
85+
[ Project[rec_enabled?: bool] | _ ] ->
86+
{ :reply, bool, config }
87+
_ ->
88+
{ :reply, true, config }
89+
end
7990
end
8091

8192
def handle_call(request, from, config) do
@@ -106,11 +117,11 @@ defmodule Mix.Server do
106117
{ :noreply, config.update_tasks Ordset.filter(fn {t, _} -> t != task end, &1) }
107118
end
108119

109-
def handle_cast({ :push_project, name, project }, config) do
110-
project = Keyword.merge(project, config.post_config)
120+
def handle_cast({ :push_project, name, conf }, config) do
121+
conf = Keyword.merge(conf, config.post_config)
122+
project = Project[name: name, config: conf]
111123
config = config.post_config([])
112-
.update_projects([{ name, project }|&1])
113-
.io_done(false)
124+
.update_projects([project|&1])
114125
{ :noreply, config }
115126
end
116127

@@ -130,19 +141,31 @@ defmodule Mix.Server do
130141
{ :noreply, config.mixfile([]) }
131142
end
132143

144+
def handle_cast({:recursive_enabled?, bool}, config) do
145+
case config.projects do
146+
[ project | tail ] ->
147+
{ :noreply, config.projects([project.rec_enabled?(bool)|tail]) }
148+
_ ->
149+
{ :noreply, config }
150+
end
151+
end
152+
133153
def handle_cast(request, config) do
134154
super(request, config)
135155
end
136156

137-
# Returns if project is part of an umbrella project
157+
# Returns true if project is part of an umbrella project
138158
defp in_umbrella?(config) do
139-
Enum.any? config.projects, fn { _, conf } -> conf[:apps_path] != nil end
159+
Enum.any?(config.projects, fn(Project[config: conf]) ->
160+
conf[:apps_path] != nil
161+
end)
140162
end
141163

142-
# Returns if project is an umbrella project
164+
# Returns true if project is an umbrella project
143165
defp umbrella?(config) do
144166
case config.projects do
145-
[ { h, conf } | _ ] when h != nil -> conf[:apps_path] != nil
167+
[ Project[name: name, config: config] | _ ] when name != nil ->
168+
config[:apps_path] != nil
146169
_ -> false
147170
end
148171
end

lib/mix/lib/mix/task.ex

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,16 @@ defmodule Mix.Task do
141141

142142
recursive = recursive(module)
143143

144-
if recursive do
144+
if recursive && Mix.Server.call(:recursive_enabled?) do
145+
Mix.Server.cast({ :recursive_enabled?, false })
145146
res = if Mix.Project.umbrella? and recursive == :both do
146147
[module.run(args)]
147148
else
148149
[]
149150
end
150-
res ++ Mix.Project.recur(fn _ -> module.run(args) end)
151+
res = res ++ Mix.Project.recur(fn _ -> module.run(args) end)
152+
Mix.Server.cast({ :recursive_enabled?, true })
153+
res
151154
else
152155
module.run(args)
153156
end

0 commit comments

Comments
 (0)