ソースを参照

Merge branch 'state' of https://github.com/saleyn/rebar3 into saleyn-state

pull/1100/head
Fred Hebert 9年前
コミット
bc86eb7314
6個のファイルの変更68行の追加4行の削除
  1. +1
    -0
      README.md
  2. +1
    -0
      src/rebar.app.src
  3. +4
    -4
      src/rebar3.erl
  4. +1
    -0
      src/rebar_hooks.erl
  5. +44
    -0
      src/rebar_prv_state.erl
  6. +17
    -0
      src/rebar_state.erl

+ 1
- 0
README.md ファイルの表示

@ -169,3 +169,4 @@ General rebar community resources and links:
- [Documentation](http://www.rebar3.org/v3.0/docs) - [Documentation](http://www.rebar3.org/v3.0/docs)
To contribute to rebar3, please refer to [CONTRIBUTING](CONTRIBUTING.md). To contribute to rebar3, please refer to [CONTRIBUTING](CONTRIBUTING.md).

+ 1
- 0
src/rebar.app.src ファイルの表示

@ -66,6 +66,7 @@
rebar_prv_relup, rebar_prv_relup,
rebar_prv_report, rebar_prv_report,
rebar_prv_shell, rebar_prv_shell,
rebar_prv_state,
rebar_prv_tar, rebar_prv_tar,
rebar_prv_unlock, rebar_prv_unlock,
rebar_prv_update, rebar_prv_update,

+ 4
- 4
src/rebar3.erl ファイルの表示

@ -252,10 +252,10 @@ set_global_flag(State, Options, Flag) ->
%% %%
global_option_spec_list() -> 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) -> handle_error(rebar_abort) ->

+ 1
- 0
src/rebar_hooks.erl ファイルの表示

@ -87,6 +87,7 @@ run_hooks(Dir, post, Command, Opts, State) ->
run_hooks(Dir, Type, Command, Opts, State) -> run_hooks(Dir, Type, Command, Opts, State) ->
case rebar_opts:get(Opts, Type, []) of case rebar_opts:get(Opts, Type, []) of
[] -> [] ->
?DEBUG("run_hooks(~p, ~p, ~p) -> no hooks defined\n", [Dir, Type, Command]),
ok; ok;
Hooks -> Hooks ->
Env = create_env(State, Opts), Env = create_env(State, Opts),

+ 44
- 0
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]).

+ 17
- 0
src/rebar_state.erl ファイルの表示

@ -36,6 +36,8 @@
deps_names/1, deps_names/1,
to_list/1,
resources/1, resources/2, add_resource/2, resources/1, resources/2, add_resource/2,
providers/1, providers/2, add_provider/2, providers/1, providers/2, add_provider/2,
allow_provider_overrides/1, allow_provider_overrides/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."}) throw({error, "Failed creating providers. Run with DEBUG=1 for stacktrace."})
end. 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 %% Internal functions
%% =================================================================== %% ===================================================================

読み込み中…
キャンセル
保存