Skip to content

Commit a03580b

Browse files
alt-romessheaf
authored andcommitted
testsuite: Pass pkgdb of store used for intree Cabal
1 parent fd82379 commit a03580b

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

cabal-testsuite/main/cabal-tests.hs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,29 +125,38 @@ mainArgParser = MainArgs
125125
<*> commonArgParser
126126

127127
-- Unpack and build a specific released version of Cabal and Cabal-syntax libraries
128-
buildCabalLibsProject :: String -> Verbosity -> Maybe FilePath -> FilePath -> IO FilePath
128+
buildCabalLibsProject :: String -> Verbosity -> Maybe FilePath -> FilePath -> IO [FilePath]
129129
buildCabalLibsProject projString verb mbGhc dir = do
130130
let prog_db = userSpecifyPaths [("ghc", path) | Just path <- [mbGhc] ] defaultProgramDb
131131
(cabal, _) <- requireProgram verb (simpleProgram "cabal") prog_db
132132
(ghc, _) <- requireProgram verb ghcProgram prog_db
133133

134+
let storeRoot = dir </> "store"
134135
let pv = fromMaybe (error "no ghc version") (programVersion ghc)
135136
let final_package_db = dir </> "dist-newstyle" </> "packagedb" </> "ghc-" ++ prettyShow pv
136137
createDirectoryIfMissing True dir
137138
writeFile (dir </> "cabal.project-test") projString
138139

139140
runProgramInvocation verb
140141
((programInvocation cabal
141-
["--store-dir", dir </> "store"
142+
["--store-dir", storeRoot
142143
, "--project-file=" ++ dir </> "cabal.project-test"
143144
, "build"
144145
, "-w", programPath ghc
145146
, "Cabal", "Cabal-syntax", "Cabal-hooks"
146147
] ) { progInvokeCwd = Just dir })
147-
return final_package_db
148148

149+
-- Determine the path to the packagedb in the store for this ghc version
150+
storesByGhc <- getDirectoryContents storeRoot
151+
case filter (prettyShow pv `isInfixOf`) storesByGhc of
152+
[] -> return [final_package_db]
153+
storeForGhc:_ -> do
154+
let storePackageDB = (storeRoot </> storeForGhc </> "package.db")
155+
return [storePackageDB, final_package_db]
149156

150-
buildCabalLibsSpecific :: String -> Verbosity -> Maybe FilePath -> FilePath -> IO FilePath
157+
158+
159+
buildCabalLibsSpecific :: String -> Verbosity -> Maybe FilePath -> FilePath -> IO [FilePath]
151160
buildCabalLibsSpecific ver verb mbGhc builddir_rel = do
152161
let prog_db = userSpecifyPaths [("ghc", path) | Just path <- [mbGhc] ] defaultProgramDb
153162
(cabal, _) <- requireProgram verb (simpleProgram "cabal") prog_db
@@ -166,7 +175,7 @@ buildCabalLibsSpecific ver verb mbGhc builddir_rel = do
166175
buildCabalLibsProject ("packages: Cabal-" ++ ver ++ " Cabal-syntax-" ++ ver ++ " Cabal-hooks-" ++ hooksVer) verb mbGhc dir
167176

168177

169-
buildCabalLibsIntree :: String -> Verbosity -> Maybe FilePath -> FilePath -> IO FilePath
178+
buildCabalLibsIntree :: String -> Verbosity -> Maybe FilePath -> FilePath -> IO [FilePath]
170179
buildCabalLibsIntree root verb mbGhc builddir_rel = do
171180
dir <- canonicalizePath (builddir_rel </> "intree")
172181
buildCabalLibsProject ("packages: " ++ root </> "Cabal" ++ " " ++ root </> "Cabal-syntax" ++ " " ++ root </> "Cabal-hooks") verb mbGhc dir
@@ -182,26 +191,26 @@ main = do
182191
args <- execParser $ info (mainArgParser <**> helper) mempty
183192
let verbosity = if mainArgVerbose args then verbose else normal
184193

185-
mpkg_db <-
194+
pkg_dbs <-
186195
-- Not path to cabal-install so we're not going to run cabal-install tests so we
187196
-- can skip setting up a Cabal library to use with cabal-install.
188197
case argCabalInstallPath (mainCommonArgs args) of
189198
Nothing -> do
190199
when (isJust $ mainArgCabalSpec args)
191200
(putStrLn "Ignoring Cabal library specification as cabal-install tests are not running")
192-
return Nothing
201+
return []
193202
-- Path to cabal-install is passed, so need to install the requested relevant version of Cabal
194203
-- library.
195204
Just {} ->
196205
case mainArgCabalSpec args of
197206
Nothing -> do
198207
putStrLn "No Cabal library specified, using boot Cabal library with cabal-install tests"
199-
return Nothing
200-
Just BootCabalLib -> return Nothing
208+
return []
209+
Just BootCabalLib -> return []
201210
Just (InTreeCabalLib root build_dir) ->
202-
Just <$> buildCabalLibsIntree root verbosity (argGhcPath (mainCommonArgs args)) build_dir
211+
buildCabalLibsIntree root verbosity (argGhcPath (mainCommonArgs args)) build_dir
203212
Just (SpecificCabalLib ver build_dir) ->
204-
Just <$> buildCabalLibsSpecific ver verbosity (argGhcPath (mainCommonArgs args)) build_dir
213+
buildCabalLibsSpecific ver verbosity (argGhcPath (mainCommonArgs args)) build_dir
205214

206215
-- To run our test scripts, we need to be able to run Haskell code
207216
-- linked against the Cabal library under test. The most efficient
@@ -228,7 +237,7 @@ main = do
228237
-> IO result
229238
runTest runner path
230239
= runner Nothing [] path $
231-
["--builddir", dist_dir, path] ++ ["--extra-package-db=" ++ pkg_db | Just pkg_db <- [mpkg_db]] ++ renderCommonArgs (mainCommonArgs args)
240+
["--builddir", dist_dir, path] ++ ["--extra-package-db=" ++ pkg_db | pkg_db <- pkg_dbs] ++ renderCommonArgs (mainCommonArgs args)
232241

233242
case mainArgTestPaths args of
234243
[path] -> do

cabal-testsuite/src/Test/Cabal/Monad.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ renderCommonArgs args =
158158

159159
data TestArgs = TestArgs {
160160
testArgDistDir :: FilePath,
161-
testArgPackageDb :: Maybe FilePath,
161+
testArgPackageDb :: [FilePath],
162162
testArgScriptPath :: FilePath,
163163
testCommonArgs :: CommonArgs
164164
}
@@ -169,7 +169,7 @@ testArgParser = TestArgs
169169
( help "Build directory of cabal-testsuite"
170170
<> long "builddir"
171171
<> metavar "DIR")
172-
<*> optional (option str
172+
<*> many (option str
173173
( help "Package DB which contains Cabal and Cabal-syntax"
174174
<> long "extra-package-db"
175175
<> metavar "DIR"))
@@ -333,7 +333,7 @@ runTestM mode m =
333333
testMtimeChangeDelay = Nothing,
334334
testScriptEnv = senv,
335335
testSetupPath = dist_dir </> "build" </> "setup" </> "setup",
336-
testPackageDbPath = testArgPackageDb args,
336+
testPackageDbPath = case testArgPackageDb args of [] -> Nothing; xs -> Just xs,
337337
testSkipSetupTests = argSkipSetupTests (testCommonArgs args),
338338
testHaveCabalShared = runnerWithSharedLib senv,
339339
testEnvironment =
@@ -649,8 +649,8 @@ data TestEnv = TestEnv
649649
-- | Setup script path
650650
, testSetupPath :: FilePath
651651
-- | Setup package-db path which contains Cabal and Cabal-syntax for cabal-install to
652-
-- use when compiling custom setups.
653-
, testPackageDbPath :: Maybe FilePath
652+
-- use when compiling custom setups, plus the store with possible dependencies of those setup packages.
653+
, testPackageDbPath :: Maybe [FilePath]
654654
-- | Skip Setup tests?
655655
, testSkipSetupTests :: Bool
656656
-- | Do we have shared libraries for the Cabal-under-tests?

cabal-testsuite/src/Test/Cabal/Prelude.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ cabalGArgs global_args cmd args input = do
324324
= [ "--builddir", testDistDir env
325325
, "-j1" ]
326326
++ [ "--project-file=" ++ fp | Just fp <- [testCabalProjectFile env] ]
327-
++ ["--package-db=" ++ db | Just db <- [testPackageDbPath env]]
327+
++ ["--package-db=" ++ db | Just dbs <- [testPackageDbPath env], db <- dbs]
328328

329329
| otherwise
330330
= [ "--builddir", testDistDir env ] ++
@@ -871,7 +871,7 @@ allCabalVersion = isCabalVersion all
871871
isCabalVersion :: WithCallStack (((Version -> Bool) -> [Version] -> Bool) -> String -> TestM Bool)
872872
isCabalVersion decide range = do
873873
env <- getTestEnv
874-
cabal_pkgs <- ghcPkg_raw' $ ["--global", "list", "Cabal", "--simple"] ++ ["--package-db=" ++ db | Just db <- [testPackageDbPath env]]
874+
cabal_pkgs <- ghcPkg_raw' $ ["--global", "list", "Cabal", "--simple"] ++ ["--package-db=" ++ db | Just dbs <- [testPackageDbPath env], db <- dbs]
875875
let pkg_versions :: [PackageIdentifier] = mapMaybe simpleParsec (words (resultOutput cabal_pkgs))
876876
vr <- case eitherParsec range of
877877
Left err -> fail err

0 commit comments

Comments
 (0)