@@ -30,6 +30,7 @@ defmodule Mix.Tasks.App.Start do
30
30
* `--force` - forces compilation regardless of compilation times
31
31
* `--temporary` - starts the application as temporary
32
32
* `--permanent` - starts the application as permanent
33
+ * `--preload-modules` - preloads all modules defined in applications
33
34
* `--no-compile` - does not compile even if files require compilation
34
35
* `--no-protocols` - does not load consolidated protocols
35
36
* `--no-archives-check` - does not check archives
@@ -38,11 +39,18 @@ defmodule Mix.Tasks.App.Start do
38
39
* `--no-start` - does not start applications after compilation
39
40
40
41
"""
42
+
43
+ @ switches [
44
+ permanent: :boolean ,
45
+ temporary: :boolean ,
46
+ preload_modules: :boolean
47
+ ]
48
+
41
49
def run ( args ) do
42
50
Mix.Project . get! ( )
43
51
config = Mix.Project . config ( )
44
52
45
- { opts , _ , _ } = OptionParser . parse ( args , switches: [ permanent: :boolean , temporary: :boolean ] )
53
+ { opts , _ , _ } = OptionParser . parse ( args , switches: @ switches )
46
54
Mix.Task . run ( "loadpaths" , args )
47
55
48
56
unless "--no-compile" in args do
@@ -76,6 +84,13 @@ defmodule Mix.Tasks.App.Start do
76
84
end
77
85
else
78
86
start ( Mix.Project . config ( ) , opts )
87
+
88
+ # If there is a build path, we will let the application
89
+ # that owns the build path do the actual check
90
+ unless config [ :build_path ] do
91
+ loaded = loaded_applications ( opts )
92
+ check_configured ( loaded )
93
+ end
79
94
end
80
95
81
96
:ok
@@ -97,13 +112,6 @@ defmodule Mix.Tasks.App.Start do
97
112
98
113
type = type ( config , opts )
99
114
Enum . each ( apps , & ensure_all_started ( & 1 , type ) )
100
-
101
- # If there is a build path, we will let the application
102
- # that owns the build path do the actual check
103
- unless config [ :build_path ] do
104
- check_configured ( )
105
- end
106
-
107
115
:ok
108
116
end
109
117
@@ -146,25 +154,35 @@ defmodule Mix.Tasks.App.Start do
146
154
end
147
155
end
148
156
149
- defp check_configured ( ) do
157
+ defp loaded_applications ( opts ) do
158
+ preload_modules? = opts [ :preload_modules ]
159
+
160
+ for { app , _ , _ } <- Application . loaded_applications ( ) do
161
+ if modules = preload_modules? && Application . spec ( app , :modules ) do
162
+ :code . ensure_modules_loaded ( modules )
163
+ end
164
+
165
+ app
166
+ end
167
+ end
168
+
169
+ defp check_configured ( loaded ) do
150
170
configured = Mix.ProjectStack . configured_applications ( )
151
- loaded = for { app , _ , _ } <- Application . loaded_applications ( ) , do: app
152
171
153
- _ =
154
- for app <- configured -- loaded , :code . lib_dir ( app ) == { :error , :bad_name } do
155
- Mix . shell ( ) . error ( """
156
- You have configured application #{ inspect ( app ) } in your configuration
157
- file, but the application is not available.
172
+ for app <- configured -- loaded , :code . lib_dir ( app ) == { :error , :bad_name } do
173
+ Mix . shell ( ) . error ( """
174
+ You have configured application #{ inspect ( app ) } in your configuration file,
175
+ but the application is not available.
158
176
159
- This usually means one of:
177
+ This usually means one of:
160
178
161
179
1. You have not added the application as a dependency in a mix.exs file.
162
180
163
181
2. You are configuring an application that does not really exist.
164
182
165
- Please ensure #{ inspect ( app ) } exists or remove the configuration.
166
- """ )
167
- end
183
+ Please ensure #{ inspect ( app ) } exists or remove the configuration.
184
+ """ )
185
+ end
168
186
169
187
:ok
170
188
end
0 commit comments