GHC_PACKAGE_PATH not visible from running code
Opened this issue · 5 comments
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
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
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.
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.
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.
Haha told you I had your back 😄