Skip to content

Commit

Permalink
Fix epp:open call for OTP 24
Browse files Browse the repository at this point in the history
The arity of epp:open has changed and in order for xref
and dialyzer to be happy with both version we need to hide
it behind a version macro.
  • Loading branch information
garazdawi committed Apr 6, 2021
1 parent 359f952 commit 6efe47c
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions apps/els_core/src/els_escript.erl
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,7 @@ parse_source(S, File, Fd, StartLine, HeaderSz) ->
_ = io:get_line(Fd, ''),
Encoding = epp:set_encoding(Fd),
{ok, _} = file:position(Fd, HeaderSz),
{ok, Epp} =
case erlang:function_exported(epp, open, 5) of
true ->
%% Pre OTP-24 function to call for escripts
%% Done via apply in order to silence dialyzer
apply(epp, open, [File, Fd, StartLine,
IncludePath, PreDefMacros]);
false ->
epp:open([{fd, Fd}, {name, File}, {location, StartLine},
{includes, IncludePath}, {macros, PreDefMacros}])
end,
{ok, Epp} = epp_open(File, Fd, StartLine, IncludePath, PreDefMacros),
_ = [io:setopts(Fd, [{encoding, Encoding}]) || Encoding =/= none],
{ok, FileForm} = epp:parse_erl_form(Epp),
OptModRes = epp:parse_erl_form(Epp),
Expand All @@ -181,6 +171,31 @@ parse_source(S, File, Fd, StartLine, HeaderSz) ->
ok = file:close(Fd),
check_source(S2).

-spec epp_open(_, _, pos_integer(), _, _) -> {ok, term()}.
-if(?OTP_RELEASE < 24).
%% If the environment used to compile is < 24 we should test
%% if the eep:open/5 function is available, and if it is we use that.
%% We to the check as we want the a version compiled with 23 to
%% work with 24.
epp_open(File, Fd, StartLine, IncludePath, PreDefMacros) ->
case erlang:function_exported(epp, open, 5) of
true ->
epp:open(File, Fd, StartLine, IncludePath, PreDefMacros);
false ->
epp:open([{fd, Fd}, {name, File}, {location, StartLine},
{includes, IncludePath}, {macros, PreDefMacros}])
end.
-else.
%% This is compiled with 24 or later, so has no chance of working
%% with earlier releases that 24 so we can just use the new way of
%% opening an escript.
epp_open(File, Fd, StartLine, IncludePath, PreDefMacros) ->
epp:open([{fd, Fd}, {name, File}, {location, StartLine},
{includes, IncludePath}, {macros, PreDefMacros}]).
-endif.



-spec check_source(state()) -> state().
check_source(S) ->
case S of
Expand Down

0 comments on commit 6efe47c

Please sign in to comment.