Skip to content

Commit 0e85ec4

Browse files
leandrocpJosé Valim
authored andcommitted
Raise an error if the umbrella app's dir name and mix.exs app name doesn't match (#9072)
Closes #9038.
1 parent 786a3d2 commit 0e85ec4

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ defmodule Mix.Dep.Loader do
287287
end
288288
end
289289

290-
defp mix_dep(%Mix.Dep{opts: opts} = dep, nil) do
290+
defp mix_dep(%Mix.Dep{app: app, opts: opts} = dep, nil) do
291291
Mix.Dep.in_dependency(dep, fn _ ->
292292
opts =
293293
if Mix.Project.umbrella?() do
@@ -298,6 +298,17 @@ defmodule Mix.Dep.Loader do
298298

299299
child_opts =
300300
if opts[:from_umbrella] do
301+
config = Mix.Project.config()
302+
303+
if config[:app] != app do
304+
Mix.raise(
305+
"Umbrella app #{inspect(config[:app])} is located at " <>
306+
"directory #{Atom.to_string(app)}, and different names cause " <>
307+
"a name mismatch that's not allowed. Please rename either " <>
308+
"app's directory name or app's name in mix.exs to be equal."
309+
)
310+
end
311+
301312
[]
302313
else
303314
[env: Keyword.fetch!(opts, :env)]

lib/mix/test/mix/umbrella_test.exs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,28 @@ defmodule Mix.UmbrellaTest do
3030
end)
3131
end
3232

33+
test "umbrella app dir and the app name defined in mix.exs should be equal" do
34+
in_fixture("umbrella_dep/deps/umbrella", fn ->
35+
Mix.Project.in_project(:umbrella, ".", fn _ ->
36+
File.write!("apps/bar/mix.exs", """
37+
defmodule Bar.MixProject do
38+
use Mix.Project
39+
40+
def project do
41+
[app: :baz,
42+
version: "0.1.0",
43+
deps: []]
44+
end
45+
end
46+
""")
47+
48+
assert_raise Mix.Error, ~r/^Umbrella app :baz is located at directory bar/, fn ->
49+
Mix.Task.run("deps")
50+
end
51+
end)
52+
end)
53+
end
54+
3355
test "compiles umbrella" do
3456
in_fixture("umbrella_dep/deps/umbrella", fn ->
3557
Mix.Project.in_project(:umbrella, ".", fn _ ->

0 commit comments

Comments
 (0)