Skip to content

Commit db2a39a

Browse files
committed
Do not emit warnings on code generation for escript builds
1 parent 3f01b31 commit db2a39a

File tree

1 file changed

+38
-32
lines changed

1 file changed

+38
-32
lines changed

lib/mix/lib/mix/tasks/escript.build.ex

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ defmodule Mix.Tasks.Escript.Build do
376376
quote do
377377
@spec main(OptionParser.argv()) :: any
378378
def main(args) do
379-
unquote(main_body_for(language, module, app, compile_config, runtime_config))
379+
unquote(main_body_for(language, module, compile_config, runtime_config))
380380
end
381381

382382
defp load_config(config) do
@@ -389,33 +389,8 @@ defmodule Mix.Tasks.Escript.Build do
389389
:ok
390390
end
391391

392-
defp start_app(nil) do
393-
:ok
394-
end
395-
396-
defp start_app(app) do
397-
case :application.ensure_all_started(app) do
398-
{:ok, _} ->
399-
:ok
400-
401-
{:error, {app, reason}} ->
402-
formatted_error =
403-
case :code.ensure_loaded(Application) do
404-
{:module, Application} -> Application.format_error(reason)
405-
{:error, _} -> :io_lib.format(~c"~p", [reason])
406-
end
407-
408-
error_message = [
409-
"ERROR! Could not start application ",
410-
:erlang.atom_to_binary(app, :utf8),
411-
": ",
412-
formatted_error,
413-
?\n
414-
]
415-
416-
io_error(error_message)
417-
:erlang.halt(1)
418-
end
392+
defp start_app() do
393+
unquote(start_app_for(app))
419394
end
420395

421396
defp io_error(message) do
@@ -427,7 +402,7 @@ defmodule Mix.Tasks.Escript.Build do
427402
[{~c"#{name}.beam", binary}]
428403
end
429404

430-
defp main_body_for(:elixir, module, app, compile_config, runtime_config) do
405+
defp main_body_for(:elixir, module, compile_config, runtime_config) do
431406
config =
432407
if runtime_config do
433408
quote do
@@ -452,7 +427,7 @@ defmodule Mix.Tasks.Escript.Build do
452427
args = Enum.map(args, &List.to_string(&1))
453428
System.argv(args)
454429
load_config(unquote(config))
455-
start_app(unquote(app))
430+
start_app()
456431
Kernel.CLI.run(fn _ -> unquote(module).main(args) end)
457432

458433
error ->
@@ -462,11 +437,42 @@ defmodule Mix.Tasks.Escript.Build do
462437
end
463438
end
464439

465-
defp main_body_for(:erlang, module, app, compile_config, _runtime_config) do
440+
defp main_body_for(:erlang, module, compile_config, _runtime_config) do
466441
quote do
467442
load_config(unquote(compile_config))
468-
start_app(unquote(app))
443+
start_app()
469444
unquote(module).main(args)
470445
end
471446
end
447+
448+
defp start_app_for(nil) do
449+
:ok
450+
end
451+
452+
defp start_app_for(app) do
453+
quote do
454+
case :application.ensure_all_started(unquote(app)) do
455+
{:ok, _} ->
456+
:ok
457+
458+
{:error, {app, reason}} ->
459+
formatted_error =
460+
case :code.ensure_loaded(Application) do
461+
{:module, Application} -> Application.format_error(reason)
462+
{:error, _} -> :io_lib.format(~c"~p", [reason])
463+
end
464+
465+
error_message = [
466+
"ERROR! Could not start application ",
467+
:erlang.atom_to_binary(app, :utf8),
468+
": ",
469+
formatted_error,
470+
?\n
471+
]
472+
473+
io_error(error_message)
474+
:erlang.halt(1)
475+
end
476+
end
477+
end
472478
end

0 commit comments

Comments
 (0)