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.25k stars 365 forks source link

Windows/Cygwin: opam break the fish environement path #6053

Open Chimrod opened 5 months ago

Chimrod commented 5 months ago

I’m using opam on windows, with the fish environement.

After the environment intialisation, my terminal broke, not reconignizing any basic commands like ls. After digging a bit, It look likes the path where replaced with a mix of unix and windows path.

$ echo $PATH
/usr/local/bin /bin /cygdrive/c/Program Files (x86)/Common Files/Oracle/Java/java8path /cygdrive/c/Program Files (x86)/Common Files/Oracle/Java/javapath /cygdrive/c/Windows/System32 /cygdrive/c/Windows /cygdrive/c/Windows/System32/wbem /cygdrive/c/Windows/System32/WindowsPowerShell/v1.0 /cygdrive/c/Windows/System32/OpenSSH /cygdrive/c/Program Files/PuTTY /cygdrive/c/Program Files/Azure Data Studio/bin /cygdrive/c/Program Files/dotnet /cygdrive/c/Program Files (x86)/GnuPG/bin /cygdrive/c/Program Files (x86)/Microsoft SQL Server/160/DTS/Binn /cygdrive/c/Program Files/PowerShell/7 /cygdrive/c/Program Files/Python39 /cygdrive/c/Users/sdai/AppData/Local/Microsoft/WindowsApps /usr/bin /cygdrive/c/Program Files/Azure Data Studio/bin /cygdrive/c/Users/sdai/AppData/Local/Pandoc /cygdrive/c/Program Files/Neovim/bin /cygdrive/c/Users/sdai/AppData/Local/Programs/GnuPG/bin

Path variable after sourcing

$ source '/cygdrive/d/home/.opam/opam-init/env_hook.fish'
$ echo $PATH
D \home\.opam\basev0.16\bin;D \bin\cygwin\usr\local\bin;D \bin\cygwin\bin;C \Program Files (x86)\Common Files\Oracle\Java\java8path;C \Program Files (x86)\Common Files\Oracle\Java\javapath;C \Windows\System32;C \Windows;C \Windows\System32\wbem;C \Windows\System32\WindowsPowerShell\v1.0;C \Windows\System32\OpenSSH;C \Program Files\PuTTY;C \Program Files\Azure Data Studio\bin;C \Program Files\dotnet;C \Program Files (x86)\GnuPG\bin;C \Program Files (x86)\Microsoft SQL Server\160\DTS\Binn;C \Program Files\PowerShell\7;C \Program Files\Python39;C \Users\sdai\AppData\Local\Microsoft\WindowsApps;D \bin\cygwin\bin;C \Program Files\Azure Data Studio\bin;C \Users\sdai\AppData\Local\Pandoc;C \Program Files\Neovim\bin;C \Users\sdai\AppData\Local\Programs\GnuPG\bin
fish: Unknown command: opam
~/.opam/opam-init/env_hook.fish (line 1):
opam env --shell=fish --readonly 2> /dev/null
^~~^
in command substitution
        called on line 3 of file ~/.opam/opam-init/env_hook.fish
in function '__opam_env_export_eval'
in event handler: handler for generic event 'fish_prompt'
~/.opam/opam-init/env_hook.fish (line 3): Unknown command
    eval (opam env --shell=fish --readonly 2> /dev/null)
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
in function '__opam_env_export_eval'
in event handler: handler for generic event 'fish_prompt'
dra27 commented 5 months ago

Can I double-check which version of opam you're using? Also, what's the output - before sourcing env_hook.fish of opam env itself?

F-Loyer commented 2 months ago

I have a similar error with Opam2.2.1 and bash.

My /cygdrive/c/Users/frede/AppData/Local/opam/opam-init/variables.sh is updated by opam switch, but fails to use Cygwin conventions.

The PATH lines of this script are:

# Updated by package mingw-w64-shims
PATH='C:\Cygwin\usr\x86_64-w64-mingw32\sys-root\mingw\bin':"$PATH"; export PATH;
# Updated by package mingw-w64-shims
PATH='':"$PATH"; export PATH;
# Binary dir for opam switch 5.1.0
PATH='C:\Users\frede\AppData\Local\opam\5.1.0\bin':"$PATH"; export PATH;

The end result is a . in the PATH which prevents ocamlfind to install (the ./INSTALL file is found instead of /usr/bin/install). I guess the . comes from a env_hook.sh and variable.sh interaction. The mingw-w64-shims part is weird (the null entry is considered as . by bash).

I guess the mingw-w64-shims part is generated by ./.opam-switch/packages/mingw-w64-shims.0.2.0/opam which contains:

setenv: [
  [PATH += "%{_:runtime-x86_64}%"]
  [PATH += "%{_:runtime-i686}%"]
]

The first line adds a sensible PATH entry (excepted that there is no Cygwin convention conversion). The second fails to find runtime-i686 and add a null entry.

Note: the MANPATH is set correctly:

MANPATH="$MANPATH":'/cygdrive/c/Users/frede/AppData/Local/opam/5.1.0/man'; export MANPATH;

I have also opened the issue: https://github.com/dra27/mingw-w64-shims/issues/2