Skip to content

Make options in the -compile attribute take precedence #8093

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

Merged
merged 1 commit into from
Feb 9, 2024
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
19 changes: 11 additions & 8 deletions lib/compiler/src/compile.erl
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ used to give default compiler options. Its value must be a valid Erlang term. If
the value is a list, it is used as is. If it is not a list, it is put into a
list.

The list is appended to any options given to `file/2`, `forms/2`, and
[output_generated/2](`output_generated/1`). Use the alternative functions
`noenv_file/2`, `noenv_forms/2`, or
[noenv_output_generated/2](`noenv_output_generated/1`) if you do not want the
environment variable to be consulted, for example, if you are calling the
compiler recursively from inside a parse transform.
Boolean options (such as `warn_export_all` / `nowarn_export_all`) in
this list can be overridden by options given to `file/2`, `forms/2`, and
[output_generated/2](`output_generated/1`), which in turn can be overridden
by options given in the `compile()` attribute in the source code itself.

Use the alternative functions `noenv_file/2`, `noenv_forms/2`, or
[noenv_output_generated/2](`noenv_output_generated/1`) to not consult
the environment, for example, when calling the compiler recursively
from inside a parse transform.

The list can be retrieved with `env_compiler_options/0`.

Expand Down Expand Up @@ -802,7 +805,7 @@ location of an error or a warning refers.
CompRet :: comp_ret().

file(File, Opts) when is_list(Opts) ->
do_compile({file,File}, Opts++env_default_opts());
do_compile({file,File}, env_default_opts() ++ Opts);
file(File, Opt) ->
file(File, [Opt|?DEFAULT_OPTIONS]).

Expand Down Expand Up @@ -2260,7 +2263,7 @@ legalize_vars(Code0, St) ->

compile_directives(Forms, #compile{options=Opts0}=St0) ->
Opts1 = expand_opts(flatten([C || {attribute,_,compile,C} <- Forms])),
Opts = Opts1 ++ Opts0,
Opts = Opts0 ++ Opts1,
St1 = St0#compile{options=Opts},
case any_obsolete_option(Opts) of
{yes,Opt} ->
Expand Down