mirror of
https://github.com/correl/rebar.git
synced 2024-11-15 03:00:18 +00:00
Add support for $HOME/.rebar/config
This commit is contained in:
parent
2d353f82a3
commit
8263f12594
3 changed files with 31 additions and 8 deletions
|
@ -98,8 +98,19 @@ run_aux(Commands) ->
|
||||||
%% Keep track of how many operations we do, so we can detect bad commands
|
%% Keep track of how many operations we do, so we can detect bad commands
|
||||||
erlang:put(operations, 0),
|
erlang:put(operations, 0),
|
||||||
|
|
||||||
|
%% 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
|
||||||
|
true ->
|
||||||
|
?DEBUG("Load global config file ~p~n",
|
||||||
|
[GlobalConfigFile]),
|
||||||
|
rebar_config:new(GlobalConfigFile);
|
||||||
|
false ->
|
||||||
|
rebar_config:new()
|
||||||
|
end,
|
||||||
|
|
||||||
%% Process each command, resetting any state between each one
|
%% Process each command, resetting any state between each one
|
||||||
rebar_core:process_commands(CommandAtoms).
|
rebar_core:process_commands(CommandAtoms, GlobalConfig).
|
||||||
|
|
||||||
%%
|
%%
|
||||||
%% print help/usage string
|
%% print help/usage string
|
||||||
|
|
|
@ -52,7 +52,15 @@ new() ->
|
||||||
#config { dir = rebar_utils:get_cwd(),
|
#config { dir = rebar_utils:get_cwd(),
|
||||||
opts = []}.
|
opts = []}.
|
||||||
|
|
||||||
new(ParentConfig) ->
|
new(ConfigFile) when is_list(ConfigFile) ->
|
||||||
|
case consult_file(ConfigFile) of
|
||||||
|
{ok, Opts} ->
|
||||||
|
#config { dir = rebar_utils:get_cwd(),
|
||||||
|
opts = Opts };
|
||||||
|
Other ->
|
||||||
|
?ABORT("Failed to load ~s: ~p~n", [ConfigFile, Other])
|
||||||
|
end;
|
||||||
|
new(#config{}=ParentConfig)->
|
||||||
%% If we are at the top level we might want to load another rebar.config
|
%% If we are at the top level we might want to load another rebar.config
|
||||||
%% We can be certain that we are at the top level if we don't have any
|
%% We can be certain that we are at the top level if we don't have any
|
||||||
%% configs yet since if we are at another level we must have some config.
|
%% configs yet since if we are at another level we must have some config.
|
||||||
|
@ -66,7 +74,7 @@ new(ParentConfig) ->
|
||||||
%% Load terms from rebar.config, if it exists
|
%% Load terms from rebar.config, if it exists
|
||||||
Dir = rebar_utils:get_cwd(),
|
Dir = rebar_utils:get_cwd(),
|
||||||
ConfigFile = filename:join([Dir, ConfName]),
|
ConfigFile = filename:join([Dir, ConfName]),
|
||||||
Opts = case file:consult(ConfigFile) of
|
Opts = case consult_file(ConfigFile) of
|
||||||
{ok, Terms} ->
|
{ok, Terms} ->
|
||||||
%% Found a config file with some terms. We need to
|
%% Found a config file with some terms. We need to
|
||||||
%% be able to distinguish between local definitions
|
%% be able to distinguish between local definitions
|
||||||
|
@ -126,6 +134,10 @@ get_jobs() ->
|
||||||
%% Internal functions
|
%% Internal functions
|
||||||
%% ===================================================================
|
%% ===================================================================
|
||||||
|
|
||||||
|
consult_file(File) ->
|
||||||
|
?DEBUG("Consult config file ~p~n", [File]),
|
||||||
|
file:consult(File).
|
||||||
|
|
||||||
local_opts([], Acc) ->
|
local_opts([], Acc) ->
|
||||||
lists:reverse(Acc);
|
lists:reverse(Acc);
|
||||||
local_opts([local | _Rest], Acc) ->
|
local_opts([local | _Rest], Acc) ->
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
%% -------------------------------------------------------------------
|
%% -------------------------------------------------------------------
|
||||||
-module(rebar_core).
|
-module(rebar_core).
|
||||||
|
|
||||||
-export([process_commands/1,
|
-export([process_commands/2,
|
||||||
skip_dir/1,
|
skip_dir/1,
|
||||||
is_skip_dir/1,
|
is_skip_dir/1,
|
||||||
skip_dirs/0]).
|
skip_dirs/0]).
|
||||||
|
@ -63,7 +63,7 @@ skip_dirs() ->
|
||||||
%% Internal functions
|
%% Internal functions
|
||||||
%% ===================================================================
|
%% ===================================================================
|
||||||
|
|
||||||
process_commands([]) ->
|
process_commands([], _ParentConfig) ->
|
||||||
case erlang:get(operations) of
|
case erlang:get(operations) of
|
||||||
0 ->
|
0 ->
|
||||||
%% none of the commands had an effect
|
%% none of the commands had an effect
|
||||||
|
@ -71,7 +71,7 @@ process_commands([]) ->
|
||||||
_ ->
|
_ ->
|
||||||
ok
|
ok
|
||||||
end;
|
end;
|
||||||
process_commands([Command | Rest]) ->
|
process_commands([Command | Rest], ParentConfig) ->
|
||||||
%% Reset skip dirs
|
%% Reset skip dirs
|
||||||
lists:foreach(fun (D) -> erlang:erase({skip_dir, D}) end, skip_dirs()),
|
lists:foreach(fun (D) -> erlang:erase({skip_dir, D}) end, skip_dirs()),
|
||||||
Operations = erlang:get(operations),
|
Operations = erlang:get(operations),
|
||||||
|
@ -80,7 +80,7 @@ process_commands([Command | Rest]) ->
|
||||||
%% If not, code:set_path() may choke on invalid relative paths when trying
|
%% If not, code:set_path() may choke on invalid relative paths when trying
|
||||||
%% to restore the code path from inside a subdirectory.
|
%% to restore the code path from inside a subdirectory.
|
||||||
true = rebar_utils:expand_code_path(),
|
true = rebar_utils:expand_code_path(),
|
||||||
_ = process_dir(rebar_utils:get_cwd(), rebar_config:new(),
|
_ = process_dir(rebar_utils:get_cwd(), ParentConfig,
|
||||||
Command, sets:new()),
|
Command, sets:new()),
|
||||||
case erlang:get(operations) of
|
case erlang:get(operations) of
|
||||||
Operations ->
|
Operations ->
|
||||||
|
@ -89,7 +89,7 @@ process_commands([Command | Rest]) ->
|
||||||
_ ->
|
_ ->
|
||||||
ok
|
ok
|
||||||
end,
|
end,
|
||||||
process_commands(Rest).
|
process_commands(Rest, ParentConfig).
|
||||||
|
|
||||||
|
|
||||||
process_dir(Dir, ParentConfig, Command, DirSet) ->
|
process_dir(Dir, ParentConfig, Command, DirSet) ->
|
||||||
|
|
Loading…
Reference in a new issue