Skip to content

Commit d3c0b38

Browse files
wojtekmachjosevalim
authored andcommitted
Improvements to generated rel/bin/app.bat (#13679)
* Validate value of `!RELEASE_MODE!` * Exit with `ERRORLEVEL` set to `1` on errors. Previously we did not and so apps that use releases and rely on exit codes to report errors were not doing so (e.g. Livebook). * Rename rpc node name from `rem-(...)` to `rpc-(...)` * Update generated `rel/env.bat.exs`
1 parent 662dd6b commit d3c0b38

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

Diff for: lib/mix/lib/mix/tasks/release.init.ex

+30-7
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ defmodule Mix.Tasks.Release.Init do
136136
;;
137137
138138
*)
139-
echo "ERROR: Expected sname, name, or none in RELEASE_DISTRIBUTION, got: $RELEASE_DISTRIBUTION" >&2
139+
echo "ERROR: Expected RELEASE_DISTRIBUTION to be sname, name, or none, got: $RELEASE_DISTRIBUTION" >&2
140140
exit 1
141141
;;
142142
esac
@@ -280,7 +280,7 @@ defmodule Mix.Tasks.Release.Init do
280280
rem set RELEASE_MODE=interactive
281281
282282
rem Set the release to work across nodes.
283-
rem RELEASE_DISTRIBUTION must be "sname" (local), "name" (distributed) or "none".
283+
rem RELEASE_DISTRIBUTION must be sname (local), name (distributed) or none.
284284
rem set RELEASE_DISTRIBUTION=name
285285
rem set RELEASE_NODE=<%= @release.name %>
286286
"""
@@ -314,13 +314,33 @@ defmodule Mix.Tasks.Release.Init do
314314
if not defined RELEASE_BOOT_SCRIPT_CLEAN (set RELEASE_BOOT_SCRIPT_CLEAN=start_clean)
315315
if not defined RELEASE_SYS_CONFIG (set RELEASE_SYS_CONFIG=!REL_VSN_DIR!\sys)
316316
317+
if "!RELEASE_DISTRIBUTION!" == "none" (
318+
rem
319+
) else if "!RELEASE_DISTRIBUTION!" == "name" (
320+
rem
321+
) else if "!RELEASE_DISTRIBUTION!" == "sname" (
322+
rem
323+
) else (
324+
echo ERROR: Expected RELEASE_DISTRIBUTION to be sname, name, or none, got: !RELEASE_DISTRIBUTION!
325+
exit /B 1
326+
)
327+
328+
if "!RELEASE_MODE!" == "embedded" (
329+
rem
330+
) else if "!RELEASE_MODE!" == "interactive" (
331+
rem
332+
) else (
333+
echo ERROR: Expected RELEASE_MODE to be embedded or interactive, got: !RELEASE_MODE!
334+
exit /B 1
335+
)
336+
317337
if "%~1" == "start" (set "REL_EXEC=elixir" && set "REL_EXTRA=--no-halt" && set "REL_GOTO=start")
318338
if "%~1" == "start_iex" (set "REL_EXEC=iex" && set "REL_EXTRA=--werl" && set "REL_GOTO=start")
319339
if "%~1" == "install" (set "REL_GOTO=install")
320340
if "%~1" == "eval" (
321341
if "%~2" == "" (
322342
echo ERROR: EVAL expects an expression as argument
323-
goto end
343+
exit /B 1
324344
)
325345
set "REL_GOTO=eval"
326346
)
@@ -348,7 +368,7 @@ defmodule Mix.Tasks.Release.Init do
348368
if "%~1" == "rpc" (
349369
if "%~2" == "" (
350370
echo ERROR: RPC expects an expression as argument
351-
goto end
371+
exit /B 1
352372
)
353373
set "REL_RPC=%~2"
354374
goto rpc
@@ -369,7 +389,10 @@ defmodule Mix.Tasks.Release.Init do
369389
echo pid Prints the operating system PID of the running system via a remote command
370390
echo version Prints the release name and version to be booted
371391
echo.
372-
if not "%~1" == "" (echo ERROR: Unknown command %~1)
392+
if not "%~1" == "" (
393+
echo ERROR: Unknown command %~1
394+
exit /B 1
395+
)
373396
goto end
374397
375398
:start
@@ -427,7 +450,7 @@ defmodule Mix.Tasks.Release.Init do
427450
if "!RELEASE_DISTRIBUTION!" == "none" (
428451
set RELEASE_DISTRIBUTION_FLAG=
429452
) else (
430-
set RELEASE_DISTRIBUTION_FLAG=--!RELEASE_DISTRIBUTION! "rem-!RANDOM!-!RELEASE_NODE!"
453+
set RELEASE_DISTRIBUTION_FLAG=--!RELEASE_DISTRIBUTION! "rpc-!RANDOM!-!RELEASE_NODE!"
431454
)
432455
433456
"!REL_VSN_DIR!\elixir.bat" ^
@@ -452,7 +475,7 @@ defmodule Mix.Tasks.Release.Init do
452475
453476
if "!RELEASE_DISTRIBUTION!" == "none" (
454477
echo ERROR: RELEASE_DISTRIBUTION is required in install command
455-
goto end
478+
exit /B 1
456479
)
457480
458481
"!ERLSRV!" add "!RELEASE_NAME!_!RELEASE_NAME!" ^

0 commit comments

Comments
 (0)