@@ -18,15 +18,18 @@ defmodule Mix.Tasks.Escriptize do
18
18
The following options can be specified in your mix.exs file:
19
19
20
20
* `escript_name` - the name of the generated escript
21
- Defaults to project name
21
+ Defaults to app name
22
22
23
23
* `escript_path` - the path to write the escript to
24
- Defaults to project name
24
+ Defaults to app name
25
25
26
- * `escript_main_module` - the module containing the main/1 function.
26
+ * `escript_app` - the app to start with the escript
27
+ Defaults to app name
28
+
29
+ * `escript_main_module` - the module containing the main/1 function
27
30
Defaults to `Project`
28
31
29
- * `escript_embed_elixir` - if true embed elixir in the escript file.
32
+ * `escript_embed_elixir` - if true embed elixir in the escript file
30
33
Defaults to true
31
34
32
35
* `escript_embed_extra_apps` - embed additional Elixir applications
@@ -58,6 +61,7 @@ defmodule Mix.Tasks.Escriptize do
58
61
filename = project [ :escript_path ] || atom_to_binary ( script_name )
59
62
embed = Keyword . get ( project , :escript_embed_elixir , true )
60
63
beams = all_beams ( )
64
+ app = Keyword . get ( project , :escript_app , project [ :app ] )
61
65
62
66
cond do
63
67
! script_name ->
@@ -67,7 +71,7 @@ defmodule Mix.Tasks.Escriptize do
67
71
raise Mix.Error , message: "Could not generate escript #{ filename } , " <>
68
72
"no beam files available"
69
73
force or Mix.Utils . stale? ( beams , [ filename ] ) ->
70
- files = gen_main ( script_name , project [ :escript_main_module ] )
74
+ files = gen_main ( script_name , project [ :escript_main_module ] , app )
71
75
files = files ++ all_files ( )
72
76
73
77
if embed do
@@ -149,30 +153,43 @@ defmodule Mix.Tasks.Escriptize do
149
153
end
150
154
end
151
155
152
- defp gen_main ( script_name , nil ) do
156
+ defp gen_main( script_name, nil , app ) do
153
157
camelized = Mix.Utils . camelize ( atom_to_binary ( script_name ) )
154
- gen_main ( script_name , Module . concat ( [ camelized ] ) )
158
+ gen_main ( script_name , Module . concat ( [ camelized ] ) , app )
155
159
end
156
160
157
- defp gen_main ( script_name , script_name ) do
161
+ defp gen_main ( script_name , script_name , _app ) do
158
162
[ ]
159
163
end
160
164
161
- defp gen_main ( name , module ) do
165
+ defp gen_main( name, module , app ) do
162
166
{ :module , ^ name , binary , _ } =
163
167
defmodule name do
164
168
@ module module
169
+ @ app app
165
170
166
171
def main ( args ) do
167
172
case :application . start ( :elixir ) do
168
173
:ok ->
174
+ start_app
169
175
args = Enum . map ( args , :unicode . characters_to_binary ( & 1 ) )
170
176
Kernel.CLI . run fn -> @ module . main ( args ) end , true
171
177
_ ->
172
178
IO . puts :stderr , IO.ANSI . escape ( "%{red, bright} Elixir is not in the code path, aborting." )
173
179
System . halt ( 1 )
174
180
end
175
181
end
182
+
183
+ defp start_app do
184
+ if app = @ app do
185
+ case Application.Behaviour . start ( app ) do
186
+ :ok -> :ok
187
+ { :error , reason } ->
188
+ IO . puts :stderr , IO.ANSI . escape ( "%{red, bright} Could not start application #{ app } : #{ inspect reason } ." )
189
+ System . halt ( 1 )
190
+ end
191
+ end
192
+ end
176
193
end
177
194
178
195
[ { '#{ name } .beam' , binary } ]
0 commit comments