From d3f53b40f90631eb453f9f88ba8e7b41635f448f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Costas=20S=C3=A1nchez?= Date: Sat, 30 Oct 2021 12:37:44 +0200 Subject: [PATCH 1/2] Remove duplicated message when trying to upgrade a checkout dep When running `rebar3 upgrade` on a project that has checkout dependencies, a message of `"App $NAME is a checkout dependency and cannot be locked."` will be printed by the `lock` provider. As this provider is called twice (first to check the locked dependencies, and then from the `upgrade` provider after updating the dependencies), the message will show duplicated. To avoid this, this commit marks all checkout dependencies as regular ones, after checking whether it makes sense to do so, before calling the `lock` provider from the `upgrade` provider. --- src/rebar_prv_lock.erl | 6 +++--- src/rebar_prv_upgrade.erl | 22 +++++++++++++++++++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/rebar_prv_lock.erl b/src/rebar_prv_lock.erl index eb8b96ade..95dce4455 100644 --- a/src/rebar_prv_lock.erl +++ b/src/rebar_prv_lock.erl @@ -44,7 +44,6 @@ do(State) -> OldLockNames = [element(1,L) || L <- OldLocks] -- Checkouts, NewLockNames = [element(1,L) || L <- Locks], - %% TODO: don't output this message if the dep is now a checkout rebar_utils:info_useless(OldLockNames, NewLockNames), info_checkout_deps(Checkouts), @@ -67,6 +66,7 @@ build_locks(State) -> rebar_app_info:dep_level(Dep)} end || Dep <- AllDeps, not(rebar_app_info:is_checkout(Dep))]. -info_checkout_deps(Checkouts) -> +info_checkout_deps(Checkouts0) -> + Checkouts = lists:usort(Checkouts0), [?INFO("App ~ts is a checkout dependency and cannot be locked.", [CheckoutDep]) - || CheckoutDep <- Checkouts]. \ No newline at end of file + || CheckoutDep <- Checkouts]. diff --git a/src/rebar_prv_upgrade.erl b/src/rebar_prv_upgrade.erl index e1d6c6012..b5e736004 100644 --- a/src/rebar_prv_upgrade.erl +++ b/src/rebar_prv_upgrade.erl @@ -111,12 +111,32 @@ do_(State) -> [element(1,Lock) || Lock <- Locks], [rebar_app_info:name(App) || App <- rebar_state:lock(State5)] ), - rebar_prv_lock:do(State5); + State6 = maybe_ignore_checkouts(State5, Checkouts), + rebar_prv_lock:do(State6); _ -> Res end end. +-spec maybe_ignore_checkouts(rebar_state:t(), [binary()]) -> rebar_state:t(). +maybe_ignore_checkouts(State, Checkouts) -> + OldLocks = rebar_state:get(State, {locks, default}, []), + OldLockNames = [element(1,L) || L <- OldLocks], + case OldLockNames -- Checkouts of + %% If there aren't any checkout dependencies in the old lock info, + %% we can safely "ignore" them to avoid a duplicated message from + %% `rebar_prv_lock:info_checkout_deps/1`. + OldLockNames -> + DepsIgnoringCheckout = + [case rebar_app_info:is_checkout(Dep) of + true -> rebar_app_info:is_checkout(Dep, false); + false -> Dep + end || Dep <- rebar_state:all_deps(State)], + rebar_state:all_deps(State, DepsIgnoringCheckout); + _ -> + State + end. + -spec format_error(any()) -> iolist(). format_error({unknown_dependency, Name}) -> io_lib:format("Dependency ~ts not found", [Name]); From 7bf61ce66da737389677874cbe65ade6c07a8e5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Costas=20S=C3=A1nchez?= Date: Sat, 30 Oct 2021 17:05:24 +0200 Subject: [PATCH 2/2] Mark deps as checkouts, if needed, after calling the `lock` provider --- src/rebar_prv_upgrade.erl | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/rebar_prv_upgrade.erl b/src/rebar_prv_upgrade.erl index b5e736004..ebfdb3590 100644 --- a/src/rebar_prv_upgrade.erl +++ b/src/rebar_prv_upgrade.erl @@ -111,15 +111,29 @@ do_(State) -> [element(1,Lock) || Lock <- Locks], [rebar_app_info:name(App) || App <- rebar_state:lock(State5)] ), - State6 = maybe_ignore_checkouts(State5, Checkouts), - rebar_prv_lock:do(State6); + AllDeps = rebar_state:all_deps(State), + {Modified, State6} = maybe_unmark_checkouts(State5, AllDeps, Checkouts), + {ok, State7} = rebar_prv_lock:do(State6), + State8 = maybe_mark_checkouts_again(Modified, State7, AllDeps), + {ok, State8}; _ -> Res end end. --spec maybe_ignore_checkouts(rebar_state:t(), [binary()]) -> rebar_state:t(). -maybe_ignore_checkouts(State, Checkouts) -> +-spec maybe_mark_checkouts_again(Modified :: boolean(), + State0 :: rebar_state:t(), + AllDeps :: [rebar_app_info:t()]) -> State1 :: rebar_state:t(). +maybe_mark_checkouts_again(true, State, AllDeps) -> + rebar_state:all_deps(State, AllDeps); +maybe_mark_checkouts_again(false, State, _AllDeps) -> + State. + +-spec maybe_unmark_checkouts(State0 :: rebar_state:t(), + AllDeps :: [rebar_app_info:t()], + Checkouts :: [binary()]) -> + {Modified :: boolean(), State1 :: rebar_state:t()}. +maybe_unmark_checkouts(State, AllDeps, Checkouts) -> OldLocks = rebar_state:get(State, {locks, default}, []), OldLockNames = [element(1,L) || L <- OldLocks], case OldLockNames -- Checkouts of @@ -131,10 +145,10 @@ maybe_ignore_checkouts(State, Checkouts) -> [case rebar_app_info:is_checkout(Dep) of true -> rebar_app_info:is_checkout(Dep, false); false -> Dep - end || Dep <- rebar_state:all_deps(State)], - rebar_state:all_deps(State, DepsIgnoringCheckout); + end || Dep <- AllDeps], + {true, rebar_state:all_deps(State, DepsIgnoringCheckout)}; _ -> - State + {false, State} end. -spec format_error(any()) -> iolist().