From cc94a92d29003313d71b40ce05efd0a27f13c5b8 Mon Sep 17 00:00:00 2001 From: Mike Pilgrem Date: Wed, 19 Apr 2023 16:59:36 +0100 Subject: [PATCH] Re #2407 Move EnvSettings out of Stack.Types.Config --- package.yaml | 1 + src/Stack/Build/ConstructPlan.hs | 4 +- src/Stack/Build/Execute.hs | 5 +- src/Stack/ConfigCmd.hs | 5 +- src/Stack/Exec.hs | 5 +- src/Stack/Ghci.hs | 4 ++ src/Stack/Hoogle.hs | 7 +-- src/Stack/Options/ExecParser.hs | 2 +- src/Stack/Script.hs | 6 +-- src/Stack/Setup.hs | 8 +-- src/Stack/Types/Config.hs | 93 +------------------------------- src/Stack/Types/Config/Build.hs | 36 +++++++++++++ src/Stack/Types/EnvSettings.hs | 61 +++++++++++++++++++++ stack.cabal | 1 + 14 files changed, 125 insertions(+), 113 deletions(-) create mode 100644 src/Stack/Types/EnvSettings.hs diff --git a/package.yaml b/package.yaml index 2bc50c8fce..6cf0a62100 100644 --- a/package.yaml +++ b/package.yaml @@ -280,6 +280,7 @@ library: - Stack.Types.DumpLogs - Stack.Types.DumpPackage - Stack.Types.EnvConfig + - Stack.Types.EnvSettings - Stack.Types.GHCDownloadInfo - Stack.Types.GHCVariant - Stack.Types.GhcOptionKey diff --git a/src/Stack/Build/ConstructPlan.hs b/src/Stack/Build/ConstructPlan.hs index e35ab5139c..72f6144ae5 100644 --- a/src/Stack/Build/ConstructPlan.hs +++ b/src/Stack/Build/ConstructPlan.hs @@ -45,14 +45,14 @@ import Stack.Types.CompilerPaths ( CompilerPaths (..), HasCompiler (..) ) import Stack.Types.Config ( BuildOpts (..), BuildOptsCLI (..), BuildSubset (..) - , Config (..), Curator (..), EnvSettings (..), HasConfig (..) - , minimalEnvSettings, stackRootL + , Config (..), Curator (..), HasConfig (..), stackRootL ) import Stack.Types.Dependency ( DepValue (DepValue), DepType (AsLibrary) ) import Stack.Types.DumpPackage ( DumpPackage (..) ) import Stack.Types.EnvConfig ( EnvConfig (..), HasEnvConfig (..), HasSourceMap (..) ) +import Stack.Types.EnvSettings ( EnvSettings (..), minimalEnvSettings ) import Stack.Types.GHCVariant ( HasGHCVariant (..) ) import Stack.Types.GhcPkgId ( GhcPkgId ) import Stack.Types.NamedComponent ( exeComponents, renderComponent ) diff --git a/src/Stack/Build/Execute.hs b/src/Stack/Build/Execute.hs index f883bce1c2..91441d513d 100644 --- a/src/Stack/Build/Execute.hs +++ b/src/Stack/Build/Execute.hs @@ -150,8 +150,8 @@ import Stack.Types.CompilerPaths import Stack.Types.Config ( BenchmarkOpts (..), BuildOpts (..), BuildOptsCLI (..) , CabalVerbosity (..), Config (..), Curator (..) - , EnvSettings (..), HaddockOpts (..), HasConfig (..) - , TestOpts (..), buildOptsL, stackRootL, whichCompilerL + , HaddockOpts (..), HasConfig (..), TestOpts (..) + , buildOptsL, stackRootL, whichCompilerL ) import Stack.Types.DumpLogs ( DumpLogs (..) ) import Stack.Types.DumpPackage ( DumpPackage (..) ) @@ -162,6 +162,7 @@ import Stack.Types.EnvConfig , packageDatabaseLocal, platformGhcRelDir , shouldForceGhcColorFlag ) +import Stack.Types.EnvSettings ( EnvSettings (..) ) import Stack.Types.GhcPkgId ( GhcPkgId, ghcPkgIdString, unGhcPkgId ) import Stack.Types.GlobalOpts ( GlobalOpts (..) ) import Stack.Types.NamedComponent diff --git a/src/Stack/ConfigCmd.hs b/src/Stack/ConfigCmd.hs index ebac064eb3..7f5a7e65e3 100644 --- a/src/Stack/ConfigCmd.hs +++ b/src/Stack/ConfigCmd.hs @@ -39,12 +39,11 @@ import Stack.Config import Stack.Constants ( stackDotYaml ) import Stack.Prelude import Stack.Types.Config - ( Config (..), EnvSettings (..), HasConfig (..) - , ProjectConfig (..) - ) + ( Config (..), HasConfig (..), ProjectConfig (..) ) import Stack.Types.ConfigMonoid ( configMonoidInstallGHCName, configMonoidSystemGHCName ) import Stack.Types.EnvConfig ( EnvConfig ) +import Stack.Types.EnvSettings ( EnvSettings (..) ) import Stack.Types.GHCVariant ( HasGHCVariant ) import Stack.Types.GlobalOpts ( GlobalOpts (..) ) import Stack.Types.Resolver ( AbstractResolver, readAbstractResolver ) diff --git a/src/Stack/Exec.hs b/src/Stack/Exec.hs index 01722b57b5..02ec075bff 100644 --- a/src/Stack/Exec.hs +++ b/src/Stack/Exec.hs @@ -28,10 +28,11 @@ import Stack.Types.BuildConfig import Stack.Types.CompilerPaths ( CompilerPaths (..), HasCompiler (..), getGhcPkgExe ) import Stack.Types.Config - ( BuildOptsCLI (..), Config (..), EnvSettings (..) - , HasConfig (..), defaultBuildOptsCLI + ( BuildOptsCLI (..), Config (..), HasConfig (..) + , defaultBuildOptsCLI ) import Stack.Types.EnvConfig ( EnvConfig ) +import Stack.Types.EnvSettings ( EnvSettings (..) ) import Stack.Types.Runner ( Runner ) import Stack.Types.SourceMap ( SMWanted (..), ppComponents ) import System.Directory ( withCurrentDirectory ) diff --git a/src/Stack/Ghci.hs b/src/Stack/Ghci.hs index 47ceb87568..f96e383f1b 100644 --- a/src/Stack/Ghci.hs +++ b/src/Stack/Ghci.hs @@ -48,10 +48,14 @@ import Stack.Types.BuildConfig import Stack.Types.CompilerPaths ( CompilerPaths (..), HasCompiler (..) ) import Stack.Types.Config + ( ApplyCLIFlag, BuildOptsCLI (..), Config (..) + , HasConfig (..), buildOptsL, defaultBuildOptsCLI + ) import Stack.Types.EnvConfig ( EnvConfig (..), HasEnvConfig (..), actualCompilerVersionL , shaPathForBytes ) +import Stack.Types.EnvSettings ( defaultEnvSettings ) import Stack.Types.NamedComponent import Stack.Types.Package import Stack.Types.PackageFile diff --git a/src/Stack/Hoogle.hs b/src/Stack/Hoogle.hs index 65d423c818..dc9f765470 100644 --- a/src/Stack/Hoogle.hs +++ b/src/Stack/Hoogle.hs @@ -25,14 +25,15 @@ import Stack.Runners , withEnvConfig ) import Stack.Types.Config - ( BuildOptsCLI (..), Config (..), EnvSettings (..) - , HasConfig (..), buildOptsMonoidHaddockL - , defaultBuildOptsCLI, globalOptsBuildOptsMonoidL + ( BuildOptsCLI (..), Config (..), HasConfig (..) + , buildOptsMonoidHaddockL, defaultBuildOptsCLI + , globalOptsBuildOptsMonoidL ) import Stack.Types.EnvConfig ( EnvConfig, HasSourceMap (..), hoogleDatabasePath , hoogleRoot ) +import Stack.Types.EnvSettings ( EnvSettings (..) ) import Stack.Types.GlobalOpts ( GlobalOpts (..) ) import Stack.Types.Runner ( Runner, globalOptsL ) import Stack.Types.SourceMap ( DepPackage (..), SourceMap (..) ) diff --git a/src/Stack/Options/ExecParser.hs b/src/Stack/Options/ExecParser.hs index 7b7b54412d..e52bc0e93a 100644 --- a/src/Stack/Options/ExecParser.hs +++ b/src/Stack/Options/ExecParser.hs @@ -14,7 +14,7 @@ import Stack.Exec ( ExecOpts (..), ExecOptsExtra (..), SpecialExecCmd (..) ) import Stack.Options.Completion import Stack.Prelude -import Stack.Types.Config +import Stack.Types.EnvSettings ( EnvSettings (..) ) -- | Parse command line arguments for Stack's @exec@, @ghc@, @run@, -- @runghc@ and @runhaskell@ commands. diff --git a/src/Stack/Script.hs b/src/Stack/Script.hs index 988c48b97f..0ee2f1d6dd 100644 --- a/src/Stack/Script.hs +++ b/src/Stack/Script.hs @@ -45,16 +45,14 @@ import Stack.SourceMap ( getCompilerInfo, immutableLocSha ) import Stack.Types.Compiler ( ActualCompiler (..) ) import Stack.Types.CompilerPaths ( CompilerPaths (..), GhcPkgExe (..), HasCompiler (..) ) -import Stack.Types.Config - ( Config (..), HasConfig (..), defaultEnvSettings - , stackRootL - ) +import Stack.Types.Config ( Config (..), HasConfig (..), stackRootL ) import Stack.Types.ConfigMonoid ( ConfigMonoid (..) ) import Stack.Types.DumpPackage ( DumpPackage (..) ) import Stack.Types.EnvConfig ( EnvConfig (..), HasEnvConfig (..), actualCompilerVersionL , appropriateGhcColorFlag ) +import Stack.Types.EnvSettings ( defaultEnvSettings ) import Stack.Types.GlobalOpts ( GlobalOpts (..) ) import Stack.Types.Platform ( HasPlatform (..) ) import Stack.Types.Runner ( Runner, globalOptsL ) diff --git a/src/Stack/Setup.hs b/src/Stack/Setup.hs index d0e554420b..feabf0bb77 100644 --- a/src/Stack/Setup.hs +++ b/src/Stack/Setup.hs @@ -125,10 +125,9 @@ import Stack.Types.CompilerBuild import Stack.Types.CompilerPaths ( CompilerPaths (..), GhcPkgExe (..), HasCompiler (..) ) import Stack.Types.Config - ( BuildOptsCLI (..), Config (..), EnvSettings (..) - , ExtraDirs (..), HasConfig (..), envOverrideSettingsL - , ghcInstallHook, minimalEnvSettings, platformOnlyRelDir - , whichCompilerL + ( BuildOptsCLI (..), Config (..), ExtraDirs (..) + , HasConfig (..), envOverrideSettingsL + , ghcInstallHook, platformOnlyRelDir, whichCompilerL ) import Stack.Types.Docker ( dockerStackExeArgName ) import Stack.Types.DownloadInfo ( DownloadInfo (..) ) @@ -138,6 +137,7 @@ import Stack.Types.EnvConfig , packageDatabaseDeps, packageDatabaseExtra , packageDatabaseLocal ) +import Stack.Types.EnvSettings ( EnvSettings (..), minimalEnvSettings ) import Stack.Types.GHCDownloadInfo ( GHCDownloadInfo (..) ) import Stack.Types.GHCVariant ( GHCVariant (..), HasGHCVariant (..), ghcVariantName diff --git a/src/Stack/Types/Config.hs b/src/Stack/Types/Config.hs index 297e469a5d..c1e2180416 100644 --- a/src/Stack/Types/Config.hs +++ b/src/Stack/Types/Config.hs @@ -20,11 +20,6 @@ module Stack.Types.Config , askLatestSnapshotUrl , configProjectRoot -- * Details - -- ** EnvSettings - , EnvSettings (..) - , minimalEnvSettings - , defaultEnvSettings - , plainEnvSettings -- ** GlobalOpts & GlobalOptsMonoid , defaultLogLevel -- ** Project & ProjectAndConfigMonoid @@ -48,12 +43,6 @@ module Stack.Types.Config , ExtraDirs (..) , buildOptsL , globalOptsL - , buildOptsInstallExesL - , buildOptsMonoidHaddockL - , buildOptsMonoidTestsL - , buildOptsMonoidBenchmarksL - , buildOptsMonoidInstallExesL - , buildOptsHaddockL , globalOptsBuildOptsMonoidL , stackRootL , stackGlobalConfigL @@ -94,6 +83,7 @@ import Stack.Types.ConfigMonoid ( ConfigMonoid (..), parseConfigMonoidObject) import Stack.Types.Docker ( DockerOpts ) import Stack.Types.DumpLogs ( DumpLogs ) +import Stack.Types.EnvSettings ( EnvSettings ) import Stack.Types.GHCVariant ( GHCVariant (..), HasGHCVariant (..) ) import Stack.Types.GlobalOpts ( GlobalOpts (..) ) import Stack.Types.Nix ( NixOpts ) @@ -247,21 +237,6 @@ configProjectRoot c = PCGlobalProject -> Nothing PCNoProject _deps -> Nothing --- | Controls which version of the environment is used -data EnvSettings = EnvSettings - { esIncludeLocals :: !Bool - -- ^ 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 - , esLocaleUtf8 :: !Bool - -- ^ set the locale to C.UTF-8 - , esKeepGhcRts :: !Bool - -- ^ if True, keep GHCRTS variable in environment - } - deriving (Eq, Ord, Show) - -- | Project configuration information. Not every run of Stack has a -- true local project; see constructors below. data ProjectConfig a @@ -387,42 +362,6 @@ data GlobalInfoSource | GISCompiler ActualCompiler -- ^ Look up the actual information in the installed compiler -minimalEnvSettings :: EnvSettings -minimalEnvSettings = - EnvSettings - { esIncludeLocals = False - , esIncludeGhcPackagePath = False - , esStackExe = False - , esLocaleUtf8 = False - , esKeepGhcRts = False - } - --- | Default @EnvSettings@ which includes locals and GHC_PACKAGE_PATH. --- --- Note that this also passes through the GHCRTS environment variable. --- See https://github.com/commercialhaskell/stack/issues/3444 -defaultEnvSettings :: EnvSettings -defaultEnvSettings = EnvSettings - { esIncludeLocals = True - , esIncludeGhcPackagePath = True - , esStackExe = True - , esLocaleUtf8 = False - , esKeepGhcRts = True - } - --- | Environment settings which do not embellish the environment --- --- Note that this also passes through the GHCRTS environment variable. --- See https://github.com/commercialhaskell/stack/issues/3444 -plainEnvSettings :: EnvSettings -plainEnvSettings = EnvSettings - { esIncludeLocals = False - , esIncludeGhcPackagePath = False - , esStackExe = False - , esLocaleUtf8 = False - , esKeepGhcRts = True - } - data ProjectAndConfigMonoid = ProjectAndConfigMonoid !Project !ConfigMonoid @@ -542,36 +481,6 @@ buildOptsL = configL.lens configBuild (\x y -> x { configBuild = y }) -buildOptsMonoidHaddockL :: Lens' BuildOptsMonoid (Maybe Bool) -buildOptsMonoidHaddockL = - lens (getFirstFalse . buildMonoidHaddock) - (\buildMonoid t -> buildMonoid {buildMonoidHaddock = FirstFalse t}) - -buildOptsMonoidTestsL :: Lens' BuildOptsMonoid (Maybe Bool) -buildOptsMonoidTestsL = - lens (getFirstFalse . buildMonoidTests) - (\buildMonoid t -> buildMonoid {buildMonoidTests = FirstFalse t}) - -buildOptsMonoidBenchmarksL :: Lens' BuildOptsMonoid (Maybe Bool) -buildOptsMonoidBenchmarksL = - lens (getFirstFalse . buildMonoidBenchmarks) - (\buildMonoid t -> buildMonoid {buildMonoidBenchmarks = FirstFalse t}) - -buildOptsMonoidInstallExesL :: Lens' BuildOptsMonoid (Maybe Bool) -buildOptsMonoidInstallExesL = - lens (getFirstFalse . buildMonoidInstallExes) - (\buildMonoid t -> buildMonoid {buildMonoidInstallExes = FirstFalse t}) - -buildOptsInstallExesL :: Lens' BuildOpts Bool -buildOptsInstallExesL = - lens boptsInstallExes - (\bopts t -> bopts {boptsInstallExes = t}) - -buildOptsHaddockL :: Lens' BuildOpts Bool -buildOptsHaddockL = - lens boptsHaddock - (\bopts t -> bopts {boptsHaddock = t}) - globalOptsBuildOptsMonoidL :: Lens' GlobalOpts BuildOptsMonoid globalOptsBuildOptsMonoidL = lens diff --git a/src/Stack/Types/Config/Build.hs b/src/Stack/Types/Config/Build.hs index 37b0411c86..cd34d44184 100644 --- a/src/Stack/Types/Config/Build.hs +++ b/src/Stack/Types/Config/Build.hs @@ -5,11 +5,17 @@ -- | Configuration options for building. module Stack.Types.Config.Build ( BuildOpts (..) + , buildOptsHaddockL + , buildOptsInstallExesL , BuildCommand (..) , defaultBuildOpts , defaultBuildOptsCLI , BuildOptsCLI (..) , BuildOptsMonoid (..) + , buildOptsMonoidBenchmarksL + , buildOptsMonoidHaddockL + , buildOptsMonoidInstallExesL + , buildOptsMonoidTestsL , TestOpts (..) , defaultTestOpts , TestOptsMonoid (..) @@ -531,3 +537,33 @@ instance FromJSON CabalVerbosity where instance Parsec CabalVerbosity where parsec = CabalVerbosity <$> parsec + +buildOptsMonoidHaddockL :: Lens' BuildOptsMonoid (Maybe Bool) +buildOptsMonoidHaddockL = + lens (getFirstFalse . buildMonoidHaddock) + (\buildMonoid t -> buildMonoid {buildMonoidHaddock = FirstFalse t}) + +buildOptsMonoidTestsL :: Lens' BuildOptsMonoid (Maybe Bool) +buildOptsMonoidTestsL = + lens (getFirstFalse . buildMonoidTests) + (\buildMonoid t -> buildMonoid {buildMonoidTests = FirstFalse t}) + +buildOptsMonoidBenchmarksL :: Lens' BuildOptsMonoid (Maybe Bool) +buildOptsMonoidBenchmarksL = + lens (getFirstFalse . buildMonoidBenchmarks) + (\buildMonoid t -> buildMonoid {buildMonoidBenchmarks = FirstFalse t}) + +buildOptsMonoidInstallExesL :: Lens' BuildOptsMonoid (Maybe Bool) +buildOptsMonoidInstallExesL = + lens (getFirstFalse . buildMonoidInstallExes) + (\buildMonoid t -> buildMonoid {buildMonoidInstallExes = FirstFalse t}) + +buildOptsInstallExesL :: Lens' BuildOpts Bool +buildOptsInstallExesL = + lens boptsInstallExes + (\bopts t -> bopts {boptsInstallExes = t}) + +buildOptsHaddockL :: Lens' BuildOpts Bool +buildOptsHaddockL = + lens boptsHaddock + (\bopts t -> bopts {boptsHaddock = t}) diff --git a/src/Stack/Types/EnvSettings.hs b/src/Stack/Types/EnvSettings.hs new file mode 100644 index 0000000000..830d5daad6 --- /dev/null +++ b/src/Stack/Types/EnvSettings.hs @@ -0,0 +1,61 @@ +{-# LANGUAGE NoImplicitPrelude #-} + +module Stack.Types.EnvSettings + ( EnvSettings (..) + , minimalEnvSettings + , defaultEnvSettings + , plainEnvSettings + ) where + +import Stack.Prelude + +-- | Controls which version of the environment is used +data EnvSettings = EnvSettings + { esIncludeLocals :: !Bool + -- ^ 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 + , esLocaleUtf8 :: !Bool + -- ^ set the locale to C.UTF-8 + , esKeepGhcRts :: !Bool + -- ^ if True, keep GHCRTS variable in environment + } + deriving (Eq, Ord, Show) + +minimalEnvSettings :: EnvSettings +minimalEnvSettings = + EnvSettings + { esIncludeLocals = False + , esIncludeGhcPackagePath = False + , esStackExe = False + , esLocaleUtf8 = False + , esKeepGhcRts = False + } + +-- | Default @EnvSettings@ which includes locals and GHC_PACKAGE_PATH. +-- +-- Note that this also passes through the GHCRTS environment variable. +-- See https://github.com/commercialhaskell/stack/issues/3444 +defaultEnvSettings :: EnvSettings +defaultEnvSettings = EnvSettings + { esIncludeLocals = True + , esIncludeGhcPackagePath = True + , esStackExe = True + , esLocaleUtf8 = False + , esKeepGhcRts = True + } + +-- | Environment settings which do not embellish the environment +-- +-- Note that this also passes through the GHCRTS environment variable. +-- See https://github.com/commercialhaskell/stack/issues/3444 +plainEnvSettings :: EnvSettings +plainEnvSettings = EnvSettings + { esIncludeLocals = False + , esIncludeGhcPackagePath = False + , esStackExe = False + , esLocaleUtf8 = False + , esKeepGhcRts = True + } diff --git a/stack.cabal b/stack.cabal index e1e92a0d93..f695548af4 100644 --- a/stack.cabal +++ b/stack.cabal @@ -260,6 +260,7 @@ library Stack.Types.DumpLogs Stack.Types.DumpPackage Stack.Types.EnvConfig + Stack.Types.EnvSettings Stack.Types.GHCDownloadInfo Stack.Types.GHCVariant Stack.Types.GhcOptionKey