Skip to content

Commit

Permalink
Always add :debug_info to :erlc_options (#9348)
Browse files Browse the repository at this point in the history
That way, if someone sets :erlc_options to `[warnings_as_errors: true]`,
`:debug_info` would still be on the options. To configure it to not
save debug info, one should only add `debug_info: false` to 
`:erlc_options`.
  • Loading branch information
kelvinst authored and fertapric committed Sep 22, 2019
1 parent 96c187e commit 87d5255
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/elixir/lib/code.ex
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ defmodule Code do
* `:debug_info` - when `true`, retain debug information in the compiled
module. This allows a developer to reconstruct the original source
code. Defaults to `false`.
code. Defaults to `true`.
* `:ignore_module_conflict` - when `true`, override modules that were
already defined without raising errors. Defaults to `false`.
Expand Down
2 changes: 1 addition & 1 deletion lib/mix/lib/mix/project.ex
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ defmodule Mix.Project do
elixirc_paths: ["lib"],
erlc_paths: ["src"],
erlc_include_path: "include",
erlc_options: [:debug_info],
erlc_options: [],
lockfile: "mix.lock",
preferred_cli_env: [],
start_permanent: false
Expand Down
11 changes: 6 additions & 5 deletions lib/mix/lib/mix/tasks/compile.erlang.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ defmodule Mix.Tasks.Compile.Erlang do
Defaults to `"include"`.
* `:erlc_options` - compilation options that apply to Erlang's
compiler. Defaults to `[:debug_info]`.
compiler. Defaults to `[]`.
For a complete list of options, see `:compile.file/2`.
For example, to configure the `erlc_options` for your Erlang project you
may run:
The option `:debug_info` is always added to the end of it. You can
disable that using:
erlc_options: [:debug_info, {:i, 'path/to/include'}]
erlc_options: [debug_info: false]
"""

Expand All @@ -74,7 +74,8 @@ defmodule Mix.Tasks.Compile.Erlang do
Mix.raise(":erlc_options should be a list of options, got: #{inspect(erlc_options)}")
end

erlc_options = erlc_options ++ [:return, :report, outdir: compile_path, i: include_path]
erlc_options =
erlc_options ++ [:debug_info, :return, :report, outdir: compile_path, i: include_path]

erlc_options =
Enum.map(erlc_options, fn
Expand Down
14 changes: 14 additions & 0 deletions lib/mix/test/mix/tasks/compile.erlang_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,18 @@ defmodule Mix.Tasks.Compile.ErlangTest do
assert output == ""
end)
end

@tag erlc_options: [{:warnings_as_errors, true}]
test "adds :debug_info to erlc_options by default" do
in_fixture("compile_erlang", fn ->
Mix.Tasks.Compile.Erlang.run([])

binary = File.read!("_build/dev/lib/sample/ebin/b.beam")

{:ok, {_, [debug_info: {:debug_info_v1, _, {debug_info, _}}]}} =
:beam_lib.chunks(binary, [:debug_info])

assert debug_info != :none
end)
end
end

0 comments on commit 87d5255

Please sign in to comment.