|
24 | 24 | -type struct() :: #{'__struct__' := atom(), atom() => any()}. |
25 | 25 |
|
26 | 26 | %% OTP Application API |
| 27 | +%% TODO: Remove Erlang/OTP 26+ checks |
27 | 28 |
|
28 | | --if(?OTP_RELEASE >= 26). |
29 | | -load_paths(Paths) -> code:add_pathsa(Paths, cache). |
30 | | --else. |
31 | | -load_paths(Paths) -> code:add_pathsa(Paths). |
32 | | --endif. |
| 29 | +load_paths(OTP, Paths) when OTP >= 26 -> code:add_pathsa(Paths, cache); |
| 30 | +load_paths(_OTP, Paths) -> code:add_pathsa(Paths). |
33 | 31 |
|
34 | 32 | start(_Type, _Args) -> |
35 | | - _ = parse_otp_release(), |
| 33 | + OTP = parse_otp_release(), |
36 | 34 | preload_common_modules(), |
37 | | - set_stdio_and_stderr_to_binary_and_maybe_utf8(), |
| 35 | + set_stdio_and_stderr_to_binary_and_maybe_utf8(OTP), |
38 | 36 | check_file_encoding(file:native_name_encoding()), |
39 | 37 |
|
40 | 38 | case init:get_argument(elixir_root) of |
41 | 39 | {ok, [[Root]]} -> |
42 | | - load_paths([ |
| 40 | + load_paths(OTP, [ |
43 | 41 | Root ++ "/eex/ebin", |
44 | 42 | Root ++ "/ex_unit/ebin", |
45 | 43 | Root ++ "/iex/ebin", |
@@ -117,9 +115,16 @@ stop(Tab) -> |
117 | 115 | config_change(_Changed, _New, _Remove) -> |
118 | 116 | ok. |
119 | 117 |
|
120 | | -set_stdio_and_stderr_to_binary_and_maybe_utf8() -> |
121 | | - %% TODO: Remove me once we require Erlang/OTP 26+ |
122 | | - ok = io:setopts(standard_io, [binary, {encoding, utf8}]), |
| 118 | +set_stdio_and_stderr_to_binary_and_maybe_utf8(OTP) when OTP >= 26 -> |
| 119 | + ok = io:setopts(standard_io, [binary]), |
| 120 | + ok; |
| 121 | +set_stdio_and_stderr_to_binary_and_maybe_utf8(_OTP) -> |
| 122 | + Opts = |
| 123 | + case init:get_argument(noshell) of |
| 124 | + {ok, _} -> [binary, {encoding, utf8}]; |
| 125 | + error -> [binary] |
| 126 | + end, |
| 127 | + ok = io:setopts(standard_io, Opts), |
123 | 128 | ok = io:setopts(standard_error, [{encoding, utf8}]), |
124 | 129 | ok. |
125 | 130 |
|
@@ -349,27 +354,27 @@ eval_external_handler(Env) -> |
349 | 354 | Fun = fun(Ann, FunOrModFun, Args) -> |
350 | 355 | try |
351 | 356 | case FunOrModFun of |
352 | | - {Mod, Fun} -> apply(Mod, Fun, Args); |
353 | | - Fun -> apply(Fun, Args) |
| 357 | + {Mod, Fun} -> apply(Mod, Fun, Args); |
| 358 | + Fun -> apply(Fun, Args) |
354 | 359 | end |
355 | 360 | catch |
356 | 361 | Kind:Reason:Stacktrace -> |
357 | 362 | %% Take everything up to the Elixir module |
358 | 363 | Pruned = |
359 | | - lists:takewhile(fun |
360 | | - ({elixir,_,_,_}) -> false; |
361 | | - (_) -> true |
362 | | - end, Stacktrace), |
| 364 | + lists:takewhile(fun |
| 365 | + ({elixir,_,_,_}) -> false; |
| 366 | + (_) -> true |
| 367 | + end, Stacktrace), |
363 | 368 |
|
364 | 369 | Caller = |
365 | | - lists:dropwhile(fun |
366 | | - ({elixir,_,_,_}) -> false; |
367 | | - (_) -> true |
368 | | - end, Stacktrace), |
| 370 | + lists:dropwhile(fun |
| 371 | + ({elixir,_,_,_}) -> false; |
| 372 | + (_) -> true |
| 373 | + end, Stacktrace), |
369 | 374 |
|
370 | 375 | %% Now we prune any shared code path from erl_eval |
371 | 376 | {current_stacktrace, Current} = |
372 | | - erlang:process_info(self(), current_stacktrace), |
| 377 | + erlang:process_info(self(), current_stacktrace), |
373 | 378 |
|
374 | 379 | %% We need to make sure that we don't generate more |
375 | 380 | %% frames than supported. So we do our best to drop |
|
0 commit comments