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

Make sure that OPAMROOT and OPAMSWITCH are properly set when executing build commands #4668

Merged
merged 4 commits into from
May 21, 2021

Conversation

LasseBlaauwbroek
Copy link
Contributor

If one installs a package in a root or switch that is not currently active, and that package calls the opam binary during installation, it will not see the correct root/switch because the environment variables are not set.

Examples:

opam install coq-tactician-stdlib --root=my-root
opam install coq-tactician-stdlib --switch=my-switch

@dra27 dra27 added this to PR in Progress in Opam 2.1.x via automation May 18, 2021
@dra27
Copy link
Member

dra27 commented May 18, 2021

Ouch! Thanks for spotting and fixing this. I think we should fix it more defensively, though:

  • OpamConfigCommand.exec does not need optional parameters (all uses of it are labelled)
  • OpamEnv.get_opam and OpamEnv.get_opam_raw are never called with optional arguments, so ?set_opamswitch and ?set_opamroot can sensible be made non-optional
  • Having done that, the only uses of OpamEnv.get_full with explicit ~set_opamroot and ~set_opamswitch are the ones in this PR: we can either change the default to be true (which I think is better) or do what's here and have OpamEnv.get_full have non-optional arguments too

However, this is a breaking change, albeit a sensible one. It is possible to workaround the present behaviour by explicitly passing --root and --switch to opam calls - i.e. adding "--root" root "--switch" switch to your opam file or using %{root}% and %{switch}% as appropriate.

@LasseBlaauwbroek
Copy link
Contributor Author

Is this what you propose?

@dra27
Copy link
Member

dra27 commented May 18, 2021

Yes, except for OpamEnv.get_full - I meant that it would either have ?set_opamroot and ?set_opamswitch as now but with ?(set_opamroot=true) and ?(set_opamswitch=true) or just ~set_opamroot and ~set_opamswitch (as for OpamEnv.get_opam_raw)

@LasseBlaauwbroek
Copy link
Contributor Author

Done

@dra27
Copy link
Member

dra27 commented May 18, 2021

Thanks for the fast updates! This looks fine to me (assuming CI agrees), we just need to determine whether the "breakage" is OK

@rjbou
Copy link
Collaborator

rjbou commented May 18, 2021

I'll take a look to failing tests.

@rjbou rjbou self-assigned this May 18, 2021
@rjbou rjbou self-requested a review May 18, 2021 13:29
@rjbou
Copy link
Collaborator

rjbou commented May 18, 2021

héhé in fact the PR fixed the test. It was kept on purpose ^^ (to be checked later)

@rjbou
Copy link
Collaborator

rjbou commented May 18, 2021

Updated with a test for this specific case. Otherwise, lgtm! Thanks @LasseBlaauwbroek !

Opam 2.1.x automation moved this from PR in Progress to PR Finalised May 18, 2021
@dra27
Copy link
Member

dra27 commented May 18, 2021

Thanks, @rjbou! We just now need to decide whether this is 2.0+, 2.1+ or 2.2+ 🙂

@LasseBlaauwbroek
Copy link
Contributor Author

Thanks @rjbou! Regarding versions: It seems to me that If this is breaking, and it is happening in a 2.x, then it might as well be the most recent unreleased one, so 2.1. I would say it is exceedingly unlikely that a package or workflow is relying on an incorrectly set root or switch specifically for opam invocations during builds.

@dra27
Copy link
Member

dra27 commented May 19, 2021

@LasseBlaauwbroek - it is definitely a breaking change! We already have --set-switch and --set-root for opam config and opam exec to control precisely this. I don't think there's a sensible use-case for the old behaviour, but there is the fact that once changed, there are then two different behaviours in released versions.

@LasseBlaauwbroek
Copy link
Contributor Author

LasseBlaauwbroek commented May 19, 2021

Sure, I agree it is breaking. I'm just suggesting that the break might as well be early then (in 2.1) because the breakage seems exceedingly small and it'll have to break at some point.

Copy link
Member

@dra27 dra27 left a comment

Choose a reason for hiding this comment

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

Discussed this morning, and approved for 2.0.9 and 2.1, thanks!

@dra27 dra27 merged commit 200552b into ocaml:master May 21, 2021
Opam 2.1.x automation moved this from PR Finalised to Done May 21, 2021
@dra27 dra27 mentioned this pull request May 21, 2021
2 tasks
dra27 added a commit that referenced this pull request May 25, 2021
Parameter accidentally lost rebasing over #4668.
@rjbou rjbou added this to the 2.1.0~rc milestone May 28, 2021
@rjbou rjbou modified the milestones: 2.1.0~rc, 2.0.9 Jun 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Opam 2.1.x
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants