diff options
author | Fred Hebert <mononcqc@ferd.ca> | 2015-09-07 12:36:01 -0400 |
---|---|---|
committer | Fred Hebert <mononcqc@ferd.ca> | 2015-09-07 12:36:01 -0400 |
commit | 77e5e6b8f3028626afb4a687c1b02709a2dbd9b6 (patch) | |
tree | ea4ab722100305136680acb8300e546013ce38bb | |
parent | 7594c30876fa8a9c10e3b89bf028b979d4a974d6 (diff) | |
parent | 586a1a487cd70bc92816b35e7dfc07bc893a9ff3 (diff) |
Merge pull request #780 from tsloughter/hook_app_info
support updating of per app info by hooks
-rw-r--r-- | src/rebar_hooks.erl | 18 | ||||
-rw-r--r-- | src/rebar_prv_clean.erl | 14 | ||||
-rw-r--r-- | src/rebar_prv_compile.erl | 16 | ||||
-rw-r--r-- | src/rebar_prv_plugins.erl | 2 | ||||
-rw-r--r-- | test/rebar_plugins_SUITE.erl | 9 |
5 files changed, 34 insertions, 25 deletions
diff --git a/src/rebar_hooks.erl b/src/rebar_hooks.erl index c3b17bb..bbb916d 100644 --- a/src/rebar_hooks.erl +++ b/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}}) -> diff --git a/src/rebar_prv_clean.erl b/src/rebar_prv_clean.erl index 503291d..8bdea4d 100644 --- a/src/rebar_prv_clean.erl +++ b/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), diff --git a/src/rebar_prv_compile.erl b/src/rebar_prv_compile.erl index 56e5e84..89ea430 100644 --- a/src/rebar_prv_compile.erl +++ b/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. diff --git a/src/rebar_prv_plugins.erl b/src/rebar_prv_plugins.erl index 328958e..20bc1ea 100644 --- a/src/rebar_prv_plugins.erl +++ b/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, []), diff --git a/test/rebar_plugins_SUITE.erl b/test/rebar_plugins_SUITE.erl index 5e2c782..3df3c0e 100644 --- a/test/rebar_plugins_SUITE.erl +++ b/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), |