summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Sloughter <t@crashfast.com>2016-01-31 11:11:46 -0600
committerTristan Sloughter <t@crashfast.com>2016-01-31 11:11:55 -0600
commitc4aaff7a06f55b555f9278ff20e8225a724d9faa (patch)
tree5f1688123b54ed784801dacd17f296c3d35e8abd
parent3522c929f9cda647e7fe0b1c8fb10765fabe7d1b (diff)
don't lose overrides in an app when installing plugins it uses'
-rw-r--r--src/rebar_plugins.erl18
-rw-r--r--test/rebar_plugins_SUITE.erl45
2 files changed, 57 insertions, 6 deletions
diff --git a/src/rebar_plugins.erl b/src/rebar_plugins.erl
index b4cc3ec..3c33498 100644
--- a/src/rebar_plugins.erl
+++ b/src/rebar_plugins.erl
@@ -42,10 +42,20 @@ project_apps_install(State) ->
-spec install(rebar_state:t(), rebar_app_info:t()) -> rebar_state:t().
install(State, AppInfo) ->
Profiles = rebar_state:current_profiles(State),
- lists:foldl(fun(Profile, StateAcc) ->
- Plugins = rebar_app_info:get(AppInfo, {plugins, Profile}, []),
- handle_plugins(Profile, Plugins, StateAcc)
- end, State, Profiles).
+
+ %% don't lose the overrides of the dep we are processing plugins for
+ Overrides = rebar_app_info:get(AppInfo, overrides, []),
+ StateOverrides = rebar_state:get(State, overrides, []),
+ AllOverrides = Overrides ++ StateOverrides,
+ State1 = rebar_state:set(State, overrides, AllOverrides),
+
+ State2 = lists:foldl(fun(Profile, StateAcc) ->
+ Plugins = rebar_app_info:get(AppInfo, {plugins, Profile}, []),
+ handle_plugins(Profile, Plugins, StateAcc)
+ end, State1, Profiles),
+
+ %% Reset the overrides after processing the dep
+ rebar_state:set(State2, overrides, StateOverrides).
handle_plugins(Profile, Plugins, State) ->
handle_plugins(Profile, Plugins, State, false).
diff --git a/test/rebar_plugins_SUITE.erl b/test/rebar_plugins_SUITE.erl
index cce6126..c1a98de 100644
--- a/test/rebar_plugins_SUITE.erl
+++ b/test/rebar_plugins_SUITE.erl
@@ -11,7 +11,8 @@
complex_plugins/1,
list/1,
upgrade/1,
- sub_app_plugins/1]).
+ sub_app_plugins/1,
+ sub_app_plugin_overrides/1]).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
@@ -33,7 +34,7 @@ end_per_testcase(_, _Config) ->
catch meck:unload().
all() ->
- [compile_plugins, compile_global_plugins, complex_plugins, list, upgrade, sub_app_plugins].
+ [compile_plugins, compile_global_plugins, complex_plugins, list, upgrade, sub_app_plugins, sub_app_plugin_overrides].
%% Tests that compiling a project installs and compiles the plugins of deps
compile_plugins(Config) ->
@@ -240,3 +241,43 @@ sub_app_plugins(Config) ->
Config, RConf, ["compile"],
{ok, [{app, Name}, {dep, DepName}, {plugin, PluginName}]}
).
+
+%% Tests that overrides in a dep that includes a plugin are applied to plugin fetching
+sub_app_plugin_overrides(Config) ->
+ AppDir = ?config(apps, Config),
+
+ Name = rebar_test_utils:create_random_name("sub_app1_"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ Dep2Name = rebar_test_utils:create_random_name("dep2_"),
+
+ DepName = rebar_test_utils:create_random_name("dep1_"),
+ PluginName = rebar_test_utils:create_random_name("plugin1_"),
+ Vsn2 = rebar_test_utils:create_random_vsn(),
+
+ Deps = rebar_test_utils:expand_deps(git, [{PluginName, Vsn, [{DepName, Vsn, []}]},
+ {DepName, Vsn, []}]),
+ {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
+ mock_git_resource:mock([{deps, SrcDeps}]),
+
+ mock_pkg_resource:mock([{pkgdeps, [{{list_to_binary(Dep2Name), list_to_binary(Vsn)}, []}]},
+ {config, [{plugins, [{list_to_atom(PluginName),
+ {git, "http://site.com/user/"++PluginName++".git",
+ {tag, Vsn}}}]},
+ %% Dep2 overrides the plugin's deps to have vsn2 of dep1
+ {overrides, [{override, list_to_atom(PluginName),
+ [{deps, [{list_to_atom(DepName),
+ {git, "http://site.com/user/"++DepName++".git",
+ {tag, Vsn2}}}]}]}]}]}]),
+
+ SubAppsDir = filename:join([AppDir, "apps", Name]),
+
+ rebar_test_utils:create_app(SubAppsDir, Name, Vsn, [kernel, stdlib]),
+
+ RConfFile = rebar_test_utils:create_config(AppDir, [{deps, [{list_to_binary(Dep2Name), list_to_binary(Vsn)}]}]),
+ {ok, RConf} = file:consult(RConfFile),
+
+ %% Build with deps.
+ rebar_test_utils:run_and_check(
+ Config, RConf, ["compile"],
+ {ok, [{app, Name}, {dep, Dep2Name, Vsn}, {plugin, DepName, Vsn2}, {plugin, PluginName}]}
+ ).