ソースを参照

Merge pull request #780 from tsloughter/hook_app_info

support updating of per app info by hooks
pull/785/head
Fred Hebert 9年前
コミット
77e5e6b8f3
5個のファイルの変更34行の追加25行の削除
  1. +10
    -8
      src/rebar_hooks.erl
  2. +7
    -7
      src/rebar_prv_clean.erl
  3. +8
    -8
      src/rebar_prv_compile.erl
  4. +1
    -1
      src/rebar_prv_plugins.erl
  5. +8
    -1
      test/rebar_plugins_SUITE.erl

+ 10
- 8
src/rebar_hooks.erl ファイルの表示

@ -9,11 +9,12 @@
-spec run_all_hooks(file:filename_all(), pre | post,
atom() | {atom(), atom()} | string(),
[providers:t()], rebar_app_info:t(), rebar_state:t()) -> ok.
[providers:t()], rebar_app_info:t(), rebar_state:t()) -> rebar_app_info:t().
run_all_hooks(Dir, Type, Command, Providers, AppInfo, State) ->
State1 = rebar_state:current_app(State, AppInfo),
run_provider_hooks(Dir, Type, Command, Providers, rebar_app_info:opts(AppInfo), State1),
run_hooks(Dir, Type, Command, rebar_app_info:opts(AppInfo), State1).
State2 = run_provider_hooks(Dir, Type, Command, Providers, rebar_app_info:opts(AppInfo), State1),
run_hooks(Dir, Type, Command, rebar_app_info:opts(AppInfo), State1),
rebar_state:current_app(State2).
run_all_hooks(Dir, Type, Command, Providers, State) ->
run_provider_hooks(Dir, Type, Command, Providers, rebar_state:opts(State), State),
@ -22,14 +23,14 @@ run_all_hooks(Dir, Type, Command, Providers, State) ->
run_provider_hooks(Dir, Type, Command, Providers, Opts, State) ->
case rebar_opts:get(Opts, provider_hooks, []) of
[] ->
ok;
State;
AllHooks ->
TypeHooks = proplists:get_value(Type, AllHooks, []),
run_provider_hooks_(Dir, Type, Command, Providers, TypeHooks, rebar_state:opts(State, Opts))
end.
run_provider_hooks_(_Dir, _Type, _Command, _Providers, [], _State) ->
ok;
run_provider_hooks_(_Dir, _Type, _Command, _Providers, [], State) ->
State;
run_provider_hooks_(Dir, Type, Command, Providers, TypeHooks, State) ->
PluginDepsPaths = rebar_state:code_paths(State, all_plugin_deps),
code:add_pathsa(PluginDepsPaths),
@ -40,8 +41,9 @@ run_provider_hooks_(Dir, Type, Command, Providers, TypeHooks, State) ->
{error, ProviderName} ->
?DEBUG(format_error({bad_provider, Type, Command, ProviderName}), []),
throw(?PRV_ERROR({bad_provider, Type, Command, ProviderName}));
{ok, _} ->
rebar_utils:remove_from_code_path(PluginDepsPaths)
{ok, State2} ->
rebar_utils:remove_from_code_path(PluginDepsPaths),
State2
end.
format_error({bad_provider, Type, Command, {Name, Namespace}}) ->

+ 7
- 7
src/rebar_prv_clean.erl ファイルの表示

@ -62,13 +62,13 @@ format_error(Reason) ->
%% ===================================================================
clean_apps(State, Providers, Apps) ->
lists:foreach(fun(AppInfo) ->
?INFO("Cleaning out ~s...", [rebar_app_info:name(AppInfo)]),
AppDir = rebar_app_info:dir(AppInfo),
rebar_hooks:run_all_hooks(AppDir, pre, ?PROVIDER, Providers, AppInfo, State),
rebar_erlc_compiler:clean(State, rebar_app_info:out_dir(AppInfo)),
rebar_hooks:run_all_hooks(AppDir, post, ?PROVIDER, Providers, AppInfo, State)
end, Apps).
[begin
?INFO("Cleaning out ~s...", [rebar_app_info:name(AppInfo)]),
AppDir = rebar_app_info:dir(AppInfo),
AppInfo1 = rebar_hooks:run_all_hooks(AppDir, pre, ?PROVIDER, Providers, AppInfo, State),
rebar_erlc_compiler:clean(State, rebar_app_info:out_dir(AppInfo1)),
rebar_hooks:run_all_hooks(AppDir, post, ?PROVIDER, Providers, AppInfo1, State)
end || AppInfo <- Apps].
handle_args(State) ->
{Args, _} = rebar_state:command_parsed_args(State),

+ 8
- 8
src/rebar_prv_compile.erl ファイルの表示

@ -84,14 +84,14 @@ build_app(State, Providers, AppInfo) ->
compile(State, Providers, AppInfo) ->
?INFO("Compiling ~s", [rebar_app_info:name(AppInfo)]),
AppDir = rebar_app_info:dir(AppInfo),
rebar_hooks:run_all_hooks(AppDir, pre, ?PROVIDER, Providers, AppInfo, State),
rebar_erlc_compiler:compile(AppInfo),
case rebar_otp_app:compile(State, AppInfo) of
{ok, AppInfo1} ->
rebar_hooks:run_all_hooks(AppDir, post, ?PROVIDER, Providers, AppInfo, State),
has_all_artifacts(AppInfo1),
AppInfo1;
AppInfo1 = rebar_hooks:run_all_hooks(AppDir, pre, ?PROVIDER, Providers, AppInfo, State),
rebar_erlc_compiler:compile(AppInfo1),
case rebar_otp_app:compile(State, AppInfo1) of
{ok, AppInfo2} ->
AppInfo3 = rebar_hooks:run_all_hooks(AppDir, post, ?PROVIDER, Providers, AppInfo2, State),
has_all_artifacts(AppInfo3),
AppInfo3;
Error ->
throw(Error)
end.

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

@ -34,7 +34,7 @@ do(State) ->
GlobalConfigFile = rebar_dir:global_config(),
GlobalConfig = rebar_state:new(rebar_config:consult_file(GlobalConfigFile)),
GlobalPlugins = rebar_state:get(GlobalConfig, plugins, []),
GlobalPluginsDir = filename:join(rebar_dir:global_cache_dir(State), "plugins"),
GlobalPluginsDir = filename:join(rebar_dir:global_cache_dir(rebar_state:opts(State)), "plugins"),
display_plugins("Global plugins", GlobalPluginsDir, GlobalPlugins),
Plugins = rebar_state:get(State, plugins, []),

+ 8
- 1
test/rebar_plugins_SUITE.erl ファイルの表示

@ -9,6 +9,7 @@
compile_plugins/1,
compile_global_plugins/1,
complex_plugins/1,
list/1,
upgrade/1]).
-include_lib("common_test/include/ct.hrl").
@ -31,7 +32,7 @@ end_per_testcase(_, _Config) ->
catch meck:unload().
all() ->
[compile_plugins, compile_global_plugins, complex_plugins, upgrade].
[compile_plugins, compile_global_plugins, complex_plugins, list, upgrade].
%% Tests that compiling a project installs and compiles the plugins of deps
compile_plugins(Config) ->
@ -163,6 +164,12 @@ complex_plugins(Config) ->
meck:unload(rebar_dir).
list(Config) ->
rebar_test_utils:run_and_check(
Config, [], ["plugins", "list"],
{ok, []}
).
upgrade(Config) ->
AppDir = ?config(apps, Config),

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