Plugins: How to determine ghc vs ghci

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Plugins: How to determine ghc vs ghci

Levent Erkok
I'm working on a plugin, and would like to be able to tell if it's GHC or GHCi that's running.

I tried:

   df   <- getDynFlags
   let isGHCi = ghcMode df == CompManager

Alas, while that correctly tells apart "ghci" from "ghc -c", it also returns True when ghc is called without the "-c" argument.

Is there a better/more robust way of figuring out whether we're in an interactive session?

-Levent.

_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: Plugins: How to determine ghc vs ghci

Levent Erkok
Thanks! That indeed does work.

I'm a bit surprised though that there isn't already an internal boolean set somewhere; checking for a string in the arguments sounds a bit fragile.

On Tue, Nov 24, 2015 at 12:28 AM, Aycan İrican <[hidden email]> wrote:
How about `GHC.Environment.getFullArgs` which includes “—interactive” when you’re in GHCi?


> On 24 Nov 2015, at 09:37, Levent Erkok <[hidden email]> wrote:
>
> I'm working on a plugin, and would like to be able to tell if it's GHC or GHCi that's running.
>
> I tried:
>
>    df   <- getDynFlags
>    let isGHCi = ghcMode df == CompManager
>
> Alas, while that correctly tells apart "ghci" from "ghc -c", it also returns True when ghc is called without the "-c" argument.
>
> Is there a better/more robust way of figuring out whether we're in an interactive session?
>
> -Levent.
> _______________________________________________
> ghc-devs mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs



_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: Plugins: How to determine ghc vs ghci

Michael Sloan
The executable-path package wraps this up nicely with its `getScriptPath` function:


Probably best to use this existing function.  Then, if a less fragile solution comes along, getScriptPath can do that instead.

-Michael

On Tue, Nov 24, 2015 at 5:58 PM, Levent Erkok <[hidden email]> wrote:
Thanks! That indeed does work.

I'm a bit surprised though that there isn't already an internal boolean set somewhere; checking for a string in the arguments sounds a bit fragile.

On Tue, Nov 24, 2015 at 12:28 AM, Aycan İrican <[hidden email]> wrote:
How about `GHC.Environment.getFullArgs` which includes “—interactive” when you’re in GHCi?


> On 24 Nov 2015, at 09:37, Levent Erkok <[hidden email]> wrote:
>
> I'm working on a plugin, and would like to be able to tell if it's GHC or GHCi that's running.
>
> I tried:
>
>    df   <- getDynFlags
>    let isGHCi = ghcMode df == CompManager
>
> Alas, while that correctly tells apart "ghci" from "ghc -c", it also returns True when ghc is called without the "-c" argument.
>
> Is there a better/more robust way of figuring out whether we're in an interactive session?
>
> -Levent.
> _______________________________________________
> ghc-devs mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs



_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs



_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: Plugins: How to determine ghc vs ghci

Simon Marlow-7
In reply to this post by Levent Erkok
On 24/11/2015 07:37, Levent Erkok wrote:

> I'm working on a plugin, and would like to be able to tell if it's GHC
> or GHCi that's running.
>
> I tried:
>
>     df   <- getDynFlags
>     let isGHCi = ghcMode df == CompManager
>
> Alas, while that correctly tells apart "ghci" from "ghc -c", it also
> returns True when ghc is called without the "-c" argument.
>
> Is there a better/more robust way of figuring out whether we're in an
> interactive session?

The best way is to check whether hscTarget df == HscInterpreted, and you
can also check whether ghcLink df == LinkInMemory.

Checking for the `--interactive` flag only works for the standalone
GHCi, and not users of the GHC API.

Cheers,
Simon
_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: Plugins: How to determine ghc vs ghci

Levent Erkok
Thanks Simon.. I tried the 'hscTarget df == HscInterpreted' check, and it works perfectly well.

-Levent.

On Fri, Dec 4, 2015 at 12:34 AM, Simon Marlow <[hidden email]> wrote:
On 24/11/2015 07:37, Levent Erkok wrote:
I'm working on a plugin, and would like to be able to tell if it's GHC
or GHCi that's running.

I tried:

    df   <- getDynFlags
    let isGHCi = ghcMode df == CompManager

Alas, while that correctly tells apart "ghci" from "ghc -c", it also
returns True when ghc is called without the "-c" argument.

Is there a better/more robust way of figuring out whether we're in an
interactive session?

The best way is to check whether hscTarget df == HscInterpreted, and you can also check whether ghcLink df == LinkInMemory.

Checking for the `--interactive` flag only works for the standalone GHCi, and not users of the GHC API.

Cheers,
Simon


_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs