Skip to content

Commit

Permalink
Add a stack-developer-mode flag #5134
Browse files Browse the repository at this point in the history
  • Loading branch information
snoyberg committed Jun 24, 2020
1 parent 779fb66 commit f2f2acf
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 4 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Behavior changes:

Other enhancements:

* Add the `stack-developer-mode` flag

Bug fixes:

* When using the `STACK_YAML` env var with Docker, make the path absolute.
Expand Down
10 changes: 10 additions & 0 deletions doc/yaml_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1187,3 +1187,13 @@ recommend-stack-upgrade: true
```

Since 2.0

### stack-developer-mode

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.

```yaml
stack-developer-mode: false
```

Since 2.3.3
2 changes: 1 addition & 1 deletion etc/scripts/release.hs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ main =
gUploadLabel = Nothing
gTestHaddocks = True
gProjectRoot = "" -- Set to real value velow.
gBuildArgs = []
gBuildArgs = ["--flag", "stack:-developer-mode"]
gCertificateName = Nothing
gUploadOnly = False
global0 = foldl (flip id) Global{..} flags
Expand Down
9 changes: 9 additions & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ when:
- hsc2hs
dependencies:
- unix
- condition: flag(developer-mode)
then:
cpp-options: -DSTACK_DEVELOPER_MODE_DEFAULT=True
else:
cpp-options: -DSTACK_DEVELOPER_MODE_DEFAULT=False
library:
source-dirs: src/
ghc-options:
Expand Down Expand Up @@ -348,3 +353,7 @@ flags:
requests more difficult."
manual: true
default: false
developer-mode:
description: "By default, should extra developer information be output?"
manual: true
default: false
3 changes: 3 additions & 0 deletions src/Stack/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,9 @@ configFromConfigMonoid
Nothing -> throwString $ "Failed to parse PANTRY_ROOT environment variable (expected absolute directory): " ++ show dir
Just x -> pure x
Nothing -> pure $ configStackRoot </> relDirPantry

let configStackDeveloperMode = fromFirst stackDeveloperModeDefault configMonoidStackDeveloperMode

withPantryConfig
pantryRoot
hsc
Expand Down
5 changes: 5 additions & 0 deletions src/Stack/Constants.hs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ module Stack.Constants
,usrLibDirs
,testGhcEnvRelFile
,relFileBuildLock
,stackDeveloperModeDefault
)
where

Expand Down Expand Up @@ -555,3 +556,7 @@ testGhcEnvRelFile = $(mkRelFile "test-ghc-env")
-- | File inside a dist directory to use for locking
relFileBuildLock :: Path Rel File
relFileBuildLock = $(mkRelFile "build-lock")

-- | What should the default be for stack-developer-mode
stackDeveloperModeDefault :: Bool
stackDeveloperModeDefault = STACK_DEVELOPER_MODE_DEFAULT
2 changes: 1 addition & 1 deletion src/Stack/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,7 @@ parseHI hiPath = do
result <- liftIO $ Iface.fromFile hiPath
case result of
Left msg -> do
prettyWarnL
prettyStackDevL
[ flow "Failed to decode module interface:"
, style File $ fromString hiPath
, flow "Decoding failure:"
Expand Down
21 changes: 20 additions & 1 deletion src/Stack/Types/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ module Stack.Types.Config
,envOverrideSettingsL
,shouldForceGhcColorFlag
,appropriateGhcColorFlag
-- * Helper logging functions
,prettyStackDevL
-- * Lens reexport
,view
,to
Expand Down Expand Up @@ -214,7 +216,7 @@ import Pantry.Internal (Storage)
import Path
import qualified Paths_stack as Meta
import qualified RIO.List as List
import RIO.PrettyPrint (HasTerm (..))
import RIO.PrettyPrint (HasTerm (..), StyleDoc, prettyWarnL, prettyDebugL)
import RIO.PrettyPrint.StylesUpdate (StylesUpdate,
parseStylesUpdateFromString, HasStylesUpdate (..))
import Stack.Constants
Expand Down Expand Up @@ -377,6 +379,8 @@ data Config =
-- ^ Enable GHC hiding source paths?
,configRecommendUpgrade :: !Bool
-- ^ Recommend a Stack upgrade?
,configStackDeveloperMode :: !Bool
-- ^ Turn on Stack developer mode for additional messages?
}

-- | A bit of type safety to ensure we're talking to the right database.
Expand Down Expand Up @@ -859,6 +863,8 @@ data ConfigMonoid =
, configMonoidRecommendUpgrade :: !FirstTrue
-- ^ See 'configRecommendUpgrade'
, configMonoidCasaRepoPrefix :: !(First CasaRepoPrefix)
, configMonoidStackDeveloperMode :: !(First Bool)
-- ^ See 'configStackDeveloperMode'
}
deriving (Show, Generic)

Expand Down Expand Up @@ -983,6 +989,8 @@ parseConfigMonoidObject rootDir obj = do

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

configMonoidStackDeveloperMode <- First <$> obj ..:? configMonoidStackDeveloperModeName

return ConfigMonoid {..}
where
handleExplicitSetupDep :: (Monad m, MonadFail m) => (Text, Bool) -> m (Maybe PackageName, Bool)
Expand Down Expand Up @@ -1148,6 +1156,9 @@ configMonoidRecommendUpgradeName = "recommend-stack-upgrade"
configMonoidCasaRepoPrefixName :: Text
configMonoidCasaRepoPrefixName = "casa-repo-prefix"

configMonoidStackDeveloperModeName :: Text
configMonoidStackDeveloperModeName = "stack-developer-mode"

data ConfigException
= ParseConfigFileException (Path Abs File) ParseException
| ParseCustomSnapshotException Text ParseException
Expand Down Expand Up @@ -2126,3 +2137,11 @@ terminalL = globalOptsL.lens globalTerminal (\x y -> x { globalTerminal = y })
-- | See 'globalReExecVersion'
reExecL :: HasRunner env => SimpleGetter env Bool
reExecL = globalOptsL.to (isJust . globalReExecVersion)

-- | In dev mode, print as a warning, otherwise as debug
prettyStackDevL :: HasConfig env => [StyleDoc] -> RIO env ()
prettyStackDevL docs = do
config <- view configL
if configStackDeveloperMode config
then prettyWarnL docs
else prettyDebugL docs
4 changes: 4 additions & 0 deletions stack-ghc-84.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ resolver: lts-12.26
packages:
- .

flags:
stack:
developer-mode: true

docker:
enable: false
repo: fpco/stack-build-small:lts-12.26
Expand Down
1 change: 1 addition & 0 deletions stack-ghc-88.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ flags:
stack:
hide-dependency-versions: true
supported-build: true
developer-mode: true

ghc-options:
"$locals": -fhide-source-paths
Expand Down
23 changes: 22 additions & 1 deletion stack.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cabal-version: 2.0
--
-- see: https://github.com/sol/hpack
--
-- hash: 193fddca62eb34c1190cee7abae3779a02ec73b4c02e85853ce430a7c8104d20
-- hash: 09229f434502c702e4058371b91cc64f9e800aab8abe66fb228d8da3137558b7

name: stack
version: 2.3.2
Expand Down Expand Up @@ -77,6 +77,11 @@ custom-setup
, base >=4.10 && <5
, filepath

flag developer-mode
description: By default, should extra developer information be output?
manual: True
default: False

flag disable-git-info
description: Disable compile-time inclusion of current git info in stack
manual: True
Expand Down Expand Up @@ -312,6 +317,10 @@ library
hsc2hs
build-depends:
unix
if flag(developer-mode)
cpp-options: -DSTACK_DEVELOPER_MODE_DEFAULT=True
else
cpp-options: -DSTACK_DEVELOPER_MODE_DEFAULT=False
if os(windows)
other-modules:
System.Uname
Expand Down Expand Up @@ -433,6 +442,10 @@ executable stack
hsc2hs
build-depends:
unix
if flag(developer-mode)
cpp-options: -DSTACK_DEVELOPER_MODE_DEFAULT=True
else
cpp-options: -DSTACK_DEVELOPER_MODE_DEFAULT=False
if flag(static)
ld-options: -static -pthread
if !(flag(disable-git-info))
Expand Down Expand Up @@ -551,6 +564,10 @@ executable stack-integration-test
hsc2hs
build-depends:
unix
if flag(developer-mode)
cpp-options: -DSTACK_DEVELOPER_MODE_DEFAULT=True
else
cpp-options: -DSTACK_DEVELOPER_MODE_DEFAULT=False
if !(flag(integration-tests))
buildable: False
if flag(static)
Expand Down Expand Up @@ -678,4 +695,8 @@ test-suite stack-test
hsc2hs
build-depends:
unix
if flag(developer-mode)
cpp-options: -DSTACK_DEVELOPER_MODE_DEFAULT=True
else
cpp-options: -DSTACK_DEVELOPER_MODE_DEFAULT=False
default-language: Haskell2010
1 change: 1 addition & 0 deletions stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ flags:
stack:
hide-dependency-versions: true
supported-build: true
developer-mode: true

ghc-options:
"$locals": -fhide-source-paths
Expand Down

0 comments on commit f2f2acf

Please sign in to comment.