summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2016-03-01 12:00:24 -0500
committerFred Hebert <mononcqc@ferd.ca>2016-03-01 12:00:24 -0500
commit0bcacad782d915b837d179412ae4bed5c00e2936 (patch)
treed3831b21476ff63ba26f503cdc5f448db3ff7f29
parent4fd77ef17236d2cdeb66ec968fbe6e37532270d3 (diff)
parentbc86eb73146150630b7634332a55ab0ed53757f3 (diff)
Merge branch 'saleyn-state'
-rw-r--r--README.md1
-rw-r--r--src/rebar.app.src1
-rw-r--r--src/rebar3.erl8
-rw-r--r--src/rebar_hooks.erl1
-rw-r--r--src/rebar_prv_state.erl44
-rw-r--r--src/rebar_state.erl17
6 files changed, 68 insertions, 4 deletions
diff --git a/README.md b/README.md
index 0fa486a..6e5f102 100644
--- a/README.md
+++ b/README.md
@@ -169,3 +169,4 @@ General rebar community resources and links:
- [Documentation](http://www.rebar3.org/v3.0/docs)
To contribute to rebar3, please refer to [CONTRIBUTING](CONTRIBUTING.md).
+
diff --git a/src/rebar.app.src b/src/rebar.app.src
index 58fee02..bd0f871 100644
--- a/src/rebar.app.src
+++ b/src/rebar.app.src
@@ -66,6 +66,7 @@
rebar_prv_relup,
rebar_prv_report,
rebar_prv_shell,
+ rebar_prv_state,
rebar_prv_tar,
rebar_prv_unlock,
rebar_prv_update,
diff --git a/src/rebar3.erl b/src/rebar3.erl
index 10eccfd..c1a1ae4 100644
--- a/src/rebar3.erl
+++ b/src/rebar3.erl
@@ -252,10 +252,10 @@ set_global_flag(State, Options, Flag) ->
%%
global_option_spec_list() ->
[
- %% {Name, ShortOpt, LongOpt, ArgSpec, HelpMsg}
- {help, $h, "help", undefined, "Print this help."},
- {version, $v, "version", undefined, "Show version information."},
- {task, undefined, undefined, string, "Task to run."}
+ %% {Name, ShortOpt, LongOpt, ArgSpec, HelpMsg}
+ {help, $h, "help", undefined, "Print this help."},
+ {version, $v, "version", undefined, "Show version information."},
+ {task, undefined, undefined, string, "Task to run."}
].
handle_error(rebar_abort) ->
diff --git a/src/rebar_hooks.erl b/src/rebar_hooks.erl
index 769890f..3af17ca 100644
--- a/src/rebar_hooks.erl
+++ b/src/rebar_hooks.erl
@@ -87,6 +87,7 @@ run_hooks(Dir, post, Command, Opts, State) ->
run_hooks(Dir, Type, Command, Opts, State) ->
case rebar_opts:get(Opts, Type, []) of
[] ->
+ ?DEBUG("run_hooks(~p, ~p, ~p) -> no hooks defined\n", [Dir, Type, Command]),
ok;
Hooks ->
Env = create_env(State, Opts),
diff --git a/src/rebar_prv_state.erl b/src/rebar_prv_state.erl
new file mode 100644
index 0000000..4fbcb67
--- /dev/null
+++ b/src/rebar_prv_state.erl
@@ -0,0 +1,44 @@
+%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*-
+%% ex: ts=4 sw=4 et
+
+-module(rebar_prv_state).
+
+-behaviour(provider).
+
+-export([init/1,
+ do/1,
+ format_error/1]).
+
+-include("rebar.hrl").
+
+-define(PROVIDER, state).
+-define(DEPS, []).
+
+%% ===================================================================
+%% Public API
+%% ===================================================================
+
+-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
+init(State) ->
+ Provider = providers:create(
+ [{name, ?PROVIDER},
+ {module, ?MODULE},
+ {bare, false},
+ {deps, ?DEPS},
+ {example, "rebar3 state"},
+ {short_desc, "Print current configuration state"},
+ {desc, "Display rebar configuration for debugging purpose"},
+ {opts, []}]),
+ State1 = rebar_state:add_provider(State, Provider),
+ {ok, State1}.
+
+-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
+do(State) ->
+ L = rebar_state:to_list(State),
+ ?CONSOLE("State:", []),
+ [?CONSOLE(" ~w: ~p", [K, V]) || {K,V} <- L],
+ {ok, State}.
+
+-spec format_error(any()) -> iolist().
+format_error(Reason) ->
+ io_lib:format("~p", [Reason]).
diff --git a/src/rebar_state.erl b/src/rebar_state.erl
index 30eff2f..a613a00 100644
--- a/src/rebar_state.erl
+++ b/src/rebar_state.erl
@@ -36,6 +36,8 @@
deps_names/1,
+ to_list/1,
+
resources/1, resources/2, add_resource/2,
providers/1, providers/2, add_provider/2,
allow_provider_overrides/1, allow_provider_overrides/2
@@ -418,6 +420,21 @@ create_logic_providers(ProviderModules, State0) ->
throw({error, "Failed creating providers. Run with DEBUG=1 for stacktrace."})
end.
+to_list(#state_t{} = State) ->
+ Fields = record_info(fields, state_t),
+ Values = tl(tuple_to_list(State)),
+ DictSz = tuple_size(dict:new()),
+ lists:zip(Fields, [reformat(I, DictSz) || I <- Values]).
+
+reformat({K,V}, DSz) when is_list(V) ->
+ {K, [reformat(I, DSz) || I <- V]};
+reformat(V, DSz) when is_tuple(V), element(1,V) =:= dict, tuple_size(V) =:= DSz ->
+ [reformat(I, DSz) || I <- dict:to_list(V)];
+reformat({K,V}, DSz) when is_tuple(V), element(1,V) =:= dict, tuple_size(V) =:= DSz ->
+ {K, [reformat(I, DSz) || I <- dict:to_list(V)]};
+reformat(Other, _DSz) ->
+ Other.
+
%% ===================================================================
%% Internal functions
%% ===================================================================