Skip to content

Commit

Permalink
Add STACK_WORK env var #3063
Browse files Browse the repository at this point in the history
  • Loading branch information
mgsloan committed Mar 16, 2017
1 parent 9e47ba5 commit 1bd5f6a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Other enhancements:
possible to avoid running out of space in `/tmp`.
See [#3018](https://github.com/commercialhaskell/stack/issues/3018)
* Add short synonyms for `test-arguments` and `benchmark-arguments` options.
* Adds `STACK_WORK` environment variable, to specify work dir.
See [#3063](https://github.com/commercialhaskell/stack/issues/3063)

Bug fixes:

Expand Down
6 changes: 5 additions & 1 deletion src/Stack/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,11 @@ configFromConfigMonoid
configFromConfigMonoid
configStackRoot configUserConfigPath configAllowLocals mresolver
mproject ConfigMonoid{..} = do
let configWorkDir = fromFirst $(mkRelDir ".stack-work") configMonoidWorkDir
-- If --stack-work is passed, prefer it. Otherwise, if STACK_WORK
-- is set, use that. If neither, use the default ".stack-work"
mstackWorkEnv <- liftIO $ lookupEnv stackWorkEnvVar
configWorkDir0 <- maybe (return $(mkRelDir ".stack-work")) parseRelDir mstackWorkEnv
let configWorkDir = fromFirst configWorkDir0 configMonoidWorkDir
-- This code is to handle the deprecation of latest-snapshot-url
configUrls <- case (getFirst configMonoidLatestSnapshotUrl, getFirst (urlsMonoidLatestSnapshot configMonoidUrls)) of
(Just url, Nothing) -> do
Expand Down
5 changes: 5 additions & 0 deletions src/Stack/Constants.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module Stack.Constants
,imageStagingDir
,projectDockerSandboxDir
,stackDotYaml
,stackWorkEnvVar
,stackRootEnvVar
,stackRootOptionName
,deprecatedStackRootOptionName
Expand Down Expand Up @@ -201,6 +202,10 @@ stackProgName = "stack"
stackDotYaml :: Path Rel File
stackDotYaml = $(mkRelFile "stack.yaml")

-- | Environment variable used to override the '.stack-work' relative dir.
stackWorkEnvVar :: String
stackWorkEnvVar = "STACK_WORK"

-- | Environment variable used to override the '~/.stack' location.
stackRootEnvVar :: String
stackRootEnvVar = "STACK_ROOT"
Expand Down
3 changes: 2 additions & 1 deletion src/Stack/Options/ConfigParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ configOptsParser hide0 =
<*> optionalFirst (option (eitherReader (mapLeft showWorkDirError . parseRelDir))
( long "work-dir"
<> metavar "WORK-DIR"
<> help "Override work directory (default: .stack-work)"
<> help ("Relative path of work directory " ++
"(Overrides any STACK_WORK environment variable, default is '.stack-work')")
<> hide
))
<*> buildOptsMonoidParser hide0
Expand Down

0 comments on commit 1bd5f6a

Please sign in to comment.