haskell / haskell-ide-engine

The engine for haskell ide-integration. Not an IDE
BSD 3-Clause "New" or "Revised" License
2.38k stars 211 forks source link

stack ./install.hs stack-install-cabal failed #1436

Closed muhajirdev closed 4 years ago

muhajirdev commented 4 years ago
$ stack ./install.hs stack-install-cabal
run from: stack
# stack (for cabal)
# stack (for cabal)
Error when running Shake build system:
  at want, called at src/Development/Shake/Internal/Args.hs:81:69 in shake-0.17.8-42j6WLpuW2RLDjaIMjbO7Y:Development.Shake.Internal.Args
* Depends on: stack-install-cabal
  at need, called at src/HieInstall.hs:94:55 in hie-install-0.8.0.0-217T3gMG2hYDJU1sGHGe5h:HieInstall
* Depends on: cabal
* Raised the exception:
PATH: getEnv: does not exist (no environment variable)
muhajirdev commented 4 years ago

Anyone how do I solve this? Do I need provide any other information?

jneira commented 4 years ago

Hi! The code is assuming the environment variable PATH is set. What is your system? It should not fail in this case but it is weird that the variable dont ever exist in the environment. As temporary workaround you can try set the variable (with an empty value) before calling the script.

jhrcek commented 4 years ago

What operating system are you using? It seems that you PATH environment variable is not set, not sure why. My understanding is that the installation script is trying to check if cabal is installed on your system (by checking for presence of "cabal" binary on your PATH). If I were you, I'd first start to investigate why the PATH variable is not set in your environment.

jneira commented 4 years ago

In any case i've done a patch to ignore the $PATH env var if it is not set. Unfortunately the lookupEnv :: IO (Maybe String) function throws an error if the env var is not set, instead return Nothing (as i expected)

muhajirdev commented 4 years ago

I am using Mac OS catalina.

I tried to echo $PATH

it gives me this

/Users/muhammadmuhajir/.local/bin:/Users/muhammadmuhajir/.bin:/Users/muhammadmuhajir/tools/flutter/bin:/Users/muhammadmuhajir/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Library/Apple/bin:/usr/local/go/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users/muhammadmuhajir/Library/Android/sdk/tools:/Users/muhammadmuhajir/Library/Android/sdk/tools/bin:/Users/muhammadmuhajir/Library/Android/sdk/platform-tools:/Users/muhammadmuhajir/Library/Android/sdk/emulator:/Users/muhammadmuhajir/go/bin:/Users/muhammadmuhajir/.local/bin

Also when I open VSCode Haskell Language server's log.

I got this

Executable named nix-shell not found on path: ["/Users/muhammadmuhajir/.local/bin","/Users/muhammadmuhajir/.bin","/Users/muhammadmuhajir/tools/flutter/bin","/Users/muhammadmuhajir/.cargo/bin","/usr/local/bin","/usr/bin","/bin","/usr/sbin","/sbin","/Library/Apple/usr/bin","/Library/Apple/bin","/usr/local/go/bin","/Library/Frameworks/Mono.framework/Versions/Current/Commands","/Users/muhammadmuhajir/Library/Android/sdk/tools","/Users/muhammadmuhajir/Library/Android/sdk/tools/bin","/Users/muhammadmuhajir/Library/Android/sdk/platform-tools","/Users/muhammadmuhajir/Library/Android/sdk/emulator","/Users/muhammadmuhajir/go/bin"]
Warning: readStack:
         Bootstrapping stack project environment failed: readCreateProcess: /usr/local/bin/stack "path" (exit 1): failed
cabal-helper-wrapper: dieVerbatim: user error (cabal-helper-wrapper: The program 'ghc' version >=7.0.1 is required but it
could not be found.
)
hie-wrapper: readCreateProcess: /Users/muhammadmuhajir/dev/haskell-ide-engine/.stack-work/install/x86_64-osx/5d17925ab3b750b1436967f307d653fe48255385833608c3cbf760d29f9c8f9d/8.6.1/bin/cabal-helper-wrapper "--with-ghc=ghc" "--with-ghc-pkg=ghc-pkg" "--with-cabal=cabal" "v1-style" "/Users/muhammadmuhajir/dev/haskell-ide-engine" "dist-newstyle" "dist-dir" (exit 1): failed
[Info  - 8:05:03 PM] Connection to server got closed. Server will restart.
2019-11-06 20:05:03.898358 [ThreadId 4] - run entered for hie-wrapper(hie-wrapper) Version 0.13.0.0, Git revision 7cf1295a2804a527381331bb7b73d58255721edc (dirty) (3051 commits) x86_64 ghc-8.6.1
2019-11-06 20:05:03.899699 [ThreadId 4] - Current directory:/Users/muhammadmuhajir/dev/haskell-ide-engine
2019-11-06 20:05:03.900088 [ThreadId 4] - Operating system:darwin
Executable named nix-shell not found on path: ["/Users/muhammadmuhajir/.local/bin","/Users/muhammadmuhajir/.bin","/Users/muhammadmuhajir/tools/flutter/bin","/Users/muhammadmuhajir/.cargo/bin","/usr/local/bin","/usr/bin","/bin","/usr/sbin","/sbin","/Library/Apple/usr/bin","/Library/Apple/bin","/usr/local/go/bin","/Library/Frameworks/Mono.framework/Versions/Current/Commands","/Users/muhammadmuhajir/Library/Android/sdk/tools","/Users/muhammadmuhajir/Library/Android/sdk/tools/bin","/Users/muhammadmuhajir/Library/Android/sdk/platform-tools","/Users/muhammadmuhajir/Library/Android/sdk/emulator","/Users/muhammadmuhajir/go/bin"]
Warning: readStack:
         Bootstrapping stack project environment failed: readCreateProcess: /usr/local/bin/stack "path" (exit 1): failed
cabal-helper-wrapper: dieVerbatim: user error (cabal-helper-wrapper: The program 'ghc' version >=7.0.1 is required but it
could not be found.
)
hie-wrapper: readCreateProcess: /Users/muhammadmuhajir/dev/haskell-ide-engine/.stack-work/install/x86_64-osx/5d17925ab3b750b1436967f307d653fe48255385833608c3cbf760d29f9c8f9d/8.6.1/bin/cabal-helper-wrapper "--with-ghc=ghc" "--with-ghc-pkg=ghc-pkg" "--with-cabal=cabal" "v1-style" "/Users/muhammadmuhajir/dev/haskell-ide-engine" "dist-newstyle" "dist-dir" (exit 1): failed
[Info  - 8:05:04 PM] Connection to server got closed. Server will restart.
2019-11-06 20:05:04.161147 [ThreadId 4] - run entered for hie-wrapper(hie-wrapper) Version 0.13.0.0, Git revision 7cf1295a2804a527381331bb7b73d58255721edc (dirty) (3051 commits) x86_64 ghc-8.6.1
2019-11-06 20:05:04.16278 [ThreadId 4] - Current directory:/Users/muhammadmuhajir/dev/haskell-ide-engine
2019-11-06 20:05:04.163207 [ThreadId 4] - Operating system:darwin
Executable named nix-shell not found on path: ["/Users/muhammadmuhajir/.local/bin","/Users/muhammadmuhajir/.bin","/Users/muhammadmuhajir/tools/flutter/bin","/Users/muhammadmuhajir/.cargo/bin","/usr/local/bin","/usr/bin","/bin","/usr/sbin","/sbin","/Library/Apple/usr/bin","/Library/Apple/bin","/usr/local/go/bin","/Library/Frameworks/Mono.framework/Versions/Current/Commands","/Users/muhammadmuhajir/Library/Android/sdk/tools","/Users/muhammadmuhajir/Library/Android/sdk/tools/bin","/Users/muhammadmuhajir/Library/Android/sdk/platform-tools","/Users/muhammadmuhajir/Library/Android/sdk/emulator","/Users/muhammadmuhajir/go/bin"]
Warning: readStack:
         Bootstrapping stack project environment failed: readCreateProcess: /usr/local/bin/stack "path" (exit 1): failed
cabal-helper-wrapper: dieVerbatim: user error (cabal-helper-wrapper: The program 'ghc' version >=7.0.1 is required but it
could not be found.
)
hie-wrapper: readCreateProcess: /Users/muhammadmuhajir/dev/haskell-ide-engine/.stack-work/install/x86_64-osx/5d17925ab3b750b1436967f307d653fe48255385833608c3cbf760d29f9c8f9d/8.6.1/bin/cabal-helper-wrapper "--with-ghc=ghc" "--with-ghc-pkg=ghc-pkg" "--with-cabal=cabal" "v1-style" "/Users/muhammadmuhajir/dev/haskell-ide-engine" "dist-newstyle" "dist-dir" (exit 1): failed
[Info  - 8:05:04 PM] Connection to server got closed. Server will restart.
2019-11-06 20:05:04.413266 [ThreadId 4] - run entered for hie-wrapper(hie-wrapper) Version 0.13.0.0, Git revision 7cf1295a2804a527381331bb7b73d58255721edc (dirty) (3051 commits) x86_64 ghc-8.6.1
2019-11-06 20:05:04.414979 [ThreadId 4] - Current directory:/Users/muhammadmuhajir/dev/haskell-ide-engine
2019-11-06 20:05:04.415425 [ThreadId 4] - Operating system:darwin
Executable named nix-shell not found on path: ["/Users/muhammadmuhajir/.local/bin","/Users/muhammadmuhajir/.bin","/Users/muhammadmuhajir/tools/flutter/bin","/Users/muhammadmuhajir/.cargo/bin","/usr/local/bin","/usr/bin","/bin","/usr/sbin","/sbin","/Library/Apple/usr/bin","/Library/Apple/bin","/usr/local/go/bin","/Library/Frameworks/Mono.framework/Versions/Current/Commands","/Users/muhammadmuhajir/Library/Android/sdk/tools","/Users/muhammadmuhajir/Library/Android/sdk/tools/bin","/Users/muhammadmuhajir/Library/Android/sdk/platform-tools","/Users/muhammadmuhajir/Library/Android/sdk/emulator","/Users/muhammadmuhajir/go/bin"]
Warning: readStack:
         Bootstrapping stack project environment failed: readCreateProcess: /usr/local/bin/stack "path" (exit 1): failed
cabal-helper-wrapper: dieVerbatim: user error (cabal-helper-wrapper: The program 'ghc' version >=7.0.1 is required but it
could not be found.
)
hie-wrapper: readCreateProcess: /Users/muhammadmuhajir/dev/haskell-ide-engine/.stack-work/install/x86_64-osx/5d17925ab3b750b1436967f307d653fe48255385833608c3cbf760d29f9c8f9d/8.6.1/bin/cabal-helper-wrapper "--with-ghc=ghc" "--with-ghc-pkg=ghc-pkg" "--with-cabal=cabal" "v1-style" "/Users/muhammadmuhajir/dev/haskell-ide-engine" "dist-newstyle" "dist-dir" (exit 1): failed
[Info  - 8:05:04 PM] Connection to server got closed. Server will restart.
2019-11-06 20:05:04.6665 [ThreadId 4] - run entered for hie-wrapper(hie-wrapper) Version 0.13.0.0, Git revision 7cf1295a2804a527381331bb7b73d58255721edc (dirty) (3051 commits) x86_64 ghc-8.6.1
2019-11-06 20:05:04.668041 [ThreadId 4] - Current directory:/Users/muhammadmuhajir/dev/haskell-ide-engine
2019-11-06 20:05:04.668454 [ThreadId 4] - Operating system:darwin
Executable named nix-shell not found on path: ["/Users/muhammadmuhajir/.local/bin","/Users/muhammadmuhajir/.bin","/Users/muhammadmuhajir/tools/flutter/bin","/Users/muhammadmuhajir/.cargo/bin","/usr/local/bin","/usr/bin","/bin","/usr/sbin","/sbin","/Library/Apple/usr/bin","/Library/Apple/bin","/usr/local/go/bin","/Library/Frameworks/Mono.framework/Versions/Current/Commands","/Users/muhammadmuhajir/Library/Android/sdk/tools","/Users/muhammadmuhajir/Library/Android/sdk/tools/bin","/Users/muhammadmuhajir/Library/Android/sdk/platform-tools","/Users/muhammadmuhajir/Library/Android/sdk/emulator","/Users/muhammadmuhajir/go/bin"]
Warning: readStack:
         Bootstrapping stack project environment failed: readCreateProcess: /usr/local/bin/stack "path" (exit 1): failed
cabal-helper-wrapper: dieVerbatim: user error (cabal-helper-wrapper: The program 'ghc' version >=7.0.1 is required but it
could not be found.
)
hie-wrapper: readCreateProcess: /Users/muhammadmuhajir/dev/haskell-ide-engine/.stack-work/install/x86_64-osx/5d17925ab3b750b1436967f307d653fe48255385833608c3cbf760d29f9c8f9d/8.6.1/bin/cabal-helper-wrapper "--with-ghc=ghc" "--with-ghc-pkg=ghc-pkg" "--with-cabal=cabal" "v1-style" "/Users/muhammadmuhajir/dev/haskell-ide-engine" "dist-newstyle" "dist-dir" (exit 1): failed
[Error - 8:05:04 PM] Connection to server got closed. Server will not be restarted.
fendor commented 4 years ago

While this is a separate issue, do you have nix installed on your system? Or maybe in the config.yaml enabled nix although nix is not installed?

jneira commented 4 years ago

@muhajirdev hi! the pr is merged and it should fix the error, unfortunately i can test it myself cause it is not reproducible in windows systems could you try again to install cabal after update the hie project to lastest master?

jneira commented 4 years ago

Maybe we should continue investigate why the $PATH env var is not accesible through System.Environment.lookupEnv but it seems it is not related directly with hie itself (maybe it is defined in ~/.bash_profile but no in ~/.bashrc?)

muhajirdev commented 4 years ago

Okay, I tried to git pull.

stack ./install.hs stack-install-cabal
run from: stack
# stack (for cabal)
# stack (for cabal)
Error when running Shake build system:
  at want, called at src/Development/Shake/Internal/Args.hs:81:69 in shake-0.17.8-42j6WLpuW2RLDjaIMjbO7Y:Development.Shake.Internal.Args
* Depends on: stack-install-cabal
  at need, called at src/HieInstall.hs:94:55 in hie-install-0.8.0.0-217T3gMG2hYDJU1sGHGe5h:HieInstall
* Depends on: cabal
* Raised the exception:
PATH: getEnv: does not exist (no environment variable)

Still giving me this.

But I tried build-all. It doesn't gives any error.

jneira commented 4 years ago

Well, that is really weird. Thanks for test, it is hard to fix a bug that is not reproducible in local. Just in case, could you check if you local copy contains the commit with the fix (c253cbb)? If it is so the only cause i can think of is the IOException throwed is not a doesNotExistError but that would be really strange cause the message is exactly the same.

pcaisse commented 4 years ago

I'm running into this same issue (and I have c253cbb). I'm very new to the Haskell ecosystem, so bear with me.

I installed ghc and stack successfully but when I ran stack install.hs cabal-ghcs I saw that I had an older version of ghc installed (8.0.1). I then went and installed the latest and greatest (8.8.1) according to these instructions (I'm on Debian Stretch) and then I started getting the error.

In case it helps:

$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.8.1
$ stack --version
Version 2.1.3, Git revision 636e3a759d51127df2b62f90772def126cdf6d1f (7735 commits) x86_64 hpack-0.31.2
$ cabal --version
cabal-install version 3.0.0.0
compiled using version 3.0.0.0 of the Cabal library
$ stack install.hs cabal-ghcs
run from: stack

******************************
Found the following GHC paths:
ghc-8.8.1: /opt/ghc/bin/ghc
ghc-8.0.1: /usr/bin/ghc

******************************

Build completed in 0.00s
$ stack ./install.hs help
run from: stack

Usage:
    stack install.hs <target>
    or
    cabal new-run install.hs --project-file install/shake.project <target>

Targets:
    help                    Show help message including all targets

    build                   Builds hie with all installed GHCs
    build-all               Builds hie for all installed GHC versions and the data files
    build-data              Get the required data-files for `hie` (Hoogle DB)
    hie-8.4.2               Builds hie for GHC version 8.4.2
    hie-8.4.3               Builds hie for GHC version 8.4.3
    hie-8.4.4               Builds hie for GHC version 8.4.4
    hie-8.6.1               Builds hie for GHC version 8.6.1
    hie-8.6.2               Builds hie for GHC version 8.6.2
    hie-8.6.3               Builds hie for GHC version 8.6.3
    hie-8.6.4               Builds hie for GHC version 8.6.4
    hie-8.6.5               Builds hie for GHC version 8.6.5

    stack-build             Builds hie with all installed GHCs; with stack
    stack-build-all         Builds hie for all installed GHC versions and the data files; with stack
    stack-build-data        Get the required data-files for `hie` (Hoogle DB); with stack
    stack-install-cabal     Install the cabal executable. It will install the required minimum version for hie (currently 2.4.1.0) if it isn't already present in $PATH; with stack
    stack-hie-8.4.2         Builds hie for GHC version 8.4.2; with stack
    stack-hie-8.4.3         Builds hie for GHC version 8.4.3; with stack
    stack-hie-8.4.4         Builds hie for GHC version 8.4.4; with stack
    stack-hie-8.6.1         Builds hie for GHC version 8.6.1; with stack
    stack-hie-8.6.2         Builds hie for GHC version 8.6.2; with stack
    stack-hie-8.6.3         Builds hie for GHC version 8.6.3; with stack
    stack-hie-8.6.4         Builds hie for GHC version 8.6.4; with stack
    stack-hie-8.6.5         Builds hie for GHC version 8.6.5; with stack

    cabal-ghcs              Show all GHC versions that can be installed via `cabal-build` and `cabal-build-all`.
    cabal-build             Builds hie with all installed GHCs; with cabal
    cabal-build-all         Builds hie for all installed GHC versions and the data files; with cabal
    cabal-build-data        Get the required data-files for `hie` (Hoogle DB); with cabal
    cabal-hie-8.8.1         Builds hie for GHC version 8.8.1; with cabal
    cabal-hie-8.0.1         Builds hie for GHC version 8.0.1; with cabal

    icu-macos-fix           Fixes icu related problems in MacOS

Build completed in 0.00s
$ stack install.hs cabal-hie-8.8.1
run from: stack
# git (for submodules)
Synchronizing submodule url for 'submodules/HaRe'
Synchronizing submodule url for 'submodules/cabal-helper'
Synchronizing submodule url for 'submodules/ghc-mod'
# git (for submodules)
# stack (for cabal)
# stack (for cabal)
Error when running Shake build system:
  at want, called at src/Development/Shake/Internal/Args.hs:81:69 in shake-0.17.8-42j6WLpuW2RLDjaIMjbO7Y:Development.Shake.Internal.Args
* Depends on: cabal-hie-8.8.1
  at need, called at src/HieInstall.hs:121:9 in hie-install-0.8.0.0-217T3gMG2hYDJU1sGHGe5h:HieInstall
* Depends on: cabal
* Raised the exception:
PATH: getEnv: does not exist (no environment variable)
$ git show c253cbb
commit c253cbb68a0e36521442fd0882c4ca1e81cf3641
Merge: 0bbec7d7 b089c8b6
Author: Javier Neira <atreyu.bbb@gmail.com>
Date:   Thu Nov 7 10:33:33 2019 +0100

    Merge pull request #1437 from jneira/ignore-unset-path

    Ignore the stack PATH fix if the env var is not set
fendor commented 4 years ago

Note, hie does neither support GHC 8.0.1 nor 8.8.1 and the installation script should not actually show these as an option. I will open another issue for that.

There is a path variable defined though, right? So, echo $PATH actually exists?

pcaisse commented 4 years ago

There is a path variable defined though, right? So, echo $PATH actually exists?

Yes, it does. When I run echo $PATH everything seems correct and /opt/ghc/bin is in there.

jneira commented 4 years ago

Well, as there is more than one case with enough info, i think we should start to think to remove the $PATH hack, whatever it is the cause of the exception.

jneira commented 4 years ago

Hi, i've pushed a version that catch all IOException's trying to get the $PATH environment var: https://github.com/haskell/haskell-ide-engine/compare/ignore-unset-path?expand=1 That is the unique cause that can i think of to explain the bug.

@pcaisse @muhajirdev could you try it? In your clone of haskell-ide-engine you can do

$ git fetch
$ git checkout ignore-unset-path
$ stack ./install.hs stack-install-cabal

Thanks in advance!

NOTE: if that doesnt work we can try (the last attempt!) to catch all exceptions, replacing IOException by SomeException in this line

pcaisse commented 4 years ago

This didn't seem to help or make any difference for me :man_shrugging:

samhopp commented 4 years ago

I have this same issue on one of my machines. On my macOS 10.13 (High Sierra) machine the command works fine. But on my macOS 10.14 (Mojave) machine it fails with the same error message as in OP. I tried the fix in ignore-unset-path as well as

NOTE: if that doesnt work we can try (the last attempt!) to catch all exceptions, replacing IOException by SomeException in this line

but neither of them changes the result or error message. I even went ahead and changed the function to let getEnvErrorHandler e | isDoesNotExistError e = return Nothing | otherwise = return Nothing which did nothing. (I am a beginner in Haskell Programming, so feel free to laugh at my code-editing-fu)

Running "stack ghci", importing System.Environment and running 'getEnv "PATH"' gives a result that contains my $PATH plus some extra folders added by Stack.

I cannot figure out what else is different between my two machines related to Stack/ghc beside the macOS version. I believe Apple made some security related changes/improvements in Mojave. My guess is that the error is somehow related to those changes.

jneira commented 4 years ago

Thanks for reporting @samhopp. Sorry i should mention that (hopefully) the fix for the issue is in the pr: #1452.

samhopp commented 4 years ago

Thanks for reporting @samhopp. Sorry i should mention that (hopefully) the fix for the issue is in the pr: #1452.

I implemented that fix, and it did indeed fix the problem. 👍

I'm not sure if this warning needs fixing or not, but adding this here just in case. This is the end of the output of 'stack ./install.hs stack-install-cabal'. I replaced my user directory with ~ as it contains my real name. My system's $PATH does not contain that snapshots directory, but Stack will add that to it's own PATH. That is 'getEnv "PATH"' contains $PATH plus that snapshots directory.

cabal-install > Installing executable cabal in ~/.stack/snapshots/x86_64-osx/24ec7d661c33b5e1cb4cca2c3d5614cb9e7a02b67f7bb4a8f9f0a727e14c37e2/8.6.4/bin Completed 11 action(s).
Copying from ~/.stack/snapshots/x86_64-osx/24ec7d661c33b5e1cb4cca2c3d5614cb9e7a02b67f7bb4a8f9f0a727e14c37e2/8.6.4/bin/cabal to ~/.local/bin/cabal

Copied executables to ~/.local/bin:

  • cabal

Warning: The cabal executable found on the PATH environment variable is ~/.stack/snapshots/x86_64->osx/24ec7d661c33b5e1cb4cca2c3d5614cb9e7a02b67f7bb4a8f9f0a727e14c37e2/8.6.4/bin/cabal and not the version that was just installed. This means that cabal calls on the command line will not use this version. Build completed in 12m00s

jneira commented 4 years ago

thanks all for your patience and test reports and sorry for the inconveniences (the error was caused by a bug introduced by myself) @pcaisse, @muhajirdev could you give a try to actual master? 6e0b7bf should fix the issue

pcaisse commented 4 years ago

@jneira that fixes it for me :+1: