From 7ee67a812ba28ce8fe6f546f8953a5df0d778a73 Mon Sep 17 00:00:00 2001 From: kelvinst Date: Sat, 14 Sep 2019 10:35:59 -0300 Subject: [PATCH 1/6] Always adding :debug_info on erlc_options 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 --- lib/elixir/lib/code.ex | 2 +- lib/mix/lib/mix/tasks/compile.erlang.ex | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/elixir/lib/code.ex b/lib/elixir/lib/code.ex index 41fc6e6b45..c3ae3ba578 100644 --- a/lib/elixir/lib/code.ex +++ b/lib/elixir/lib/code.ex @@ -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`. diff --git a/lib/mix/lib/mix/tasks/compile.erlang.ex b/lib/mix/lib/mix/tasks/compile.erlang.ex index 465757e6ba..7a8f970a09 100644 --- a/lib/mix/lib/mix/tasks/compile.erlang.ex +++ b/lib/mix/lib/mix/tasks/compile.erlang.ex @@ -74,7 +74,7 @@ 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 From 638fd3d3ed1f561f5bf028af43e47b9c3a8532ef Mon Sep 17 00:00:00 2001 From: kelvinst Date: Sat, 14 Sep 2019 10:45:48 -0300 Subject: [PATCH 2/6] Running formatter --- lib/mix/lib/mix/tasks/compile.erlang.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/mix/lib/mix/tasks/compile.erlang.ex b/lib/mix/lib/mix/tasks/compile.erlang.ex index 7a8f970a09..ac9ecfefb6 100644 --- a/lib/mix/lib/mix/tasks/compile.erlang.ex +++ b/lib/mix/lib/mix/tasks/compile.erlang.ex @@ -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 ++ [:debug_info, :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 From bef9709699de606e54fea747e52f5dba03ea0e1d Mon Sep 17 00:00:00 2001 From: kelvinst Date: Sat, 14 Sep 2019 18:20:06 -0300 Subject: [PATCH 3/6] Adding tests for :debug_info on erlang compiler --- lib/mix/test/mix/tasks/compile.erlang_test.exs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/mix/test/mix/tasks/compile.erlang_test.exs b/lib/mix/test/mix/tasks/compile.erlang_test.exs index bcd15ec0b2..4bdde53abc 100644 --- a/lib/mix/test/mix/tasks/compile.erlang_test.exs +++ b/lib/mix/test/mix/tasks/compile.erlang_test.exs @@ -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, {module, [debug_info: {:debug_info_v1, backend, data}]}} = + :beam_lib.chunks(binary, [:debug_info]) + + assert backend.debug_info(:elixir_v1, module, data, []) != {:error, :missing} + end) + end end From 5be92dd7a6703bc9c3052f7529bf269576843170 Mon Sep 17 00:00:00 2001 From: kelvinst Date: Sun, 15 Sep 2019 15:19:08 -0300 Subject: [PATCH 4/6] Using :erlang_v1 for :erl_abstract_code.debug_info format param As suggested by @michalmuskala --- lib/mix/test/mix/tasks/compile.erlang_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mix/test/mix/tasks/compile.erlang_test.exs b/lib/mix/test/mix/tasks/compile.erlang_test.exs index 4bdde53abc..839a95e0ea 100644 --- a/lib/mix/test/mix/tasks/compile.erlang_test.exs +++ b/lib/mix/test/mix/tasks/compile.erlang_test.exs @@ -185,7 +185,7 @@ defmodule Mix.Tasks.Compile.ErlangTest do {:ok, {module, [debug_info: {:debug_info_v1, backend, data}]}} = :beam_lib.chunks(binary, [:debug_info]) - assert backend.debug_info(:elixir_v1, module, data, []) != {:error, :missing} + assert backend.debug_info(:erlang_v1, module, data, []) != {:error, :missing} end) end end From 9c4eabb4cf9ebe35803e1717cbaa234fe8098945 Mon Sep 17 00:00:00 2001 From: kelvinst Date: Sun, 15 Sep 2019 15:33:23 -0300 Subject: [PATCH 5/6] Set default `:erlc_options` to `[]` as now `:debug_info` is added + better docs for `erlc_options` --- lib/mix/lib/mix/project.ex | 2 +- lib/mix/lib/mix/tasks/compile.erlang.ex | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/mix/lib/mix/project.ex b/lib/mix/lib/mix/project.ex index 0b3f3ff418..4240da0566 100644 --- a/lib/mix/lib/mix/project.ex +++ b/lib/mix/lib/mix/project.ex @@ -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 diff --git a/lib/mix/lib/mix/tasks/compile.erlang.ex b/lib/mix/lib/mix/tasks/compile.erlang.ex index ac9ecfefb6..f2b9e72900 100644 --- a/lib/mix/lib/mix/tasks/compile.erlang.ex +++ b/lib/mix/lib/mix/tasks/compile.erlang.ex @@ -41,14 +41,19 @@ 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: + ### Important notice - erlc_options: [:debug_info, {:i, 'path/to/include'}] + The following options are always added to `:erlc_options` when running the compiler: + + [:debug_info, :return, :report, outdir: compile_path, i: include_path] + + You can set any of those options like this to override them: + + erlc_options: [debug_info: false, return: false, i: my_includes] """ From 9f118550de00fe2d2318dc7c0b06b193ed7c1b4c Mon Sep 17 00:00:00 2001 From: kelvinst Date: Mon, 16 Sep 2019 14:53:54 -0300 Subject: [PATCH 6/6] Fixing tests and docs --- lib/mix/lib/mix/tasks/compile.erlang.ex | 11 +++-------- lib/mix/test/mix/tasks/compile.erlang_test.exs | 4 ++-- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/mix/lib/mix/tasks/compile.erlang.ex b/lib/mix/lib/mix/tasks/compile.erlang.ex index f2b9e72900..4111fe8a0e 100644 --- a/lib/mix/lib/mix/tasks/compile.erlang.ex +++ b/lib/mix/lib/mix/tasks/compile.erlang.ex @@ -45,15 +45,10 @@ defmodule Mix.Tasks.Compile.Erlang do For a complete list of options, see `:compile.file/2`. - ### Important notice + The option `:debug_info` is always added to the end of it. You can + disable that using: - The following options are always added to `:erlc_options` when running the compiler: - - [:debug_info, :return, :report, outdir: compile_path, i: include_path] - - You can set any of those options like this to override them: - - erlc_options: [debug_info: false, return: false, i: my_includes] + erlc_options: [debug_info: false] """ diff --git a/lib/mix/test/mix/tasks/compile.erlang_test.exs b/lib/mix/test/mix/tasks/compile.erlang_test.exs index 839a95e0ea..414642ebad 100644 --- a/lib/mix/test/mix/tasks/compile.erlang_test.exs +++ b/lib/mix/test/mix/tasks/compile.erlang_test.exs @@ -182,10 +182,10 @@ defmodule Mix.Tasks.Compile.ErlangTest do binary = File.read!("_build/dev/lib/sample/ebin/b.beam") - {:ok, {module, [debug_info: {:debug_info_v1, backend, data}]}} = + {:ok, {_, [debug_info: {:debug_info_v1, _, {debug_info, _}}]}} = :beam_lib.chunks(binary, [:debug_info]) - assert backend.debug_info(:erlang_v1, module, data, []) != {:error, :missing} + assert debug_info != :none end) end end