Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't crash if a BEAM's compile_info does not include key options #13

Merged
merged 1 commit into from
Nov 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/geas_beam.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ is_native_from_file(File) ->
Bn = filename:rootname(File, ".beam"),
case filelib:is_regular(File) of
true -> {ok,{_,[{compile_info, L}]}} = beam_lib:chunks(Bn, [compile_info]),
{options, O} = lists:keyfind(options, 1, L),
case lists:member(native, O) of
case is_native_from_compile_info(lists:keyfind(options, 1, L)) of
true -> true ;
false -> % rebar3 does not add 'native' in compile option
case get_arch_from_chunks(File) of
Expand All @@ -116,6 +115,18 @@ is_native_from_file(File) ->
end
end.

%%-------------------------------------------------------------------------
%% @doc If a module's `compile_info` has `options` check if they contain
%% `native`. Return `false` otherwise.
%% @end
%%-------------------------------------------------------------------------
-spec is_native_from_compile_info(false | {options, [term()]}) -> boolean().

is_native_from_compile_info(false) ->
false;
is_native_from_compile_info({options, O}) ->
lists:member(native, O).

%%-------------------------------------------------------------------------
%% @doc Get compile module version
%% @end
Expand Down