mirror of
https://github.com/correl/rebar.git
synced 2024-12-24 03:00:16 +00:00
Do not use application:set_env
This commit is contained in:
parent
3c56fbab6f
commit
252757c753
18 changed files with 320 additions and 292 deletions
|
@ -50,9 +50,6 @@
|
|||
%% Default log level
|
||||
{log_level, error},
|
||||
|
||||
%% Default parallel jobs
|
||||
{jobs, 3},
|
||||
|
||||
%% any_dir processing modules
|
||||
{any_dir_modules, [
|
||||
rebar_require_vsn,
|
||||
|
|
193
src/rebar.erl
193
src/rebar.erl
|
@ -29,7 +29,8 @@
|
|||
-export([main/1,
|
||||
help/0,
|
||||
parse_args/1,
|
||||
version/0]).
|
||||
version/0,
|
||||
get_jobs/1]).
|
||||
|
||||
-include("rebar.hrl").
|
||||
|
||||
|
@ -45,6 +46,8 @@
|
|||
-define(OTP_INFO, "undefined").
|
||||
-endif.
|
||||
|
||||
-define(DEFAULT_JOBS, 3).
|
||||
|
||||
%% ====================================================================
|
||||
%% Public API
|
||||
%% ====================================================================
|
||||
|
@ -66,55 +69,39 @@ main(Args) ->
|
|||
%% Internal functions
|
||||
%% ====================================================================
|
||||
|
||||
run(["help"]) ->
|
||||
help();
|
||||
run(["version"]) ->
|
||||
ok = load_rebar_app(),
|
||||
%% Display vsn and build time info
|
||||
version();
|
||||
run(RawArgs) ->
|
||||
%% Pre-load the rebar app so that we get default configuration
|
||||
ok = application:load(rebar),
|
||||
ok = load_rebar_app(),
|
||||
%% Parse out command line arguments -- what's left is a list of commands to
|
||||
%% run -- and start running commands
|
||||
Args = parse_args(RawArgs),
|
||||
BaseConfig = init_config(Args),
|
||||
{BaseConfig1, Cmds} = save_options(BaseConfig, Args),
|
||||
|
||||
case rebar_config:get_global(enable_profiling, false) of
|
||||
case rebar_config:get_xconf(BaseConfig1, enable_profiling, false) of
|
||||
true ->
|
||||
io:format("Profiling!\n"),
|
||||
try
|
||||
fprof:apply(fun(A) -> run_aux(A) end, [Args])
|
||||
fprof:apply(fun([C, A]) -> run_aux(C, A) end,
|
||||
[BaseConfig1, Cmds])
|
||||
after
|
||||
fprof:profile(),
|
||||
fprof:analyse([{dest, "fprof.analysis"}])
|
||||
end;
|
||||
_ ->
|
||||
run_aux(Args)
|
||||
false ->
|
||||
run_aux(BaseConfig1, Cmds)
|
||||
end.
|
||||
|
||||
run_aux(["help"]) ->
|
||||
help(),
|
||||
ok;
|
||||
run_aux(["version"]) ->
|
||||
%% Display vsn and build time info
|
||||
version(),
|
||||
ok;
|
||||
run_aux(Commands) ->
|
||||
%% Make sure crypto is running
|
||||
case crypto:start() of
|
||||
ok -> ok;
|
||||
{error,{already_started,crypto}} -> ok
|
||||
end,
|
||||
|
||||
%% Initialize logging system
|
||||
rebar_log:init(),
|
||||
|
||||
%% Convert command strings to atoms
|
||||
CommandAtoms = [list_to_atom(C) || C <- Commands],
|
||||
|
||||
%% Determine the location of the rebar executable; important for pulling
|
||||
%% resources out of the escript
|
||||
rebar_config:set_global(escript, filename:absname(escript:script_name())),
|
||||
?DEBUG("Rebar location: ~p\n",
|
||||
[rebar_config:get_global(escript, undefined)]),
|
||||
|
||||
%% Note the top-level directory for reference
|
||||
rebar_config:set_global(base_dir, filename:absname(rebar_utils:get_cwd())),
|
||||
load_rebar_app() ->
|
||||
%% Pre-load the rebar app so that we get default configuration
|
||||
ok = application:load(rebar).
|
||||
|
||||
init_config({Options, _NonOptArgs}) ->
|
||||
%% If $HOME/.rebar/config exists load and use as global config
|
||||
GlobalConfigFile = filename:join([os:getenv("HOME"), ".rebar", "config"]),
|
||||
GlobalConfig = case filelib:is_regular(GlobalConfigFile) of
|
||||
|
@ -125,12 +112,45 @@ run_aux(Commands) ->
|
|||
false ->
|
||||
rebar_config:new()
|
||||
end,
|
||||
BaseConfig = rebar_config:base_config(GlobalConfig),
|
||||
|
||||
%% Set the rebar config to use
|
||||
GlobalConfig1 = case proplists:get_value(config, Options) of
|
||||
undefined ->
|
||||
GlobalConfig;
|
||||
Conf ->
|
||||
rebar_config:set_global(GlobalConfig, config, Conf)
|
||||
end,
|
||||
|
||||
GlobalConfig2 = set_log_level(GlobalConfig1, Options),
|
||||
%% Initialize logging system
|
||||
ok = rebar_log:init(GlobalConfig2),
|
||||
|
||||
BaseConfig = rebar_config:base_config(GlobalConfig2),
|
||||
|
||||
%% Keep track of how many operations we do, so we can detect bad commands
|
||||
BaseConfig1 = rebar_config:set_xconf(BaseConfig, operations, 0),
|
||||
%% Initialize vsn cache
|
||||
BaseConfig2 = rebar_config:set_xconf(BaseConfig1, vsn_cache, dict:new()),
|
||||
rebar_config:set_xconf(BaseConfig1, vsn_cache, dict:new()).
|
||||
|
||||
run_aux(BaseConfig, Commands) ->
|
||||
%% Make sure crypto is running
|
||||
case crypto:start() of
|
||||
ok -> ok;
|
||||
{error,{already_started,crypto}} -> ok
|
||||
end,
|
||||
|
||||
%% Convert command strings to atoms
|
||||
CommandAtoms = [list_to_atom(C) || C <- Commands],
|
||||
|
||||
%% Determine the location of the rebar executable; important for pulling
|
||||
%% resources out of the escript
|
||||
ScriptName = filename:absname(escript:script_name()),
|
||||
BaseConfig1 = rebar_config:set_xconf(BaseConfig, escript, ScriptName),
|
||||
?DEBUG("Rebar location: ~p\n", [ScriptName]),
|
||||
|
||||
%% Note the top-level directory for reference
|
||||
AbsCwd = filename:absname(rebar_utils:get_cwd()),
|
||||
BaseConfig2 = rebar_config:set_xconf(BaseConfig1, base_dir, AbsCwd),
|
||||
|
||||
%% Process each command, resetting any state between each one
|
||||
rebar_core:process_commands(CommandAtoms, BaseConfig2).
|
||||
|
@ -149,63 +169,59 @@ help() ->
|
|||
%% Parse command line arguments using getopt and also filtering out any
|
||||
%% key=value pairs. What's left is the list of commands to run
|
||||
%%
|
||||
parse_args(Args) ->
|
||||
parse_args(RawArgs) ->
|
||||
%% Parse getopt options
|
||||
OptSpecList = option_spec_list(),
|
||||
case getopt:parse(OptSpecList, Args) of
|
||||
{ok, {Options, NonOptArgs}} ->
|
||||
%% Check options and maybe halt execution
|
||||
ok = show_info_maybe_halt(Options, NonOptArgs),
|
||||
|
||||
GlobalDefines = proplists:get_all_values(defines, Options),
|
||||
rebar_config:set_global(defines, GlobalDefines),
|
||||
|
||||
%% Setup profiling flag
|
||||
rebar_config:set_global(enable_profiling,
|
||||
proplists:get_bool(profile, Options)),
|
||||
|
||||
%% Setup flag to keep running after a single command fails
|
||||
rebar_config:set_global(keep_going,
|
||||
proplists:get_bool(keep_going, Options)),
|
||||
|
||||
%% Set global variables based on getopt options
|
||||
set_log_level(Options),
|
||||
set_global_flag(Options, force),
|
||||
DefJobs = rebar_config:get_jobs(),
|
||||
case proplists:get_value(jobs, Options, DefJobs) of
|
||||
DefJobs ->
|
||||
ok;
|
||||
Jobs ->
|
||||
rebar_config:set_global(jobs, Jobs)
|
||||
end,
|
||||
|
||||
%% Set the rebar config to use
|
||||
case proplists:get_value(config, Options) of
|
||||
undefined -> ok;
|
||||
Conf -> rebar_config:set_global(config, Conf)
|
||||
end,
|
||||
|
||||
%% Filter all the flags (i.e. strings of form key=value) from the
|
||||
%% command line arguments. What's left will be the commands to run.
|
||||
unabbreviate_command_names(filter_flags(NonOptArgs, []));
|
||||
|
||||
case getopt:parse(OptSpecList, RawArgs) of
|
||||
{ok, Args} ->
|
||||
Args;
|
||||
{error, {Reason, Data}} ->
|
||||
?ERROR("~s ~p~n~n", [Reason, Data]),
|
||||
help(),
|
||||
rebar_utils:delayed_halt(1)
|
||||
end.
|
||||
|
||||
save_options(Config, {Options, NonOptArgs}) ->
|
||||
%% Check options and maybe halt execution
|
||||
ok = show_info_maybe_halt(Options, NonOptArgs),
|
||||
|
||||
GlobalDefines = proplists:get_all_values(defines, Options),
|
||||
|
||||
Config1 = rebar_config:set_xconf(Config, defines, GlobalDefines),
|
||||
|
||||
%% Setup profiling flag
|
||||
Config2 = rebar_config:set_xconf(Config1, enable_profiling,
|
||||
proplists:get_bool(profile, Options)),
|
||||
|
||||
%% Setup flag to keep running after a single command fails
|
||||
Config3 = rebar_config:set_xconf(Config2, keep_going,
|
||||
proplists:get_bool(keep_going, Options)),
|
||||
|
||||
%% Set global variables based on getopt options
|
||||
Config4 = set_global_flag(Config3, Options, force),
|
||||
Config5 = case proplists:get_value(jobs, Options, ?DEFAULT_JOBS) of
|
||||
?DEFAULT_JOBS ->
|
||||
Config4;
|
||||
Jobs ->
|
||||
rebar_config:set_global(Config4, jobs, Jobs)
|
||||
end,
|
||||
|
||||
%% Filter all the flags (i.e. strings of form key=value) from the
|
||||
%% command line arguments. What's left will be the commands to run.
|
||||
{Config6, RawCmds} = filter_flags(Config5, NonOptArgs, []),
|
||||
{Config6, unabbreviate_command_names(RawCmds)}.
|
||||
|
||||
%%
|
||||
%% set log level based on getopt option
|
||||
%%
|
||||
set_log_level(Options) ->
|
||||
set_log_level(Config, Options) ->
|
||||
LogLevel = case proplists:get_all_values(verbose, Options) of
|
||||
[] ->
|
||||
rebar_log:default_level();
|
||||
Verbosities ->
|
||||
lists:last(Verbosities)
|
||||
end,
|
||||
rebar_config:set_global(verbose, LogLevel).
|
||||
rebar_config:set_global(Config, verbose, LogLevel).
|
||||
|
||||
%%
|
||||
%% show version information and halt
|
||||
|
@ -219,14 +235,14 @@ version() ->
|
|||
%%
|
||||
%% set global flag based on getopt option boolean value
|
||||
%%
|
||||
set_global_flag(Options, Flag) ->
|
||||
set_global_flag(Config, Options, Flag) ->
|
||||
Value = case proplists:get_bool(Flag, Options) of
|
||||
true ->
|
||||
"1";
|
||||
false ->
|
||||
"0"
|
||||
end,
|
||||
rebar_config:set_global(Flag, Value).
|
||||
rebar_config:set_global(Config, Flag, Value).
|
||||
|
||||
%%
|
||||
%% show info and maybe halt execution
|
||||
|
@ -291,11 +307,14 @@ version Show version information
|
|||
">>,
|
||||
io:put_chars(S).
|
||||
|
||||
get_jobs(Config) ->
|
||||
rebar_config:get_global(Config, jobs, ?DEFAULT_JOBS).
|
||||
|
||||
%%
|
||||
%% options accepted via getopt
|
||||
%%
|
||||
option_spec_list() ->
|
||||
Jobs = rebar_config:get_jobs(),
|
||||
Jobs = ?DEFAULT_JOBS,
|
||||
JobsHelp = io_lib:format(
|
||||
"Number of concurrent workers a command may use. Default: ~B",
|
||||
[Jobs]),
|
||||
|
@ -319,12 +338,12 @@ option_spec_list() ->
|
|||
%% Seperate all commands (single-words) from flags (key=value) and store
|
||||
%% values into the rebar_config global storage.
|
||||
%%
|
||||
filter_flags([], Commands) ->
|
||||
lists:reverse(Commands);
|
||||
filter_flags([Item | Rest], Commands) ->
|
||||
filter_flags(Config, [], Commands) ->
|
||||
{Config, lists:reverse(Commands)};
|
||||
filter_flags(Config, [Item | Rest], Commands) ->
|
||||
case string:tokens(Item, "=") of
|
||||
[Command] ->
|
||||
filter_flags(Rest, [Command | Commands]);
|
||||
filter_flags(Config, Rest, [Command | Commands]);
|
||||
[KeyStr, RawValue] ->
|
||||
Key = list_to_atom(KeyStr),
|
||||
Value = case Key of
|
||||
|
@ -333,11 +352,11 @@ filter_flags([Item | Rest], Commands) ->
|
|||
_ ->
|
||||
RawValue
|
||||
end,
|
||||
rebar_config:set_global(Key, Value),
|
||||
filter_flags(Rest, Commands);
|
||||
Config1 = rebar_config:set_global(Config, Key, Value),
|
||||
filter_flags(Config1, Rest, Commands);
|
||||
Other ->
|
||||
?CONSOLE("Ignoring command line argument: ~p\n", [Other]),
|
||||
filter_flags(Rest, Commands)
|
||||
filter_flags(Config, Rest, Commands)
|
||||
end.
|
||||
|
||||
command_names() ->
|
||||
|
|
|
@ -111,10 +111,10 @@ is_skipped_app(Config, AppFile) ->
|
|||
%% Check for apps global parameter; this is a comma-delimited list
|
||||
%% of apps on which we want to run commands
|
||||
Skipped =
|
||||
case get_apps() of
|
||||
case get_apps(Config) of
|
||||
undefined ->
|
||||
%% No apps parameter specified, check the skip_apps list..
|
||||
case get_skip_apps() of
|
||||
case get_skip_apps(Config) of
|
||||
undefined ->
|
||||
%% No skip_apps list, run everything..
|
||||
false;
|
||||
|
@ -136,8 +136,8 @@ is_skipped_app(Config, AppFile) ->
|
|||
|
||||
load_app_file(Config, Filename) ->
|
||||
AppFile = {app_file, Filename},
|
||||
case rebar_config:get_xconf(Config, {appfile, AppFile}) of
|
||||
error ->
|
||||
case rebar_config:get_xconf(Config, {appfile, AppFile}, undefined) of
|
||||
undefined ->
|
||||
case file:consult(Filename) of
|
||||
{ok, [{application, AppName, AppData}]} ->
|
||||
Config1 = rebar_config:set_xconf(Config,
|
||||
|
@ -149,7 +149,7 @@ load_app_file(Config, Filename) ->
|
|||
Other ->
|
||||
{error, {unexpected_terms, Other}}
|
||||
end;
|
||||
{ok, {AppName, AppData}} ->
|
||||
{AppName, AppData} ->
|
||||
{ok, Config, AppName, AppData}
|
||||
end.
|
||||
|
||||
|
@ -179,8 +179,8 @@ is_skipped(ThisApp, TargetApps) ->
|
|||
{true, ThisApp}
|
||||
end.
|
||||
|
||||
get_apps() ->
|
||||
rebar_utils:get_deprecated_global(app, apps, "soon").
|
||||
get_apps(Config) ->
|
||||
rebar_utils:get_deprecated_global(Config, app, apps, "soon").
|
||||
|
||||
get_skip_apps() ->
|
||||
rebar_utils:get_deprecated_global(skip_app, skip_apps, "soon").
|
||||
get_skip_apps(Config) ->
|
||||
rebar_utils:get_deprecated_global(Config, skip_app, skip_apps, "soon").
|
||||
|
|
|
@ -41,10 +41,11 @@
|
|||
'generate-appups'(Config, ReltoolFile) ->
|
||||
%% Get the old release path
|
||||
{Config1, ReltoolConfig} = rebar_rel_utils:load_config(Config, ReltoolFile),
|
||||
TargetParentDir = rebar_rel_utils:get_target_parent_dir(ReltoolConfig),
|
||||
TargetParentDir = rebar_rel_utils:get_target_parent_dir(Config,
|
||||
ReltoolConfig),
|
||||
|
||||
OldVerPath = filename:join([TargetParentDir,
|
||||
rebar_rel_utils:get_previous_release_path()]),
|
||||
PrevRelPath = rebar_rel_utils:get_previous_release_path(Config),
|
||||
OldVerPath = filename:join([TargetParentDir, PrevRelPath]),
|
||||
|
||||
%% Get the new and old release name and versions
|
||||
{Name, _Ver} = rebar_rel_utils:get_reltool_release_info(ReltoolConfig),
|
||||
|
|
|
@ -47,7 +47,7 @@ run(Config, FirstFiles, RestFiles, CompileFn) ->
|
|||
_ ->
|
||||
Self = self(),
|
||||
F = fun() -> compile_worker(Self, Config, CompileFn) end,
|
||||
Jobs = rebar_config:get_jobs(),
|
||||
Jobs = rebar:get_jobs(Config),
|
||||
?DEBUG("Starting ~B compile worker(s)~n", [Jobs]),
|
||||
Pids = [spawn_monitor(F) || _I <- lists:seq(1,Jobs)],
|
||||
compile_queue(Pids, RestFiles)
|
||||
|
|
|
@ -30,17 +30,18 @@
|
|||
get/3, get_local/3, get_list/3,
|
||||
get_all/2,
|
||||
set/3,
|
||||
set_global/2, get_global/2,
|
||||
is_verbose/0, get_jobs/0,
|
||||
set_global/3, get_global/3,
|
||||
is_verbose/1,
|
||||
set_env/3, get_env/2, reset_env/1,
|
||||
set_skip_dir/2, is_skip_dir/2, reset_skip_dirs/1,
|
||||
clean_config/2,
|
||||
set_xconf/3, get_xconf/2, erase_xconf/2, reset_xconf/1]).
|
||||
set_xconf/3, get_xconf/2, get_xconf/3, erase_xconf/2]).
|
||||
|
||||
-include("rebar.hrl").
|
||||
|
||||
-record(config, { dir :: file:filename(),
|
||||
opts = [] :: list(),
|
||||
globals = new_globals() :: dict(),
|
||||
%% TODO: consider storing envs in xconf
|
||||
envs = new_env() :: dict(),
|
||||
%% cross-directory config
|
||||
|
@ -60,7 +61,7 @@
|
|||
%% ===================================================================
|
||||
|
||||
base_config(GlobalConfig) ->
|
||||
ConfName = rebar_config:get_global(config, ?DEFAULT_NAME),
|
||||
ConfName = rebar_config:get_global(GlobalConfig, config, ?DEFAULT_NAME),
|
||||
new(GlobalConfig, ConfName).
|
||||
|
||||
new() ->
|
||||
|
@ -74,8 +75,10 @@ new(ConfigFile) when is_list(ConfigFile) ->
|
|||
Other ->
|
||||
?ABORT("Failed to load ~s: ~p~n", [ConfigFile, Other])
|
||||
end;
|
||||
new(_ParentConfig=#config{opts=Opts0, skip_dirs=SkipDirs, xconf=Xconf})->
|
||||
new(#config{opts=Opts0, skip_dirs=SkipDirs, xconf=Xconf}, ?DEFAULT_NAME).
|
||||
new(_ParentConfig=#config{opts=Opts0, globals=Globals, skip_dirs=SkipDirs,
|
||||
xconf=Xconf}) ->
|
||||
new(#config{opts=Opts0, globals=Globals, skip_dirs=SkipDirs, xconf=Xconf},
|
||||
?DEFAULT_NAME).
|
||||
|
||||
get(Config, Key, Default) ->
|
||||
proplists:get_value(Key, Config#config.opts, Default).
|
||||
|
@ -93,27 +96,26 @@ set(Config, Key, Value) ->
|
|||
Opts = proplists:delete(Key, Config#config.opts),
|
||||
Config#config { opts = [{Key, Value} | Opts] }.
|
||||
|
||||
set_global(jobs=Key, Value) when is_list(Value) ->
|
||||
set_global(Key, list_to_integer(Value));
|
||||
set_global(jobs=Key, Value) when is_integer(Value) ->
|
||||
application:set_env(rebar_global, Key, erlang:max(1, Value));
|
||||
set_global(Key, Value) ->
|
||||
application:set_env(rebar_global, Key, Value).
|
||||
set_global(Config, jobs=Key, Value) when is_list(Value) ->
|
||||
set_global(Config, Key, list_to_integer(Value));
|
||||
set_global(Config, jobs=Key, Value) when is_integer(Value) ->
|
||||
NewGlobals = dict:store(Key, erlang:max(1, Value), Config#config.globals),
|
||||
Config#config{globals = NewGlobals};
|
||||
set_global(Config, Key, Value) ->
|
||||
NewGlobals = dict:store(Key, Value, Config#config.globals),
|
||||
Config#config{globals = NewGlobals}.
|
||||
|
||||
get_global(Key, Default) ->
|
||||
case application:get_env(rebar_global, Key) of
|
||||
undefined ->
|
||||
get_global(Config, Key, Default) ->
|
||||
case dict:find(Key, Config#config.globals) of
|
||||
error ->
|
||||
Default;
|
||||
{ok, Value} ->
|
||||
Value
|
||||
end.
|
||||
|
||||
is_verbose() ->
|
||||
is_verbose(Config) ->
|
||||
DefaulLevel = rebar_log:default_level(),
|
||||
get_global(verbose, DefaulLevel) > DefaulLevel.
|
||||
|
||||
get_jobs() ->
|
||||
get_global(jobs, 3).
|
||||
get_global(Config, verbose, DefaulLevel) > DefaulLevel.
|
||||
|
||||
consult_file(File) ->
|
||||
case filename:extension(File) of
|
||||
|
@ -162,15 +164,21 @@ set_xconf(Config, Key, Value) ->
|
|||
Config#config{xconf=NewXconf}.
|
||||
|
||||
get_xconf(Config, Key) ->
|
||||
dict:find(Key, Config#config.xconf).
|
||||
{ok, Value} = dict:find(Key, Config#config.xconf),
|
||||
Value.
|
||||
|
||||
get_xconf(Config, Key, Default) ->
|
||||
case dict:find(Key, Config#config.xconf) of
|
||||
error ->
|
||||
Default;
|
||||
{ok, Value} ->
|
||||
Value
|
||||
end.
|
||||
|
||||
erase_xconf(Config, Key) ->
|
||||
NewXconf = dict:erase(Key, Config#config.xconf),
|
||||
Config#config{xconf = NewXconf}.
|
||||
|
||||
reset_xconf(Config) ->
|
||||
Config#config{xconf = new_xconf()}.
|
||||
|
||||
%% TODO: reconsider after config inheritance removal/redesign
|
||||
clean_config(Old, New) ->
|
||||
New#config{opts=Old#config.opts}.
|
||||
|
@ -208,7 +216,6 @@ consult_and_eval(File, Script) ->
|
|||
ConfigData = try_consult(File),
|
||||
file:script(Script, bs([{'CONFIG', ConfigData}, {'SCRIPT', Script}])).
|
||||
|
||||
|
||||
remove_script_ext(F) ->
|
||||
"tpircs." ++ Rev = lists:reverse(F),
|
||||
lists:reverse(Rev).
|
||||
|
@ -236,6 +243,8 @@ local_opts([local | _Rest], Acc) ->
|
|||
local_opts([Item | Rest], Acc) ->
|
||||
local_opts(Rest, [Item | Acc]).
|
||||
|
||||
new_globals() -> dict:new().
|
||||
|
||||
new_env() -> dict:new().
|
||||
|
||||
new_skip_dirs() -> dict:new().
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
%% ===================================================================
|
||||
|
||||
process_commands([], ParentConfig) ->
|
||||
AbortTrapped = rebar_config:get_global(abort_trapped, false),
|
||||
AbortTrapped = rebar_config:get_xconf(ParentConfig, abort_trapped, false),
|
||||
case {get_operations(ParentConfig), AbortTrapped} of
|
||||
{0, _} ->
|
||||
%% None of the commands had any effect
|
||||
|
@ -49,7 +49,7 @@ process_commands([], ParentConfig) ->
|
|||
process_commands([Command | Rest], ParentConfig) ->
|
||||
%% Reset skip dirs
|
||||
ParentConfig1 = rebar_config:reset_skip_dirs(ParentConfig),
|
||||
Operations = rebar_config:get_xconf(ParentConfig1, operations),
|
||||
Operations = get_operations(ParentConfig1),
|
||||
|
||||
ParentConfig4 =
|
||||
try
|
||||
|
@ -75,13 +75,13 @@ process_commands([Command | Rest], ParentConfig) ->
|
|||
rebar_config:set_xconf(ParentConfig3, vsn_cache, dict:new())
|
||||
catch
|
||||
throw:rebar_abort ->
|
||||
case rebar_config:get_global(keep_going, false) of
|
||||
case rebar_config:get_xconf(ParentConfig1, keep_going, false) of
|
||||
false ->
|
||||
?ABORT;
|
||||
true ->
|
||||
?WARN("Continuing on after abort: ~p\n", [Rest]),
|
||||
rebar_config:set_global(abort_trapped, true),
|
||||
ParentConfig1
|
||||
rebar_config:set_xconf(ParentConfig1,
|
||||
abort_trapped, true)
|
||||
end
|
||||
end,
|
||||
process_commands(Rest, ParentConfig4).
|
||||
|
@ -242,15 +242,15 @@ remember_cwd_subdir(Cwd, Subdirs) ->
|
|||
maybe_load_local_config(Dir, ParentConfig) ->
|
||||
%% We need to ensure we don't overwrite custom
|
||||
%% config when we are dealing with base_dir.
|
||||
case processing_base_dir(Dir) of
|
||||
case processing_base_dir(ParentConfig, Dir) of
|
||||
true ->
|
||||
ParentConfig;
|
||||
false ->
|
||||
rebar_config:new(ParentConfig)
|
||||
end.
|
||||
|
||||
processing_base_dir(Dir) ->
|
||||
Dir == rebar_config:get_global(base_dir, undefined).
|
||||
processing_base_dir(Config, Dir) ->
|
||||
Dir == rebar_config:get_xconf(Config, base_dir).
|
||||
|
||||
%%
|
||||
%% Given a list of directories and a set of previously processed directories,
|
||||
|
@ -357,8 +357,7 @@ increment_operations(Config) ->
|
|||
rebar_config:set_xconf(Config, operations, Operations + 1).
|
||||
|
||||
get_operations(Config) ->
|
||||
{ok, Operations} = rebar_config:get_xconf(Config, operations),
|
||||
Operations.
|
||||
rebar_config:get_xconf(Config, operations).
|
||||
|
||||
update_code_path(Config) ->
|
||||
case rebar_config:get_local(Config, lib_dirs, []) of
|
||||
|
|
|
@ -64,7 +64,7 @@ run_test_if_present(TestDir, Config, File) ->
|
|||
run_test(TestDir, Config, _File) ->
|
||||
{Cmd, RawLog} = make_cmd(TestDir, Config),
|
||||
clear_log(RawLog),
|
||||
case rebar_config:is_verbose() of
|
||||
case rebar_config:is_verbose(Config) of
|
||||
false ->
|
||||
Output = " >> " ++ RawLog ++ " 2>&1";
|
||||
true ->
|
||||
|
@ -72,7 +72,7 @@ run_test(TestDir, Config, _File) ->
|
|||
end,
|
||||
|
||||
rebar_utils:sh(Cmd ++ Output, [{env,[{"TESTDIR", TestDir}]}]),
|
||||
check_log(RawLog).
|
||||
check_log(Config, RawLog).
|
||||
|
||||
|
||||
clear_log(RawLog) ->
|
||||
|
@ -88,7 +88,7 @@ clear_log(RawLog) ->
|
|||
|
||||
%% calling ct with erl does not return non-zero on failure - have to check
|
||||
%% log results
|
||||
check_log(RawLog) ->
|
||||
check_log(Config, RawLog) ->
|
||||
{ok, Msg} =
|
||||
rebar_utils:sh("grep -e 'TEST COMPLETE' -e '{error,make_failed}' "
|
||||
++ RawLog, [{use_stdout, false}]),
|
||||
|
@ -96,12 +96,12 @@ check_log(RawLog) ->
|
|||
RunFailed = string:str(Msg, ", 0 failed") =:= 0,
|
||||
if
|
||||
MakeFailed ->
|
||||
show_log(RawLog),
|
||||
show_log(Config, RawLog),
|
||||
?ERROR("Building tests failed\n",[]),
|
||||
?ABORT;
|
||||
|
||||
RunFailed ->
|
||||
show_log(RawLog),
|
||||
show_log(Config, RawLog),
|
||||
?ERROR("One or more tests failed\n",[]),
|
||||
?ABORT;
|
||||
|
||||
|
@ -110,9 +110,9 @@ check_log(RawLog) ->
|
|||
end.
|
||||
|
||||
%% Show the log if it hasn't already been shown because verbose was on
|
||||
show_log(RawLog) ->
|
||||
show_log(Config, RawLog) ->
|
||||
?CONSOLE("Showing log\n", []),
|
||||
case rebar_config:is_verbose() of
|
||||
case rebar_config:is_verbose(Config) of
|
||||
false ->
|
||||
{ok, Contents} = file:read_file(RawLog),
|
||||
?CONSOLE("~s", [Contents]);
|
||||
|
@ -159,8 +159,8 @@ make_cmd(TestDir, Config) ->
|
|||
get_cover_config(Config, Cwd) ++
|
||||
get_ct_config_file(TestDir) ++
|
||||
get_config_file(TestDir) ++
|
||||
get_suites(TestDir) ++
|
||||
get_case();
|
||||
get_suites(Config, TestDir) ++
|
||||
get_case(Config);
|
||||
SpecFlags ->
|
||||
?FMT("erl " % should we expand ERL_PATH?
|
||||
" -noshell -pa ~s ~s"
|
||||
|
@ -248,8 +248,8 @@ get_config_file(TestDir) ->
|
|||
" -config " ++ Config
|
||||
end.
|
||||
|
||||
get_suites(TestDir) ->
|
||||
case rebar_utils:get_deprecated_global(suite, suites, "soon") of
|
||||
get_suites(Config, TestDir) ->
|
||||
case rebar_utils:get_deprecated_global(Config, suite, suites, "soon") of
|
||||
undefined ->
|
||||
" -dir " ++ TestDir;
|
||||
Suites ->
|
||||
|
@ -268,8 +268,8 @@ find_suite_path(Suite, TestDir) ->
|
|||
Path
|
||||
end.
|
||||
|
||||
get_case() ->
|
||||
case rebar_config:get_global('case', undefined) of
|
||||
get_case(Config) ->
|
||||
case rebar_config:get_global(Config, 'case', undefined) of
|
||||
undefined ->
|
||||
"";
|
||||
Case ->
|
||||
|
|
|
@ -52,40 +52,41 @@ preprocess(Config, _) ->
|
|||
%% Side effect to set deps_dir globally for all dependencies from
|
||||
%% top level down. Means the root deps_dir is honoured or the default
|
||||
%% used globally since it will be set on the first time through here
|
||||
set_global_deps_dir(Config, rebar_config:get_global(deps_dir, [])),
|
||||
DepsDir = rebar_config:get_global(Config, deps_dir, []),
|
||||
Config1 = set_global_deps_dir(Config, DepsDir),
|
||||
|
||||
%% Get the list of deps for the current working directory and identify those
|
||||
%% deps that are available/present.
|
||||
Deps = rebar_config:get_local(Config, deps, []),
|
||||
{Config1, {AvailableDeps, MissingDeps}} = find_deps(Config, find, Deps),
|
||||
Deps = rebar_config:get_local(Config1, deps, []),
|
||||
{Config2, {AvailableDeps, MissingDeps}} = find_deps(Config1, find, Deps),
|
||||
|
||||
?DEBUG("Available deps: ~p\n", [AvailableDeps]),
|
||||
?DEBUG("Missing deps : ~p\n", [MissingDeps]),
|
||||
|
||||
%% Add available deps to code path
|
||||
Config2 = update_deps_code_path(Config1, AvailableDeps),
|
||||
Config3 = update_deps_code_path(Config2, AvailableDeps),
|
||||
|
||||
%% If skip_deps=true, mark each dep dir as a skip_dir w/ the core so that
|
||||
%% the current command doesn't run on the dep dir. However, pre/postprocess
|
||||
%% WILL run (and we want it to) for transitivity purposes.
|
||||
NewConfig = case rebar_config:get_global(skip_deps, false) of
|
||||
NewConfig = case rebar_config:get_global(Config3, skip_deps, false) of
|
||||
"true" ->
|
||||
lists:foldl(
|
||||
fun(#dep{dir = Dir}, C) ->
|
||||
rebar_config:set_skip_dir(C, Dir)
|
||||
end, Config2, AvailableDeps);
|
||||
end, Config3, AvailableDeps);
|
||||
_ ->
|
||||
Config2
|
||||
Config3
|
||||
end,
|
||||
|
||||
%% Return all the available dep directories for process
|
||||
{ok, NewConfig, dep_dirs(AvailableDeps)}.
|
||||
|
||||
postprocess(Config, _) ->
|
||||
case rebar_config:get_xconf(Config, ?MODULE) of
|
||||
error ->
|
||||
case rebar_config:get_xconf(Config, ?MODULE, undefined) of
|
||||
undefined ->
|
||||
{ok, []};
|
||||
{ok, Dirs} ->
|
||||
Dirs ->
|
||||
NewConfig = rebar_config:erase_xconf(Config, ?MODULE),
|
||||
{ok, NewConfig, Dirs}
|
||||
end.
|
||||
|
@ -94,8 +95,8 @@ compile(Config, AppFile) ->
|
|||
'check-deps'(Config, AppFile).
|
||||
|
||||
%% set REBAR_DEPS_DIR and ERL_LIBS environment variables
|
||||
setup_env(_Config) ->
|
||||
{true, DepsDir} = get_deps_dir(),
|
||||
setup_env(Config) ->
|
||||
{true, DepsDir} = get_deps_dir(Config),
|
||||
%% include rebar's DepsDir in ERL_LIBS
|
||||
Separator = case os:type() of
|
||||
{win32, nt} ->
|
||||
|
@ -149,7 +150,8 @@ setup_env(_Config) ->
|
|||
{Config1, Deps} = find_deps(Config, read, RawDeps),
|
||||
|
||||
%% Update each dep
|
||||
UpdatedDeps = [update_source(D) || D <- Deps, D#dep.source =/= undefined],
|
||||
UpdatedDeps = [update_source(Config1, D)
|
||||
|| D <- Deps, D#dep.source =/= undefined],
|
||||
|
||||
%% Add each updated dep to our list of dirs for post-processing. This yields
|
||||
%% the necessary transitivity of the deps
|
||||
|
@ -157,7 +159,7 @@ setup_env(_Config) ->
|
|||
|
||||
'delete-deps'(Config, _) ->
|
||||
%% Delete all the available deps in our deps/ directory, if any
|
||||
{true, DepsDir} = get_deps_dir(),
|
||||
{true, DepsDir} = get_deps_dir(Config),
|
||||
Deps = rebar_config:get_local(Config, deps, []),
|
||||
{Config1, {AvailableDeps, _}} = find_deps(Config, find, Deps),
|
||||
_ = [delete_dep(D)
|
||||
|
@ -183,17 +185,17 @@ setup_env(_Config) ->
|
|||
%% need all deps in same dir and should be the one set by the root rebar.config
|
||||
%% Sets a default if root config has no deps_dir set
|
||||
set_global_deps_dir(Config, []) ->
|
||||
rebar_config:set_global(deps_dir,
|
||||
rebar_config:set_global(Config, deps_dir,
|
||||
rebar_config:get_local(Config, deps_dir, "deps"));
|
||||
set_global_deps_dir(_Config, _DepsDir) ->
|
||||
ok.
|
||||
set_global_deps_dir(Config, _DepsDir) ->
|
||||
Config.
|
||||
|
||||
get_deps_dir() ->
|
||||
get_deps_dir("").
|
||||
get_deps_dir(Config) ->
|
||||
get_deps_dir(Config, "").
|
||||
|
||||
get_deps_dir(App) ->
|
||||
BaseDir = rebar_config:get_global(base_dir, []),
|
||||
DepsDir = rebar_config:get_global(deps_dir, "deps"),
|
||||
get_deps_dir(Config, App) ->
|
||||
BaseDir = rebar_config:get_xconf(Config, base_dir, []),
|
||||
DepsDir = rebar_config:get_global(Config, deps_dir, "deps"),
|
||||
{true, filename:join([BaseDir, DepsDir, App])}.
|
||||
|
||||
dep_dirs(Deps) ->
|
||||
|
@ -262,7 +264,7 @@ find_dep(Config, Dep) ->
|
|||
find_dep(Config, Dep, undefined) ->
|
||||
%% 'source' is undefined. If Dep is not satisfied locally,
|
||||
%% go ahead and find it amongst the lib_dir's.
|
||||
case find_dep_in_dir(Config, Dep, get_deps_dir(Dep#dep.app)) of
|
||||
case find_dep_in_dir(Config, Dep, get_deps_dir(Config, Dep#dep.app)) of
|
||||
{_Config1, {avail, _Dir}} = Avail ->
|
||||
Avail;
|
||||
{Config1, {missing, _}} ->
|
||||
|
@ -272,7 +274,7 @@ find_dep(Config, Dep, _Source) ->
|
|||
%% _Source is defined. Regardless of what it is, we must find it
|
||||
%% locally satisfied or fetch it from the original source
|
||||
%% into the project's deps
|
||||
find_dep_in_dir(Config, Dep, get_deps_dir(Dep#dep.app)).
|
||||
find_dep_in_dir(Config, Dep, get_deps_dir(Config, Dep#dep.app)).
|
||||
|
||||
find_dep_in_dir(Config, _Dep, {false, Dir}) ->
|
||||
{Config, {missing, Dir}};
|
||||
|
@ -365,7 +367,7 @@ use_source(Config, Dep, Count) ->
|
|||
false ->
|
||||
?CONSOLE("Pulling ~p from ~p\n", [Dep#dep.app, Dep#dep.source]),
|
||||
require_source_engine(Dep#dep.source),
|
||||
{true, TargetDir} = get_deps_dir(Dep#dep.app),
|
||||
{true, TargetDir} = get_deps_dir(Config, Dep#dep.app),
|
||||
download_source(TargetDir, Dep#dep.source),
|
||||
use_source(Config, Dep#dep { dir = TargetDir }, Count-1)
|
||||
end.
|
||||
|
@ -408,17 +410,17 @@ download_source(AppDir, {rsync, Url}) ->
|
|||
ok = filelib:ensure_dir(AppDir),
|
||||
rebar_utils:sh(?FMT("rsync -az --delete ~s/ ~s", [Url, AppDir]), []).
|
||||
|
||||
update_source(Dep) ->
|
||||
update_source(Config, Dep) ->
|
||||
%% It's possible when updating a source, that a given dep does not have a
|
||||
%% VCS directory, such as when a source archive is built of a project, with
|
||||
%% all deps already downloaded/included. So, verify that the necessary VCS
|
||||
%% directory exists before attempting to do the update.
|
||||
{true, AppDir} = get_deps_dir(Dep#dep.app),
|
||||
{true, AppDir} = get_deps_dir(Config, Dep#dep.app),
|
||||
case has_vcs_dir(element(1, Dep#dep.source), AppDir) of
|
||||
true ->
|
||||
?CONSOLE("Updating ~p from ~p\n", [Dep#dep.app, Dep#dep.source]),
|
||||
require_source_engine(Dep#dep.source),
|
||||
update_source(AppDir, Dep#dep.source),
|
||||
update_source1(AppDir, Dep#dep.source),
|
||||
Dep;
|
||||
false ->
|
||||
?WARN("Skipping update for ~p: "
|
||||
|
@ -426,29 +428,29 @@ update_source(Dep) ->
|
|||
Dep
|
||||
end.
|
||||
|
||||
update_source(AppDir, {git, Url}) ->
|
||||
update_source(AppDir, {git, Url, {branch, "HEAD"}});
|
||||
update_source(AppDir, {git, Url, ""}) ->
|
||||
update_source(AppDir, {git, Url, {branch, "HEAD"}});
|
||||
update_source(AppDir, {git, _Url, {branch, Branch}}) ->
|
||||
update_source1(AppDir, {git, Url}) ->
|
||||
update_source1(AppDir, {git, Url, {branch, "HEAD"}});
|
||||
update_source1(AppDir, {git, Url, ""}) ->
|
||||
update_source1(AppDir, {git, Url, {branch, "HEAD"}});
|
||||
update_source1(AppDir, {git, _Url, {branch, Branch}}) ->
|
||||
ShOpts = [{cd, AppDir}],
|
||||
rebar_utils:sh("git fetch origin", ShOpts),
|
||||
rebar_utils:sh(?FMT("git checkout -q origin/~s", [Branch]), ShOpts);
|
||||
update_source(AppDir, {git, _Url, {tag, Tag}}) ->
|
||||
update_source1(AppDir, {git, _Url, {tag, Tag}}) ->
|
||||
ShOpts = [{cd, AppDir}],
|
||||
rebar_utils:sh("git fetch --tags origin", ShOpts),
|
||||
rebar_utils:sh(?FMT("git checkout -q ~s", [Tag]), ShOpts);
|
||||
update_source(AppDir, {git, _Url, Refspec}) ->
|
||||
update_source1(AppDir, {git, _Url, Refspec}) ->
|
||||
ShOpts = [{cd, AppDir}],
|
||||
rebar_utils:sh("git fetch origin", ShOpts),
|
||||
rebar_utils:sh(?FMT("git checkout -q ~s", [Refspec]), ShOpts);
|
||||
update_source(AppDir, {svn, _Url, Rev}) ->
|
||||
update_source1(AppDir, {svn, _Url, Rev}) ->
|
||||
rebar_utils:sh(?FMT("svn up -r ~s", [Rev]), [{cd, AppDir}]);
|
||||
update_source(AppDir, {hg, _Url, Rev}) ->
|
||||
update_source1(AppDir, {hg, _Url, Rev}) ->
|
||||
rebar_utils:sh(?FMT("hg pull -u -r ~s", [Rev]), [{cd, AppDir}]);
|
||||
update_source(AppDir, {bzr, _Url, Rev}) ->
|
||||
update_source1(AppDir, {bzr, _Url, Rev}) ->
|
||||
rebar_utils:sh(?FMT("bzr update -r ~s", [Rev]), [{cd, AppDir}]);
|
||||
update_source(AppDir, {rsync, Url}) ->
|
||||
update_source1(AppDir, {rsync, Url}) ->
|
||||
rebar_utils:sh(?FMT("rsync -az --delete ~s/ ~s",[Url,AppDir]),[]).
|
||||
|
||||
%% ===================================================================
|
||||
|
|
|
@ -139,7 +139,7 @@ eunit(Config, _AppFile) ->
|
|||
ModuleBeamFiles = BeamFiles ++ OtherBeamFiles,
|
||||
Modules = [rebar_utils:beam_to_mod(?EUNIT_DIR, N) || N <- ModuleBeamFiles],
|
||||
SrcModules = [rebar_utils:erl_to_mod(M) || M <- SrcErls],
|
||||
FilteredModules = filter_modules(Modules),
|
||||
FilteredModules = filter_modules(Config, Modules),
|
||||
|
||||
{ok, CoverLog} = cover_init(Config, ModuleBeamFiles),
|
||||
|
||||
|
@ -181,14 +181,15 @@ eunit_dir() ->
|
|||
ebin_dir() ->
|
||||
filename:join(rebar_utils:get_cwd(), "ebin").
|
||||
|
||||
filter_modules(Modules) ->
|
||||
RawSuites = rebar_utils:get_deprecated_global(suite, suites, [], "soon"),
|
||||
filter_modules(Config, Modules) ->
|
||||
RawSuites = rebar_utils:get_deprecated_global(Config, suite, suites,
|
||||
[], "soon"),
|
||||
Suites = [list_to_atom(Suite) || Suite <- string:tokens(RawSuites, ",")],
|
||||
filter_modules(Modules, Suites).
|
||||
filter_modules1(Modules, Suites).
|
||||
|
||||
filter_modules(Modules, []) ->
|
||||
filter_modules1(Modules, []) ->
|
||||
Modules;
|
||||
filter_modules(Modules, Suites) ->
|
||||
filter_modules1(Modules, Suites) ->
|
||||
[M || M <- Modules, lists:member(M, Suites)].
|
||||
|
||||
perform_eunit(Config, FilteredModules) ->
|
||||
|
@ -208,7 +209,7 @@ perform_eunit(Config, FilteredModules) ->
|
|||
|
||||
get_eunit_opts(Config) ->
|
||||
%% Enable verbose in eunit if so requested..
|
||||
BaseOpts = case rebar_config:is_verbose() of
|
||||
BaseOpts = case rebar_config:is_verbose(Config) of
|
||||
true ->
|
||||
[verbose];
|
||||
false ->
|
||||
|
@ -247,8 +248,8 @@ define_if(Def, true) -> [{d, Def}];
|
|||
define_if(_Def, false) -> [].
|
||||
|
||||
is_lib_avail(Config, DictKey, Mod, Hrl, Name) ->
|
||||
case rebar_config:get_xconf(Config, DictKey) of
|
||||
error ->
|
||||
case rebar_config:get_xconf(Config, DictKey, undefined) of
|
||||
undefined ->
|
||||
IsAvail = case code:lib_dir(Mod, include) of
|
||||
{error, bad_name} ->
|
||||
false;
|
||||
|
@ -258,7 +259,7 @@ is_lib_avail(Config, DictKey, Mod, Hrl, Name) ->
|
|||
NewConfig = rebar_config:set_xconf(Config, DictKey, IsAvail),
|
||||
?DEBUG("~s availability: ~p\n", [Name, IsAvail]),
|
||||
{NewConfig, IsAvail};
|
||||
{ok, IsAvail} ->
|
||||
IsAvail ->
|
||||
{Config, IsAvail}
|
||||
end.
|
||||
|
||||
|
|
|
@ -26,16 +26,17 @@
|
|||
%% -------------------------------------------------------------------
|
||||
-module(rebar_log).
|
||||
|
||||
-export([init/0,
|
||||
set_level/1, get_level/0, default_level/0,
|
||||
-export([init/1,
|
||||
set_level/1, default_level/0,
|
||||
log/3]).
|
||||
|
||||
%% ===================================================================
|
||||
%% Public API
|
||||
%% ===================================================================
|
||||
|
||||
init() ->
|
||||
case valid_level(rebar_config:get_global(verbose, error_level())) of
|
||||
init(Config) ->
|
||||
Verbosity = rebar_config:get_global(Config, verbose, default_level()),
|
||||
case valid_level(Verbosity) of
|
||||
0 -> set_level(error);
|
||||
1 -> set_level(warn);
|
||||
2 -> set_level(info);
|
||||
|
@ -45,14 +46,6 @@ init() ->
|
|||
set_level(Level) ->
|
||||
ok = application:set_env(rebar, log_level, Level).
|
||||
|
||||
get_level() ->
|
||||
case application:get_env(rebar, log_level) of
|
||||
undefined ->
|
||||
error;
|
||||
{ok, Value} ->
|
||||
Value
|
||||
end.
|
||||
|
||||
log(Level, Str, Args) ->
|
||||
{ok, LogLevel} = application:get_env(rebar, log_level),
|
||||
case should_log(LogLevel, Level) of
|
||||
|
|
|
@ -179,12 +179,13 @@ setup_env(Config, ExtraEnv) ->
|
|||
%% max flexibility for users.
|
||||
DefaultEnv = filter_env(default_env(), []),
|
||||
PortEnv = filter_env(port_env(Config), []),
|
||||
OverrideEnv = global_defines() ++ PortEnv ++ filter_env(ExtraEnv, []),
|
||||
GlobalDefines = global_defines(Config),
|
||||
OverrideEnv = GlobalDefines ++ PortEnv ++ filter_env(ExtraEnv, []),
|
||||
RawEnv = apply_defaults(os_env(), DefaultEnv) ++ OverrideEnv,
|
||||
expand_vars_loop(merge_each_var(RawEnv, [])).
|
||||
|
||||
global_defines() ->
|
||||
Defines = rebar_config:get_global(defines, []),
|
||||
global_defines(Config) ->
|
||||
Defines = rebar_config:get_global(Config, defines, []),
|
||||
Flags = string:join(["-D" ++ D || D <- Defines], " "),
|
||||
[{"ERL_CFLAGS", "$ERL_CFLAGS " ++ Flags}].
|
||||
|
||||
|
|
|
@ -33,13 +33,13 @@
|
|||
get_rel_release_info/2,
|
||||
get_rel_apps/1,
|
||||
get_rel_apps/2,
|
||||
get_previous_release_path/0,
|
||||
get_previous_release_path/1,
|
||||
get_rel_file_path/2,
|
||||
load_config/2,
|
||||
get_sys_tuple/1,
|
||||
get_target_dir/1,
|
||||
get_root_dir/1,
|
||||
get_target_parent_dir/1]).
|
||||
get_target_dir/2,
|
||||
get_root_dir/2,
|
||||
get_target_parent_dir/2]).
|
||||
|
||||
-include("rebar.hrl").
|
||||
|
||||
|
@ -111,8 +111,8 @@ get_rel_file_path(Name, Path) ->
|
|||
filename:join([binary_to_list(BinDir), Name ++ ".rel"]).
|
||||
|
||||
%% Get the previous release path from a global variable
|
||||
get_previous_release_path() ->
|
||||
case rebar_config:get_global(previous_release, false) of
|
||||
get_previous_release_path(Config) ->
|
||||
case rebar_config:get_global(Config, previous_release, false) of
|
||||
false ->
|
||||
?ABORT("previous_release=PATH is required to "
|
||||
"create upgrade package~n", []);
|
||||
|
@ -148,8 +148,8 @@ get_sys_tuple(ReltoolConfig) ->
|
|||
%% Look for {target_dir, TargetDir} in the reltool config file; if none is
|
||||
%% found, use the name of the release as the default target directory.
|
||||
%%
|
||||
get_target_dir(ReltoolConfig) ->
|
||||
case rebar_config:get_global(target_dir, undefined) of
|
||||
get_target_dir(Config, ReltoolConfig) ->
|
||||
case rebar_config:get_global(Config, target_dir, undefined) of
|
||||
undefined ->
|
||||
case lists:keyfind(target_dir, 1, ReltoolConfig) of
|
||||
{target_dir, TargetDir} ->
|
||||
|
@ -167,8 +167,8 @@ get_target_dir(ReltoolConfig) ->
|
|||
filename:absname(TargetDir)
|
||||
end.
|
||||
|
||||
get_target_parent_dir(ReltoolConfig) ->
|
||||
TargetDir = get_target_dir(ReltoolConfig),
|
||||
get_target_parent_dir(Config, ReltoolConfig) ->
|
||||
TargetDir = get_target_dir(Config, ReltoolConfig),
|
||||
case lists:reverse(tl(lists:reverse(filename:split(TargetDir)))) of
|
||||
[] -> ".";
|
||||
Components -> filename:join(Components)
|
||||
|
@ -178,10 +178,10 @@ get_target_parent_dir(ReltoolConfig) ->
|
|||
%% Look for root_dir in sys tuple and command line; fall back to
|
||||
%% code:root_dir().
|
||||
%%
|
||||
get_root_dir(ReltoolConfig) ->
|
||||
get_root_dir(Config, ReltoolConfig) ->
|
||||
{sys, SysInfo} = get_sys_tuple(ReltoolConfig),
|
||||
SysRootDirTuple = lists:keyfind(root_dir, 1, SysInfo),
|
||||
CmdRootDir = rebar_config:get_global(root_dir, undefined),
|
||||
CmdRootDir = rebar_config:get_global(Config, root_dir, undefined),
|
||||
case {SysRootDirTuple, CmdRootDir} of
|
||||
%% root_dir in sys typle and no root_dir on cmd-line
|
||||
{{root_dir, SysRootDir}, undefined} ->
|
||||
|
|
|
@ -67,11 +67,11 @@ generate(Config0, ReltoolFile) ->
|
|||
overlay(Config, ReltoolFile) ->
|
||||
%% Load the reltool configuration from the file
|
||||
{Config1, ReltoolConfig} = rebar_rel_utils:load_config(Config, ReltoolFile),
|
||||
{Config1, process_overlay(ReltoolConfig)}.
|
||||
{Config1, process_overlay(Config, ReltoolConfig)}.
|
||||
|
||||
clean(Config, ReltoolFile) ->
|
||||
{Config1, ReltoolConfig} = rebar_rel_utils:load_config(Config, ReltoolFile),
|
||||
TargetDir = rebar_rel_utils:get_target_dir(ReltoolConfig),
|
||||
TargetDir = rebar_rel_utils:get_target_dir(Config, ReltoolConfig),
|
||||
rebar_file_utils:rm_rf(TargetDir),
|
||||
rebar_file_utils:delete_each(["reltool.spec"]),
|
||||
{ok, Config1}.
|
||||
|
@ -98,8 +98,8 @@ check_vsn() ->
|
|||
end
|
||||
end.
|
||||
|
||||
process_overlay(ReltoolConfig) ->
|
||||
TargetDir = rebar_rel_utils:get_target_dir(ReltoolConfig),
|
||||
process_overlay(Config, ReltoolConfig) ->
|
||||
TargetDir = rebar_rel_utils:get_target_dir(Config, ReltoolConfig),
|
||||
|
||||
{_BootRelName, BootRelVsn} =
|
||||
rebar_rel_utils:get_reltool_release_info(ReltoolConfig),
|
||||
|
@ -112,7 +112,7 @@ process_overlay(ReltoolConfig) ->
|
|||
{target_dir, TargetDir}]),
|
||||
|
||||
%% Load up any variables specified by overlay_vars
|
||||
OverlayVars1 = overlay_vars(OverlayVars0, ReltoolConfig),
|
||||
OverlayVars1 = overlay_vars(Config, OverlayVars0, ReltoolConfig),
|
||||
OverlayVars = rebar_templater:resolve_variables(dict:to_list(OverlayVars1),
|
||||
OverlayVars1),
|
||||
|
||||
|
@ -135,9 +135,11 @@ process_overlay(ReltoolConfig) ->
|
|||
%% variable in the file from reltool.config and then override that value by
|
||||
%% providing an additional file on the command-line.
|
||||
%%
|
||||
overlay_vars(Vars0, ReltoolConfig) ->
|
||||
overlay_vars(Config, Vars0, ReltoolConfig) ->
|
||||
BaseVars = load_vars_file(proplists:get_value(overlay_vars, ReltoolConfig)),
|
||||
OverrideVars = load_vars_file(rebar_config:get_global(overlay_vars, undefined)),
|
||||
OverrideVars = load_vars_file(rebar_config:get_global(Config,
|
||||
overlay_vars,
|
||||
undefined)),
|
||||
M = fun(_Key, _Base, Override) -> Override end,
|
||||
dict:merge(M, dict:merge(M, Vars0, BaseVars), OverrideVars).
|
||||
|
||||
|
@ -189,18 +191,18 @@ app_exists(AppTuple, Server) when is_tuple(AppTuple) ->
|
|||
app_exists(element(1, AppTuple), Server).
|
||||
|
||||
|
||||
run_reltool(Server, _Config, ReltoolConfig) ->
|
||||
run_reltool(Server, Config, ReltoolConfig) ->
|
||||
case reltool:get_target_spec(Server) of
|
||||
{ok, Spec} ->
|
||||
%% Pull the target dir and make sure it exists
|
||||
TargetDir = rebar_rel_utils:get_target_dir(ReltoolConfig),
|
||||
mk_target_dir(TargetDir),
|
||||
TargetDir = rebar_rel_utils:get_target_dir(Config, ReltoolConfig),
|
||||
mk_target_dir(Config, TargetDir),
|
||||
|
||||
%% Determine the otp root dir to use
|
||||
RootDir = rebar_rel_utils:get_root_dir(ReltoolConfig),
|
||||
RootDir = rebar_rel_utils:get_root_dir(Config, ReltoolConfig),
|
||||
|
||||
%% Dump the spec, if necessary
|
||||
dump_spec(Spec),
|
||||
dump_spec(Config, Spec),
|
||||
|
||||
%% Have reltool actually run
|
||||
case reltool:eval_target_spec(Spec, RootDir, TargetDir) of
|
||||
|
@ -216,20 +218,20 @@ run_reltool(Server, _Config, ReltoolConfig) ->
|
|||
|
||||
ok = create_RELEASES(TargetDir, BootRelName, BootRelVsn),
|
||||
|
||||
process_overlay(ReltoolConfig);
|
||||
process_overlay(Config, ReltoolConfig);
|
||||
|
||||
{error, Reason} ->
|
||||
?ABORT("Unable to generate spec: ~s\n", [Reason])
|
||||
end.
|
||||
|
||||
|
||||
mk_target_dir(TargetDir) ->
|
||||
mk_target_dir(Config, TargetDir) ->
|
||||
case filelib:ensure_dir(filename:join(TargetDir, "dummy")) of
|
||||
ok ->
|
||||
ok;
|
||||
{error, eexist} ->
|
||||
%% Output directory already exists; if force=1, wipe it out
|
||||
case rebar_config:get_global(force, "0") of
|
||||
case rebar_config:get_global(Config, force, "0") of
|
||||
"1" ->
|
||||
rebar_file_utils:rm_rf(TargetDir),
|
||||
ok = file:make_dir(TargetDir);
|
||||
|
@ -245,8 +247,8 @@ mk_target_dir(TargetDir) ->
|
|||
end.
|
||||
|
||||
|
||||
dump_spec(Spec) ->
|
||||
case rebar_config:get_global(dump_spec, "0") of
|
||||
dump_spec(Config, Spec) ->
|
||||
case rebar_config:get_global(Config, dump_spec, "0") of
|
||||
"1" ->
|
||||
SpecBin = list_to_binary(io_lib:print(Spec, 1, 120, -1)),
|
||||
ok = file:write_file("reltool.spec", SpecBin);
|
||||
|
|
|
@ -43,16 +43,16 @@
|
|||
%% Public API
|
||||
%% ===================================================================
|
||||
|
||||
'create-app'(_Config, _File) ->
|
||||
'create-app'(Config, _File) ->
|
||||
%% Alias for create w/ template=simpleapp
|
||||
create("simpleapp").
|
||||
create1(Config, "simpleapp").
|
||||
|
||||
'create-node'(_Config, _File) ->
|
||||
'create-node'(Config, _File) ->
|
||||
%% Alias for create w/ template=simplenode
|
||||
create("simplenode").
|
||||
create1(Config, "simplenode").
|
||||
|
||||
'list-templates'(_Config, _File) ->
|
||||
{AvailTemplates, Files} = find_templates(),
|
||||
'list-templates'(Config, _File) ->
|
||||
{AvailTemplates, Files} = find_templates(Config),
|
||||
?DEBUG("Available templates: ~p\n", [AvailTemplates]),
|
||||
|
||||
lists:foreach(
|
||||
|
@ -68,9 +68,9 @@
|
|||
end, AvailTemplates),
|
||||
ok.
|
||||
|
||||
create(_Config, _) ->
|
||||
TemplateId = template_id(),
|
||||
create(TemplateId).
|
||||
create(Config, _) ->
|
||||
TemplateId = template_id(Config),
|
||||
create1(Config, TemplateId).
|
||||
|
||||
%%
|
||||
%% Given a list of key value pairs, for each string value attempt to
|
||||
|
@ -98,8 +98,8 @@ render(Bin, Context) ->
|
|||
%% Internal functions
|
||||
%% ===================================================================
|
||||
|
||||
create(TemplateId) ->
|
||||
{AvailTemplates, Files} = find_templates(),
|
||||
create1(Config, TemplateId) ->
|
||||
{AvailTemplates, Files} = find_templates(Config),
|
||||
?DEBUG("Available templates: ~p\n", [AvailTemplates]),
|
||||
|
||||
%% Using the specified template id, find the matching template file/type.
|
||||
|
@ -130,7 +130,7 @@ create(TemplateId) ->
|
|||
end,
|
||||
|
||||
%% Load variables from disk file, if provided
|
||||
Context1 = case rebar_config:get_global(template_vars, undefined) of
|
||||
Context1 = case rebar_config:get_global(Config, template_vars, undefined) of
|
||||
undefined ->
|
||||
Context0;
|
||||
File ->
|
||||
|
@ -147,7 +147,7 @@ create(TemplateId) ->
|
|||
|
||||
%% For each variable, see if it's defined in global vars -- if it is,
|
||||
%% prefer that value over the defaults
|
||||
Context2 = update_vars(dict:fetch_keys(Context1), Context1),
|
||||
Context2 = update_vars(Config, dict:fetch_keys(Context1), Context1),
|
||||
?DEBUG("Template ~p context: ~p\n", [TemplateId, dict:to_list(Context1)]),
|
||||
|
||||
%% Handle variables that possibly include other variables in their
|
||||
|
@ -163,33 +163,34 @@ create(TemplateId) ->
|
|||
?DEBUG("Final template def ~p: ~p\n", [TemplateId, FinalTemplate]),
|
||||
|
||||
%% Execute the instructions in the finalized template
|
||||
Force = rebar_config:get_global(force, "0"),
|
||||
Force = rebar_config:get_global(Config, force, "0"),
|
||||
execute_template(Files, FinalTemplate, Type, Template, Context, Force, []).
|
||||
|
||||
find_templates() ->
|
||||
find_templates(Config) ->
|
||||
%% Load a list of all the files in the escript -- cache them since
|
||||
%% we'll potentially need to walk it several times over the course of
|
||||
%% a run.
|
||||
Files = cache_escript_files(),
|
||||
Files = cache_escript_files(Config),
|
||||
|
||||
%% Build a list of available templates
|
||||
AvailTemplates = find_disk_templates() ++ find_escript_templates(Files),
|
||||
AvailTemplates = find_disk_templates(Config)
|
||||
++ find_escript_templates(Files),
|
||||
|
||||
{AvailTemplates, Files}.
|
||||
|
||||
%%
|
||||
%% Scan the current escript for available files
|
||||
%%
|
||||
cache_escript_files() ->
|
||||
cache_escript_files(Config) ->
|
||||
{ok, Files} = rebar_utils:escript_foldl(
|
||||
fun(Name, _, GetBin, Acc) ->
|
||||
[{Name, GetBin()} | Acc]
|
||||
end,
|
||||
[], rebar_config:get_global(escript, undefined)),
|
||||
[], rebar_config:get_xconf(Config, escript)),
|
||||
Files.
|
||||
|
||||
template_id() ->
|
||||
case rebar_config:get_global(template, undefined) of
|
||||
template_id(Config) ->
|
||||
case rebar_config:get_global(Config, template, undefined) of
|
||||
undefined ->
|
||||
?ABORT("No template specified.\n", []);
|
||||
TemplateId ->
|
||||
|
@ -201,16 +202,16 @@ find_escript_templates(Files) ->
|
|||
|| {Name, _Bin} <- Files,
|
||||
re:run(Name, ?TEMPLATE_RE, [{capture, none}]) == match].
|
||||
|
||||
find_disk_templates() ->
|
||||
OtherTemplates = find_other_templates(),
|
||||
find_disk_templates(Config) ->
|
||||
OtherTemplates = find_other_templates(Config),
|
||||
HomeFiles = rebar_utils:find_files(filename:join([os:getenv("HOME"),
|
||||
".rebar", "templates"]),
|
||||
?TEMPLATE_RE),
|
||||
LocalFiles = rebar_utils:find_files(".", ?TEMPLATE_RE),
|
||||
[{file, F} || F <- OtherTemplates ++ HomeFiles ++ LocalFiles].
|
||||
|
||||
find_other_templates() ->
|
||||
case rebar_config:get_global(template_dir, undefined) of
|
||||
find_other_templates(Config) ->
|
||||
case rebar_config:get_global(Config, template_dir, undefined) of
|
||||
undefined ->
|
||||
[];
|
||||
TemplateDir ->
|
||||
|
@ -253,11 +254,11 @@ parse_vars(Other, _Dict) ->
|
|||
%% Given a list of keys in Dict, see if there is a corresponding value defined
|
||||
%% in the global config; if there is, update the key in Dict with it
|
||||
%%
|
||||
update_vars([], Dict) ->
|
||||
update_vars(_Config, [], Dict) ->
|
||||
Dict;
|
||||
update_vars([Key | Rest], Dict) ->
|
||||
Value = rebar_config:get_global(Key, dict:fetch(Key, Dict)),
|
||||
update_vars(Rest, dict:store(Key, Value, Dict)).
|
||||
update_vars(Config, [Key | Rest], Dict) ->
|
||||
Value = rebar_config:get_global(Config, Key, dict:fetch(Key, Dict)),
|
||||
update_vars(Config, Rest, dict:store(Key, Value, Dict)).
|
||||
|
||||
|
||||
%%
|
||||
|
@ -324,8 +325,8 @@ execute_template(_Files, [], _TemplateType, _TemplateName,
|
|||
_ ->
|
||||
Msg = lists:flatten([io_lib:format("\t* ~p~n", [F]) ||
|
||||
F <- lists:reverse(ExistingFiles)]),
|
||||
Help =
|
||||
"To force overwriting, specify force=1 on the command line.\n",
|
||||
Help = "To force overwriting, specify -f/--force/force=1"
|
||||
" on the command line.\n",
|
||||
?ERROR("One or more files already exist on disk and "
|
||||
"were not generated:~n~s~s", [Msg , Help])
|
||||
end;
|
||||
|
|
|
@ -41,14 +41,16 @@
|
|||
'generate-upgrade'(Config0, ReltoolFile) ->
|
||||
%% Get the old release path
|
||||
{Config, ReltoolConfig} = rebar_rel_utils:load_config(Config0, ReltoolFile),
|
||||
TargetParentDir = rebar_rel_utils:get_target_parent_dir(ReltoolConfig),
|
||||
TargetDir = rebar_rel_utils:get_target_dir(ReltoolConfig),
|
||||
TargetParentDir = rebar_rel_utils:get_target_parent_dir(Config,
|
||||
ReltoolConfig),
|
||||
TargetDir = rebar_rel_utils:get_target_dir(Config, ReltoolConfig),
|
||||
|
||||
OldVerPath = filename:join([TargetParentDir,
|
||||
rebar_rel_utils:get_previous_release_path()]),
|
||||
PrevRelPath = rebar_rel_utils:get_previous_release_path(Config),
|
||||
OldVerPath = filename:join([TargetParentDir, PrevRelPath]),
|
||||
|
||||
%% Run checks to make sure that building a package is possible
|
||||
{NewVerPath, NewName, NewVer} = run_checks(OldVerPath, ReltoolConfig),
|
||||
{NewVerPath, NewName, NewVer} = run_checks(Config, OldVerPath,
|
||||
ReltoolConfig),
|
||||
NameVer = NewName ++ "_" ++ NewVer,
|
||||
|
||||
%% Save the code path prior to doing anything
|
||||
|
@ -78,7 +80,7 @@
|
|||
%% Internal functions
|
||||
%% ==================================================================
|
||||
|
||||
run_checks(OldVerPath, ReltoolConfig) ->
|
||||
run_checks(Config, OldVerPath, ReltoolConfig) ->
|
||||
true = rebar_utils:prop_check(filelib:is_dir(OldVerPath),
|
||||
"Release directory doesn't exist (~p)~n",
|
||||
[OldVerPath]),
|
||||
|
@ -86,8 +88,9 @@ run_checks(OldVerPath, ReltoolConfig) ->
|
|||
{Name, Ver} = rebar_rel_utils:get_reltool_release_info(ReltoolConfig),
|
||||
|
||||
NewVerPath =
|
||||
filename:join([rebar_rel_utils:get_target_parent_dir(ReltoolConfig),
|
||||
Name]),
|
||||
filename:join(
|
||||
[rebar_rel_utils:get_target_parent_dir(Config, ReltoolConfig),
|
||||
Name]),
|
||||
true = rebar_utils:prop_check(filelib:is_dir(NewVerPath),
|
||||
"Release directory doesn't exist (~p)~n",
|
||||
[NewVerPath]),
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
expand_env_variable/3,
|
||||
vcs_vsn/3,
|
||||
deprecated/3, deprecated/4,
|
||||
get_deprecated_global/3, get_deprecated_global/4,
|
||||
get_deprecated_global/4, get_deprecated_global/5,
|
||||
get_deprecated_list/4, get_deprecated_list/5,
|
||||
get_deprecated_local/4, get_deprecated_local/5,
|
||||
delayed_halt/1,
|
||||
|
@ -200,7 +200,7 @@ expand_env_variable(InStr, VarName, RawVarValue) ->
|
|||
|
||||
vcs_vsn(Config, Vcs, Dir) ->
|
||||
Key = {Vcs, Dir},
|
||||
{ok, Cache} = rebar_config:get_xconf(Config, vsn_cache),
|
||||
Cache = rebar_config:get_xconf(Config, vsn_cache),
|
||||
case dict:find(Key, Cache) of
|
||||
error ->
|
||||
VsnString = vcs_vsn_1(Vcs, Dir),
|
||||
|
@ -211,13 +211,13 @@ vcs_vsn(Config, Vcs, Dir) ->
|
|||
{Config, VsnString}
|
||||
end.
|
||||
|
||||
get_deprecated_global(OldOpt, NewOpt, When) ->
|
||||
get_deprecated_global(OldOpt, NewOpt, undefined, When).
|
||||
get_deprecated_global(Config, OldOpt, NewOpt, When) ->
|
||||
get_deprecated_global(Config, OldOpt, NewOpt, undefined, When).
|
||||
|
||||
get_deprecated_global(OldOpt, NewOpt, Default, When) ->
|
||||
case rebar_config:get_global(NewOpt, Default) of
|
||||
get_deprecated_global(Config, OldOpt, NewOpt, Default, When) ->
|
||||
case rebar_config:get_global(Config, NewOpt, Default) of
|
||||
Default ->
|
||||
case rebar_config:get_global(OldOpt, Default) of
|
||||
case rebar_config:get_global(Config, OldOpt, Default) of
|
||||
Default ->
|
||||
Default;
|
||||
Old ->
|
||||
|
@ -291,7 +291,7 @@ delayed_halt(Code) ->
|
|||
erl_opts(Config) ->
|
||||
RawErlOpts = filter_defines(rebar_config:get(Config, erl_opts, []), []),
|
||||
GlobalDefines = [{d, list_to_atom(D)} ||
|
||||
D <- rebar_config:get_global(defines, [])],
|
||||
D <- rebar_config:get_global(Config, defines, [])],
|
||||
Opts = GlobalDefines ++ RawErlOpts,
|
||||
case proplists:is_defined(no_debug_info, Opts) of
|
||||
true ->
|
||||
|
|
|
@ -47,7 +47,7 @@ xref(Config, _) ->
|
|||
|
||||
xref:set_default(xref, [{warnings,
|
||||
rebar_config:get(Config, xref_warnings, false)},
|
||||
{verbose, rebar_config:is_verbose()}]),
|
||||
{verbose, rebar_config:is_verbose(Config)}]),
|
||||
|
||||
{ok, _} = xref:add_directory(xref, "ebin"),
|
||||
|
||||
|
|
Loading…
Reference in a new issue