summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerge Aleynikov <saleyn@gmail.com>2015-12-18 08:38:54 -0500
committerSerge Aleynikov <saleyn@gmail.com>2016-02-08 19:22:52 -0500
commitcf03345486f5e3b09960deb861c07e2d1dcca3a1 (patch)
tree810b146cf4d7fdcf81e2dfe0e9293a45257d74f7
parentd7def6e9ffbbe21ce8a3b4f9e56d344ad2e417a9 (diff)
Add a state display provider
The provider is used for debugging to help displaying current rebar's state. Usage: rebar3 state
-rw-r--r--README.md1
-rw-r--r--src/rebar.app.src1
-rw-r--r--src/rebar3.erl9
-rw-r--r--src/rebar_hooks.erl1
-rw-r--r--src/rebar_prv_state.erl44
-rw-r--r--src/rebar_state.erl10
6 files changed, 62 insertions, 4 deletions
diff --git a/README.md b/README.md
index cddb843..873a990 100644
--- a/README.md
+++ b/README.md
@@ -42,6 +42,7 @@ locations ([hex.pm](http://hex.pm), git, hg, and so on).
| relup | Creates relup from 2 releases |
| report | Report on environment and versions for bug reports |
| shell | Run shell with project apps in path |
+| state | Display configuration state |
| tar | Package release into tarball |
| tree | Print dependency tree |
| unlock | Unlock dependencies |
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 9106bb8..01d3d7f 100644
--- a/src/rebar3.erl
+++ b/src/rebar3.erl
@@ -247,10 +247,11 @@ 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."},
+ {state, undefined, "state", undefined, "Display configuration state"}
].
handle_error(rebar_abort) ->
diff --git a/src/rebar_hooks.erl b/src/rebar_hooks.erl
index 4e6d486..a5ab048 100644
--- a/src/rebar_hooks.erl
+++ b/src/rebar_hooks.erl
@@ -81,6 +81,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..0e2ca21
--- /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, true},
+ {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),
+ io:put_chars("State:\n"),
+ [io:format(" ~w: ~p\n", [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 0c07b2a..a97eca5 100644
--- a/src/rebar_state.erl
+++ b/src/rebar_state.erl
@@ -36,6 +36,7 @@
deps_names/1,
+ to_list/1,
resources/1, resources/2, add_resource/2,
providers/1, providers/2, add_provider/2]).
@@ -406,6 +407,15 @@ create_logic_providers(ProviderModules, State0) ->
throw({error, "Failed creating providers. Run with DEBUG=1 for stacktrace."})
end.
+to_list(#state_t{opts=O, code_paths=CP, default=D} = State) ->
+ O1 = dict:to_list(O),
+ CP1 = dict:to_list(CP),
+ D1 = dict:to_list(D),
+ State1 = State#state_t{opts=O1, code_paths=CP1, default=D1},
+ Fields = record_info(fields, state_t),
+ Values = tl(tuple_to_list(State1)),
+ lists:zip(Fields, Values).
+
%% ===================================================================
%% Internal functions
%% ===================================================================