-
Notifications
You must be signed in to change notification settings - Fork 365
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
Small refactoring and fixes to opam init
on Windows.
#6000
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kit-ty-kate
added
the
PR: QUEUED
Pending pull request, waiting for other work to be merged or closed
label
Jun 6, 2024
dra27
force-pushed
the
revised-windows-init
branch
5 times, most recently
from
June 6, 2024 20:44
22be138
to
fbf5a9e
Compare
kit-ty-kate
approved these changes
Jun 6, 2024
dra27
force-pushed
the
revised-windows-init
branch
5 times, most recently
from
June 7, 2024 10:48
13850da
to
4697b20
Compare
dra27
force-pushed
the
revised-windows-init
branch
from
June 7, 2024 13:53
4697b20
to
c9bf1f4
Compare
dra27
removed
the
PR: QUEUED
Pending pull request, waiting for other work to be merged or closed
label
Jun 7, 2024
dra27
force-pushed
the
revised-windows-init
branch
from
June 7, 2024 14:11
c9bf1f4
to
719290e
Compare
dra27
force-pushed
the
revised-windows-init
branch
from
June 8, 2024 09:09
719290e
to
c47b295
Compare
Previously, --git-location was treated as a default answer for the Git menu, so it would display an error if Git wasn't found, but then simply exit and fallback to adding Git to the Cygwin installation. Fix this and validate either --git-location argument or the git-location opamrc field as referring to a directory which contains Git.
Rather than filtering git out of the package list, instead add it when required.
Make the ~cygbin parameter to the various executable identification functions optional. The parameter is renamed to search_in_first with a slightly revised semantics - if cygcheck.exe is not found in the directory, then PATH is still searched. This has a key benefit early on in opam init, as it allows cygbin to be set for an internal Cygwin installation which has not yet happened, but still permits curl (et al) to be used from PATH (e.g. when running opam init from an MSYS2 shell). Where before ~cygbin implied that cygcheck _must_ be used from the directory, the new parameter effectively prepends an additional directory to PATH.
Previously, MSYS2 required os-distribution to be overridden in global-variables. Now, as with Cygwin, it is inferred in the same way from cygcheck. In this commit, opam init still sets os-distribution, however, if it is manually removed from the root config file, previously `opam var os-distribution` would return `win32` but now returns `msys2`. Additionally, sys_pkg_manager_cmd is handled in the same way for MSYS2 as for Cygwin, allowing MSYS2 to be automatically added in the same way as Cygwin.
Single argument function with a non-base type.
Includes more checks and also returns the kind of installation which was found.
The ability to copy setup-x86_64.exe is no longer needed - but restore the previous functionality which only downloaded setup if it didn't exist and use this when displaying a command to the user. In this mode, we only download setup-x86_64.exe so that the command we give to the user actually works. If we're actually going to run setup-x86_64.exe, then we download the latest version.
dra27
force-pushed
the
revised-windows-init
branch
from
June 10, 2024 08:54
0ca3440
to
c0cd8f4
Compare
rjbou
approved these changes
Jun 10, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What a small refactoring!! :D it's working smoothly, thanks!
Thanks! |
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
At present includes #5991, #5994 and #5997. The diff becomes slightly less hideous with #5997 merged. The PR includes the behaviour of #5996 and may need #5998 for CI to pass properly.
This PR considerably extends the ideas from #5963. The primary goal is to extend
opam init
on Windows to recognise as many scenarios for getting either Cygwin or MSYS2 as we at present know to exist, so that users are presented with meaningful choices. In particular, this addresses runningopam init
from with a Cygwin or MSYS2 bash shell (in particular, #5952 is fixed).I think it's helpful to start with some scenarios with beta2, and then explain the fixes from there:
opam
installed, we already have an excellent experience which recommends pausing to install Git for Windows (with helpful advice on that added Improvements toopam init
"Git" menu on Windows #5963) and which installs Cygwin.choco install git /GitAndUnixToolsOnPath
), then beta2 displays rather more Git options than might be nice, but Improvements toopam init
"Git" menu on Windows #5963 also makes this a quite elegant experience by default (thebash.exe
included on PATH is correctly shadowed by the internal Cygwin installation, which is recommended).scoop install cygwin msys2 git
- thenopam init
presently works, but neither Git for Windows, MSYS2 or Cygwin are recognised by opam.choco install cyg-get msys2 git
- thenopam init
does detect Git for Windows, but does not detect either the MSYS2 or Cygwin installations.winget install Cygwin.Cygwin MSYS2.MSYS2 Git.Git
- then we have an experience similar to Chocolatey, although as Cygwin is installed to the default C:\cygwin64, that is recognised by opam.opam init
from Git Bash (not a recommended thing to do), then we get hit by Harden curl output parsing #5984, but if we work around that then the experience is OK. This is a scenario where there are tools on the PATH, and running with--no-cygwin-setup
is not as OK -opam var os-distribution
reportingwin32
instead ofmsys2
. That said, using Git Bash to runopam init
is never going to be a good idea (it has no package manager - it's intended for interaction with Git only).PATH
to have MSYS2's main bin directory permanently installed, then the default behaviour ofopam init
is pretty good, unless MSYS2'scurl
shadows Windowscurl
.opam init
from within MSYS2'sbash
the experience both with and without--no-cygwin-setup
is pretty good.PATH
to have Cygwin's main bin directory permanently installed, then the default behaviour is affected by opam init --cygwin-internal-install is ignored from cygwin terminal #5952.opam init
from within Cygwin'sbash
is similarly affected by opam init --cygwin-internal-install is ignored from cygwin terminal #5952.In all of these scenarios where the user has preinstalled either MSYS2 or Cygwin, we do have the issue that
opam init --no-cygwin-setup
(i.e. just using what's found) will typically fail becausepatch
,unzip
and so forth are not installed by default.The changes here seek to make all of those scenarios as awesome as possible.
At a very high-level the changes are:
sys-pkg-manager-cmd
is concerned (if both have been defined, Cygwin takes priority). In particular that means that MSYS2 gets added to PATH in exactly the same way as Cygwin.os-distribution
is no longer explicitly set byopam init
. Instead,os-distribution
is always determined by looking atcygpath.exe
. The internal or--cygwin-location
treatment merely affects PATH resolution (i.e. the internal cygbin addition) - once cygpath.exe is resolved, it becomes the source of truth. Thus, from an MSYS2 shell,opam var os-distribution
is nowmsys2
by default.--cygwin-location
as Cygwin setup was never downloaded.bash
since we have no idea what it may do.opam init
so opam will offer to add the required packages to both Cygwin and MSYS2 for existing installations, rather than simply erroring.Put together, the changes mean that the user is presented with meaningful choices in all 10 of those scenarios and, in particular, they will see all of the packages they have already installed. If they agree with everything opam suggests, they should then always end up with initialised opam with a compiler 🥳
On my system, when added to #5992,
opam init
run from Cygwin's bash now offers: