@@ -602,28 +602,42 @@ defmodule Mix do
602602 """
603603 @ doc since: "1.15.0"
604604 def ensure_application! ( app ) when is_atom ( app ) do
605- ensure_application! ( app , Mix.State . builtin_apps ( ) , [ ] )
605+ ensure_application! ( app , Mix.State . builtin_apps ( ) , [ ] , % { } )
606606 :ok
607607 end
608608
609- defp ensure_application! ( app , builtin_apps , optional ) do
610- case builtin_apps do
611- % { ^ app => path } ->
612- Code . prepend_path ( path , cache: true )
613- Application . load ( app )
614- optional = List . wrap ( Application . spec ( app , :optional_applications ) )
615-
616- Application . spec ( app , :applications )
617- |> List . wrap ( )
618- |> Enum . each ( & ensure_application! ( & 1 , builtin_apps , optional ) )
609+ defp ensure_application! ( app , builtin_apps , optional , seen ) do
610+ case seen do
611+ % { ^ app => _ } ->
612+ seen
619613
620614 % { } ->
621- unless app in optional do
622- Mix . raise (
623- "The application \" #{ app } \" could not be found. This may happen if your " <>
624- "Operating System broke Erlang into multiple packages and may be fixed " <>
625- "by installing the missing \" erlang-dev\" and \" erlang-#{ app } \" packages"
626- )
615+ seen = Map . put ( seen , app , true )
616+
617+ case builtin_apps do
618+ % { ^ app => path } ->
619+ Code . prepend_path ( path , cache: true )
620+ Application . load ( app )
621+
622+ required = List . wrap ( Application . spec ( app , :applications ) )
623+ optional = List . wrap ( Application . spec ( app , :optional_applications ) )
624+
625+ Enum . reduce (
626+ required ++ optional ,
627+ seen ,
628+ & ensure_application! ( & 1 , builtin_apps , optional , & 2 )
629+ )
630+
631+ % { } ->
632+ unless app in optional do
633+ Mix . raise (
634+ "The application \" #{ app } \" could not be found. This may happen if your " <>
635+ "Operating System broke Erlang into multiple packages and may be fixed " <>
636+ "by installing the missing \" erlang-dev\" and \" erlang-#{ app } \" packages"
637+ )
638+ end
639+
640+ seen
627641 end
628642 end
629643 end
0 commit comments