Skip to content
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

Allow apps_vars_file to be specified per application in config #2616

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JesseStimpson
Copy link

@JesseStimpson JesseStimpson commented Sep 15, 2021

Hello,

[PR submitted in reference to Issue #2615]

While converting an old app from rebar to rebar3, I found some unexpected behavior from the app_vars_file configuration option in rebar3.

With this change, when apps_vars_file is a proplist, rebar3 will inspect the proplist for each app's name and only apply env vars if found. For backward compatibility, if app_vars_file is not a proplist, the vars will still be applied to all apps.

I've not attempted to create any new tests for this yet, but if the PR is deemed valuable I'm happy to include tests and documentation as needed.

jstimpson:[~/dev/erlang]: ./JesseStimpson-rebar3/_build/prod/bin/rebar3 new app foo
===> Writing foo/src/foo_app.erl
===> Writing foo/src/foo_sup.erl
===> Writing foo/src/foo.app.src
===> Writing foo/rebar.config
===> Writing foo/.gitignore
===> Writing foo/LICENSE
===> Writing foo/README.md
jstimpson:[~/dev/erlang]: cd foo
jstimpson:[~/dev/erlang/foo]: echo '{deps, [{recon, {git, "https://github.com/ferd/recon.git", {branch, "master"}}}]}.' > rebar.config
jstimpson:[~/dev/erlang/foo]: echo '{app_vars_file, [{foo, "myvars.app.config"}]}.' >> rebar.config
jstimpson:[~/dev/erlang/foo]: echo '{env, [{bar, baz}]}.' > myvars.app.config
jstimpson:[~/dev/erlang/foo]: ../JesseStimpson-rebar3/_build/prod/bin/rebar3 compile
===> Verifying dependencies...
===> Analyzing applications...
===> Compiling foo
===> Loading app vars from "myvars.app.config"
jstimpson:[~/dev/erlang/foo]: cat _build/default/lib/recon/ebin/recon.app
{application,recon,
             [{description,"Diagnostic tools for production use"},
              {vsn,"2.5.2"},
              {modules,[recon,recon_alloc,recon_lib,recon_map,recon_rec,
                        recon_trace]},
              {registered,[]},
              {applications,[kernel,stdlib]},
              {licenses,["BSD"]},
              {links,[{"Github","https://github.com/ferd/recon/"},
                      {"Documentation","http://ferd.github.io/recon/"}]},
              {build_tools,["mix","rebar3"]},
              {files,["src/","script/","rebar.lock","mix.exs","README.md",
                      "LICENSE"]}]}.
jstimpson:[~/dev/erlang/foo]: cat _build/default/lib/foo/ebin/foo.app
{application,foo,
             [{description,"An OTP application"},
              {vsn,"0.1.0"},
              {registered,[]},
              {mod,{foo_app,[]}},
              {applications,[kernel,stdlib]},
              {env,[{bar,baz}]},
              {modules,[foo_app,foo_sup]},
              {licenses,["Apache 2.0"]},
              {links,[]}]}.

@@ -156,6 +156,29 @@ load_app_vars(State) ->
Vars
end.

get_app_vars_file_from_state(AppName, State) ->
case rebar_state:get(State, app_vars_file, undefined) of
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the wrong call to use I believe. The problem here is that this will use the top-level rebar.config file and inject its values into all OTP Applications. I think it would make more sense to use rebar_app_info:get to fetch the values within the app's own rebar configuration value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants