@@ -14,19 +14,32 @@ import qualified Data.Text.Lazy as T (toStrict)
14
14
import qualified Data.Text.Lazy.Encoding as T (decodeUtf8 )
15
15
import Data.Version (makeVersion , showVersion )
16
16
import System.FilePath ((</>) )
17
+ import System.IO (BufferMode (LineBuffering ), hSetBuffering , stderr , stdout )
17
18
import System.Process.Typed (proc , readProcessStdout_ )
18
19
19
- import ANSI (SGR (Bold , BrightCyan , Reset ), setSGR )
20
- import Cli (Compiler (.. ), HackageTests (.. ), Opts (.. ), parseOpts )
21
- import ClockUtil (diffAbsoluteTime , formatDiffTime , getAbsoluteTime )
20
+ import Cli (Compiler (.. ), HackageTests (.. ), Opts (.. ), parseOpts , whenVerbose )
22
21
import OutputUtil (printHeader , withTiming )
23
22
import ProcessUtil (timed , timedWithCwd )
24
23
import Step (Step (.. ), displayStep )
25
24
26
25
-- | Entry-point for @cabal-validate@.
27
26
main :: IO ()
28
27
main = do
28
+ -- You'd _think_ that line-buffering for stdout and stderr would be the
29
+ -- default behavior, and the documentation makes gestures at it, but it
30
+ -- appears to not be the case!
31
+ --
32
+ -- > For most implementations, physical files will normally be
33
+ -- > block-buffered and terminals will normally be line-buffered.
34
+ --
35
+ -- However, on GitHub Actions and on my machine (macOS M1), adding these
36
+ -- lines makes output appear in the correct order!
37
+ hSetBuffering stdout LineBuffering
38
+ hSetBuffering stderr LineBuffering
39
+
29
40
opts <- parseOpts
41
+ printConfig opts
42
+ printToolVersions opts
30
43
forM_ (steps opts) $ \ step -> do
31
44
runStep opts step
32
45
@@ -36,8 +49,6 @@ runStep opts step = do
36
49
let title = displayStep step
37
50
printHeader title
38
51
let action = case step of
39
- PrintConfig -> printConfig opts
40
- PrintToolVersions -> printToolVersions opts
41
52
Build -> build opts
42
53
Doctest -> doctest opts
43
54
LibTests -> libTests opts
@@ -47,7 +58,6 @@ runStep opts step = do
47
58
CliTests -> cliTests opts
48
59
SolverBenchmarksTests -> solverBenchmarksTests opts
49
60
SolverBenchmarksRun -> solverBenchmarksRun opts
50
- TimeSummary -> timeSummary opts
51
61
withTiming (startTime opts) title action
52
62
T. putStrLn " "
53
63
@@ -106,11 +116,11 @@ cabalListBinArgs opts = "list-bin" : cabalArgs opts
106
116
cabalListBin :: Opts -> String -> IO FilePath
107
117
cabalListBin opts target = do
108
118
let args = cabalListBinArgs opts ++ [target]
109
- stdout <-
119
+ stdout' <-
110
120
readProcessStdout_ $
111
121
proc (cabal opts) args
112
122
113
- pure (T. unpack $ T. strip $ T. toStrict $ T. decodeUtf8 stdout)
123
+ pure (T. unpack $ T. strip $ T. toStrict $ T. decodeUtf8 stdout' )
114
124
115
125
-- | Get the RTS arguments for invoking test suites.
116
126
--
@@ -139,57 +149,62 @@ timedCabalBin opts package component args = do
139
149
140
150
-- | Print the configuration for CI logs.
141
151
printConfig :: Opts -> IO ()
142
- printConfig opts = do
143
- putStr $
144
- unlines
145
- [ " compiler: "
146
- <> compilerExecutable (compiler opts)
147
- , " cabal-install: "
148
- <> cabal opts
149
- , " jobs: "
150
- <> show (jobs opts)
151
- , " steps: "
152
- <> unwords (map displayStep (steps opts))
153
- , " Hackage tests: "
154
- <> show (hackageTests opts)
155
- , " verbose: "
156
- <> show (verbose opts)
157
- , " extra compilers: "
158
- <> unwords (extraCompilers opts)
159
- , " extra RTS options: "
160
- <> unwords (rtsArgs opts)
161
- ]
152
+ printConfig opts =
153
+ whenVerbose opts $ do
154
+ printHeader " Configuration"
155
+ putStr $
156
+ unlines
157
+ [ " compiler: "
158
+ <> compilerExecutable (compiler opts)
159
+ , " cabal-install: "
160
+ <> cabal opts
161
+ , " jobs: "
162
+ <> show (jobs opts)
163
+ , " steps: "
164
+ <> unwords (map displayStep (steps opts))
165
+ , " Hackage tests: "
166
+ <> show (hackageTests opts)
167
+ , " verbosity: "
168
+ <> show (verbosity opts)
169
+ , " extra compilers: "
170
+ <> unwords (extraCompilers opts)
171
+ , " extra RTS options: "
172
+ <> unwords (rtsArgs opts)
173
+ ]
162
174
163
175
-- | Print the versions of tools being used.
164
176
printToolVersions :: Opts -> IO ()
165
- printToolVersions opts = do
166
- timed opts (compilerExecutable (compiler opts)) [" --version" ]
167
- timed opts (cabal opts) [" --version" ]
177
+ printToolVersions opts =
178
+ whenVerbose opts $ do
179
+ printHeader " Tool versions"
180
+ timed opts (cabal opts) [" --version" ]
181
+ timed opts (compilerExecutable (compiler opts)) [" --version" ]
168
182
169
- forM_ (extraCompilers opts) $ \ compiler' -> do
170
- timed opts compiler' [" --version" ]
183
+ forM_ (extraCompilers opts) $ \ compiler' -> do
184
+ timed opts compiler' [" --version" ]
171
185
172
186
-- | Run the build step.
173
187
build :: Opts -> IO ()
174
188
build opts = do
175
- printHeader " build (dry run)"
176
- timed
177
- opts
178
- (cabal opts)
179
- ( cabalNewBuildArgs opts
180
- ++ targets opts
181
- ++ [" --dry-run" ]
182
- )
183
-
184
- printHeader " build (full build plan; cached and to-be-built dependencies)"
185
- timed
186
- opts
187
- " jq"
188
- [ " -r"
189
- , -- TODO: Maybe use `cabal-plan`? It's a heavy dependency though...
190
- " .\" install-plan\" | map(.\" pkg-name\" + \" -\" + .\" pkg-version\" + \" \" + .\" component-name\" ) | join(\"\n\" )"
191
- , baseBuildDir opts </> " cache" </> " plan.json"
192
- ]
189
+ whenVerbose opts $ do
190
+ printHeader " build (dry run)"
191
+ timed
192
+ opts
193
+ (cabal opts)
194
+ ( cabalNewBuildArgs opts
195
+ ++ targets opts
196
+ ++ [" --dry-run" ]
197
+ )
198
+
199
+ printHeader " build (full build plan; cached and to-be-built dependencies)"
200
+ timed
201
+ opts
202
+ " jq"
203
+ [ " -r"
204
+ , -- TODO: Maybe use `cabal-plan`? It's a heavy dependency though...
205
+ " .\" install-plan\" | map(.\" pkg-name\" + \" -\" + .\" pkg-version\" + \" \" + .\" component-name\" ) | join(\"\n\" )"
206
+ , baseBuildDir opts </> " cache" </> " plan.json"
207
+ ]
193
208
194
209
printHeader " build (actual build)"
195
210
timed
@@ -413,14 +428,3 @@ solverBenchmarksRun opts = do
413
428
, " --packages=Chart-diagrams"
414
429
, " --print-trials"
415
430
]
416
-
417
- -- | Print the total time taken so far.
418
- timeSummary :: Opts -> IO ()
419
- timeSummary opts = do
420
- endTime <- getAbsoluteTime
421
- let totalDuration = diffAbsoluteTime endTime (startTime opts)
422
- putStrLn $
423
- setSGR [Bold , BrightCyan ]
424
- <> " !!! Validation completed in "
425
- <> formatDiffTime totalDuration
426
- <> setSGR [Reset ]
0 commit comments