@@ -18,13 +18,16 @@ defmodule Mix.Tasks.Compile.App do
1818 function in your `mix.exs` with the following options:
1919
2020 * `:applications` - all applications your application depends
21- on at runtime. For example, if your application depends on
22- Erlang's `:crypto`, it needs to be added to this list. Most
23- of your dependencies must be added as well (unless they're
24- a development or test dependency). Mix and other tools use this
25- list in order to properly boot your application dependencies
21+ on at runtime. By default, this list is automatically inflected
22+ from your dependencies. Any extra Erlang/Elixir dependency
23+ must be specified in `:extra_applications`. Mix and other tools
24+ use the application list in order to start your dependencies
2625 before starting the application itself.
2726
27+ * `:extra_applications` - a list of Erlang/Elixir applications
28+ that you want started before your application. For example,
29+ Elixir's `:logger` or Erlang's `:crypto`.
30+
2831 * `:registered` - the name of all registered processes in the
2932 application. If your application defines a local GenServer
3033 with name `MyServer`, it is recommended to add `MyServer`
@@ -79,10 +82,10 @@ defmodule Mix.Tasks.Compile.App do
7982
8083 if opts [ :force ] || Mix.Utils . stale? ( sources , [ target ] ) || modules_changed? ( mods , target ) do
8184 best_guess = [
82- vsn : to_charlist ( version ) ,
85+ description : to_charlist ( config [ :description ] || app ) ,
8386 modules: mods ,
84- applications: [ ] ,
8587 registered: [ ] ,
88+ vsn: to_charlist ( version ) ,
8689 ]
8790
8891 properties = if function_exported? ( project , :application , 0 ) do
@@ -95,13 +98,7 @@ defmodule Mix.Tasks.Compile.App do
9598 best_guess
9699 end
97100
98- properties = ensure_correct_properties ( app , config , properties )
99-
100- # Ensure we always prepend the standard application dependencies
101- properties = Keyword . update! ( properties , :applications , fn apps ->
102- [ :kernel , :stdlib ] ++ language_app ( config ) ++ apps
103- end )
104-
101+ properties = ensure_correct_properties ( properties , config )
105102 contents = :io_lib . format ( "~p.~n" , [ { :application , app , properties } ] )
106103
107104 Mix.Project . ensure_structure ( )
@@ -152,13 +149,14 @@ defmodule Mix.Tasks.Compile.App do
152149 end
153150 end
154151
155- defp ensure_correct_properties ( app , config , properties ) do
152+ defp ensure_correct_properties ( properties , config ) do
156153 properties
157- |> Keyword . put_new ( :description , to_charlist ( config [ :description ] || app ) )
158- |> validate_properties
154+ |> validate_properties!
155+ |> Keyword . put_new_lazy ( :applications , fn -> apps_from_prod_non_optional_deps ( properties ) end )
156+ |> Keyword . update! ( :applications , fn apps -> normalize_apps ( apps , properties , config ) end )
159157 end
160158
161- defp validate_properties ( properties ) do
159+ defp validate_properties! ( properties ) do
162160 Enum . each properties , fn
163161 { :description , value } ->
164162 unless is_list ( value ) do
@@ -188,13 +186,17 @@ defmodule Mix.Tasks.Compile.App do
188186 unless is_list ( value ) and Enum . all? ( value , & is_atom ( & 1 ) ) do
189187 Mix . raise "Application included applications (:included_applications) should be a list of atoms, got: #{ inspect value } "
190188 end
189+ { :extra_applications , value } ->
190+ unless is_list ( value ) and Enum . all? ( value , & is_atom ( & 1 ) ) do
191+ Mix . raise "Application extra applications (:extra_applications) should be a list of atoms, got: #{ inspect value } "
192+ end
191193 { :applications , value } ->
192194 unless is_list ( value ) and Enum . all? ( value , & is_atom ( & 1 ) ) do
193- Mix . raise "Application dependencies (:applications) should be a list of atoms, got: #{ inspect value } "
195+ Mix . raise "Application applications (:applications) should be a list of atoms, got: #{ inspect value } "
194196 end
195197 { :env , value } ->
196198 unless Keyword . keyword? ( value ) do
197- Mix . raise "Application dependencies (:env) should be a keyword list, got: #{ inspect value } "
199+ Mix . raise "Application environment (:env) should be a keyword list, got: #{ inspect value } "
198200 end
199201 { :start_phases , value } ->
200202 unless Keyword . keyword? ( value ) do
@@ -212,4 +214,20 @@ defmodule Mix.Tasks.Compile.App do
212214
213215 properties
214216 end
217+
218+ defp apps_from_prod_non_optional_deps ( properties ) do
219+ included_applications = Keyword . get ( properties , :included_applications , [ ] )
220+
221+ for % { app: app , opts: opts , top_level: true } <- Mix.Dep . cached ,
222+ Keyword . get ( opts , :app , true ) ,
223+ Keyword . get ( opts , :runtime , true ) ,
224+ not Keyword . get ( opts , :optional , false ) ,
225+ not app in included_applications ,
226+ do: app
227+ end
228+
229+ defp normalize_apps ( apps , properties , config ) do
230+ extra = Keyword . get ( properties , :extra_applications , [ ] )
231+ Enum . uniq ( [ :kernel , :stdlib ] ++ language_app ( config ) ++ extra ++ apps )
232+ end
215233end
0 commit comments