Skip to content

Commit b79c5a3

Browse files
committed
Consider optional apps in Mix.ensure_application!
1 parent 3bb0a83 commit b79c5a3

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

lib/mix/lib/mix.ex

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -600,26 +600,29 @@ defmodule Mix do
600600
"""
601601
@doc since: "1.15.0"
602602
def ensure_application!(app) when is_atom(app) do
603-
ensure_application!(app, Mix.State.builtin_apps())
603+
ensure_application!(app, Mix.State.builtin_apps(), [])
604604
:ok
605605
end
606606

607-
defp ensure_application!(app, builtin_apps) do
607+
defp ensure_application!(app, builtin_apps, optional) do
608608
case builtin_apps do
609609
%{^app => path} ->
610610
Code.prepend_path(path, cache: true)
611611
Application.load(app)
612+
optional = List.wrap(Application.spec(app, :optional_applications))
612613

613614
Application.spec(app, :applications)
614615
|> List.wrap()
615-
|> Enum.each(&ensure_application!(&1, builtin_apps))
616+
|> Enum.each(&ensure_application!(&1, builtin_apps, optional))
616617

617618
%{} ->
618-
Mix.raise(
619-
"The application \"#{app}\" could not be found. This may happen if your " <>
620-
"Operating System broke Erlang into multiple packages and may be fixed " <>
621-
"by installing the missing \"erlang-dev\" and \"erlang-#{app}\" packages"
622-
)
619+
unless app in optional do
620+
Mix.raise(
621+
"The application \"#{app}\" could not be found. This may happen if your " <>
622+
"Operating System broke Erlang into multiple packages and may be fixed " <>
623+
"by installing the missing \"erlang-dev\" and \"erlang-#{app}\" packages"
624+
)
625+
end
623626
end
624627
end
625628

0 commit comments

Comments
 (0)