atom-haskell-archive / haskell-ghc-mod

haskell-ghc-mod atom package
https://atom.io/packages/haskell-ghc-mod
MIT License
69 stars 20 forks source link

fails to recognize bash PATH for ghc-mod / ghc-modi #52

Closed wolftune closed 8 years ago

wolftune commented 8 years ago

I had tested this originally when installing ghc-mod via cabal and now with installing via stack. In both cases, I have ghc-mod on my bash PATH, i.e. I can run "which ghc-mod" and see the path and also can simply run "ghc-mod" with no path specified anywhere in bash and it works. It is on my path.

However, haskell-ghc-mod says that it can't find ghc-mod and ghc-modi unless I go to the settings and provide the path explicitly. So, the default path of just ghc-mod (thus deferring to the path known by bash) is not working.

lierdakil commented 8 years ago

Are you on OSX?

wolftune commented 8 years ago

I'm on Ubuntu

lierdakil commented 8 years ago

That's interesting. What version of haskell-ghc-mod are you running?

lierdakil commented 8 years ago

In any case, if you're below v0.9.1, try updating. If it's still the case with v0.9.1, open haskell-ghc-mod settings, enable debug, restart Atom, and post dev.console output here. That should give me a general idea of what goes wrong.

wolftune commented 8 years ago

Looks like it's somehow just ignoring my PATH settings from .bashrc

I have in that file: export PATH=.cabal-sandbox/bin:$HOME/.cabal/bin:$HOME/bin:$HOME/.local/bin:$PATH

And ghc-mod (per everything that happens with stack install) is in ~/.local/bin — which is in that export line I just posted above. It looks like this is what is happening: haskell-ghc-mod is skipping any hidden path that starts with .. I can tell because it included the one path from my line above that was not a dot (hidden) directory.

haskell-ghc-mod debug: getProcessOptions(undefined)
util.coffee:10 haskell-ghc-mod trace:util.coffee:10 module.exports.Util.debug
util.coffee:9 haskell-ghc-mod debug: PATH = /home/aaron/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
util.coffee:10 haskell-ghc-mod trace:util.coffee:10 module.exports.Util.debug
util.coffee:9 haskell-ghc-mod debug: getProcessOptions(undefined)
util.coffee:10 haskell-ghc-mod trace:util.coffee:10 module.exports.Util.debug
util.coffee:9 haskell-ghc-mod debug: PATH = /home/aaron/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
util.coffee:10 haskell-ghc-mod trace:util.coffee:10 module.exports.Util.debug
util.coffee:9 haskell-ghc-mod debug: running ghc-mod lang with options.cwd = undefined,options.env = [object Object]
util.coffee:10 haskell-ghc-mod trace:util.coffee:10 module.exports.Util.debug
util.coffee:9 haskell-ghc-mod debug: getProcessOptions(undefined)
util.coffee:10 haskell-ghc-mod trace:util.coffee:10 module.exports.Util.debug
util.coffee:9 haskell-ghc-mod debug: PATH = /home/aaron/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
util.coffee:10 haskell-ghc-mod trace:util.coffee:10 module.exports.Util.debug
index.js:46 Window load time: 2542ms
util.coffee:9 haskell-ghc-mod debug: getRootDir path = /home/aaron/sites-programs/snowdrift atom.project.getDirectories()[0] = /home/aaron/sites-programs/snowdrift buffer.file?.getParent?() = /home/aaron/sites-programs/snowdrift/Handler
util.coffee:10 haskell-ghc-mod trace:util.coffee:10 module.exports.Util.debug
util.coffee:9 haskell-ghc-mod debug: Handler.Donate created
util.coffee:10 haskell-ghc-mod trace:util.coffee:10 module.exports.Util.debug
util.coffee:9 haskell-ghc-mod debug: Handler.Donate updating
util.coffee:10 haskell-ghc-mod trace:util.coffee:10 module.exports.Util.debug
util.coffee:9 haskell-ghc-mod debug: getProcessOptions(/home/aaron/sites-programs/snowdrift)
util.coffee:10 haskell-ghc-mod trace:util.coffee:10 module.exports.Util.debug
util.coffee:9 haskell-ghc-mod debug: PATH = /home/aaron/sites-programs/snowdrift/.cabal-sandbox/bin:/home/aaron/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
util.coffee:10 haskell-ghc-mod trace:util.coffee:10 module.exports.Util.debug
util.coffee:9 haskell-ghc-mod debug: running ghc-mod browse,-d,Handler.Donate with options.cwd = /home/aaron/sites-programs/snowdrift,options.env = [object Object]
util.coffee:10 haskell-ghc-mod trace:util.coffee:10 module.exports.Util.debug
util.coffee:9 haskell-ghc-mod debug: getRootDir path = /home/aaron/sites-programs/snowdrift atom.project.getDirectories()[0] = /home/aaron/sites-programs/snowdrift buffer.file?.getParent?() = /home/aaron/sites-programs/snowdrift/Handler
util.coffee:10 haskell-ghc-mod trace:util.coffee:10 module.exports.Util.debug
util.coffee:9 haskell-ghc-mod debug: Handler.Donate buffer is set
util.coffee:10 haskell-ghc-mod trace:util.coffee:10 module.exports.Util.debug
util.coffee:9 haskell-ghc-mod debug: Import created
util.coffee:10 haskell-ghc-mod trace:util.coffee:10 module.exports.Util.debug
util.coffee:9 haskell-ghc-mod debug: Import updating
util.coffee:10 haskell-ghc-mod trace:util.coffee:10 module.exports.Util.debug
util.coffee:9 haskell-ghc-mod debug: getProcessOptions(/home/aaron/sites-programs/snowdrift)
util.coffee:10 haskell-ghc-mod trace:util.coffee:10 module.exports.Util.debug
util.coffee:9 haskell-ghc-mod debug: PATH = /home/aaron/sites-programs/snowdrift/.cabal-sandbox/bin:/home/aaron/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
util.coffee:10 haskell-ghc-mod trace:util.coffee:10 module.exports.Util.debug
util.coffee:9 haskell-ghc-mod debug: getRootDir path = /home/aaron/sites-programs/snowdrift atom.project.getDirectories()[0] = /home/aaron/sites-programs/snowdrift buffer.file?.getParent?() = /home/aaron/sites-programs/snowdrift/Handler
util.coffee:10 haskell-ghc-mod trace:util.coffee:10 module.exports.Util.debug
util.coffee:9 haskell-ghc-mod debug: Import moduleName mismatch: Handler.Donate != Import
util.coffee:10 haskell-ghc-mod trace:util.coffee:10 module.exports.Util.debug
util.coffee:9 haskell-ghc-mod debug: getRootDir path = /home/aaron/sites-programs/snowdrift atom.project.getDirectories()[0] = /home/aaron/sites-programs/snowdrift buffer.file?.getParent?() = /home/aaron/sites-programs/snowdrift/Handler
util.coffee:10 haskell-ghc-mod trace:util.coffee:10 module.exports.Util.debug
util.coffee:9 haskell-ghc-mod debug: Import moduleName mismatch: Handler.HonorPledge != Import
util.coffee:10 haskell-ghc-mod trace:util.coffee:10 module.exports.Util.debug
util.coffee:9 haskell-ghc-mod debug: getRootDir path = /home/aaron/sites-programs/snowdrift atom.project.getDirectories()[0] = /home/aaron/sites-programs/snowdrift buffer.file?.getParent?() = /home/aaron/sites-programs/snowdrift/Handler
util.coffee:10 haskell-ghc-mod trace:util.coffee:10 module.exports.Util.debug
util.coffee:9 haskell-ghc-mod debug: Import moduleName mismatch: Handler.Image != Import
util.coffee:10 haskell-ghc-mod trace:util.coffee:10 module.exports.Util.debug
util.coffee:9 haskell-ghc-mod debug: Prelude created
util.coffee:10 haskell-ghc-mod trace:util.coffee:10 module.exports.Util.debug
util.coffee:9 haskell-ghc-mod debug: Prelude updating
util.coffee:10 haskell-ghc-mod trace:util.coffee:10 module.exports.Util.debug
util.coffee:9 haskell-ghc-mod debug: getProcessOptions(/home/aaron/sites-programs/snowdrift)
util.coffee:10 haskell-ghc-mod trace:util.coffee:10 module.exports.Util.debug
util.coffee:9 haskell-ghc-mod debug: PATH = /home/aaron/sites-programs/snowdrift/.cabal-sandbox/bin:/home/aaron/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
util.coffee:10 haskell-ghc-mod trace:util.coffee:10 module.exports.Util.debug
util.coffee:9 haskell-ghc-mod debug: getRootDir path = /home/aaron/sites-programs/snowdrift atom.project.getDirectories()[0] = /home/aaron/sites-programs/snowdrift buffer.file?.getParent?() = /home/aaron/sites-programs/snowdrift/Handler
util.coffee:10 haskell-ghc-mod trace:util.coffee:10 module.exports.Util.debug
util.coffee:9 haskell-ghc-mod debug: Prelude moduleName mismatch: Handler.Donate != Prelude
util.coffee:10 haskell-ghc-mod trace:util.coffee:10 module.exports.Util.debug
util.coffee:9 haskell-ghc-mod debug: getRootDir path = /home/aaron/sites-programs/snowdrift atom.project.getDirectories()[0] = /home/aaron/sites-programs/snowdrift buffer.file?.getParent?() = /home/aaron/sites-programs/snowdrift/Handler
util.coffee:10 haskell-ghc-mod trace:util.coffee:10 module.exports.Util.debug
util.coffee:9 haskell-ghc-mod debug: Prelude moduleName mismatch: Handler.HonorPledge != Prelude
/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:19 haskell-ghc-mod trace:/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:19 module.exports.Util.debug
/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:18 haskell-ghc-mod debug: getRootDir path = /home/aaron/sites-programs/snowdrift atom.project.getDirectories()[0] = /home/aaron/sites-programs/snowdrift buffer.file?.getParent?() = /home/aaron/sites-programs/snowdrift/Handler
/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:19 haskell-ghc-mod trace:/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:19 module.exports.Util.debug
/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:18 haskell-ghc-mod debug: Prelude moduleName mismatch: Handler.Image != Prelude
/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:19 haskell-ghc-mod trace:/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:19 module.exports.Util.debug
2/home/aaron/.atom/packages/haskell-ghc-mod/lib/ghc-modi-process-base.coffee:137 Using fallback child_process because of spawn ghc-mod ENOENT
/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:18 haskell-ghc-mod debug: running ghc-mod flag with options.cwd = undefined,options.env = [object Object]
/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:19 haskell-ghc-mod trace:/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:19 module.exports.Util.debug
/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:18 haskell-ghc-mod debug: Handler.Donate updated
/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:19 haskell-ghc-mod trace:/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:19 module.exports.Util.debug
/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:18 haskell-ghc-mod debug: running ghc-mod browse,-d,Import with options.cwd = /home/aaron/sites-programs/snowdrift,options.env = [object Object]
/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:19 haskell-ghc-mod trace:/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:19 module.exports.Util.debug
2/home/aaron/.atom/packages/haskell-ghc-mod/lib/ghc-modi-process-base.coffee:137 Using fallback child_process because of spawn ghc-mod ENOENT
/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:18 haskell-ghc-mod debug: Import updated
/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:19 haskell-ghc-mod trace:/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:19 module.exports.Util.debug
/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:18 haskell-ghc-mod debug: running ghc-mod browse,-d,Prelude with options.cwd = /home/aaron/sites-programs/snowdrift,options.env = [object Object]
/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:19 haskell-ghc-mod trace:/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:19 module.exports.Util.debug
/home/aaron/.atom/packages/haskell-ghc-mod/lib/ghc-modi-process-base.coffee:137 Using fallback child_process because of spawn ghc-mod ENOENT
/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:18 haskell-ghc-mod debug: Prelude updated
/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:19 haskell-ghc-mod trace:/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:19 module.exports.Util.debug
/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:18 haskell-ghc-mod debug: getRootDir path = /home/aaron/sites-programs/snowdrift atom.project.getDirectories()[0] = /home/aaron/sites-programs/snowdrift buffer.file?.getParent?() = /home/aaron/sites-programs/snowdrift/Handler
/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:19 haskell-ghc-mod trace:/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:19 module.exports.Util.debug
/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:18 haskell-ghc-mod debug: getProcessOptions(/home/aaron/sites-programs/snowdrift)
/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:19 haskell-ghc-mod trace:/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:19 module.exports.Util.debug
/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:18 haskell-ghc-mod debug: PATH = /home/aaron/sites-programs/snowdrift/.cabal-sandbox/bin:/home/aaron/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:19 haskell-ghc-mod trace:/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:19 module.exports.Util.debug
/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:18 haskell-ghc-mod debug: Trying to run ghc-modi in /home/aaron/sites-programs/snowdrift
/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:19 haskell-ghc-mod trace:/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:19 module.exports.Util.debug
/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:18 haskell-ghc-mod debug: Checking for ghc-modi in /home/aaron/sites-programs/snowdrift
/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:19 haskell-ghc-mod trace:/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:19 module.exports.Util.debug
/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:18 haskell-ghc-mod debug: Spawning new ghc-modi instance for /home/aaron/sites-programs/snowdrift with options.cwd = /home/aaron/sites-programs/snowdrift,options.env = [object Object]
/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:19 haskell-ghc-mod trace:/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:19 module.exports.Util.debug
/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:18 haskell-ghc-mod debug: Running ghc-modi command type,/home/aaron/sites-programs/snowdrift/Handler/HonorPledge.hs,,17,31
/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:19 haskell-ghc-mod trace:/home/aaron/.atom/packages/haskell-ghc-mod/lib/util.coffee:19 module.exports.Util.debug
events.js:141 Uncaught Error: spawn ghc-modi ENOENT
lierdakil commented 8 years ago

Here's a crazy idea: does Atom execute your bashrc at all? bashrc is supposed to run only on interactive sessions, so while any terminal will execute it, Atom will likely not.

Quick test: add this line to .bash_profile: source ~/.bashrc Another quick test: run this in dev.console to get PATH Atom gets from environment: process.env.PATH

wolftune commented 8 years ago

Well, this is getting somewhere. The .bash_profile idea didn't help — again, it was clear that this wasn't the issue, because Atom was getting something from .bashrc already, it just was selecting only the path that wasn't a hidden directory.

process.env.PATH showed the same list that I posted in the debug report. Atom is getting only the non-hidden-directory paths. I suppose I should open a ticket for Atom itself?

lierdakil commented 8 years ago

Okay, one last thing before you go to Atom's repo. Try to start Atom from a terminal session (do check that PATH is what you expect it to be in terminal first), and running process.env.PATH. You'll need to do this when writing Atom issue report anyway.

wolftune commented 8 years ago

That did it! All works fine when I run atom from the terminal. So now what? Report to Atom? Can you do that? Or you know what to fix otherwise?

lierdakil commented 8 years ago

This seems to suggest that I was right after all.

Try restarting X session after adding source ~/.bashrc to .bash_profile -- it might not pick this up otherwise... Sorry I forgot to mention it before.

lierdakil commented 8 years ago

A usual caveat with this is that .bash_profile is run only on login shell, so there would be no way to change this without a session restart...

wolftune commented 8 years ago

source ~/.bashrc did not work, but I tried putting the export path statement itself directly in .bash_profile and that worked.

In some sense, this exact detail is fixed for me, but this can only be considered a work-around because lots of instructions and standard things about having ghc-mod or other things on one's path, including the instructions for Stack, mention .bashrc as the example thing. I know it varies by system and shell in some ways, but if something is on the path via .bashrc, it would be ideal not to have to tell everyone to duplicate or move the lines to .bash_profile. So, I hope there's a clean way to fix this.

lierdakil commented 8 years ago

Long story short: you can't change environment of a parent process. There are some hacky options, like BASH_ENV (see here for details: https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html). But there is no silver bullet for environment setup.

If it helps, here is my take on this: .bash_profile:

[ -r ~/.profile ] && source ~/.profile
[ -r ~/.bashrc ] && source ~/.bashrc

.profile:

export EDITOR=`which vim`
export PATH=$PATH:$HOME/bin
export PATH=$PATH:$HOME/node_modules/.bin
export PATH=$PATH:$HOME/work/phymonus/stage/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/work/phymonus/stage/lib
export  LESS_TERMCAP_mb=$'\E[01;36m' \
    LESS_TERMCAP_md=$'\E[01;32m' \
    LESS_TERMCAP_me=$'\E[0m' \
    LESS_TERMCAP_mu=$'\E[01;37m' \
    LESS_TERMCAP_se=$'\E[0m' \
    LESS_TERMCAP_so=$'\E[01;44;33m' \
    LESS_TERMCAP_ue=$'\E[0m' \
    LESS_TERMCAP_us=$'\E[01;36m'
export GROFF_NO_SGR=1

Bashrc has only shell setup in it (prompt etc).

Reason why I have all environment in .profile is I use zsh sometimes. Not sure on why examples suggest .bashrc, since environment setup in bashrc is usually not a very good idea (since it's only executed on non-login interactive sessions)

wolftune commented 8 years ago

Well, I think I understand the issue and it's bigger than haskell-ghc-mod, so this should be closed?