Skip to content

Commit

Permalink
Move path loading and IEx booting to Elixir (#12375)
Browse files Browse the repository at this point in the history
This gives us more control to cache paths
and over boot compared to relying on scripts.

This also makes it easier for someone to provide
alternatives to IEx.
  • Loading branch information
josevalim authored Feb 2, 2023
1 parent bcf789f commit e1eecb8
Show file tree
Hide file tree
Showing 11 changed files with 235 additions and 286 deletions.
14 changes: 3 additions & 11 deletions bin/elixir
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Usage: $(basename "$0") [options] [.exs file] [data]
-pz "PATH" Appends the given path to Erlang code path (*)
-v, --version Prints Erlang/OTP and Elixir versions (standalone)
--app APP Starts the given app and its dependencies (*)
--erl "SWITCHES" Switches to be passed down to Erlang (*)
--eval "COMMAND" Evaluates the given command, same as -e (*)
--logger-otp-reports BOOL Enables or disables OTP reporting
Expand Down Expand Up @@ -95,7 +94,6 @@ starts_with () {
}

ERL_EXEC="erl"
MODE="elixir"
I=1
E=0
LENGTH=$#
Expand All @@ -106,18 +104,13 @@ while [ $I -le $LENGTH ]; do
S=0
C=0
case "$1" in
+iex)
+elixirc|+iex)
C=1
MODE="iex"
;;
+elixirc)
C=1
MODE="elixirc"
;;
-v|--no-halt|--dbg)
C=1
;;
-e|-r|-pr|-pa|-pz|--app|--eval|--remsh|--dot-iex)
-e|-r|-pr|-pa|-pz|--eval|--remsh|--dot-iex)
C=2
;;
--rpc-eval)
Expand Down Expand Up @@ -220,7 +213,6 @@ SELF=$(readlink_f "$0")
SCRIPT_PATH=$(dirname "$SELF")

if [ "$OSTYPE" = "cygwin" ]; then SCRIPT_PATH=$(cygpath -m "$SCRIPT_PATH"); fi
if [ "$MODE" != "iex" ]; then ERL="-noshell -s elixir start_cli $ERL"; fi

if [ "$OS" != "Windows_NT" ] && [ -z "$NO_COLOR" ]; then
if test -t 1 -a -t 2; then ERL="-elixir ansi_enabled true $ERL"; fi
Expand All @@ -231,7 +223,7 @@ fi
ERTS_BIN=
ERTS_BIN="$ERTS_BIN"

set -- "$ERTS_BIN$ERL_EXEC" -pa "$SCRIPT_PATH"/../lib/*/ebin $ELIXIR_ERL_OPTIONS $ERL "$@"
set -- "$ERTS_BIN$ERL_EXEC" -noshell -elixir_root "$SCRIPT_PATH"/../lib -pa "$SCRIPT_PATH"/../lib/elixir/ebin $ELIXIR_ERL_OPTIONS -s elixir start_cli $ERL "$@"

if [ -n "$RUN_ERL_PIPE" ]; then
ESCAPED=""
Expand Down
22 changes: 6 additions & 16 deletions bin/elixir.bat
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ echo -pa "PATH" Prepends the given path to Erlang code path
echo -pz "PATH" Appends the given path to Erlang code path (*)
echo -v, --version Prints Erlang/OTP and Elixir versions (standalone)
echo.
echo --app APP Starts the given app and its dependencies (*)
echo --erl "SWITCHES" Switches to be passed down to Erlang (*)
echo --eval "COMMAND" Evaluates the given command, same as -e (*)
echo --logger-otp-reports BOOL Enables or disables OTP reporting
Expand Down Expand Up @@ -97,7 +96,7 @@ rem Recursive loop called for each parameter that parses the cmd line parameters
set "par=%~1"
if "!par!"=="" (
rem skip if no parameter
goto expand_erl_libs
goto run
)
shift
set par="!par:"=\"!"
Expand All @@ -107,8 +106,8 @@ if !endLoop! == 1 (
)
rem ******* EXECUTION OPTIONS **********************
if !par!=="--werl" (set useWerl=1 && goto startloop)
if !par!=="+iex" (set parsElixir=!parsElixir! +iex && set runMode="iex" && goto startloop)
if !par!=="+elixirc" (set parsElixir=!parsElixir! +elixirc && set runMode="elixirc" && goto startloop)
if !par!=="+iex" (set parsElixir=!parsElixir! +iex && goto startloop)
if !par!=="+elixirc" (set parsElixir=!parsElixir! +elixirc && goto startloop)
rem ******* EVAL PARAMETERS ************************
if ""==!par:-e=! (
set "VAR=%~1"
Expand Down Expand Up @@ -139,7 +138,6 @@ if ""==!par:-pa=! (set "parsElixir=!parsElixir! -pa %~1" && shift && got
if ""==!par:-pz=! (set "parsElixir=!parsElixir! -pz %~1" && shift && goto startloop)
if ""==!par:-v=! (set "parsElixir=!parsElixir! -v" && goto startloop)
if ""==!par:--version=! (set "parsElixir=!parsElixir! --version" && goto startloop)
if ""==!par:--app=! (set "parsElixir=!parsElixir! --app %~1" && shift && goto startloop)
if ""==!par:--no-halt=! (set "parsElixir=!parsElixir! --no-halt" && goto startloop)
if ""==!par:--remsh=! (set "parsElixir=!parsElixir! --remsh %~1" && shift && goto startloop)
if ""==!par:--dot-iex=! (set "parsElixir=!parsElixir! --dot-iex %~1" && shift && goto startloop)
Expand All @@ -149,7 +147,6 @@ if ""==!par:--boot=! (set "parsErlang=!parsErlang! -boot %~1" &&
if ""==!par:--boot-var=! (set "parsErlang=!parsErlang! -boot_var %~1 %~2" && shift && shift && goto startloop)
if ""==!par:--cookie=! (set "parsErlang=!parsErlang! -setcookie %~1" && shift && goto startloop)
if ""==!par:--hidden=! (set "parsErlang=!parsErlang! -hidden" && goto startloop)
if ""==!par:--detached=! (set "parsErlang=!parsErlang! -detached" && echo warning: the --detached option is deprecated && goto startloop)
if ""==!par:--erl-config=! (set "parsErlang=!parsErlang! -config %~1" && shift && goto startloop)
if ""==!par:--logger-otp-reports=! (set "parsErlang=!parsErlang! -logger handle_otp_reports %1" && shift && goto startloop)
if ""==!par:--logger-sasl-reports=! (set "parsErlang=!parsErlang! -logger handle_sasl_reports %1" && shift && goto startloop)
Expand All @@ -162,21 +159,14 @@ set endLoop=1
set parsElixir=!parsElixir! !par!
goto startloop

:expand_erl_libs
rem expand all ebin paths as Windows does not support the ..\*\ebin wildcard
set ext_libs=
for /d %%d in ("!SCRIPT_PATH!..\lib\*.") do (
set ext_libs=!ext_libs! -pa "%%~fd\ebin"
)

:run
reg query HKCU\Console /v VirtualTerminalLevel 2>nul | findstr /e "0x1" >nul 2>nul
if %errorlevel% == 0 (
set beforeExtra=-elixir ansi_enabled true !beforeExtra!
)
if not !runMode! == "iex" (
set beforeExtra=-noshell -s elixir start_cli !beforeExtra!
)

set beforeExtra=-noshell -elixir_root !SCRIPT_PATH!..\lib -pa !SCRIPT_PATH!..\lib\elixir\ebin -s elixir start_cli !beforeExtra!

if defined ELIXIR_CLI_DRY_RUN (
if defined useWerl (
echo start "" "!ERTS_BIN!werl.exe" !ext_libs! !ELIXIR_ERL_OPTIONS! !parsErlang! !beforeExtra! -extra !parsElixir!
Expand Down
2 changes: 1 addition & 1 deletion bin/iex
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ readlink_f () {

SELF=$(readlink_f "$0")
SCRIPT_PATH=$(dirname "$SELF")
exec "$SCRIPT_PATH"/elixir --no-halt --erl "-noshell -user Elixir.IEx.CLI" +iex "$@"
exec "$SCRIPT_PATH"/elixir --no-halt --erl "-user elixir" +iex "$@"
2 changes: 1 addition & 1 deletion bin/iex.bat
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ goto end

:run
if defined IEX_WITH_WERL (set __ELIXIR_IEX_FLAGS=--werl) else (set __ELIXIR_IEX_FLAGS=)
call "%~dp0\elixir.bat" --no-halt --erl "-noshell -user Elixir.IEx.CLI" +iex %__ELIXIR_IEX_FLAGS% %*
call "%~dp0\elixir.bat" --no-halt --erl "-user elixir" +iex %__ELIXIR_IEX_FLAGS% %*
:end
endlocal
Loading

0 comments on commit e1eecb8

Please sign in to comment.