@@ -25,6 +25,7 @@ import Control.Monad
25
25
import Control.Monad.Trans
26
26
import qualified Data.ByteString.Lazy as BS
27
27
import qualified Data.Map as M
28
+ import qualified Data.Set as S
28
29
29
30
import qualified Codec.Compression.GZip as GZip
30
31
import qualified Codec.Archive.Tar as Tar
@@ -137,6 +138,23 @@ initialise opts uri auxUris
137
138
where
138
139
readMissingOpt prompt = maybe (putStrLn prompt >> getLine ) return
139
140
141
+
142
+ -- | Parse the @00-index.cache@ file of the available package repositories.
143
+ parseRepositoryIndices :: IO (S. Set PackageIdentifier )
144
+ parseRepositoryIndices = do
145
+ cabalDir <- getAppUserDataDirectory " cabal/packages"
146
+ cacheDirs <- listDirectory cabalDir
147
+ indexFiles <- filterM doesFileExist $ map (\ dir -> cabalDir </> dir </> " 00-index.cache" ) cacheDirs
148
+ S. unions <$> mapM readCache indexFiles
149
+ where
150
+ readCache fname =
151
+ S. fromList . mapMaybe parseLine . lines <$> readFile fname
152
+ parseLine line
153
+ | " pkg:" : name : ver : _ <- words line
154
+ = PackageIdentifier <$> simpleParse name <*> simpleParse ver
155
+ | otherwise
156
+ = Nothing
157
+
140
158
writeConfig :: BuildOpts -> BuildConfig -> IO ()
141
159
writeConfig opts BuildConfig {
142
160
bc_srcURI = uri,
@@ -391,6 +409,11 @@ getDocumentationStats verbosity config didFail = do
391
409
buildOnce :: BuildOpts -> [PackageId ] -> IO ()
392
410
buildOnce opts pkgs = keepGoing $ do
393
411
config <- readConfig opts
412
+ -- Due to caching sometimes the package repository state may lag behind the
413
+ -- documentation index. Consequently, we make sure that the packages we are
414
+ -- going to build actually appear in the repository before building. See
415
+ -- #543.
416
+ repoIndex <- parseRepositoryIndices
394
417
395
418
notice verbosity " Initialising"
396
419
(has_failed, mark_as_failed, persist_failed) <- mkPackageFailed opts
@@ -409,6 +432,7 @@ buildOnce opts pkgs = keepGoing $ do
409
432
-- Find those files *not* marked as having documentation in our cache
410
433
let toBuild :: [DocInfo ]
411
434
toBuild = filter shouldBuild
435
+ . filter (flip S. member repoIndex . docInfoPackage)
412
436
. latestFirst
413
437
. map (sortBy (flip (comparing docInfoPackageVersion)))
414
438
. groupBy (equating docInfoPackageName)
0 commit comments