ocaml / opam

opam is a source-based package manager. It supports multiple simultaneous compiler installations, flexible package constraints, and a Git-friendly development workflow.
https://opam.ocaml.org
Other
1.23k stars 351 forks source link

Installation of `ocp-indent` fails on Windows under Cygwin with `CYGWIN=winsymlinks:nativestrict` #6185

Open nojb opened 2 weeks ago

nojb commented 2 weeks ago

I tried to install ocamlformat.0.26.2 under Windows (running under Cygwin, with the Mingw64 compiler), and it fails when trying to install ocp-indent. I have CYGWIN=winsymlinks:nativestrict set (see https://cygwin.com/cygwin-ug-net/using-cygwinenv.html).

$ opam reinstall ocp-indent
The following actions will be performed:
=== recompile 3 packages
  ↻ ocamlformat     0.26.2 [uses ocamlformat-lib]
  ↻ ocamlformat-lib 0.26.2 [uses ocp-indent]
  ↻ ocp-indent      1.8.1

Proceed with ↻ 3 recompilations? [y/n]

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫
[ERROR] Failed to get sources of ocp-indent.1.8.1: "C:\\cygwin64\\bin\\tar.exe xfz /cygdrive/c/Users/nojebar/AppData/Local/opam/download-cache/md5/70/70db6649a8c08a682ad63730c9752e31 -C /tmp/opam-11712-2b7ba0" exited with code 2
⬇ retrieved ocamlformat.0.26.2, ocamlformat-lib.0.26.2  (cached)

#=== ERROR while fetching sources for ocp-indent.1.8.1 ========================#
OpamSolution.Fetch_fail("\027[33m#\027[0m \027[33mpath\027[0m        ~\\dune\n\027[33m#\027[0m \027[33mcommand\027[0m     C:\\cygwin64\\bin\\tar.exe xfz /cygdrive/c/Users/nojebar/AppData/Local/opam/download-cache/md5/70/70db6649a8c08a682ad63730c9752e31 -C /tmp/opam-11712-2b7ba0\n\027[33m#\027[0m \027[33mexit-code\027[0m   2\n\027[33m#\027[0m \027[33menv-file\027[0m    ~\\AppData\\Local\\opam\\log\\log-11712-2a98a1.env\n\027[33m#\027[0m \027[33moutput-file\027[0m ~\\AppData\\Local\\opam\\log\\log-11712-2a98a1.out\n\027[33m### output ###\n\027[0m\027[33m# \027[0m/usr/bin/tar: ocp-indent-1.8.1/tests/inplace/link.ml: Cannot create symlink to \226\128\152otherfile.ml\226\128\153: No such file or directory\n\027[33m# \027[0m/usr/bin/tar: ocp-indent-1.8.1/tests/inplace/link2.ml: Cannot create symlink to \226\128\152link.ml\226\128\153: No such file or directory\n\027[33m# \027[0m/usr/bin/tar: Exiting with failure status due to previous errors\n")

<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫
β”Œβ”€ The following actions failed
β”‚ ⬇ fetch ocp-indent 1.8.1
└─
╢─ No changes have been performed
# Run eval $(opam env) to update the current shell environment

If I set CYGWIN=winsymlinks:native, then it passes, with a warning:

$ CYGWIN=winsymlinks:native opam install ocp-indent
The following actions will be performed:
=== install 1 package
  βˆ— ocp-indent 1.8.1

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫
[WARNING] Warning: cannot copy C:\cygwin64\tmp\opam-23436-2572f7\ocp-indent-1.8.1\tests\inplace\link.ml to C:\Users\nojebar\dune\_opam\.opam-switch\sources\ocp-indent.1.8.1\tests\inplace
⬇ retrieved ocp-indent.1.8.1  (cached)
βˆ— installed ocp-indent.1.8.1
Done.

My config:

nojebar@PERVERSESHEAF ~/dune
$ opam config report
# opam config report
# opam-version         2.2.1
# self-upgrade         no
# system               arch=x86_64 os=win32 os-distribution=cygwin os-version=10.0.22621
# solver               builtin-mccs+glpk
# install-criteria     -removed,-count[avoid-version,changed],-count[version-lag,request],-count[version-lag,changed],-count[missing-depexts,changed],-changed
# upgrade-criteria     -removed,-count[avoid-version,changed],-count[version-lag,solution],-count[missing-depexts,changed],-new
# jobs                 11
# repositories         1 (http) (default repo at f45685efec14dffa74b060edb3fcc572bfcea34c)
# pinned               0
# current-switch       C:\Users\nojebar\dune
# invariant            []
# compiler-packages    arch-x86_64.1, conf-mingw-w64-gcc-x86_64.1, flexdll.0.43, mingw-w64-shims.0.2.0, ocaml-base-compiler.5.2.0, ocaml-env-mingw64.1, ocaml-options-vanilla.1, system-mingw.1
# mingw-w64-shims:runtime-x86_64 C:\cygwin64\usr\x86_64-w64-mingw32\sys-root\mingw\bin
# mingw-w64-shims:runtime-i686
# ocaml:native         true
# ocaml:native-tools   true
# ocaml:native-dynlink true
# ocaml:stubsdir       C:/Users/nojebar/dune/_opam/lib/ocaml/stublibs;C:/Users/nojebar/dune/_opam/lib/ocaml
# ocaml:preinstalled   false
# ocaml:compiler       5.2.0
dra27 commented 1 week ago

At some point, we would like to switch to using ocaml-tar for the extraction, which would solve this, but the problem usually is having a tarball where the symlink appears before the file itself - this is a problem on Windows, but not on Unix (this is the reason for the mitigation added in #5953 which you can see with your winsymlinks:native version). Having dangling symlinks in a tarball will always be a problem and we should encourage any package which ships tarballs like that, um, not to!

opam internally sets CYGWIN=winsymlinks:native if it detects that native symbolic links are available - I opted to preserve the winsymlinks:nativestrict for Cygwin, on the basis that the user knows best. I'm persuadable, but at the moment, opam is kinda operating as intended.

Note that MSYS2 has a fallback to copying for symlinks, but as far as I know Cygwin doesn't have an equivalent mode for doing that.

nojb commented 6 days ago

Thanks for the explanation @dra27!