Skip to content

Commit c8352db

Browse files
committed
Add a stack-developer-mode flag #5134
1 parent d2fed91 commit c8352db

12 files changed

+79
-4
lines changed

ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Behavior changes:
1313

1414
Other enhancements:
1515

16+
* Add the `stack-developer-mode` flag
17+
1618
Bug fixes:
1719

1820
* When using the `STACK_YAML` env var with Docker, make the path absolute.

doc/yaml_configuration.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,3 +1187,13 @@ recommend-stack-upgrade: true
11871187
```
11881188

11891189
Since 2.0
1190+
1191+
### stack-developer-mode
1192+
1193+
Turns on a mode where some messages are printed at WARN level instead of DEBUG level, especially useful for developers of Stack itself. For official distributed binaries, this is set to `false` by default. When you build from source, it is set to `true` by default.
1194+
1195+
```yaml
1196+
stack-developer-mode: false
1197+
```
1198+
1199+
Since 2.3.3

etc/scripts/release.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ main =
9191
gUploadLabel = Nothing
9292
gTestHaddocks = True
9393
gProjectRoot = "" -- Set to real value velow.
94-
gBuildArgs = []
94+
gBuildArgs = ["--flag", "stack:-developer-mode"]
9595
gCertificateName = Nothing
9696
gUploadOnly = False
9797
global0 = foldl (flip id) Global{..} flags

package.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ when:
141141
- hsc2hs
142142
dependencies:
143143
- unix
144+
- condition: flag(developer-mode)
145+
then:
146+
cpp-options: -DSTACK_DEVELOPER_MODE_DEFAULT=True
147+
else:
148+
cpp-options: -DSTACK_DEVELOPER_MODE_DEFAULT=False
144149
library:
145150
source-dirs: src/
146151
ghc-options:
@@ -348,3 +353,7 @@ flags:
348353
requests more difficult."
349354
manual: true
350355
default: false
356+
developer-mode:
357+
description: "By default, should extra developer information be output?"
358+
manual: true
359+
default: false

src/Stack/Config.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@ configFromConfigMonoid
371371
Nothing -> throwString $ "Failed to parse PANTRY_ROOT environment variable (expected absolute directory): " ++ show dir
372372
Just x -> pure x
373373
Nothing -> pure $ configStackRoot </> relDirPantry
374+
375+
let configStackDeveloperMode = fromFirst stackDeveloperModeDefault configMonoidStackDeveloperMode
376+
374377
withPantryConfig
375378
pantryRoot
376379
hsc

src/Stack/Constants.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ module Stack.Constants
120120
,usrLibDirs
121121
,testGhcEnvRelFile
122122
,relFileBuildLock
123+
,stackDeveloperModeDefault
123124
)
124125
where
125126

@@ -555,3 +556,7 @@ testGhcEnvRelFile = $(mkRelFile "test-ghc-env")
555556
-- | File inside a dist directory to use for locking
556557
relFileBuildLock :: Path Rel File
557558
relFileBuildLock = $(mkRelFile "build-lock")
559+
560+
-- | What should the default be for stack-developer-mode
561+
stackDeveloperModeDefault :: Bool
562+
stackDeveloperModeDefault = STACK_DEVELOPER_MODE_DEFAULT

src/Stack/Package.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,7 @@ parseHI hiPath = do
11001100
result <- liftIO $ Iface.fromFile hiPath
11011101
case result of
11021102
Left msg -> do
1103-
prettyWarnL
1103+
prettyStackDevL
11041104
[ flow "Failed to decode module interface:"
11051105
, style File $ fromString hiPath
11061106
, flow "Decoding failure:"

src/Stack/Types/Config.hs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ module Stack.Types.Config
169169
,envOverrideSettingsL
170170
,shouldForceGhcColorFlag
171171
,appropriateGhcColorFlag
172+
-- * Helper logging functions
173+
,prettyStackDevL
172174
-- * Lens reexport
173175
,view
174176
,to
@@ -214,7 +216,7 @@ import Pantry.Internal (Storage)
214216
import Path
215217
import qualified Paths_stack as Meta
216218
import qualified RIO.List as List
217-
import RIO.PrettyPrint (HasTerm (..))
219+
import RIO.PrettyPrint (HasTerm (..), StyleDoc, prettyWarnL, prettyDebugL)
218220
import RIO.PrettyPrint.StylesUpdate (StylesUpdate,
219221
parseStylesUpdateFromString, HasStylesUpdate (..))
220222
import Stack.Constants
@@ -377,6 +379,8 @@ data Config =
377379
-- ^ Enable GHC hiding source paths?
378380
,configRecommendUpgrade :: !Bool
379381
-- ^ Recommend a Stack upgrade?
382+
,configStackDeveloperMode :: !Bool
383+
-- ^ Turn on Stack developer mode for additional messages?
380384
}
381385

382386
-- | A bit of type safety to ensure we're talking to the right database.
@@ -859,6 +863,8 @@ data ConfigMonoid =
859863
, configMonoidRecommendUpgrade :: !FirstTrue
860864
-- ^ See 'configRecommendUpgrade'
861865
, configMonoidCasaRepoPrefix :: !(First CasaRepoPrefix)
866+
, configMonoidStackDeveloperMode :: !(First Bool)
867+
-- ^ See 'configStackDeveloperMode'
862868
}
863869
deriving (Show, Generic)
864870

@@ -983,6 +989,8 @@ parseConfigMonoidObject rootDir obj = do
983989

984990
configMonoidCasaRepoPrefix <- First <$> obj ..:? configMonoidCasaRepoPrefixName
985991

992+
configMonoidStackDeveloperMode <- First <$> obj ..:? configMonoidStackDeveloperModeName
993+
986994
return ConfigMonoid {..}
987995
where
988996
handleExplicitSetupDep :: (Monad m, MonadFail m) => (Text, Bool) -> m (Maybe PackageName, Bool)
@@ -1148,6 +1156,9 @@ configMonoidRecommendUpgradeName = "recommend-stack-upgrade"
11481156
configMonoidCasaRepoPrefixName :: Text
11491157
configMonoidCasaRepoPrefixName = "casa-repo-prefix"
11501158

1159+
configMonoidStackDeveloperModeName :: Text
1160+
configMonoidStackDeveloperModeName = "stack-developer-mode"
1161+
11511162
data ConfigException
11521163
= ParseConfigFileException (Path Abs File) ParseException
11531164
| ParseCustomSnapshotException Text ParseException
@@ -2126,3 +2137,11 @@ terminalL = globalOptsL.lens globalTerminal (\x y -> x { globalTerminal = y })
21262137
-- | See 'globalReExecVersion'
21272138
reExecL :: HasRunner env => SimpleGetter env Bool
21282139
reExecL = globalOptsL.to (isJust . globalReExecVersion)
2140+
2141+
-- | In dev mode, print as a warning, otherwise as debug
2142+
prettyStackDevL :: HasConfig env => [StyleDoc] -> RIO env ()
2143+
prettyStackDevL docs = do
2144+
config <- view configL
2145+
if configStackDeveloperMode config
2146+
then prettyWarnL docs
2147+
else prettyDebugL docs

stack-ghc-84.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ resolver: lts-12.26
33
packages:
44
- .
55

6+
flags:
7+
stack:
8+
developer-mode: true
9+
610
docker:
711
enable: false
812
repo: fpco/stack-build-small:lts-12.26

stack-ghc-88.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ flags:
1616
stack:
1717
hide-dependency-versions: true
1818
supported-build: true
19+
developer-mode: true
1920

2021
ghc-options:
2122
"$locals": -fhide-source-paths

stack.cabal

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ cabal-version: 2.0
44
--
55
-- see: https://github.com/sol/hpack
66
--
7-
-- hash: 193fddca62eb34c1190cee7abae3779a02ec73b4c02e85853ce430a7c8104d20
7+
-- hash: 09229f434502c702e4058371b91cc64f9e800aab8abe66fb228d8da3137558b7
88

99
name: stack
1010
version: 2.3.2
@@ -77,6 +77,11 @@ custom-setup
7777
, base >=4.10 && <5
7878
, filepath
7979

80+
flag developer-mode
81+
description: By default, should extra developer information be output?
82+
manual: True
83+
default: False
84+
8085
flag disable-git-info
8186
description: Disable compile-time inclusion of current git info in stack
8287
manual: True
@@ -312,6 +317,10 @@ library
312317
hsc2hs
313318
build-depends:
314319
unix
320+
if flag(developer-mode)
321+
cpp-options: -DSTACK_DEVELOPER_MODE_DEFAULT=True
322+
else
323+
cpp-options: -DSTACK_DEVELOPER_MODE_DEFAULT=False
315324
if os(windows)
316325
other-modules:
317326
System.Uname
@@ -433,6 +442,10 @@ executable stack
433442
hsc2hs
434443
build-depends:
435444
unix
445+
if flag(developer-mode)
446+
cpp-options: -DSTACK_DEVELOPER_MODE_DEFAULT=True
447+
else
448+
cpp-options: -DSTACK_DEVELOPER_MODE_DEFAULT=False
436449
if flag(static)
437450
ld-options: -static -pthread
438451
if !(flag(disable-git-info))
@@ -551,6 +564,10 @@ executable stack-integration-test
551564
hsc2hs
552565
build-depends:
553566
unix
567+
if flag(developer-mode)
568+
cpp-options: -DSTACK_DEVELOPER_MODE_DEFAULT=True
569+
else
570+
cpp-options: -DSTACK_DEVELOPER_MODE_DEFAULT=False
554571
if !(flag(integration-tests))
555572
buildable: False
556573
if flag(static)
@@ -678,4 +695,8 @@ test-suite stack-test
678695
hsc2hs
679696
build-depends:
680697
unix
698+
if flag(developer-mode)
699+
cpp-options: -DSTACK_DEVELOPER_MODE_DEFAULT=True
700+
else
701+
cpp-options: -DSTACK_DEVELOPER_MODE_DEFAULT=False
681702
default-language: Haskell2010

stack.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ flags:
1818
stack:
1919
hide-dependency-versions: true
2020
supported-build: true
21+
developer-mode: true
2122

2223
ghc-options:
2324
"$locals": -fhide-source-paths

0 commit comments

Comments
 (0)