summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2015-08-03 13:28:06 -0400
committerFred Hebert <mononcqc@ferd.ca>2015-08-03 13:28:06 -0400
commita705f1e4f6a93313546fd68ce857a6d69a45661a (patch)
treebc6f0f86d129a0f417f7e649802b2faf54d21309
parente786d8eb6a37f5e651dc911fec85445d850d28e6 (diff)
parent6d01729c682fa56933753ef70c1e97b4b19042d8 (diff)
Merge pull request #682 from tsloughter/upgrade_lock_dep
upgrade depends on the lock provider and lock prv sets state
-rw-r--r--src/rebar_prv_lock.erl9
-rw-r--r--src/rebar_prv_upgrade.erl24
-rw-r--r--src/rebar_utils.erl9
-rw-r--r--test/rebar_upgrade_SUITE.erl10
4 files changed, 30 insertions, 22 deletions
diff --git a/src/rebar_prv_lock.erl b/src/rebar_prv_lock.erl
index 058846a..1844934 100644
--- a/src/rebar_prv_lock.erl
+++ b/src/rebar_prv_lock.erl
@@ -29,11 +29,18 @@ init(State) ->
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
+ OldLocks = rebar_state:get(State, {locks, default}, []),
Locks = build_locks(State),
Dir = rebar_state:dir(State),
file:write_file(filename:join(Dir, ?LOCK_FILE),
io_lib:format("~p.~n", [Locks])),
- {ok, State}.
+ State1 = rebar_state:set(State, {locks, default}, Locks),
+
+ OldLockNames = [element(1,L) || L <- OldLocks],
+ NewLockNames = [element(1,L) || L <- Locks],
+ rebar_utils:info_useless(OldLockNames, NewLockNames),
+
+ {ok, State1}.
-spec format_error(any()) -> iolist().
format_error(Reason) ->
diff --git a/src/rebar_prv_upgrade.erl b/src/rebar_prv_upgrade.erl
index a50e64f..3a371ca 100644
--- a/src/rebar_prv_upgrade.erl
+++ b/src/rebar_prv_upgrade.erl
@@ -13,7 +13,7 @@
-include_lib("providers/include/providers.hrl").
-define(PROVIDER, upgrade).
--define(DEPS, []).
+-define(DEPS, [lock]).
%% Also only upgrade top-level (0) deps. Transitive deps shouldn't be
%% upgradable -- if the user wants this, they should declare it at the
%% top level and then upgrade.
@@ -55,13 +55,15 @@ do(State) ->
State1 = rebar_state:set(State, {deps, default}, Deps0),
State2 = rebar_state:set(State1, {locks, default}, Locks0),
State3 = rebar_state:set(State2, upgrade, true),
- Res = rebar_prv_install_deps:do(State3),
+ UpdatedLocks = [L || L <- rebar_state:lock(State3),
+ lists:keymember(rebar_app_info:name(L), 1, Locks0)],
+ Res = rebar_prv_install_deps:do(rebar_state:lock(State3, UpdatedLocks)),
case Res of
{ok, State4} ->
- info_useless(
- [element(1,Lock) || Lock <- Locks],
- [rebar_app_info:name(App) || App <- rebar_state:lock(State4)]
- ),
+ rebar_utils:info_useless(
+ [element(1,Lock) || Lock <- Locks],
+ [rebar_app_info:name(App) || App <- rebar_state:lock(State4)]
+ ),
rebar_prv_lock:do(State4);
_ ->
Res
@@ -73,8 +75,8 @@ format_error({unknown_dependency, Name}) ->
io_lib:format("Dependency ~ts not found", [Name]);
format_error({transitive_dependency, Name}) ->
io_lib:format("Dependency ~ts is transient and cannot be safely upgraded. "
- "Promote it to your top-level rebar.config file to upgrade it.",
- [Name]);
+ "Promote it to your top-level rebar.config file to upgrade it.",
+ [Name]);
format_error(Reason) ->
io_lib:format("~p", [Reason]).
@@ -138,9 +140,3 @@ unlock_higher_than(Level, [App = {_,_,AppLevel} | Apps], Locks, Unlocks) ->
if AppLevel > Level -> unlock_higher_than(Level, Apps, Locks, [App | Unlocks]);
AppLevel =< Level -> unlock_higher_than(Level, Apps, [App | Locks], Unlocks)
end.
-
-info_useless(Old, New) ->
- [?INFO("App ~ts is no longer needed and can be deleted.", [Name])
- || Name <- Old,
- not lists:member(Name, New)],
- ok.
diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl
index 7ae3d9c..30da523 100644
--- a/src/rebar_utils.erl
+++ b/src/rebar_utils.erl
@@ -63,7 +63,8 @@
escape_double_quotes/1,
escape_double_quotes_weak/1,
check_min_otp_version/1,
- check_blacklisted_otp_versions/1]).
+ check_blacklisted_otp_versions/1,
+ info_useless/2]).
%% for internal use only
-export([otp_release/0]).
@@ -766,3 +767,9 @@ escape_double_quotes(Str) ->
%% "escape inside these" but allow *
escape_double_quotes_weak(Str) ->
re:replace(Str, "([\"\\\\`!$&;])", "\\\\&", [global, {return, list}]).
+
+info_useless(Old, New) ->
+ [?INFO("App ~ts is no longer needed and can be deleted.", [Name])
+ || Name <- Old,
+ not lists:member(Name, New)],
+ ok.
diff --git a/test/rebar_upgrade_SUITE.erl b/test/rebar_upgrade_SUITE.erl
index f2d4133..4ab99c7 100644
--- a/test/rebar_upgrade_SUITE.erl
+++ b/test/rebar_upgrade_SUITE.erl
@@ -48,7 +48,7 @@ init_per_testcase(novsn_pkg, Config0) ->
end},
{mock_update, fun() ->
catch mock_pkg_resource:unmock(),
- mock_pkg_resource:mock([{pkgdeps, UpDeps}, {upgrade, Upgrades}])
+ mock_pkg_resource:mock([{pkgdeps, UpDeps++Deps}, {upgrade, Upgrades}])
end},
{expected, {ok, [{dep, "fakeapp", "1.1.0"}, {lock, "fakeapp", "1.1.0"}]}}
| Config];
@@ -430,14 +430,12 @@ mock_deps(pkg, Deps, Upgrades) ->
catch mock_pkg_resource:unmock(),
mock_pkg_resource:mock([{pkgdeps, rebar_test_utils:flat_pkgdeps(Deps)}, {upgrade, Upgrades}]).
-mock_deps(git, _OldDeps, Deps, Upgrades) ->
+mock_deps(git, OldDeps, Deps, Upgrades) ->
catch mock_git_resource:unmock(),
- mock_git_resource:mock([{deps, rebar_test_utils:flat_deps(Deps)}, {upgrade, Upgrades}]);
+ mock_git_resource:mock([{deps, rebar_test_utils:flat_deps(Deps++OldDeps)}, {upgrade, Upgrades}]);
mock_deps(pkg, OldDeps, Deps, Upgrades) ->
- Merged = Deps ++ [Dep || Dep <- OldDeps,
- not lists:keymember(element(1, Dep), 1, Deps)],
catch mock_pkg_resource:unmock(),
- mock_pkg_resource:mock([{pkgdeps, rebar_test_utils:flat_pkgdeps(Merged)}, {upgrade, Upgrades}]).
+ mock_pkg_resource:mock([{pkgdeps, rebar_test_utils:flat_pkgdeps(Deps++OldDeps)}, {upgrade, Upgrades}]).
normalize_unlocks({App, Locks}) ->
{iolist_to_binary(App),