Skip to content

Commit

Permalink
STACK_EXE environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
snoyberg committed Jun 25, 2015
1 parent 5e5edac commit 221602b
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* `stack exec` accepts the `--no-ghc-package-path` parameter
* Don't require build plan to upload [#400](https://github.com/commercialhaskell/stack/issues/400)
* Specifying test components only builds/runs those tests [#398](https://github.com/commercialhaskell/stack/issues/398)
* `STACK_EXE` environment variable

Bug fixes:

Expand Down
2 changes: 2 additions & 0 deletions src/Stack/Build/Execute.hs
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ withSingleContext ActionContext {..} ExecuteEnv {..} task@Task {..} inner0 =
menv <- liftIO $ configEnvOverride config EnvSettings
{ esIncludeLocals = taskLocation task == Local
, esIncludeGhcPackagePath = False
, esStackExe = False
}
exeName <- liftIO $ join $ findExecutable menv "runhaskell"
distRelativeDir' <- distRelativeDir
Expand Down Expand Up @@ -716,6 +717,7 @@ singleTest ac ee task =
menv <- liftIO $ configEnvOverride config EnvSettings
{ esIncludeLocals = taskLocation task == Local
, esIncludeGhcPackagePath = True
, esStackExe = True
}
if exists
then do
Expand Down
1 change: 1 addition & 0 deletions src/Stack/Exec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ defaultEnvSettings :: EnvSettings
defaultEnvSettings = EnvSettings
{ esIncludeLocals = True
, esIncludeGhcPackagePath = True
, esStackExe = True
}

-- | Execute a process within the Stack configured environment.
Expand Down
7 changes: 7 additions & 0 deletions src/Stack/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import Stack.Solver (getGhcVersion)
import Stack.Types
import Stack.Types.StackT
import System.Directory (doesDirectoryExist, createDirectoryIfMissing, removeFile)
import System.Environment (getExecutablePath)
import System.Exit (ExitCode (ExitSuccess))
import System.FilePath (searchPathSeparator)
import qualified System.FilePath as FP
Expand Down Expand Up @@ -170,6 +171,8 @@ setupEnv = do
, [toFilePath globalDB]
]

executablePath <- liftIO getExecutablePath

envRef <- liftIO $ newIORef Map.empty
let getEnvOverride' es = do
m <- readIORef envRef
Expand All @@ -182,6 +185,10 @@ setupEnv = do
then Map.insert "GHC_PACKAGE_PATH" (mkGPP (esIncludeLocals es))
else id)

$ (if esStackExe es
then Map.insert "STACK_EXE" (T.pack executablePath)
else id)

-- For reasoning and duplication, see: https://github.com/fpco/stack/issues/70
$ Map.insert "HASKELL_PACKAGE_SANDBOX" (T.pack $ toFilePath deps)
$ Map.insert "HASKELL_PACKAGE_SANDBOXES"
Expand Down
3 changes: 3 additions & 0 deletions src/Stack/Types/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ data EnvSettings = EnvSettings
-- ^ include local project bin directory, GHC_PACKAGE_PATH, etc
, esIncludeGhcPackagePath :: !Bool
-- ^ include the GHC_PACKAGE_PATH variable
, esStackExe :: !Bool
-- ^ set the STACK_EXE variable to the current executable name
}
deriving (Show, Eq, Ord)

Expand Down Expand Up @@ -689,6 +691,7 @@ getMinimalEnvOverride = do
liftIO $ configEnvOverride config EnvSettings
{ esIncludeLocals = False
, esIncludeGhcPackagePath = False
, esStackExe = False
}

data ProjectAndConfigMonoid
Expand Down
4 changes: 4 additions & 0 deletions src/main/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ main =
<*> boolFlags True
"ghc-package-path"
"setting the GHC_PACKAGE_PATH variable for the subprocess"
idm
<*> boolFlags True
"stack-exe"
"setting the STACK_EXE environment variable to the path for the stack executable"
idm))
addCommand "ghc"
"Run ghc"
Expand Down

0 comments on commit 221602b

Please sign in to comment.