Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GHC_PACKAGE_PATH not visible from running code #294

Open
mgsloan opened this issue Jul 22, 2015 · 5 comments
Open

GHC_PACKAGE_PATH not visible from running code #294

mgsloan opened this issue Jul 22, 2015 · 5 comments
Labels
Milestone

Comments

@mgsloan
Copy link
Contributor

mgsloan commented Jul 22, 2015

This is a side effect of #295

Repro:

stack runghc test.hs, where "test.hs" is

{-# LANGUAGE OverloadedStrings #-}
import qualified Data.ByteString.Char8 as S8
import           Data.Monoid           ((<>))
import           IdeSession

main :: IO ()
main = do
    -- Initialization and providing some code
    config <- sessionConfigFromEnv
    sess <- initSession defaultSessionInitParams config
        { configLocalWorkingDir = Nothing }
    let upd = updateSourceFile "Main.hs" "import System.Environment\nmain = print =<< lookupEnv \"GHC_PACKAGE_PATH\""
           <> updateCodeGeneration True
    updateSession sess upd print -- print is used for progress updates
    -- Run the code
    ra <- runStmt sess "Main" "main"
    let loop = do
            res <- runWait ra
            case res of
                Left bs -> S8.putStr bs >> loop
                Right rr -> putStrLn $ "Run result: " ++ show rr
    loop

Expected: something like `Just "STACK:PACKAGE:DB:PATHS"``

Actual: Nothing

When this is fixed, a test like the above should be added to make sure it stays fixed

@mgsloan mgsloan mentioned this issue Jul 22, 2015
@mgsloan mgsloan added the bug label Jul 22, 2015
@mgsloan mgsloan added this to the 1.0 milestone Aug 6, 2015
@urbanslug
Copy link
Contributor

Oh yeah this is what I was talking about when I told you I had an issue with sessionConfigFromEnv https://hackage.haskell.org/package/ide-backend-0.10.0/docs/IdeSession.html#v:sessionConfigFromEnv. My solution to this was getting config in the program's entry point (when it is being called from the terminal) and the config around as an argument wherever it is needed internally.

Like so: https://github.com/urbanslug/wai-devel/blob/master/src/Devel.hs#L16

@mgsloan
Copy link
Contributor Author

mgsloan commented Aug 14, 2015

Hmm, I don't follow. Why is this a problem for wai-devel? The only ramifications for wai-devel is that the web application wouldn't see GHC_PACKAGE_PATH. So, this could matter if your web application invoked stack or GHC.

@urbanslug
Copy link
Contributor

The issue wasn't that applications were unable to find GHC_PACKAGE_PATH but ide-backend (and consequently wai-devel) failed to properly load sessionConfigFromEnv during recompiles. Wai-devel calls for recompiles from within a function when it notices file changes. Therefore, when wai-devel looked up sessionConfigFromEnv when a recompile was kicked off internally it failed to find GHC_PACKAGE_PATH because ide-backend could not.

@mgsloan
Copy link
Contributor Author

mgsloan commented Aug 14, 2015

Ahh, yes, that's a good point! Currently sessionConfigFromEnv, won't work properly after one session has run (it clears the GHC_PACKAGE_PATH environment). I hadn't considered that, thanks for bringing it up.

@urbanslug
Copy link
Contributor

Haha told you I had your back 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants