Skip to content

Commit d221e9a

Browse files
author
José Valim
committed
Allow apps to be selected in umbrella projects
Closes #1731 Closes #1730
1 parent 4638831 commit d221e9a

File tree

4 files changed

+63
-30
lines changed

4 files changed

+63
-30
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* [Enum] Add `Enum.take_every/2`
55
* [IEx] IEx now respects signals sent from the Ctrl+G menu
66
* [Kernel] Allow documentation for types with `@typedoc`
7+
* [Mix] Allow apps to be selected in umbrella projects
78
* [Stream] Add `Stream.unfold/1`
89

910
* Bug fixes

lib/mix/lib/mix/project.ex

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -141,27 +141,37 @@ defmodule Mix.Project do
141141
def recur(post_config // [], fun) do
142142
if apps_path = config[:apps_path] do
143143
paths = Path.wildcard(Path.join(apps_path, "*"))
144-
paths = Enum.filter(paths, &File.dir?(&1))
145144

146-
projects = Enum.map paths, fn path ->
147-
dir = Path.basename(path)
148-
app = dir |> String.downcase |> binary_to_atom
149-
{ app, path }
150-
end
151-
152-
projects = topsort_projects(projects, Path.expand(apps_path))
153-
154-
results = Enum.map projects, fn { app, app_path } ->
155-
in_project(app, app_path, post_config, fun)
156-
end
157-
158-
results
145+
paths
146+
|> Enum.filter(&File.dir?(&1))
147+
|> extract_projects
148+
|> filter_projects(config[:apps])
149+
|> topsort_projects(Path.expand(apps_path))
150+
|> recur_projects(post_config, fun)
159151
else
160152
# Note that post_config isnt used for this case
161153
[fun.(get)]
162154
end
163155
end
164156

157+
defp extract_projects(paths) do
158+
lc path inlist paths do
159+
app = path |> Path.basename |> String.downcase |> binary_to_atom
160+
{ app, path }
161+
end
162+
end
163+
164+
defp filter_projects(pairs, nil), do: pairs
165+
defp filter_projects(pairs, apps) when is_list(apps) do
166+
lc { app, _ } = pair inlist pairs, app in apps, do: pair
167+
end
168+
169+
defp recur_projects(pairs, post_config, fun) do
170+
lc { app, path } inlist pairs do
171+
in_project(app, path, post_config, fun)
172+
end
173+
end
174+
165175
@doc """
166176
Runs the given `fun` inside the given project by changing
167177
the current working directory and loading the given project

lib/mix/test/mix/tasks/compile.elixir_test.exs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,6 @@ defmodule Mix.Tasks.Compile.ElixirTest do
9696
end
9797
end
9898

99-
test "recompiles after path dependency changed" do
100-
in_fixture("umbrella_dep/deps/umbrella/apps", fn ->
101-
Mix.Project.in_project(:bar, "bar", fn _ ->
102-
Mix.Tasks.Deps.Compile.run []
103-
104-
assert Mix.Tasks.Compile.Elixir.run([]) == :ok
105-
assert Mix.Tasks.Compile.Elixir.run([]) == :noop
106-
purge [Bar]
107-
108-
future = { { 2020, 4, 17 }, { 14, 0, 0 } }
109-
File.touch!("../foo/ebin/.compile.elixir", future)
110-
assert Mix.Tasks.Compile.Elixir.run([]) == :ok
111-
end)
112-
end)
113-
end
114-
11599
test "recompiles with --force" do
116100
in_fixture "no_mixfile", fn ->
117101
assert Mix.Tasks.Compile.Elixir.run([]) == :ok

lib/mix/test/mix/umbrella_test.exs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,42 @@ defmodule Mix.UmbrellaTest do
5151
end)
5252
end
5353
end
54+
55+
test "recompiles after path dependency changed" do
56+
in_fixture("umbrella_dep/deps/umbrella/apps", fn ->
57+
Mix.Project.in_project(:bar, "bar", fn _ ->
58+
Mix.Tasks.Deps.Compile.run []
59+
60+
assert Mix.Tasks.Compile.Elixir.run([]) == :ok
61+
assert Mix.Tasks.Compile.Elixir.run([]) == :noop
62+
purge [Bar]
63+
64+
future = { { 2020, 4, 17 }, { 14, 0, 0 } }
65+
File.touch!("../foo/ebin/.compile.elixir", future)
66+
assert Mix.Tasks.Compile.Elixir.run([]) == :ok
67+
end)
68+
end)
69+
end
70+
71+
defmodule Selective.Mixfile do
72+
def project do
73+
[ apps_path: "apps",
74+
apps: [:foo, :bar] ]
75+
end
76+
end
77+
78+
test "can select which apps to use" do
79+
in_fixture("umbrella_dep/deps/umbrella", fn ->
80+
Mix.Project.push Selective.Mixfile
81+
82+
File.mkdir_p! "apps/errors/lib"
83+
File.write! "apps/errors/lib/always_fail.ex", "raise %s[oops]"
84+
85+
assert Mix.Task.run("compile.elixir") == [:ok, :ok]
86+
assert_received { :mix_shell, :info, ["Compiled lib/bar.ex"] }
87+
assert_received { :mix_shell, :info, ["Compiled lib/foo.ex"] }
88+
end)
89+
after
90+
Mix.Project.pop
91+
end
5492
end

0 commit comments

Comments
 (0)