Skip to content

Commit b270c00

Browse files
authored
Merge pull request #6350 from commercialhaskell/fix6340
Fix #6340 `stack path --stack-root` does not need environment
2 parents 3d0a483 + 23b9aa1 commit b270c00

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Behavior changes:
2222
manager is available. In YAML configuration files, the `notify-if-nix-on-path`
2323
key is introduced, to allow the notification to be muted if unwanted.
2424
* Drop support for Intero (end of life in November 2019).
25+
* `stack path --stack-root` no longer sets up Stack's environment and does not
26+
load Stack's configuration.
2527

2628
Other enhancements:
2729

src/Stack/Config.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module Stack.Config
2929
, getProjectConfig
3030
, withBuildConfig
3131
, withNewLogFunc
32+
, determineStackRootAndOwnership
3233
) where
3334

3435
import Control.Monad.Extra ( firstJustM )

src/Stack/Path.hs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import qualified Data.Text.IO as T
1515
import Path ( (</>), parent )
1616
import Path.Extra ( toFilePathNoTrailingSep )
1717
import RIO.Process ( HasProcessContext (..), exeSearchPathL )
18+
import Stack.Config ( determineStackRootAndOwnership )
1819
import Stack.Constants
1920
( docDirSuffix, stackGlobalConfigOptionName
2021
, stackRootOptionName
@@ -41,14 +42,22 @@ import Stack.Types.EnvConfig
4142
, packageDatabaseExtra, packageDatabaseLocal
4243
)
4344
import Stack.Types.GHCVariant ( HasGHCVariant (..) )
44-
import Stack.Types.GlobalOpts ( globalOptsBuildOptsMonoidL )
45+
import Stack.Types.GlobalOpts
46+
( GlobalOpts (..), globalOptsBuildOptsMonoidL )
4547
import Stack.Types.Platform ( HasPlatform (..) )
4648
import Stack.Types.Runner ( HasRunner (..), Runner, globalOptsL )
4749
import qualified System.FilePath as FP
4850

49-
-- | Print out useful path information in a human-readable format (and
50-
-- support others later).
51+
-- | Print out useful path information in a human-readable format (and support
52+
-- others later).
5153
path :: [Text] -> RIO Runner ()
54+
-- Distinguish a request for only the Stack root, as such a request does not
55+
-- require 'withDefaultEnvConfig'.
56+
path [key] | key == stackRootOptionName' = do
57+
clArgs <- view $ globalOptsL.to globalConfigMonoid
58+
liftIO $ do
59+
(_, stackRoot, _) <- determineStackRootAndOwnership clArgs
60+
T.putStrLn $ T.pack $ toFilePathNoTrailingSep stackRoot
5261
path keys = do
5362
let -- filter the chosen paths in flags (keys), or show all of them if no
5463
-- specific paths chosen.
@@ -172,7 +181,7 @@ data UseHaddocks a
172181
paths :: [(String, Text, UseHaddocks (PathInfo -> Text))]
173182
paths =
174183
[ ( "Global Stack root directory"
175-
, T.pack stackRootOptionName
184+
, stackRootOptionName'
176185
, WithoutHaddocks $ view (stackRootL.to toFilePathNoTrailingSep.to T.pack))
177186
, ( "Global Stack configuration file"
178187
, T.pack stackGlobalConfigOptionName
@@ -258,3 +267,7 @@ paths =
258267
, "local-hpc-root"
259268
, WithoutHaddocks $ T.pack . toFilePathNoTrailingSep . piHpcDir )
260269
]
270+
271+
-- | 'Text' equivalent of 'stackRootOptionName'.
272+
stackRootOptionName' :: Text
273+
stackRootOptionName' = T.pack stackRootOptionName

0 commit comments

Comments
 (0)