Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove duplicated message when trying to upgrade a checkout dep #2634

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

pablocostass
Copy link
Contributor

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.

Fixes #2466.

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.
@@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was already addresses by #2335, I think, but I forgot to remove it then.

@@ -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),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes the checkouts list will have duplicated dep names, this should also help remove duplicated messages.

OldLockNames ->
DepsIgnoringCheckout =
[case rebar_app_info:is_checkout(Dep) of
true -> rebar_app_info:is_checkout(Dep, false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this will now hide status of whether a dep is a checkout dep to any provider that relies on locking (i.e. compiling). This may break a lot of stuff.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I thought so too. If the state that lock uses has no checkout apps, it will definitely be passed onto other providers that lock calls/relies on.

Thanks for bringing it up, because for a second I forgot that although the code executed by lock will not have any issues, the provider returns its own state for others to use.

Would it make sense then to, in line 115, match on {ok, State7} = rebar_prv_lock:do(State6) and patch again the state by marking again as checkouts accordingly the dependencies?

Copy link
Collaborator

@ferd ferd Oct 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might work. It could possibly be simpler to just keep a quick cache entry about it. The rebar agent does it internally by carrying explicit state:

rebar3/src/rebar_agent.erl

Lines 166 to 172 in c102379

%% @private function to display a warning for the feature only once
-spec maybe_show_warning(#state{}) -> #state{}.
maybe_show_warning(S=#state{show_warning=true}) ->
?WARN("This feature is experimental and may be modified or removed at any time.", []),
S#state{show_warning=false};
maybe_show_warning(State) ->
State.

The config handler uses the app env values to do it:
%% @private outputs a warning for a newer lockfile format than supported
%% at most once.
%% The warning can also be cancelled by configuring the `warn_config_vsn'
%% OTP env variable.
-spec warn_vsn_once() -> ok.
warn_vsn_once() ->
Warn = application:get_env(rebar, warn_config_vsn) =/= {ok, false},
application:set_env(rebar, warn_config_vsn, false),
case Warn of
false -> ok;
true ->
?WARN("Rebar3 detected a lock file from a newer version. "
"It will be loaded in compatibility mode, but important "
"information may be missing or lost. It is recommended to "
"upgrade Rebar3.", [])
end.

I like that one because it also allows people to tweak or change the cache behaviour in weird cases like tests.

The pdict could work in more restrained cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah using app environment is a nice thing that rebar3 uses in some features. I do not think, however, it would translate well into removing a duplicated message :/

As for the cache, the idea is good, but given that the lock provider does not modify the list of dependencies, the simplest approach IMO is to keep said list in a variable and after calling that provider from upgrade, setting the list of dependencies of the new state to that. No need to introduce a record/cache to keep track of the list when the use case is this minimal, although I will keep it in mind for other providers :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

upgrade: duplicate messages for checkouts not being locked
2 participants