summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTuncer Ayaz <tuncer.ayaz@gmail.com>2011-06-21 21:46:41 +0200
committerTuncer Ayaz <tuncer.ayaz@gmail.com>2011-07-06 20:14:15 +0200
commit8263f12594c82edda1c5b80d2e9494fed925b423 (patch)
tree90318d1cf42fb24a0c9b73d0df33d212fbdec228 /src
parent2d353f82a3b272c184aea0a1ece272f8ff4a1337 (diff)
Add support for $HOME/.rebar/config
Diffstat (limited to 'src')
-rw-r--r--src/rebar.erl13
-rw-r--r--src/rebar_config.erl16
-rw-r--r--src/rebar_core.erl10
3 files changed, 31 insertions, 8 deletions
diff --git a/src/rebar.erl b/src/rebar.erl
index 7f33d4d..797f71a 100644
--- a/src/rebar.erl
+++ b/src/rebar.erl
@@ -98,8 +98,19 @@ run_aux(Commands) ->
%% Keep track of how many operations we do, so we can detect bad commands
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
- rebar_core:process_commands(CommandAtoms).
+ rebar_core:process_commands(CommandAtoms, GlobalConfig).
%%
%% print help/usage string
diff --git a/src/rebar_config.erl b/src/rebar_config.erl
index 751e088..56a8828 100644
--- a/src/rebar_config.erl
+++ b/src/rebar_config.erl
@@ -52,7 +52,15 @@ new() ->
#config { dir = rebar_utils:get_cwd(),
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
%% 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.
@@ -66,7 +74,7 @@ new(ParentConfig) ->
%% Load terms from rebar.config, if it exists
Dir = rebar_utils:get_cwd(),
ConfigFile = filename:join([Dir, ConfName]),
- Opts = case file:consult(ConfigFile) of
+ Opts = case consult_file(ConfigFile) of
{ok, Terms} ->
%% Found a config file with some terms. We need to
%% be able to distinguish between local definitions
@@ -126,6 +134,10 @@ get_jobs() ->
%% Internal functions
%% ===================================================================
+consult_file(File) ->
+ ?DEBUG("Consult config file ~p~n", [File]),
+ file:consult(File).
+
local_opts([], Acc) ->
lists:reverse(Acc);
local_opts([local | _Rest], Acc) ->
diff --git a/src/rebar_core.erl b/src/rebar_core.erl
index cb2c508..9a8814d 100644
--- a/src/rebar_core.erl
+++ b/src/rebar_core.erl
@@ -26,7 +26,7 @@
%% -------------------------------------------------------------------
-module(rebar_core).
--export([process_commands/1,
+-export([process_commands/2,
skip_dir/1,
is_skip_dir/1,
skip_dirs/0]).
@@ -63,7 +63,7 @@ skip_dirs() ->
%% Internal functions
%% ===================================================================
-process_commands([]) ->
+process_commands([], _ParentConfig) ->
case erlang:get(operations) of
0 ->
%% none of the commands had an effect
@@ -71,7 +71,7 @@ process_commands([]) ->
_ ->
ok
end;
-process_commands([Command | Rest]) ->
+process_commands([Command | Rest], ParentConfig) ->
%% Reset skip dirs
lists:foreach(fun (D) -> erlang:erase({skip_dir, D}) end, skip_dirs()),
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
%% to restore the code path from inside a subdirectory.
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()),
case erlang:get(operations) of
Operations ->
@@ -89,7 +89,7 @@ process_commands([Command | Rest]) ->
_ ->
ok
end,
- process_commands(Rest).
+ process_commands(Rest, ParentConfig).
process_dir(Dir, ParentConfig, Command, DirSet) ->