Skip to content

Commit 221602b

Browse files
committed
STACK_EXE environment variable
1 parent 5e5edac commit 221602b

File tree

6 files changed

+18
-0
lines changed

6 files changed

+18
-0
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* `stack exec` accepts the `--no-ghc-package-path` parameter
1212
* Don't require build plan to upload [#400](https://github.com/commercialhaskell/stack/issues/400)
1313
* Specifying test components only builds/runs those tests [#398](https://github.com/commercialhaskell/stack/issues/398)
14+
* `STACK_EXE` environment variable
1415

1516
Bug fixes:
1617

src/Stack/Build/Execute.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ withSingleContext ActionContext {..} ExecuteEnv {..} task@Task {..} inner0 =
521521
menv <- liftIO $ configEnvOverride config EnvSettings
522522
{ esIncludeLocals = taskLocation task == Local
523523
, esIncludeGhcPackagePath = False
524+
, esStackExe = False
524525
}
525526
exeName <- liftIO $ join $ findExecutable menv "runhaskell"
526527
distRelativeDir' <- distRelativeDir
@@ -716,6 +717,7 @@ singleTest ac ee task =
716717
menv <- liftIO $ configEnvOverride config EnvSettings
717718
{ esIncludeLocals = taskLocation task == Local
718719
, esIncludeGhcPackagePath = True
720+
, esStackExe = True
719721
}
720722
if exists
721723
then do

src/Stack/Exec.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ defaultEnvSettings :: EnvSettings
2323
defaultEnvSettings = EnvSettings
2424
{ esIncludeLocals = True
2525
, esIncludeGhcPackagePath = True
26+
, esStackExe = True
2627
}
2728

2829
-- | Execute a process within the Stack configured environment.

src/Stack/Setup.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import Stack.Solver (getGhcVersion)
5656
import Stack.Types
5757
import Stack.Types.StackT
5858
import System.Directory (doesDirectoryExist, createDirectoryIfMissing, removeFile)
59+
import System.Environment (getExecutablePath)
5960
import System.Exit (ExitCode (ExitSuccess))
6061
import System.FilePath (searchPathSeparator)
6162
import qualified System.FilePath as FP
@@ -170,6 +171,8 @@ setupEnv = do
170171
, [toFilePath globalDB]
171172
]
172173

174+
executablePath <- liftIO getExecutablePath
175+
173176
envRef <- liftIO $ newIORef Map.empty
174177
let getEnvOverride' es = do
175178
m <- readIORef envRef
@@ -182,6 +185,10 @@ setupEnv = do
182185
then Map.insert "GHC_PACKAGE_PATH" (mkGPP (esIncludeLocals es))
183186
else id)
184187

188+
$ (if esStackExe es
189+
then Map.insert "STACK_EXE" (T.pack executablePath)
190+
else id)
191+
185192
-- For reasoning and duplication, see: https://github.com/fpco/stack/issues/70
186193
$ Map.insert "HASKELL_PACKAGE_SANDBOX" (T.pack $ toFilePath deps)
187194
$ Map.insert "HASKELL_PACKAGE_SANDBOXES"

src/Stack/Types/Config.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ data EnvSettings = EnvSettings
158158
-- ^ include local project bin directory, GHC_PACKAGE_PATH, etc
159159
, esIncludeGhcPackagePath :: !Bool
160160
-- ^ include the GHC_PACKAGE_PATH variable
161+
, esStackExe :: !Bool
162+
-- ^ set the STACK_EXE variable to the current executable name
161163
}
162164
deriving (Show, Eq, Ord)
163165

@@ -689,6 +691,7 @@ getMinimalEnvOverride = do
689691
liftIO $ configEnvOverride config EnvSettings
690692
{ esIncludeLocals = False
691693
, esIncludeGhcPackagePath = False
694+
, esStackExe = False
692695
}
693696

694697
data ProjectAndConfigMonoid

src/main/Main.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ main =
151151
<*> boolFlags True
152152
"ghc-package-path"
153153
"setting the GHC_PACKAGE_PATH variable for the subprocess"
154+
idm
155+
<*> boolFlags True
156+
"stack-exe"
157+
"setting the STACK_EXE environment variable to the path for the stack executable"
154158
idm))
155159
addCommand "ghc"
156160
"Run ghc"

0 commit comments

Comments
 (0)