Skip to content

Commit

Permalink
Merge pull request #13 from kivra-pauoli/fix/crash-on-beam-without-op…
Browse files Browse the repository at this point in the history
…tions-in-compile_info

Don't crash if a BEAM's `compile_info` does not include key `options`
  • Loading branch information
crownedgrouse authored Nov 11, 2023
2 parents aaa34cb + 5f5c137 commit 33d3ed1
Showing 1 changed file with 13 additions and 2 deletions.
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

0 comments on commit 33d3ed1

Please sign in to comment.