Skip to content

Commit

Permalink
Add dump-logs (fixes #426)
Browse files Browse the repository at this point in the history
  • Loading branch information
snoyberg committed Sep 17, 2016
1 parent f6747b6 commit 770e620
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 2 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Other enhancements:
* Make `stack list-dependencies` understand all of the `stack dot` options too.
* Add the ability for `stack list-dependencies` to list dependency licenses by
passing the `--license` flag.
* Add the `dump-logs` config option and `--dump-logs` command line
option to get full build output on the
console. [#426](https://github.com/commercialhaskell/stack/issues/426)

Bug fixes:

Expand Down
14 changes: 14 additions & 0 deletions doc/yaml_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,20 @@ The meanings of these settings correspond directly with the CLI flags of the
same name. See the [build command docs](build_command.md) and the
[users guide](GUIDE.md#the-build-command) for more info.

### dump-logs

(Since XXX)

Tell Stack to print the log output from all local non-dependency
packages to the console. By default, Stack will only do this when
building a single target package, to avoid generating unnecessarily
verbose output. This can be useful when you want to see warnings from
all of your packages.

```yaml
dump-logs: true
```

### templates

Templates used with `stack new` have a number of parameters that affect the
Expand Down
33 changes: 32 additions & 1 deletion src/Stack/Build/Execute.hs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ data ExecuteEnv = ExecuteEnv
, eeGlobalDumpPkgs :: !(Map GhcPkgId (DumpPackage () ()))
, eeSnapshotDumpPkgs :: !(TVar (Map GhcPkgId (DumpPackage () ())))
, eeLocalDumpPkgs :: !(TVar (Map GhcPkgId (DumpPackage () ())))
, eeLogFiles :: !(TChan (Path Abs File))
}

-- | Get a compiled Setup exe
Expand Down Expand Up @@ -315,6 +316,7 @@ withExecuteEnv menv bopts boptsCli baseConfigOpts locals globalPackages snapshot
globalDB <- getGlobalDB menv =<< getWhichCompiler
snapshotPackagesTVar <- liftIO $ newTVarIO (toDumpPackagesByGhcPkgId snapshotPackages)
localPackagesTVar <- liftIO $ newTVarIO (toDumpPackagesByGhcPkgId localPackages)
logFilesTChan <- liftIO $ atomically newTChan
inner ExecuteEnv
{ eeEnvOverride = menv
, eeBuildOpts = bopts
Expand All @@ -338,10 +340,32 @@ withExecuteEnv menv bopts boptsCli baseConfigOpts locals globalPackages snapshot
, eeGlobalDumpPkgs = toDumpPackagesByGhcPkgId globalPackages
, eeSnapshotDumpPkgs = snapshotPackagesTVar
, eeLocalDumpPkgs = localPackagesTVar
}
, eeLogFiles = logFilesTChan
} `finally` dumpLogs logFilesTChan
where
toDumpPackagesByGhcPkgId = Map.fromList . map (\dp -> (dpGhcPkgId dp, dp))

dumpLogs chan = do
toDump <- asks (configDumpLogs . getConfig)
when toDump loop
where
loop = do
mfilepath <- liftIO $ atomically $ tryReadTChan chan
case mfilepath of
Nothing -> return ()
Just filepath -> do
dumpLog filepath
loop

dumpLog filepath = do
$logInfo $ T.pack $ "\nDumping log file: " ++ toFilePath filepath ++ "\n"
runResourceT
$ CB.sourceFile (toFilePath filepath)
$$ CT.decodeUtf8Lenient
=$ CT.lines
=$ CL.mapM_ $logInfo
$logInfo $ T.pack $ "\nEnd of log file: " ++ toFilePath filepath ++ "\n"

-- | Perform the actual plan
executePlan :: M env m
=> EnvOverride
Expand Down Expand Up @@ -801,6 +825,13 @@ withSingleContext runInBase ActionContext {..} ExecuteEnv {..} task@Task {..} md
logPath <- buildLogPath package msuffix
ensureDir (parent logPath)
let fp = toFilePath logPath

-- We only want to dump logs for local non-dependency packages
case taskType of
TTLocal lp | lpWanted lp ->
liftIO $ atomically $ writeTChan eeLogFiles logPath
_ -> return ()

bracket
(liftIO $ openBinaryFile fp WriteMode)
(liftIO . hClose)
Expand Down
1 change: 1 addition & 0 deletions src/Stack/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ configFromConfigMonoid configStackRoot configUserConfigPath mresolver mproject C
configApplyGhcOptions = fromFirst AGOLocals configMonoidApplyGhcOptions
configAllowNewer = fromFirst False configMonoidAllowNewer
configDefaultTemplate = getFirst configMonoidDefaultTemplate
configDumpLogs = fromFirst False configMonoidDumpLogs

configAllowDifferentUser <-
case getFirst configMonoidAllowDifferentUser of
Expand Down
7 changes: 6 additions & 1 deletion src/Stack/Options/ConfigParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Stack.Types.Config
-- | Command-line arguments parser for configuration.
configOptsParser :: GlobalOptsContext -> Parser ConfigMonoid
configOptsParser hide0 =
(\stackRoot workDir buildOpts dockerOpts nixOpts systemGHC installGHC arch ghcVariant ghcBuild jobs includes libs overrideGccPath skipGHCCheck skipMsys localBin modifyCodePage allowDifferentUser -> mempty
(\stackRoot workDir buildOpts dockerOpts nixOpts systemGHC installGHC arch ghcVariant ghcBuild jobs includes libs overrideGccPath skipGHCCheck skipMsys localBin modifyCodePage allowDifferentUser dumpLogs -> mempty
{ configMonoidStackRoot = stackRoot
, configMonoidWorkDir = workDir
, configMonoidBuildOpts = buildOpts
Expand All @@ -37,6 +37,7 @@ configOptsParser hide0 =
, configMonoidLocalBinPath = localBin
, configMonoidModifyCodePage = modifyCodePage
, configMonoidAllowDifferentUser = allowDifferentUser
, configMonoidDumpLogs = dumpLogs
})
<$> optionalFirst (absDirOption
( long stackRootOptionName
Expand Down Expand Up @@ -118,4 +119,8 @@ configOptsParser hide0 =
("permission for users other than the owner of the stack root " ++
"directory to use a stack installation (POSIX only)")
hide
<*> firstBoolFlags
"dump-logs"
"dump the build output logs for local packages to the console"
hide
where hide = hideMods (hide0 /= OuterGlobalOpts)
8 changes: 8 additions & 0 deletions src/Stack/Types/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ data Config =
-- installation.
,configPackageCaches :: !(IORef (Maybe (Map PackageIdentifier (PackageIndex, PackageCache))))
-- ^ In memory cache of hackage index.
,configDumpLogs :: !Bool
-- ^ Dump logs of local non-dependencies when doing a build.
,configMaybeProject :: !(Maybe (Project, Path Abs File))
}

Expand Down Expand Up @@ -864,6 +866,8 @@ data ConfigMonoid =
, configMonoidAllowDifferentUser :: !(First Bool)
-- ^ Allow users other than the stack root owner to use the stack
-- installation.
, configMonoidDumpLogs :: !(First Bool)
-- ^ See 'configDumpLogs'
}
deriving (Show, Generic)

Expand Down Expand Up @@ -931,6 +935,7 @@ parseConfigMonoidJSON obj = do
configMonoidAllowNewer <- First <$> obj ..:? configMonoidAllowNewerName
configMonoidDefaultTemplate <- First <$> obj ..:? configMonoidDefaultTemplateName
configMonoidAllowDifferentUser <- First <$> obj ..:? configMonoidAllowDifferentUserName
configMonoidDumpLogs <- First <$> obj ..:? configMonoidDumpLogsName

return ConfigMonoid {..}
where
Expand Down Expand Up @@ -1058,6 +1063,9 @@ configMonoidDefaultTemplateName = "default-template"
configMonoidAllowDifferentUserName :: Text
configMonoidAllowDifferentUserName = "allow-different-user"

configMonoidDumpLogsName :: Text
configMonoidDumpLogsName = "dump-logs"

data ConfigException
= ParseConfigFileException (Path Abs File) ParseException
| ParseCustomSnapshotException Text ParseException
Expand Down

0 comments on commit 770e620

Please sign in to comment.