From 475de3d98acfd620aba4347af1047f1722ae386b Mon Sep 17 00:00:00 2001 From: Jesse Stimpson Date: Wed, 15 Sep 2021 13:46:22 +0000 Subject: [PATCH] Allow apps_vars_file to be specified per application in config --- src/rebar_otp_app.erl | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/rebar_otp_app.erl b/src/rebar_otp_app.erl index 9b94e8e16..12971f2e3 100644 --- a/src/rebar_otp_app.erl +++ b/src/rebar_otp_app.erl @@ -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 @@ -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 -> @@ -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 + 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) ->