Skip to content

Commit

Permalink
Re #2407 Move EnvSettings out of Stack.Types.Config
Browse files Browse the repository at this point in the history
  • Loading branch information
mpilgrem committed Apr 19, 2023
1 parent acf83c5 commit cc94a92
Show file tree
Hide file tree
Showing 14 changed files with 125 additions and 113 deletions.
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Stack/Build/ConstructPlan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
5 changes: 3 additions & 2 deletions src/Stack/Build/Execute.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (..) )
Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/Stack/ConfigCmd.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
5 changes: 3 additions & 2 deletions src/Stack/Exec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
4 changes: 4 additions & 0 deletions src/Stack/Ghci.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/Stack/Hoogle.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (..) )
Expand Down
2 changes: 1 addition & 1 deletion src/Stack/Options/ExecParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 2 additions & 4 deletions src/Stack/Script.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
8 changes: 4 additions & 4 deletions src/Stack/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (..) )
Expand All @@ -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
Expand Down
93 changes: 1 addition & 92 deletions src/Stack/Types/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ module Stack.Types.Config
, askLatestSnapshotUrl
, configProjectRoot
-- * Details
-- ** EnvSettings
, EnvSettings (..)
, minimalEnvSettings
, defaultEnvSettings
, plainEnvSettings
-- ** GlobalOpts & GlobalOptsMonoid
, defaultLogLevel
-- ** Project & ProjectAndConfigMonoid
Expand All @@ -48,12 +43,6 @@ module Stack.Types.Config
, ExtraDirs (..)
, buildOptsL
, globalOptsL
, buildOptsInstallExesL
, buildOptsMonoidHaddockL
, buildOptsMonoidTestsL
, buildOptsMonoidBenchmarksL
, buildOptsMonoidInstallExesL
, buildOptsHaddockL
, globalOptsBuildOptsMonoidL
, stackRootL
, stackGlobalConfigL
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions src/Stack/Types/Config/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (..)
Expand Down Expand Up @@ -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})
Loading

0 comments on commit cc94a92

Please sign in to comment.