opam icon indicating copy to clipboard operation
opam copied to clipboard

Create opam root in `%LOCALAPPDATA%\opam` on Windows

Open dra27 opened this issue 3 years ago • 5 comments

If .opam is found in either %HOME% or %USERPROFILE% then use that, but roots are otherwise created in %LOCALAPPDATA%\opam.

This strategy is forwards-compatible with any switch to XDG (which would definitely introduce the situation where existing roots would be read from locations other than where a new root would be init'd). The location for Windows was discussed in #3766.

dra27 avatar Aug 02 '22 16:08 dra27

This is great; ordinary opam.exe will be able to read OPAMROOT from Diskuv's opam.exe.

jonahbeckford avatar Aug 02 '22 16:08 jonahbeckford

The use of %HOME% also makes it compatible with opam-repository-mingw

dra27 avatar Aug 02 '22 20:08 dra27

LGTM

jonahbeckford avatar Aug 02 '22 20:08 jonahbeckford

Looks like a tweak is needed to the runners. opam init is also incorrectly displaying ~\.opam as the install location.

dra27 avatar Aug 03 '22 09:08 dra27

Thanks for the review, @AltGr! I've hopefully fixed the CI - beforehand, OpamStd.Sys.home was falling to the default of .opam in the CWD which was a dreadful default for Windows, but actually correct for the runners (that's fixed by setting OPAMROOT)

There's an extra commit to be checked, though. I've altered the code so that you now get the correct display on Windows:

  In normal operation, opam only alters files within ~\AppData\Local\opam.

but while there it was worth fixing #4992 as well. If the root is not the default, then you get this slightly different message:

  In normal operation, opam only alters files within your opam root
    (~\AppData\Local\opam by default; currently C:\Devel\opam-2\root).

We could possibly be more explicit about why the root has been overridden (there are three possibilities: --root, OPAMROOT or a legacy location - i.e. somewhere a root is read from but not written like %HOME%\.opam on Windows) but I expect that it's fine as it is.

dra27 avatar Aug 08 '22 19:08 dra27

Thanks a lot!

kit-ty-kate avatar Sep 01 '22 12:09 kit-ty-kate