Skip to content

Commit cc2d056

Browse files
committed
Fix dbg on Erlang/OTP 25- (#12697)
1 parent c22f734 commit cc2d056

File tree

7 files changed

+35
-19
lines changed

7 files changed

+35
-19
lines changed

bin/elixir

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ starts_with () {
9494
}
9595

9696
ERL_EXEC="erl"
97+
MODE="cli"
9798
I=1
9899
E=0
99100
LENGTH=$#
@@ -104,9 +105,13 @@ while [ $I -le $LENGTH ]; do
104105
S=0
105106
C=0
106107
case "$1" in
107-
+elixirc|+iex)
108+
+elixirc)
108109
C=1
109110
;;
111+
+iex)
112+
C=1
113+
MODE="iex"
114+
;;
110115
-v|--no-halt|--dbg)
111116
C=1
112117
;;
@@ -223,7 +228,7 @@ fi
223228
ERTS_BIN=
224229
ERTS_BIN="$ERTS_BIN"
225230

226-
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 "$@"
231+
set -- "$ERTS_BIN$ERL_EXEC" -noshell -elixir_root "$SCRIPT_PATH"/../lib -pa "$SCRIPT_PATH"/../lib/elixir/ebin $ELIXIR_ERL_OPTIONS -s elixir start_$MODE $ERL "$@"
227232

228233
if [ -n "$RUN_ERL_PIPE" ]; then
229234
ESCAPED=""

bin/elixir.bat

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ rem Option which determines whether the loop is over
8282
set endLoop=0
8383

8484
rem Designates which mode / Elixir component to run as
85-
set runMode="elixir"
85+
set runMode="cli"
8686

8787
rem Designates the path to the current script
8888
set SCRIPT_PATH=%~dp0
@@ -106,7 +106,7 @@ if !endLoop! == 1 (
106106
)
107107
rem ******* EXECUTION OPTIONS **********************
108108
if !par!=="--werl" (set useWerl=1 && goto startloop)
109-
if !par!=="+iex" (set parsElixir=!parsElixir! +iex && goto startloop)
109+
if !par!=="+iex" (set parsElixir=!parsElixir! +iex && set runMode="iex" && goto startloop)
110110
if !par!=="+elixirc" (set parsElixir=!parsElixir! +elixirc && goto startloop)
111111
rem ******* EVAL PARAMETERS ************************
112112
if ""==!par:-e=! (
@@ -164,8 +164,13 @@ reg query HKCU\Console /v VirtualTerminalLevel 2>nul | findstr /e "0x1" >nul 2>n
164164
if %errorlevel% == 0 (
165165
set beforeExtra=-elixir ansi_enabled true !beforeExtra!
166166
)
167+
if !runMode! == "iex" (
168+
set beforeExtra=-s elixir start_iex !beforeExtra!
169+
) else (
170+
set beforeExtra=-s elixir start_cli !beforeExtra!
171+
)
167172

168-
set beforeExtra=-noshell -elixir_root "!SCRIPT_PATH!..\lib" -pa "!SCRIPT_PATH!..\lib\elixir\ebin" -s elixir start_cli !beforeExtra!
173+
set beforeExtra=-noshell -elixir_root "!SCRIPT_PATH!..\lib" -pa "!SCRIPT_PATH!..\lib\elixir\ebin" !beforeExtra!
169174

170175
if defined ELIXIR_CLI_DRY_RUN (
171176
if defined useWerl (

bin/iex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ readlink_f () {
3030

3131
SELF=$(readlink_f "$0")
3232
SCRIPT_PATH=$(dirname "$SELF")
33-
exec "$SCRIPT_PATH"/elixir --no-halt --erl "-user elixir" -e ":elixir.start_iex()" +iex "$@"
33+
exec "$SCRIPT_PATH"/elixir --no-halt --erl "-user elixir" +iex "$@"

bin/iex.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ goto end
2424

2525
:run
2626
if defined IEX_WITH_WERL (set __ELIXIR_IEX_FLAGS=--werl) else (set __ELIXIR_IEX_FLAGS=)
27-
call "%~dp0\elixir.bat" --no-halt --erl "-user elixir" -e ":elixir.start_iex()" +iex %__ELIXIR_IEX_FLAGS% %*
27+
call "%~dp0\elixir.bat" --no-halt --erl "-user elixir" +iex %__ELIXIR_IEX_FLAGS% %*
2828
:end
2929
endlocal

lib/elixir/src/elixir.erl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ start_cli() ->
192192
'Elixir.Kernel.CLI':main(init:get_plain_arguments()),
193193
elixir_config:booted().
194194

195-
%% TODO: Delete prim_tty branches and -user on Erlang/OTP 26.
195+
%% TODO: Delete prim_tty branches and -user on Erlang/OTP 26
196+
%% and add "-e :elixir.start_iex" to bin/iex instead of $MODE.
196197
start() ->
197198
case code:ensure_loaded(prim_tty) of
198199
{module, _} ->
@@ -207,6 +208,7 @@ start() ->
207208
start_iex() ->
208209
case code:ensure_loaded(prim_tty) of
209210
{module, _} ->
211+
start_cli(),
210212
spawn(fun() ->
211213
elixir_config:wait_until_booted(),
212214
(shell:whereis() =:= undefined) andalso 'Elixir.IEx':cli()

lib/iex/lib/iex.ex

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,9 @@ defmodule IEx do
536536

537537
@doc """
538538
Returns `true` if IEx was started, `false` otherwise.
539+
540+
This means the IEx application was started, but not
541+
that its CLI interface is running.
539542
"""
540543
@spec started?() :: boolean()
541544
def started? do
@@ -857,6 +860,8 @@ defmodule IEx do
857860

858861
# This is a callback invoked by Erlang shell utilities
859862
# when someone presses Ctrl+G and adds `s 'Elixir.IEx'`.
863+
# Let's consider exposing this as iex:start() and rename
864+
# elixir:start_iex() to iex:cli().
860865
@doc false
861866
def start(opts \\ [], mfa \\ {IEx, :dont_display_result, []}) do
862867
# TODO: Keep only this branch, delete optional args and mfa,
@@ -869,10 +874,13 @@ defmodule IEx do
869874
end)
870875
else
871876
spawn(fn ->
872-
{:ok, _} = Application.ensure_all_started(:elixir)
873-
System.wait_until_booted()
874-
:ok = :io.setopts(binary: true, encoding: :unicode)
877+
case :init.notify_when_started(self()) do
878+
:started -> :ok
879+
_ -> :init.wait_until_started()
880+
end
881+
875882
{:ok, _} = Application.ensure_all_started(:iex)
883+
:ok = :io.setopts(binary: true, encoding: :unicode)
876884
_ = for fun <- Enum.reverse(after_spawn()), do: fun.()
877885
IEx.Server.run_from_shell(opts, mfa)
878886
end)

lib/iex/lib/iex/cli.ex

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ defmodule IEx.CLI do
66

77
def deprecated do
88
if tty_works?() do
9-
:user_drv.start([:"tty_sl -c -e", old_tty_args()])
9+
:user_drv.start([:"tty_sl -c -e", tty_args()])
1010
else
1111
if get_remsh(:init.get_plain_arguments()) do
1212
IO.puts(
@@ -20,14 +20,10 @@ defmodule IEx.CLI do
2020
# IEx.Broker is capable of considering all groups under user_drv but
2121
# when we use :user.start(), we need to explicitly register it instead.
2222
# If we don't register, pry doesn't work.
23-
IEx.start([register: true] ++ options())
23+
IEx.start([register: true] ++ options(), {:elixir, :start_cli, []})
2424
end
2525
end
2626

27-
def prompt(_n) do
28-
[]
29-
end
30-
3127
# Check if tty works. If it does not, we fall back to the
3228
# simple/dumb terminal. This is starting the linked in
3329
# driver twice, it would be nice and appropriate if we had
@@ -41,7 +37,7 @@ defmodule IEx.CLI do
4137
end
4238
end
4339

44-
defp old_tty_args do
40+
defp tty_args do
4541
if remote = get_remsh(:init.get_plain_arguments()) do
4642
remote = List.to_atom(append_hostname(remote))
4743

@@ -77,7 +73,7 @@ defmodule IEx.CLI do
7773
end
7874

7975
defp local_start_mfa do
80-
{IEx, :start, [options()]}
76+
{IEx, :start, [options(), {:elixir, :start_cli, []}]}
8177
end
8278

8379
def remote_start(parent, ref) do

0 commit comments

Comments
 (0)