Skip to content

Commit 6e528cd

Browse files
author
José Valim
committed
Fetch umbrella child deps across environments without conflicts
Closes #4069 #4105
1 parent c4d5ee5 commit 6e528cd

File tree

4 files changed

+69
-4
lines changed

4 files changed

+69
-4
lines changed

lib/mix/lib/mix/dep/loader.ex

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,17 @@ defmodule Mix.Dep.Loader do
236236
opts = Keyword.put_new(opts, :app, false)
237237
end
238238

239-
deps = mix_children(env: opts[:env] || :prod) ++ Mix.Dep.Umbrella.unloaded
239+
child_opts =
240+
cond do
241+
opts[:from_umbrella] ->
242+
[]
243+
env = opts[:env] ->
244+
[env: env]
245+
true ->
246+
[env: :prod]
247+
end
248+
249+
deps = mix_children(child_opts) ++ Mix.Dep.Umbrella.unloaded
240250
{%{dep | opts: opts}, deps}
241251
end)
242252
end

lib/mix/lib/mix/scm/path.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ defmodule Mix.SCM.Path do
1717
def accepts_options(app, opts) do
1818
cond do
1919
raw = opts[:path] ->
20-
Keyword.put opts, :dest, Path.expand(raw)
20+
Keyword.put(opts, :dest, Path.expand(raw))
2121
opts[:in_umbrella] ->
2222
path = "../#{app}"
2323

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ defmodule Mix.Tasks.Compile do
9797
manifest = Path.absname(Mix.Dep.Lock.manifest())
9898

9999
Enum.any?(Mix.Dep.children(), fn %{scm: scm} = dep ->
100-
# We ignore in_umbrella dependencies because we assume
101-
# they are sharing the same deps and build path.
102100
not scm.fetchable? and Mix.Dep.in_dependency(dep, fn _ ->
103101
files = Mix.Project.config_files ++ manifests()
104102
Mix.Utils.stale?(files, [manifest])

lib/mix/test/mix/umbrella_test.exs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,63 @@ defmodule Mix.UmbrellaTest do
9898
end
9999
end
100100

101+
test "loads umbrella child dependencies in all environments" do
102+
in_fixture "umbrella_dep/deps/umbrella", fn ->
103+
Mix.Project.in_project :umbrella, ".", fn _ ->
104+
File.write! "apps/bar/mix.exs", """
105+
defmodule Bar.Mix do
106+
use Mix.Project
107+
108+
def project do
109+
[app: :bar,
110+
version: "0.1.0",
111+
deps: [{:git_repo, git: MixTest.Case.fixture_path("git_repo"), only: :other}]]
112+
end
113+
end
114+
"""
115+
116+
# Should work across all environments
117+
Mix.Tasks.Deps.Get.run []
118+
assert_received {:mix_shell, :info, ["* Getting git_repo" <> _]}
119+
120+
# Works on the current environment only
121+
Mix.Tasks.Deps.run []
122+
refute_received {:mix_shell, :info, ["* git_repo " <> _]}
123+
124+
# Works on the other environment only
125+
Mix.env(:other)
126+
Mix.Tasks.Deps.run []
127+
assert_received {:mix_shell, :info, ["* git_repo " <> _]}
128+
end
129+
end
130+
after
131+
Mix.env(:test)
132+
end
133+
134+
test "loads umbrella child dependencies in umbrellas" do
135+
in_fixture "umbrella_dep/deps/umbrella", fn ->
136+
Mix.Project.in_project :umbrella, ".", fn _ ->
137+
File.write! "apps/bar/mix.exs", """
138+
defmodule Bar.Mix do
139+
use Mix.Project
140+
141+
def project do
142+
[app: :bar,
143+
version: "0.1.0",
144+
deps: [{:foo, in_umbrella: true}]]
145+
end
146+
end
147+
"""
148+
149+
# Running from umbrella should not cause conflicts
150+
Mix.Tasks.Deps.Get.run []
151+
Mix.Tasks.Run.run []
152+
end
153+
end
154+
end
155+
156+
## Umbrellas as a dependency
157+
101158
test "list deps for umbrella as dependency" do
102159
in_fixture("umbrella_dep", fn ->
103160
Mix.Project.in_project(:umbrella_dep, ".", fn _ ->

0 commit comments

Comments
 (0)