erlangbeam

Does a BEAM file remember whether it was built with -Werror?


I am working on a tool that deals with BEAM files, and we want to be able to assume the code was compiled with -Werror, so we don't have to repeat validations that are already done by the erl_lint compiler pass.

Is there a way to figure out if the BEAM was built with -Werror?

I'd expect beam_lib:chunks/2 to help here, but unfortunately it doesn't seem to have what I'm looking for:

beam_lib:chunks("sample.beam", [debug_info, attributes, compile_info]).
% the stuff returned says nothing about -Werror, even if I compile with -Werror

Solution

  • It seems that this information would be always stripped

    However, if you are in control of compilation process - you can put additional info into beam files, - which will be accessible through M:module_info(compile) and via beam chunks as well.

    For example in rebar:

    {erl_opts, [debug_info, {compile_info, [{my_key, my_value}]}]}.
    

    And then:

    1> my_module:module_info(compile).
    [{version,"7.6.6"},
     {options,[debug_info, ...
     {my_key,my_value}] 
    

    The same is true for "discoverability" of this key directly from beam chunks:

    2> beam_lib:chunks("my_beam.beam", [compile_info]).
    {ok, ... {my_key,my_value}]}]}}
    

    Meaning, that you can "stamp" your beam files with some meta-information easily. So, a workaround may be to stamp those beam files with this mark.