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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions src/rebar_otp_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ preprocess(State, AppInfo, AppSrcFile) ->
%% substitute. Note that we include the list of modules available in
%% ebin/ and update the app data accordingly.
OutDir = rebar_app_info:out_dir(AppInfo),
AppVars = load_app_vars(State) ++ [{modules, ebin_modules(AppInfo, OutDir)}],
AppVars = load_app_vars(AppName, State) ++ [{modules, ebin_modules(AppInfo, OutDir)}],
A1 = apply_app_vars(AppVars, AppData),

%% AppSrcFile may contain instructions for generating a vsn number
Expand Down Expand Up @@ -146,8 +146,8 @@ preprocess(State, AppInfo, AppSrcFile) ->
throw(?PRV_ERROR({file_read, rebar_app_info:name(AppInfo), ".app.src", Reason}))
end.

load_app_vars(State) ->
case rebar_state:get(State, app_vars_file, undefined) of
load_app_vars(AppName, State) ->
case get_app_vars_file_from_state(AppName, State) of
undefined ->
[];
Filename ->
Expand All @@ -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.

undefined ->
undefined;
AppVarsProplist=[T|_] when is_tuple(T) ->
%% When `apps_vars_file' is a proplist, assume that each key
%% of the proplist corresponds to an app name (atom). This
%% allows the developer to provide any number of `app_vars_file's
%% and apply the vars in any application's .app file specifically.
case proplists:get_value(AppName, AppVarsProplist) of
undefined ->
undefined;
Filename ->
Filename
end;
Filename ->
%% When app_vars_file is not a proplist, assume that it is
%% a filename. When a filename is provided, the env vars
%% contained within will be applied to all apps being
%% compiled by rebar.
Filename
end.

apply_app_vars([], AppData) ->
AppData;
apply_app_vars([{Key, Value} | Rest], AppData) ->
Expand Down