Skip to content

Commit 30af75a

Browse files
committed
Cabal library: allow setting the logging handle
The goal of this patch is to allow the logging handle to be set when calling Cabal library functions, without having to spawn a separate process and redirect handles. This allows Cabal library functions to be called in a concurrent setting without spawning separate processes. To achieve this, this commit modifies Verbosity as follows: 1. The old Verbosity datatype becomes VerbosityFlags. This is what gets passed in the command-line interface, e.g. when running a Setup executable. 2. The new Verbosity datatype contains VerbosityFlags together with VerbosityHandles, which specify where to redirect stdout/stderr. Crucially, this allows us to get rid of the isJust (useLoggingHandle options) condition in 'getSetupMethod', which forced us to use the cabal-install "act as setup" mechanism instead of directly calling Cabal library functions.
1 parent 9a343d1 commit 30af75a

File tree

145 files changed

+1180
-877
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+1180
-877
lines changed

Cabal-QuickCheck/src/Test/QuickCheck/Instances/Cabal.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,9 @@ instance Arbitrary FlagAssignment where
265265
-- Verbosity
266266
-------------------------------------------------------------------------------
267267

268-
instance Arbitrary Verbosity where
268+
instance Arbitrary VerbosityFlags where
269269
arbitrary = do
270-
v <- elements [minBound..maxBound]
270+
v <- mkVerbosityFlags <$> elements [minBound..maxBound]
271271
-- verbose markoutput is left out on purpose
272272
flags <- listOf $ elements
273273
[ verboseCallSite

Cabal-described/src/Distribution/Described.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ import Distribution.Types.TestType (TestType)
9999
import Distribution.Types.UnitId (UnitId)
100100
import Distribution.Types.UnqualComponentName (UnqualComponentName)
101101
import Distribution.Utils.Path (SymbolicPath, RelativePath)
102-
import Distribution.Verbosity (Verbosity)
102+
import Distribution.Verbosity (VerbosityFlags)
103103
import Distribution.Version (Version, VersionRange)
104104
import Language.Haskell.Extension (Extension, Language, knownLanguages)
105105

@@ -493,7 +493,7 @@ instance Described RepoType where
493493
instance Described TestType where
494494
describe _ = REUnion ["exitcode-stdio-1.0", "detailed-0.9"]
495495

496-
instance Described Verbosity where
496+
instance Described VerbosityFlags where
497497
describe _ = REUnion
498498
[ REUnion ["0", "1", "2", "3"]
499499
, REUnion ["silent", "normal", "verbose", "debug", "deafening"]

Cabal-tests/tests/UnitTests.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ main = do
109109
(mtimeChange, mtimeChange') <- calibrateMtimeChangeDelay
110110
let toMillis :: Int -> Double
111111
toMillis x = fromIntegral x / 1000.0
112-
notice normal $ "File modification time resolution calibration completed, "
112+
notice (mkVerbosity defaultVerbosityHandles normal) $ "File modification time resolution calibration completed, "
113113
++ "maximum delay observed: "
114114
++ (show . toMillis $ mtimeChange ) ++ " ms. "
115115
++ "Will be using delay of " ++ (show . toMillis $ mtimeChange')

Cabal-tests/tests/UnitTests/Distribution/Compat/Time.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import Control.Concurrent (threadDelay)
44
import System.FilePath
55

66
import Distribution.Simple.Utils (withTempDirectory)
7-
import Distribution.Verbosity
87

98
import Distribution.Compat.Time
109

@@ -19,7 +18,7 @@ tests mtimeChange =
1918

2019
getModTimeTest :: Int -> Assertion
2120
getModTimeTest mtimeChange =
22-
withTempDirectory silent "." "getmodtime-" $ \dir -> do
21+
withTempDirectory "." "getmodtime-" $ \dir -> do
2322
let fileName = dir </> "foo"
2423
writeFile fileName "bar"
2524
t0 <- getModTime fileName
@@ -31,7 +30,7 @@ getModTimeTest mtimeChange =
3130

3231
getCurTimeTest :: Int -> Assertion
3332
getCurTimeTest mtimeChange =
34-
withTempDirectory silent "." "getmodtime-" $ \dir -> do
33+
withTempDirectory "." "getmodtime-" $ \dir -> do
3534
let fileName = dir </> "foo"
3635
writeFile fileName "bar"
3736
t0 <- getModTime fileName

Cabal-tests/tests/UnitTests/Distribution/Described.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import Distribution.Types.PackageName (PackageName)
2222
import Distribution.Types.PackageVersionConstraint (PackageVersionConstraint)
2323
import Distribution.Types.Version (Version)
2424
import Distribution.Types.VersionRange (VersionRange)
25-
import Distribution.Verbosity (Verbosity)
25+
import Distribution.Verbosity (VerbosityFlags)
2626

2727
-- instances
2828
import Test.QuickCheck.Instances.Cabal ()
@@ -45,5 +45,5 @@ tests = testGroup "Described"
4545
, testDescribed (Proxy :: Proxy ModuleRenaming)
4646
, testDescribed (Proxy :: Proxy IncludeRenaming)
4747
, testDescribed (Proxy :: Proxy Mixin)
48-
, testDescribed (Proxy :: Proxy Verbosity)
48+
, testDescribed (Proxy :: Proxy VerbosityFlags)
4949
]

Cabal-tests/tests/UnitTests/Distribution/Simple/Glob.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import System.FilePath ((</>), splitFileName, normalise)
1616
import System.IO.Temp (withSystemTempDirectory)
1717
import Test.Tasty
1818
import Test.Tasty.HUnit
19+
import Distribution.Verbosity
1920

2021
sampleFileNames :: [FilePath]
2122
sampleFileNames =
@@ -100,6 +101,7 @@ testMatchesVersion version pat expected = do
100101
checkPure globPat
101102
checkIO globPat
102103
where
104+
verbosity = mkVerbosity defaultVerbosityHandles Verbosity.normal
103105
isEqual = (==) `on` (sort . fmap (fmap normalise))
104106
checkPure globPat = do
105107
let actual = mapMaybe (\p -> (p <$) <$> fileGlobMatches version globPat p) sampleFileNames
@@ -111,7 +113,7 @@ testMatchesVersion version pat expected = do
111113
checkIO globPat =
112114
withSystemTempDirectory "globstar-sample" $ \tmpdir -> do
113115
makeSampleFiles tmpdir
114-
actual <- runDirFileGlob Verbosity.normal (Just version) tmpdir globPat
116+
actual <- runDirFileGlob verbosity (Just version) tmpdir globPat
115117
unless (isEqual actual expected) $
116118
assertFailure $ "Unexpected result (impure matcher): " ++ show actual ++ "\nExpected: " ++ show expected
117119

Cabal-tests/tests/UnitTests/Distribution/Simple/Utils.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ withTempDirTest :: Assertion
3838
withTempDirTest = do
3939
dirName <- newIORef ""
4040
tempDir <- getTemporaryDirectory
41-
withTempDirectory normal tempDir "foo" $ \dirName' -> do
41+
withTempDirectory tempDir "foo" $ \dirName' -> do
4242
writeIORef dirName dirName'
4343
dirExists <- readIORef dirName >>= doesDirectoryExist
4444
assertBool "Temporary directory not deleted by 'withTempDirectory'!"
@@ -47,7 +47,7 @@ withTempDirTest = do
4747
withTempDirRemovedTest :: Assertion
4848
withTempDirRemovedTest = do
4949
tempDir <- getTemporaryDirectory
50-
withTempDirectory normal tempDir "foo" $ \dirPath -> do
50+
withTempDirectory tempDir "foo" $ \dirPath -> do
5151
removeDirectoryRecursive dirPath
5252

5353
rawSystemStdInOutTextDecodingTest :: FilePath -> Assertion
@@ -67,15 +67,15 @@ rawSystemStdInOutTextDecodingTest ghcPath
6767
hClose handleExe
6868

6969
-- Compile
70-
(resOutput, resErrors, resExitCode) <- rawSystemStdInOut normal
70+
(resOutput, resErrors, resExitCode) <- rawSystemStdInOut (mkVerbosity defaultVerbosityHandles normal)
7171
ghcPath ["-o", filenameExe, filenameHs]
7272
Nothing Nothing Nothing
7373
IODataModeText
7474
print (resOutput, resErrors, resExitCode)
7575

7676
-- Execute
7777
Exception.try $ do
78-
rawSystemStdInOut normal
78+
rawSystemStdInOut (mkVerbosity defaultVerbosityHandles normal)
7979
filenameExe []
8080
Nothing Nothing Nothing
8181
IODataModeText -- not binary mode output, ie utf8 text mode so try to decode

Cabal-tests/tests/custom-setup/CabalDoctestSetup.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ generateBuildModule
335335
-> BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ()
336336
{- FOURMOLU_DISABLE -}
337337
generateBuildModule testSuiteName flags pkg lbi = do
338-
let verbosity = fromFlag (buildVerbosity flags)
338+
let verbosity = mkVerbosity defaultVerbosityHandles $ fromFlag (buildVerbosity flags)
339339
let distPref = fromFlag (buildDistPref flags)
340340

341341
-- Package DBs & environments

Cabal-tests/tests/custom-setup/IdrisSetup.hs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import Distribution.Simple.InstallDirs as I
5656
import Distribution.Simple.LocalBuildInfo as L
5757
import qualified Distribution.Simple.Setup as S
5858
import qualified Distribution.Simple.Program as P
59+
import qualified Distribution.Verbosity as V
5960
import Distribution.Simple.Utils (createDirectoryIfMissingVerbose, notice, installOrdinaryFiles)
6061
import Distribution.Simple.Utils (rewriteFileEx)
6162
import Distribution.Compiler
@@ -161,7 +162,8 @@ mkFlagName = FlagName
161162

162163
idrisClean _ flags _ _ = cleanStdLib
163164
where
164-
verbosity = S.fromFlag $ S.cleanVerbosity flags
165+
verbosity = V.mkVerbosity V.defaultVerbosityHandles
166+
$ S.fromFlag $ S.cleanVerbosity flags
165167

166168
cleanStdLib = makeClean "libs"
167169

@@ -247,7 +249,8 @@ idrisConfigure _ flags pkgdesc local = do
247249
else
248250
generateToolchainModule verbosity libAutogenDir Nothing
249251
where
250-
verbosity = S.fromFlag $ S.configVerbosity flags
252+
verbosity = V.mkVerbosity V.defaultVerbosityHandles
253+
$ S.fromFlag $ S.configVerbosity flags
251254
version = pkgVersion . package $ localPkgDescr local
252255

253256
-- This is a hack. I don't know how to tell cabal that a data file needs
@@ -307,7 +310,8 @@ idrisPreBuild args flags = do
307310
windres verbosity ["icons/idris_icon.rc","-o", dir++"/idris_icon.o"]
308311
return (Nothing, [(fromString "idris", emptyBuildInfo { ldOptions = [dir ++ "/idris_icon.o"] })])
309312
where
310-
verbosity = S.fromFlag $ S.buildVerbosity flags
313+
verbosity = V.mkVerbosity V.defaultVerbosityHandles
314+
$ S.fromFlag $ S.buildVerbosity flags
311315

312316
dir =
313317
#if MIN_VERSION_Cabal(3,11,0)
@@ -325,7 +329,8 @@ idrisBuild _ flags _ local
325329
else do buildStdLib
326330
buildRTS
327331
where
328-
verbosity = S.fromFlag $ S.buildVerbosity flags
332+
verbosity = V.mkVerbosity V.defaultVerbosityHandles
333+
$ S.fromFlag $ S.buildVerbosity flags
329334

330335
buildStdLib = do
331336
putStrLn "Building libraries..."
@@ -396,10 +401,12 @@ main = defaultMainWithHooks $ simpleUserHooks
396401
, preBuild = idrisPreBuild
397402
, postBuild = idrisBuild
398403
, postCopy = \_ flags pkg local ->
399-
idrisInstall (S.fromFlag $ S.copyVerbosity flags)
404+
idrisInstall (V.mkVerbosity V.defaultVerbosityHandles $
405+
S.fromFlag $ S.copyVerbosity flags)
400406
(S.fromFlag $ S.copyDest flags) pkg local
401407
, postInst = \_ flags pkg local ->
402-
idrisInstall (S.fromFlag $ S.installVerbosity flags)
408+
idrisInstall (V.mkVerbosity V.defaultVerbosityHandles $
409+
S.fromFlag $ S.installVerbosity flags)
403410
NoCopyDest pkg local
404411
#if !MIN_VERSION_Cabal(3,0,0)
405412
, preSDist = idrisPreSDist

Cabal-tree-diff/src/Data/TreeDiff/Instances/Cabal.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ instance ToExpr TestSuiteInterface
121121
instance ToExpr TestType
122122
instance ToExpr UnitId
123123
instance ToExpr UnqualComponentName
124-
instance ToExpr Verbosity
124+
instance ToExpr VerbosityFlags
125125
instance ToExpr VerbosityFlag
126126
instance ToExpr VerbosityLevel
127127

0 commit comments

Comments
 (0)