Skip to content

Commit 4df1149

Browse files
author
José Valim
committed
Move the umbrella check to Mix.Project.recur
We have named the function from Mix.Project.recursive to recur in order to imply action.
1 parent 1612865 commit 4df1149

File tree

4 files changed

+34
-44
lines changed

4 files changed

+34
-44
lines changed

lib/mix/lib/mix/deps/converger.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ defmodule Mix.Deps.Converger do
123123

124124
try do
125125
Mix.env(env)
126-
Mix.Project.in_project(app, opts[:dest], post_config, fn config ->
127-
{ config, Enum.reverse Mix.Deps.Project.all }
126+
Mix.Project.in_project(app, opts[:dest], post_config, fn project ->
127+
{ project, Enum.reverse Mix.Deps.Project.all }
128128
end)
129129
after
130130
Mix.env(old_env)

lib/mix/lib/mix/project.ex

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -142,26 +142,33 @@ defmodule Mix.Project do
142142
end
143143

144144
@doc """
145-
Run fun for every application in the umbrella project. Changes current
146-
project and working directory.
145+
Runs `fun` in the current project.
146+
147+
The goal of this function is to transparently abstract umbrella projects.
148+
So if you want to gather data from a project, like beam files, you can
149+
use this function to transparently go through the project, regardless
150+
if it is an umbrella project or not.
147151
"""
148-
def recursive(fun) do
149-
apps_path = config[:apps_path]
150-
paths = Path.wildcard(Path.join(apps_path, "*"))
151-
152-
projects = Enum.map paths, fn path ->
153-
dir = Path.basename(path)
154-
app = dir |> String.downcase |> binary_to_atom
155-
{ app, path }
156-
end
152+
def recur(fun) do
153+
if apps_path = config[:apps_path] do
154+
paths = Path.wildcard(Path.join(apps_path, "*"))
155+
156+
projects = Enum.map paths, fn path ->
157+
dir = Path.basename(path)
158+
app = dir |> String.downcase |> binary_to_atom
159+
{ app, path }
160+
end
157161

158-
projects = topsort_projects(projects, Path.expand(apps_path))
162+
projects = topsort_projects(projects, Path.expand(apps_path))
159163

160-
results = Enum.map projects, fn { app, app_path } ->
161-
in_project(app, app_path, fun)
162-
end
164+
results = Enum.map projects, fn { app, app_path } ->
165+
in_project(app, app_path, fun)
166+
end
163167

164-
results
168+
results
169+
else
170+
[fun.(get)]
171+
end
165172
end
166173

167174
@doc """
@@ -185,22 +192,17 @@ defmodule Mix.Project do
185192
Returns the paths this project compiles to.
186193
"""
187194
def compile_paths do
188-
if umbrella? do
189-
List.flatten recursive(fn _ -> compile_paths end)
190-
else
191-
[ Path.expand config[:compile_path] ]
192-
end
195+
recur(fn _ -> Path.expand config[:compile_path] end)
193196
end
194197

195198
@doc """
196199
Returns all load paths for this project.
197200
"""
198201
def load_paths do
199-
paths = if umbrella? do
200-
List.flatten recursive(fn _ -> load_paths end)
201-
else
202-
Enum.map config[:load_paths], Path.expand(&1)
203-
end
202+
paths =
203+
recur(fn _ ->
204+
Enum.map(config[:load_paths], Path.expand(&1))
205+
end) |> List.concat
204206
paths ++ compile_paths
205207
end
206208

lib/mix/lib/mix/task.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ defmodule Mix.Task do
138138
module = get(task)
139139
Mix.Server.cast({ :add_task, task, app })
140140

141-
if Mix.Project.umbrella? && recursive?(module) do
142-
Mix.Project.recursive(fn _ -> module.run(args) end)
141+
if recursive?(module) do
142+
Mix.Project.recur(fn _ -> module.run(args) end)
143143
else
144144
module.run(args)
145145
end

lib/mix/lib/mix/tasks/escriptize.ex

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,7 @@ defmodule Mix.Tasks.Escriptize do
100100
end
101101

102102
defp all_beams() do
103-
if Mix.Project.umbrella? do
104-
beams = Mix.Project.recursive fn _ ->
105-
get_beams()
106-
end
107-
List.concat(beams)
108-
else
109-
get_beams()
110-
end
103+
Mix.Project.recur(fn _ -> get_beams() end) |> List.concat
111104
end
112105

113106
defp get_beams() do
@@ -119,12 +112,7 @@ defmodule Mix.Tasks.Escriptize do
119112
end
120113

121114
defp all_files() do
122-
if Mix.Project.umbrella? do
123-
files = Mix.Project.recursive(fn _ -> get_compiled_files() end)
124-
List.concat(files)
125-
else
126-
get_compiled_files()
127-
end
115+
Mix.Project.recur(fn _ -> get_compiled_files() end) |> List.concat
128116
end
129117

130118
defp get_compiled_files() do

0 commit comments

Comments
 (0)