diff --git a/ChangeLog.md b/ChangeLog.md index 2d51f41e67..9e4433a23c 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -15,6 +15,8 @@ Behavior changes: * Following a change to the Stackage project's server API, the default value of the `urls` key includes `recent-snapshots: https://stackage.org/api/v1/snapshots`. +* The `--[no-]keep-ghc-rts` flag of Stack's `config env` command is now enabled + by default, consistent with Stack's `exec` command. Other enhancements: @@ -58,6 +60,9 @@ Bug fixes: * Stack's `config set` commands will recreate the `global-project` directory contents, if Stack needs to consult its project-level configuration file and there is no file. +* The output of Stack's `path --bin-path` command is now consistent with the + Stack environment in Stack's `exec` command and includes the `bin` directory + of Stack's local install root directory. ## v3.9.3 - 2026-02-19 diff --git a/doc/commands/config_command.md b/doc/commands/config_command.md index 5e53d2ec6b..fdde787be1 100644 --- a/doc/commands/config_command.md +++ b/doc/commands/config_command.md @@ -51,7 +51,7 @@ script that is output: or not * `--[no-]locale-utf8` (disabled by default) set the `GHC_CHARENC` environment variable to `UTF-8` or not -* `--[no-]keep-ghc-rts` (disabled by default) keep/discard any `GHCRTS` +* `--[no-]keep-ghc-rts` (enabled by default) keep/discard any `GHCRTS` environment variable The command also accepts flags and options of the diff --git a/doc/topics/stack_environment.md b/doc/topics/stack_environment.md index 022c4282b7..3efb94887b 100644 --- a/doc/topics/stack_environment.md +++ b/doc/topics/stack_environment.md @@ -4,12 +4,8 @@ Command [`stack config env`](../commands/config_command.md#the-stack-config-env-command) -to see how the PATH is defined in the Stack environment. - -Alternatively, command -[`stack path --bin-path`](../commands/path_command.md) to see the PATH -excluding the project Stack work directory's `bin` directory (see further -below). +or [`stack path --bin-path`](../commands/path_command.md) to see how the PATH is +defined in the Stack environment. In that environment, Stack adds certain directories to the start of the PATH. The directories added are set out below, in order of search priority. diff --git a/src/Stack/Options/ConfigEnvParser.hs b/src/Stack/Options/ConfigEnvParser.hs index 9a03506e3e..80d3c1cd31 100644 --- a/src/Stack/Options/ConfigEnvParser.hs +++ b/src/Stack/Options/ConfigEnvParser.hs @@ -1,4 +1,5 @@ -{-# LANGUAGE NoImplicitPrelude #-} +{-# LANGUAGE NoImplicitPrelude #-} +{-# LANGUAGE OverloadedRecordDot #-} {-| Module : Stack.Options.ConfigEnvParser @@ -14,16 +15,34 @@ module Stack.Options.ConfigEnvParser import qualified Options.Applicative as OA import Options.Applicative.Builder.Extra ( boolFlags ) import Stack.Prelude -import Stack.Types.EnvSettings ( EnvSettings (..) ) +import Stack.Types.EnvSettings + ( EnvSettings (..), defaultEnvSettings ) -- | Parse command line arguments for Stack's @config env@ command. configCmdEnvParser :: OA.Parser EnvSettings configCmdEnvParser = EnvSettings - <$> boolFlags True "locals" "include information about local packages" mempty - <*> boolFlags True - "ghc-package-path" "set GHC_PACKAGE_PATH environment variable" mempty - <*> boolFlags True "stack-exe" "set STACK_EXE environment variable" mempty - <*> boolFlags False - "locale-utf8" "set the GHC_CHARENC environment variable to UTF-8" mempty - <*> boolFlags False - "keep-ghc-rts" "keep any GHCRTS environment variable" mempty + <$> boolFlags + defaultEnvSettings.includeLocals + "locals" + "include information about local packages" + mempty + <*> boolFlags + defaultEnvSettings.includeGhcPackagePath + "ghc-package-path" + "set GHC_PACKAGE_PATH environment variable" + mempty + <*> boolFlags + defaultEnvSettings.stackExe + "stack-exe" + "set STACK_EXE environment variable" + mempty + <*> boolFlags + defaultEnvSettings.localeUtf8 + "locale-utf8" + "set the GHC_CHARENC environment variable to UTF-8" + mempty + <*> boolFlags + defaultEnvSettings.keepGhcRts + "keep-ghc-rts" + "keep any GHCRTS environment variable" + mempty diff --git a/src/Stack/Options/ExecParser.hs b/src/Stack/Options/ExecParser.hs index 227b7b7419..1ad5d8eb3a 100644 --- a/src/Stack/Options/ExecParser.hs +++ b/src/Stack/Options/ExecParser.hs @@ -1,4 +1,5 @@ -{-# LANGUAGE NoImplicitPrelude #-} +{-# LANGUAGE NoImplicitPrelude #-} +{-# LANGUAGE OverloadedRecordDot #-} {-| Module : Stack.Options.ExecParser @@ -23,7 +24,8 @@ import Stack.Exec ( ExecOpts (..), ExecOptsExtra (..), SpecialExecCmd (..) ) import Stack.Options.Completion ( projectExeCompleter ) import Stack.Prelude -import Stack.Types.EnvSettings ( EnvSettings (..) ) +import Stack.Types.EnvSettings + ( EnvSettings (..), defaultEnvSettings ) -- | Parse command line arguments for Stack's @exec@, @ghc@, @run@, -- @runghc@ and @runhaskell@ commands. @@ -57,18 +59,18 @@ execOptsExtraParser = ExecOptsExtra <*> eoCwdParser where eoEnvSettingsParser :: Parser EnvSettings - eoEnvSettingsParser = EnvSettings True - <$> boolFlags True + eoEnvSettingsParser = EnvSettings defaultEnvSettings.includeLocals + <$> boolFlags defaultEnvSettings.includeGhcPackagePath "ghc-package-path" "setting the GHC_PACKAGE_PATH variable for the subprocess." idm - <*> boolFlags True + <*> boolFlags defaultEnvSettings.stackExe "stack-exe" "setting the STACK_EXE environment variable to the path for the \ \stack executable." idm - <*> pure False - <*> pure True + <*> pure defaultEnvSettings.localeUtf8 + <*> pure defaultEnvSettings.keepGhcRts eoPackagesParser :: Parser [String] eoPackagesParser = many (strOption diff --git a/src/Stack/Path.hs b/src/Stack/Path.hs index eef69b6aa7..788ec5df81 100644 --- a/src/Stack/Path.hs +++ b/src/Stack/Path.hs @@ -53,6 +53,7 @@ import Stack.Types.EnvConfig , packageDatabaseLocal ) import qualified Stack.Types.EnvConfig as EnvConfig +import Stack.Types.EnvSettings ( defaultEnvSettings ) import Stack.Types.GHCVariant ( HasGHCVariant (..) ) import Stack.Types.GlobalOpts ( GlobalOpts (..), globalOptsBuildOptsMonoidL ) @@ -123,7 +124,13 @@ printKeys extractors single info = do T.putStrLn $ prefix <> extractPath info runHaddockWithEnvConfig :: Bool -> RIO EnvConfig () -> RIO Runner () -runHaddockWithEnvConfig x action = runHaddock x (withDefaultEnvConfig action) +runHaddockWithEnvConfig x action = runHaddock x $ + withDefaultEnvConfig $ do + config <- view configL + menv <- liftIO $ config.processContextSettings defaultEnvSettings + -- Required, as otherwise (due to withDefaultEnvConfig) the environment is + -- based on Stack.Type.EnvSettings.minimalEnvSettings. + withProcessContext menv action runHaddockWithConfig :: RIO Config () -> RIO Runner () runHaddockWithConfig = runHaddock False @@ -140,11 +147,6 @@ fillEnvConfigPathInfo = do -- We must use a BuildConfig from an EnvConfig to ensure that it contains the -- full environment info including GHC paths etc. buildConfig <- view $ envConfigL . buildConfigL - -- This is the modified 'bin-path', - -- including the local GHC or MSYS if not configured to operate on - -- global GHC. - -- It was set up in 'withBuildConfigAndLock -> withBuildConfigExt -> setupEnv'. - -- So it's not the *minimal* override path. snapDb <- packageDatabaseDeps localDb <- packageDatabaseLocal extraDbs <- packageDatabaseExtra