Skip to content

Commit bdd72fa

Browse files
committed
BuildClient: Ensure that packages we build are in package repository
Due to caching sometimes the package repository state may lag behind the documentation index. Consequently, we make sure that the packages we are going to build actually appear in the repository before building. See Issue #543.
1 parent 7cbb8d8 commit bdd72fa

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

BuildClient.hs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import Control.Monad
2525
import Control.Monad.Trans
2626
import qualified Data.ByteString.Lazy as BS
2727
import qualified Data.Map as M
28+
import qualified Data.Set as S
2829

2930
import qualified Codec.Compression.GZip as GZip
3031
import qualified Codec.Archive.Tar as Tar
@@ -137,6 +138,23 @@ initialise opts uri auxUris
137138
where
138139
readMissingOpt prompt = maybe (putStrLn prompt >> getLine) return
139140

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+
140158
writeConfig :: BuildOpts -> BuildConfig -> IO ()
141159
writeConfig opts BuildConfig {
142160
bc_srcURI = uri,
@@ -391,6 +409,11 @@ getDocumentationStats verbosity config didFail = do
391409
buildOnce :: BuildOpts -> [PackageId] -> IO ()
392410
buildOnce opts pkgs = keepGoing $ do
393411
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
394417

395418
notice verbosity "Initialising"
396419
(has_failed, mark_as_failed, persist_failed) <- mkPackageFailed opts
@@ -409,6 +432,7 @@ buildOnce opts pkgs = keepGoing $ do
409432
-- Find those files *not* marked as having documentation in our cache
410433
let toBuild :: [DocInfo]
411434
toBuild = filter shouldBuild
435+
. filter (flip S.member repoIndex . docInfoPackage)
412436
. latestFirst
413437
. map (sortBy (flip (comparing docInfoPackageVersion)))
414438
. groupBy (equating docInfoPackageName)

hackage-server.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ executable hackage-build
431431
build-depends:
432432
base,
433433
containers, array, vector, bytestring, text, pretty,
434-
filepath, directory, process >= 1.0,
434+
filepath, directory >= 1.2.5, process >= 1.0,
435435
time,
436436
time-locale-compat >= 0.1.0.1,
437437
tar, zlib,

0 commit comments

Comments
 (0)