Rebar3: default macro set during release compilation

Hi rebar3 experts

Does rebar3 set any Erlang macro I can use in my code during release generation?

rebar3 as prod release

Assuming rebar3 hypothetically sets REBAR3_RELEASE_IS_BEING_GENERATED during release generation, I will be able to achieve the following:

-module(t).
-export([foo/0]).
-ifdef(REBAR3_RELEASE_IS_BEING_GENERATED).
 {release_mode, true}.
-else.
 {release_mode, false}.
-endif.

Help appreciated.

release target here will simply assemble the release after compiling the code. It will be no different than simply rebar3 as prod compile, in fact, release target depends on compile. What you can do, however, is to define your own profile, and within that profile set any variable you want to whatever value you desire.

Something like:

{profiles, [
  {my_release, [{erl_opts, [{'MY_RELEASE', true}]}]}
]}.

and then assemble the release using rebar3 as my_profile release.

1 Like

@caravan_muffin thanks a lot. I tried the following and it worked as well:

{profiles, [
  {prod, [{erl_opts, [{'MY_RELEASE', true}]}]}
]}.