Skip to content

Commit 0bdab6e

Browse files
committed
Don't require an existing GHC installation for stack config set
Fixes #2692.
1 parent 0817109 commit 0bdab6e

File tree

4 files changed

+27
-15
lines changed

4 files changed

+27
-15
lines changed

src/Stack/Config.hs

+12
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module Stack.Config
2929
,packagesParser
3030
,resolvePackageEntry
3131
,getImplicitGlobalProjectDir
32+
,getStackYaml
3233
,getSnapshots
3334
,makeConcreteResolver
3435
,checkOwnership
@@ -141,6 +142,17 @@ getImplicitGlobalProjectDir config =
141142
where
142143
stackRoot = configStackRoot config
143144

145+
-- | This is slightly more expensive than @'asks' ('bcStackYaml' '.' 'getBuildConfig')@
146+
-- and should only be used when no 'BuildConfig' is at hand.
147+
getStackYaml
148+
:: (MonadIO m, MonadLogger m, MonadReader env m, HasConfig env)
149+
=> m (Path Abs File)
150+
getStackYaml = do
151+
config <- asks getConfig
152+
case configMaybeProject config of
153+
Just (_project, stackYaml) -> return stackYaml
154+
Nothing -> liftM (</> stackDotYaml) (getImplicitGlobalProjectDir config)
155+
144156
-- | Download the 'Snapshots' value from stackage.org.
145157
getSnapshots :: (MonadThrow m, MonadMask m, MonadIO m, MonadReader env m, HasHttpManager env, HasConfig env, MonadLogger m)
146158
=> m Snapshots

src/Stack/ConfigCmd.hs

+9-8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module Stack.ConfigCmd
1212
,cfgCmdName) where
1313

1414
import Control.Applicative
15+
import Control.Monad
1516
import Control.Monad.Catch (MonadMask, throwM)
1617
import Control.Monad.IO.Class
1718
import Control.Monad.Logger
@@ -29,7 +30,7 @@ import qualified Options.Applicative.Types as OA
2930
import Path
3031
import Prelude -- Silence redundant import warnings
3132
import Stack.BuildPlan
32-
import Stack.Config (makeConcreteResolver)
33+
import Stack.Config (makeConcreteResolver, getStackYaml)
3334
import Stack.Types.BuildPlan
3435
import Stack.Types.Config
3536

@@ -56,18 +57,18 @@ cfgCmdSet :: ( MonadIO m
5657
, MonadBaseControl IO m
5758
, MonadMask m
5859
, MonadReader env m
59-
, HasBuildConfig env
60+
, HasConfig env
6061
, HasHttpManager env
6162
, HasGHCVariant env
6263
, MonadLogger m)
6364
=> ConfigCmdSet -> m ()
6465
cfgCmdSet cmd = do
6566
configFilePath <-
66-
asks
67-
(toFilePath .
68-
case configCmdSetScope cmd of
69-
CommandScopeProject -> bcStackYaml . getBuildConfig
70-
CommandScopeGlobal -> configUserConfigPath . getConfig)
67+
liftM
68+
toFilePath
69+
(case configCmdSetScope cmd of
70+
CommandScopeProject -> getStackYaml
71+
CommandScopeGlobal -> asks (configUserConfigPath . getConfig))
7172
-- We don't need to worry about checking for a valid yaml here
7273
(config :: Yaml.Object) <-
7374
liftIO (Yaml.decodeFileEither configFilePath) >>= either throwM return
@@ -87,7 +88,7 @@ cfgCmdSetValue
8788
, MonadBaseControl IO m
8889
, MonadMask m
8990
, MonadReader env m
90-
, HasBuildConfig env
91+
, HasConfig env
9192
, HasHttpManager env
9293
, HasGHCVariant env
9394
, MonadLogger m)

src/Stack/Types/Config.hs

+2
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,8 @@ data Config =
345345
,configDumpLogs :: !DumpLogs
346346
-- ^ Dump logs of local non-dependencies when doing a build.
347347
,configMaybeProject :: !(Maybe (Project, Path Abs File))
348+
-- ^ 'Just' when a local project can be found, 'Nothing' when stack must
349+
-- fall back on the implicit global project.
348350
}
349351

350352
-- | Which packages do ghc-options on the command line apply to?

src/main/Main.hs

+4-7
Original file line numberDiff line numberDiff line change
@@ -843,13 +843,10 @@ dockerCleanupCmd cleanupOpts go@GlobalOpts{..} = do
843843
Docker.cleanup cleanupOpts
844844

845845
cfgSetCmd :: ConfigCmd.ConfigCmdSet -> GlobalOpts -> IO ()
846-
cfgSetCmd co go@GlobalOpts{..} =
847-
withBuildConfigAndLock
848-
go
849-
(\_ -> do env <- ask
850-
runReaderT
851-
(cfgCmdSet co)
852-
env)
846+
cfgSetCmd co go@GlobalOpts {..} =
847+
withMiniConfigAndLock go $
848+
do env <- ask
849+
runReaderT (cfgCmdSet co) env
853850

854851
imgDockerCmd :: (Bool, [Text]) -> GlobalOpts -> IO ()
855852
imgDockerCmd (rebuild,images) go@GlobalOpts{..} = do

0 commit comments

Comments
 (0)