From 9b0d35d9869801d6ee52fde8ba443b07d95892e8 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Mon, 20 Dec 2010 08:55:31 -0700 Subject: Adding support for app_vars in external file --- src/rebar_otp_app.erl | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'src/rebar_otp_app.erl') diff --git a/src/rebar_otp_app.erl b/src/rebar_otp_app.erl index a8a4ecd..7cb70df 100644 --- a/src/rebar_otp_app.erl +++ b/src/rebar_otp_app.erl @@ -41,7 +41,7 @@ compile(Config, File) -> %% be validated as usual. AppFile = case rebar_app_utils:is_app_src(File) of true -> - preprocess(File); + preprocess(Config, File); false -> File end, @@ -86,12 +86,14 @@ clean(_Config, File) -> %% Internal functions %% =================================================================== -preprocess(AppSrcFile) -> +preprocess(Config, AppSrcFile) -> case rebar_app_utils:load_app_file(AppSrcFile) of {ok, AppName, AppData} -> - %% Get a list of all the modules available in ebin/ and update - %% the app data accordingly - A1 = lists:keystore(modules, 1, AppData, {modules, ebin_modules()}), + %% Look for a configuration file with vars we want to + %% substitute. Note that we include the list of modules available in + %% ebin/ and update the app data accordingly. + AppVars = load_app_vars(Config) ++ [{modules, ebin_modules()}], + A1 = apply_app_vars(AppVars, AppData), %% Build the final spec as a string Spec = io_lib:format("~p.\n", [{application, AppName, A1}]), @@ -109,6 +111,22 @@ preprocess(AppSrcFile) -> ?ABORT("Failed to read ~s for preprocessing: ~p\n", [AppSrcFile, Reason]) end. +load_app_vars(Config) -> + case rebar_config:get_local(Config, app_vars_file, undefined) of + undefined -> + ?INFO("No app_vars_file defined.\n", []), + []; + Filename -> + ?INFO("Loading app vars from ~p\n", [Filename]), + {ok, Vars} = file:consult(Filename), + Vars + end. + +apply_app_vars([], AppData) -> + AppData; +apply_app_vars([{Key, Value} | Rest], AppData) -> + AppData2 = lists:keystore(Key, 1, AppData, {Key, Value}), + apply_app_vars(Rest, AppData2). validate_name(AppName, File) -> %% Convert the .app file name to an atom -- check it against the identifier within the file -- cgit v1.1 From c466076ffb5a1ea4c00d49fefff0dcfbceb58236 Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Mon, 31 Jan 2011 17:43:31 +0100 Subject: Clean up emacs file local variables --- src/rebar_otp_app.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/rebar_otp_app.erl') diff --git a/src/rebar_otp_app.erl b/src/rebar_otp_app.erl index 7cb70df..af579d9 100644 --- a/src/rebar_otp_app.erl +++ b/src/rebar_otp_app.erl @@ -1,4 +1,4 @@ -%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*- %% ex: ts=4 sw=4 et %% ------------------------------------------------------------------- %% -- cgit v1.1 From 63de05d914f3c2bef6dcfc6cf966400d93c9c80d Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Fri, 28 Jan 2011 16:08:27 +0100 Subject: Clean up code --- src/rebar_otp_app.erl | 54 +++++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 23 deletions(-) (limited to 'src/rebar_otp_app.erl') diff --git a/src/rebar_otp_app.erl b/src/rebar_otp_app.erl index af579d9..4f21a67 100644 --- a/src/rebar_otp_app.erl +++ b/src/rebar_otp_app.erl @@ -40,11 +40,11 @@ compile(Config, File) -> %% written out as a ebin/*.app file. That resulting file will then %% be validated as usual. AppFile = case rebar_app_utils:is_app_src(File) of - true -> - preprocess(Config, File); - false -> - File - end, + true -> + preprocess(Config, File); + false -> + File + end, %% Load the app file and validate it. case rebar_app_utils:load_app_file(AppFile) of @@ -52,11 +52,12 @@ compile(Config, File) -> validate_name(AppName, AppFile), %% In general, the list of modules is an important thing to validate - %% for compliance with OTP guidelines and upgrade procedures. However, - %% some people prefer not to validate this list. + %% for compliance with OTP guidelines and upgrade procedures. + %% However, some people prefer not to validate this list. case rebar_config:get_local(Config, validate_app_modules, true) of true -> - validate_modules(AppName, proplists:get_value(modules, AppData)); + validate_modules(AppName, + proplists:get_value(modules, AppData)); false -> ok end; @@ -102,13 +103,15 @@ preprocess(Config, AppSrcFile) -> AppFile = rebar_app_utils:app_src_to_app(AppSrcFile), ok = file:write_file(AppFile, Spec), - %% Make certain that the ebin/ directory is available on the code path + %% Make certain that the ebin/ directory is available + %% on the code path true = code:add_path(filename:absname(filename:dirname(AppFile))), AppFile; {error, Reason} -> - ?ABORT("Failed to read ~s for preprocessing: ~p\n", [AppSrcFile, Reason]) + ?ABORT("Failed to read ~s for preprocessing: ~p\n", + [AppSrcFile, Reason]) end. load_app_vars(Config) -> @@ -129,23 +132,25 @@ apply_app_vars([{Key, Value} | Rest], AppData) -> apply_app_vars(Rest, AppData2). validate_name(AppName, File) -> - %% Convert the .app file name to an atom -- check it against the identifier within the file + %% Convert the .app file name to an atom -- check it against the + %% identifier within the file ExpApp = list_to_atom(filename:basename(File, ".app")), case ExpApp == AppName of true -> ok; false -> - ?ERROR("Invalid ~s: name of application (~p) must match filename.\n", - [File, AppName]), + ?ERROR("Invalid ~s: name of application (~p) " + "must match filename.\n", [File, AppName]), ?FAIL end. validate_modules(AppName, undefined) -> - ?ERROR("Missing modules declaration in~p.app:\n", [AppName]), - ?FAIL; + ?ERROR("Missing modules declaration in~p.app:\n", [AppName]), + ?FAIL; validate_modules(AppName, Mods) -> - %% Construct two sets -- one for the actual .beam files in ebin/ and one for the modules + %% Construct two sets -- one for the actual .beam files in ebin/ + %% and one for the modules %% listed in the .app file EbinSet = ordsets:from_list(ebin_modules()), ModSet = ordsets:from_list(Mods), @@ -155,9 +160,10 @@ validate_modules(AppName, Mods) -> [] -> ok; MissingBeams -> - Msg1 = lists:flatten([io_lib:format("\t* ~p\n", [M]) || M <- MissingBeams]), - ?ERROR("One or more modules listed in ~p.app are not present in ebin/*.beam:\n~s", - [AppName, Msg1]), + Msg1 = lists:flatten([io_lib:format("\t* ~p\n", [M]) || + M <- MissingBeams]), + ?ERROR("One or more modules listed in ~p.app are not " + "present in ebin/*.beam:\n~s", [AppName, Msg1]), ?FAIL end, @@ -166,11 +172,13 @@ validate_modules(AppName, Mods) -> [] -> ok; MissingMods -> - Msg2 = lists:flatten([io_lib:format("\t* ~p\n", [M]) || M <- MissingMods]), - ?ERROR("One or more .beam files exist that are not listed in ~p.app:\n~s", - [AppName, Msg2]), + Msg2 = lists:flatten([io_lib:format("\t* ~p\n", [M]) || + M <- MissingMods]), + ?ERROR("One or more .beam files exist that are not " + "listed in ~p.app:\n~s", [AppName, Msg2]), ?FAIL end. ebin_modules() -> - lists:sort([rebar_utils:beam_to_mod("ebin", N) || N <- rebar_utils:beams("ebin")]). + lists:sort([rebar_utils:beam_to_mod("ebin", N) || + N <- rebar_utils:beams("ebin")]). -- cgit v1.1 From b0860da1241e482e5125714e1cd343c9d734db10 Mon Sep 17 00:00:00 2001 From: Adam Kocoloski Date: Thu, 2 Dec 2010 17:12:54 -0500 Subject: Expand {vsn,git} in app.src to git-describe output --- src/rebar_otp_app.erl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/rebar_otp_app.erl') diff --git a/src/rebar_otp_app.erl b/src/rebar_otp_app.erl index 4f21a67..f92de5c 100644 --- a/src/rebar_otp_app.erl +++ b/src/rebar_otp_app.erl @@ -96,8 +96,13 @@ preprocess(Config, AppSrcFile) -> AppVars = load_app_vars(Config) ++ [{modules, ebin_modules()}], A1 = apply_app_vars(AppVars, AppData), + + %% AppSrcFile may contain instructions for generating a vsn number + Vsn = rebar_app_utils:app_vsn(AppSrcFile), + A2 = lists:keystore(vsn, 1, A1, {vsn, Vsn}), + %% Build the final spec as a string - Spec = io_lib:format("~p.\n", [{application, AppName, A1}]), + Spec = io_lib:format("~p.\n", [{application, AppName, A2}]), %% Setup file .app filename and write new contents AppFile = rebar_app_utils:app_src_to_app(AppSrcFile), -- cgit v1.1