@@ -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 ]
129129buildCabalLibsProject 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 ]
151160buildCabalLibsSpecific 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 ]
170179buildCabalLibsIntree 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
0 commit comments