diff --git a/ChangeLog.md b/ChangeLog.md index ad58cf70fa..5ffbc958ec 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -97,6 +97,7 @@ Bug fixes: [#4314](https://github.com/commercialhaskell/stack/pull/4314) * Add `--cabal-files` flag to `stack ide targets` command. * Don't download ghc when using `stack clean`. +* `dot` and `ls dependencies` commands no longer require GHC to be installed. Also, ensures the `--no-install-ghc` flag is respected. See: [#4390](https://github.com/commercialhaskell/stack/issues/4390) ## v1.9.1 diff --git a/src/Stack/Runners.hs b/src/Stack/Runners.hs index deaa68f714..7bdd5e4962 100644 --- a/src/Stack/Runners.hs +++ b/src/Stack/Runners.hs @@ -3,6 +3,7 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE RankNTypes #-} -- | Utilities for running stack commands. module Stack.Runners @@ -261,10 +262,18 @@ munlockFile Nothing = return () munlockFile (Just lk) = liftIO $ unlockFile lk -- Plumbing for --test and --bench flags +-- Force enable --no-install-ghc and --skip-ghc-check flags withBuildConfigDot :: DotOpts -> GlobalOpts -> RIO EnvConfig () -> IO () -withBuildConfigDot opts go f = withBuildConfig go' f +withBuildConfigDot opts go = withBuildConfig (updateGlobalOpts go) where - go' = - (if dotTestTargets opts then set (globalOptsBuildOptsMonoidL.buildOptsMonoidTestsL) (Just True) else id) $ - (if dotBenchTargets opts then set (globalOptsBuildOptsMonoidL.buildOptsMonoidBenchmarksL) (Just True) else id) - go + updateGlobalOpts + = updateOpts (dotTestTargets opts) (globalOptsBuildOptsMonoidL.buildOptsMonoidTestsL) (Just True) + . updateOpts (dotBenchTargets opts) (globalOptsBuildOptsMonoidL.buildOptsMonoidBenchmarksL) (Just True) + . set (globalOptsL.configMonoidSkipGHCCheckL) (Just True) + . set (globalOptsL.configMonoidInstallGHCL) (Just False) + +-- helper function for update some option +updateOpts :: Bool -> Lens' opts v -> v -> opts -> opts +updateOpts isRequired opt v + | isRequired = set opt v + | otherwise = id diff --git a/src/Stack/Setup.hs b/src/Stack/Setup.hs index 04c3caf6f5..1030ea8d07 100644 --- a/src/Stack/Setup.hs +++ b/src/Stack/Setup.hs @@ -206,6 +206,17 @@ instance Show SetupException where show UnsupportedSetupConfiguration = "I don't know how to install GHC on your system configuration, please install manually" +checkDownloadCompiler :: (HasConfig env, HasGHCVariant env) + => SetupOpts + -> WithDownloadCompiler + -> RIO env (Maybe ExtraDirs, Maybe CompilerBuild, Bool) +checkDownloadCompiler _ SkipDownloadCompiler = return (Nothing, Nothing, False) +checkDownloadCompiler sopts WithDownloadCompiler + | installIfMissing = ensureCompiler sopts + | otherwise = return (Nothing, Nothing, False) + where + installIfMissing = soptsInstallIfMissing sopts + -- | Modify the environment variables (like PATH) appropriately, possibly doing installation too setupEnv :: (HasBuildConfig env, HasGHCVariant env) => Maybe Text -- ^ Message to give user when necessary GHC is not available @@ -234,10 +245,7 @@ setupEnv mResolveMissingGHC = do , soptsGHCJSBootOpts = ["--clean"] } - (mghcBin, mCompilerBuild, _) <- - case bcDownloadCompiler bconfig of - SkipDownloadCompiler -> return (Nothing, Nothing, False) - WithDownloadCompiler -> ensureCompiler sopts + (mghcBin, mCompilerBuild, _) <- checkDownloadCompiler sopts (bcDownloadCompiler bconfig) -- Modify the initial environment to include the GHC path, if a local GHC -- is being used diff --git a/src/Stack/Types/Config.hs b/src/Stack/Types/Config.hs index fe73732617..519972603c 100644 --- a/src/Stack/Types/Config.hs +++ b/src/Stack/Types/Config.hs @@ -163,6 +163,8 @@ module Stack.Types.Config ,loadedSnapshotL ,shouldForceGhcColorFlag ,appropriateGhcColorFlag + ,configMonoidSkipGHCCheckL + ,configMonoidInstallGHCL -- * Lens reexport ,view ,to @@ -1984,3 +1986,13 @@ appropriateGhcColorFlag :: (HasRunner env, HasEnvConfig env) appropriateGhcColorFlag = f <$> shouldForceGhcColorFlag where f True = Just ghcColorForceFlag f False = Nothing + +configMonoidSkipGHCCheckL :: Lens' ConfigMonoid (Maybe Bool) +configMonoidSkipGHCCheckL = + lens (getFirst . configMonoidSkipGHCCheck) + (\configMonoid t -> configMonoid {configMonoidSkipGHCCheck = First t}) + +configMonoidInstallGHCL :: Lens' ConfigMonoid (Maybe Bool) +configMonoidInstallGHCL = + lens (getFirst . configMonoidInstallGHC) + (\configMonoid t -> configMonoid {configMonoidInstallGHC = First t}) \ No newline at end of file