rebar3 icon indicating copy to clipboard operation
rebar3 copied to clipboard

Overriding `debug_info` while using `mode` is not working

Open eshurakov opened this issue 2 years ago • 7 comments

Environment

$ rebar3 report as prod release
Rebar3 report
 version 3.16.1
 generated at 2021-07-19T15:59:23+00:00
=================
Please submit this along with your issue at https://github.com/erlang/rebar3/issues (and feel free to edit out private information, if any)
-----------------
Task: asprodrelease
Entered as:
  asprodrelease
-----------------
Operating System: x86_64-apple-darwin19.6.0
ERTS: Erlang/OTP 23 [erts-11.2.2.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe] [dtrace]
Root Directory: /usr/local/Cellar/erlang@23/23.3.4.4/lib/erlang
Library directory: /usr/local/Cellar/erlang@23/23.3.4.4/lib/erlang/lib
-----------------
Loaded Applications:
bbmustache: 1.10.0
certifi: 2.6.1
cf: 0.3.1
common_test: 1.20.2.1
compiler: 7.6.9.1
crypto: 4.9.0.2
cth_readable: 1.5.1
dialyzer: 4.3.1.1
edoc: 0.12
erlware_commons: 1.5.0
eunit: 2.6
eunit_formatters: 0.5.0
getopt: 1.0.1
hipe: 4.0.1
inets: 7.3.2.1
kernel: 7.3.1.2
providers: 1.8.1
public_key: 1.10
relx: 4.4.0
sasl: 4.0.2
snmp: 5.8.0.1
ssl_verify_fun: 1.1.6
stdlib: 3.14.2.1
syntax_tools: 2.5
tools: 3.4.4

-----------------
Escript path: undefined
Providers:
  app_discovery as clean compile compile cover ct deps dialyzer do edoc escriptize eunit get-deps help install install_deps list lock new path pkgs release relup report repos shell state tar tree unlock update upgrade upgrade upgrade version xref

Current behaviour

I created a new app using rebar3 new app test and updated rebar3.conf:

{erl_opts, [debug_info]}.
{deps, []}.

{shell, [
  % {config, "config/sys.config"},
    {apps, [test]}
]}.

{relx, [{release, {test, "0.1"}, [sasl, test]},
         {mode, dev}
]}.

{profiles, [{prod, [
              {relx, [
                {mode, prod},
                {debug_info, keep}
              ]}
            ]}
]}.

Following https://rebar3.org/docs/deployment/releases/#modes I added the following to the production profile to keep debug information:

{mode, prod},
{debug_info, keep}

When I build my app using rebar3 as prod release I see that debug information is not kept. I tested it by opening the console: _build/prod/rel/test/bin/test console and trying to get attributes of test_sup.erl:

> test_sup:module_info().
[{module,test_sup},
 {exports,[{start_link,0},
           {init,1},
           {module_info,0},
           {module_info,1}]},
 {attributes,[]},
 {compile,[]},
 {native,false},
 {md5,<<48,223,167,10,92,6,166,197,38,140,210,83,191,40,
        77,59>>}]

Note that attributes and compile lists are empty.

To see what's going on I added some debug information to rebar_relx.erl to see what the config looks like before it is converted to state:

erlang:display(RelxConfig2),
{ok, RelxState} = rlx_config:to_state(RelxConfig2),
> rebar3 as prod release

[{mode,prod},{output_dir,".../test/_build/prod/rel"},{overlay_vars_values,[{profile_string,"prod"}]},{overlay_vars,[{base_dir,".../test/_build/prod"}]},{overlay,[]},{debug_info,keep},{mode,dev},{mode,prod},{release,{test,"0.1"},[sasl,test]}]

I believe in the end {mode,prod} overrides everything.

Expected behaviour

{debug_info, keep} is applied after {mode,prod} and debug info is kept.

eshurakov avatar Jul 19 '21 16:07 eshurakov

Yeah that sounds like a bug. While {mode, prod} does imply [{include_src, false}, {debug_info, strip}, {include_erts, true}, {dev_mode, false}], we should ideally be able to know that one is more specific than the other.

ferd avatar Jul 19 '21 17:07 ferd

i found the same problem when i use relup. it not work. but i need debu_info. so i have to try to use other version of rebar3. the last, i found only rebar3 of 3.13.3 work. 3.14-3.16.1 not work

hejin1026 avatar Aug 09 '21 07:08 hejin1026

even throung [{include_src, false}, {debug_info, strip}, {include_erts, true}, {dev_mode, false}] instead of {mode, prod}, it also not work

hejin1026 avatar Aug 09 '21 07:08 hejin1026

Can you try:

{debug_info, keep},
{mode, prod}

That'll tell me quick if its just an issue of mode expanding in a way that it is keeping the mode debug_info instead of the one from the config.

tsloughter avatar Aug 09 '21 14:08 tsloughter

^ that's what the opening post is mentioning happening

ferd avatar Aug 09 '21 14:08 ferd

The opening post shows the result is it still being set to strip in the list of args, but not that it is the order that causes this. But yea, I suspect it is and should be a simple fix in relx.

tsloughter avatar Aug 09 '21 15:08 tsloughter

AFAICS, the problem is only with profiles. E.g., with the following rebar.config, using rebar3 3.17.0:

{relx,
 [{release, {test, "0.1.0"}, [test, sasl]},
  {mode, dev},
  {include_erts, "/nonexistent"}]}.

{profiles, [{foo, [{relx,
                    [{mode, dev},
                     {include_erts, "/nonexistent"}]}]}]}.

rebar3 release works as expected (i.e., complains about /nonexistent), while rebar3 as foo release doesn't try to include ERTS. Even if you remove either of the two {mode, dev} options, the behavior remains exactly that way. Only if you remove both {mode, dev} settings, rebar as foo release works as expected.

weiss avatar Nov 03 '21 11:11 weiss