Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a stack-developer-mode flag #5134 #5325

Merged
merged 1 commit into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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