Skip to content

Commit

Permalink
cabal-validate: Hide config and tool versions unless --verbose
Browse files Browse the repository at this point in the history
`print-config`, `print-tool-versions`, and `time-summary` are no longer
explicit steps, and are instead run implicitly (closes #10570).

`time-summary` is redundant in its current form and is removed. It may
be added back in the future with more detailed output (e.g., which steps
were run, how long did they take individually).

`print-config` and `print-tool-versions` are hidden unless `--verbose`
is given.
  • Loading branch information
9999years authored and Mikolaj committed Dec 13, 2024
1 parent 1586aaa commit c25983a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 55 deletions.
7 changes: 1 addition & 6 deletions cabal-validate/src/Cli.hs
Original file line number Diff line number Diff line change
Expand Up @@ -179,19 +179,14 @@ resolveOpts opts = do
then rawSteps opts
else
concat
[
[ PrintConfig
, PrintToolVersions
, Build
]
[ [Build]
, optional (rawDoctest opts) Doctest
, optional (rawRunLibTests opts) LibTests
, optional (rawRunLibSuite opts) LibSuite
, optional (rawRunLibSuite opts && not (null (rawExtraCompilers opts))) LibSuiteExtras
, optional (rawRunCliTests opts && not (rawLibOnly opts)) CliTests
, optional (rawRunCliSuite opts && not (rawLibOnly opts)) CliSuite
, optionals (rawSolverBenchmarks opts) [SolverBenchmarksTests, SolverBenchmarksRun]
, [TimeSummary]
]

targets' =
Expand Down
74 changes: 32 additions & 42 deletions cabal-validate/src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Main
, runStep
) where

import Control.Monad (forM_)
import Control.Monad (forM_, when)
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Lazy as T (toStrict)
Expand All @@ -16,9 +16,7 @@ import Data.Version (makeVersion, showVersion)
import System.FilePath ((</>))
import System.Process.Typed (proc, readProcessStdout_)

import ANSI (SGR (Bold, BrightCyan, Reset), setSGR)
import Cli (Compiler (..), HackageTests (..), Opts (..), parseOpts)
import ClockUtil (diffAbsoluteTime, formatDiffTime, getAbsoluteTime)
import OutputUtil (printHeader, withTiming)
import ProcessUtil (timed, timedWithCwd)
import Step (Step (..), displayStep)
Expand All @@ -27,6 +25,8 @@ import Step (Step (..), displayStep)
main :: IO ()
main = do
opts <- parseOpts
printConfig opts
printToolVersions opts
forM_ (steps opts) $ \step -> do
runStep opts step

Expand All @@ -36,8 +36,6 @@ runStep opts step = do
let title = displayStep step
printHeader title
let action = case step of
PrintConfig -> printConfig opts
PrintToolVersions -> printToolVersions opts
Build -> build opts
Doctest -> doctest opts
LibTests -> libTests opts
Expand All @@ -47,7 +45,6 @@ runStep opts step = do
CliTests -> cliTests opts
SolverBenchmarksTests -> solverBenchmarksTests opts
SolverBenchmarksRun -> solverBenchmarksRun opts
TimeSummary -> timeSummary opts
withTiming (startTime opts) title action
T.putStrLn ""

Expand Down Expand Up @@ -139,35 +136,39 @@ timedCabalBin opts package component args = do

-- | Print the configuration for CI logs.
printConfig :: Opts -> IO ()
printConfig opts = do
putStr $
unlines
[ "compiler: "
<> compilerExecutable (compiler opts)
, "cabal-install: "
<> cabal opts
, "jobs: "
<> show (jobs opts)
, "steps: "
<> unwords (map displayStep (steps opts))
, "Hackage tests: "
<> show (hackageTests opts)
, "verbose: "
<> show (verbose opts)
, "extra compilers: "
<> unwords (extraCompilers opts)
, "extra RTS options: "
<> unwords (rtsArgs opts)
]
printConfig opts =
when (verbose opts) $
printHeader "Configuration"
putStr $
unlines
[ "compiler: "
<> compilerExecutable (compiler opts)
, "cabal-install: "
<> cabal opts
, "jobs: "
<> show (jobs opts)
, "steps: "
<> unwords (map displayStep (steps opts))
, "Hackage tests: "
<> show (hackageTests opts)
, "verbose: "
<> show (verbose opts)
, "extra compilers: "
<> unwords (extraCompilers opts)
, "extra RTS options: "
<> unwords (rtsArgs opts)
]

-- | Print the versions of tools being used.
printToolVersions :: Opts -> IO ()
printToolVersions opts = do
timed opts (compilerExecutable (compiler opts)) ["--version"]
timed opts (cabal opts) ["--version"]
printToolVersions opts =
when (verbose opts) $ do
printHeader "Tool versions"
timed opts (cabal opts) ["--version"]
timed opts (compilerExecutable (compiler opts)) ["--version"]

forM_ (extraCompilers opts) $ \compiler' -> do
timed opts compiler' ["--version"]
forM_ (extraCompilers opts) $ \compiler' -> do
timed opts compiler' ["--version"]

-- | Run the build step.
build :: Opts -> IO ()
Expand Down Expand Up @@ -413,14 +414,3 @@ solverBenchmarksRun opts = do
, "--packages=Chart-diagrams"
, "--print-trials"
]

-- | Print the total time taken so far.
timeSummary :: Opts -> IO ()
timeSummary opts = do
endTime <- getAbsoluteTime
let totalDuration = diffAbsoluteTime endTime (startTime opts)
putStrLn $
setSGR [Bold, BrightCyan]
<> "!!! Validation completed in "
<> formatDiffTime totalDuration
<> setSGR [Reset]
8 changes: 1 addition & 7 deletions cabal-validate/src/Step.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import qualified Data.Map.Strict as Map

-- | A step to be run by @cabal-validate@.
data Step
= PrintConfig
| PrintToolVersions
| Build
= Build
| Doctest
| LibTests
| LibSuite
Expand All @@ -22,7 +20,6 @@ data Step
| CliSuite
| SolverBenchmarksTests
| SolverBenchmarksRun
| TimeSummary
deriving (Eq, Enum, Bounded, Show)

-- | Get the display identifier for a given `Step`.
Expand All @@ -34,8 +31,6 @@ data Step
displayStep :: Step -> String
displayStep step =
case step of
PrintConfig -> "print-config"
PrintToolVersions -> "print-tool-versions"
Build -> "build"
Doctest -> "doctest"
LibTests -> "lib-tests"
Expand All @@ -45,7 +40,6 @@ displayStep step =
CliSuite -> "cli-suite"
SolverBenchmarksTests -> "solver-benchmarks-tests"
SolverBenchmarksRun -> "solver-benchmarks-run"
TimeSummary -> "time-summary"

-- | A map from step names to `Steps`.
--
Expand Down

0 comments on commit c25983a

Please sign in to comment.