Skip to content

Commit 1c1472c

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 1c1472c

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

BuildClient.hs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ import Data.List
2020
import Data.Maybe
2121
import Data.IORef
2222
import Data.Time
23+
import Control.Applicative ((<$>), (<*>))
2324
import Control.Exception
2425
import Control.Monad
2526
import Control.Monad.Trans
2627
import qualified Data.ByteString.Lazy as BS
2728
import qualified Data.Map as M
29+
import qualified Data.Set as S
2830

2931
import qualified Codec.Compression.GZip as GZip
3032
import qualified Codec.Archive.Tar as Tar
@@ -137,6 +139,23 @@ initialise opts uri auxUris
137139
where
138140
readMissingOpt prompt = maybe (putStrLn prompt >> getLine) return
139141

142+
143+
-- | Parse the @00-index.cache@ file of the available package repositories.
144+
parseRepositoryIndices :: IO (S.Set PackageIdentifier)
145+
parseRepositoryIndices = do
146+
cabalDir <- getAppUserDataDirectory "cabal/packages"
147+
cacheDirs <- listDirectory cabalDir
148+
indexFiles <- filterM doesFileExist $ map (\dir -> cabalDir </> dir </> "00-index.cache") cacheDirs
149+
S.unions <$> mapM readCache indexFiles
150+
where
151+
readCache fname =
152+
S.fromList . mapMaybe parseLine . lines <$> readFile fname
153+
parseLine line
154+
| "pkg:" : name : ver : _ <- words line
155+
= PackageIdentifier <$> simpleParse name <*> simpleParse ver
156+
| otherwise
157+
= Nothing
158+
140159
writeConfig :: BuildOpts -> BuildConfig -> IO ()
141160
writeConfig opts BuildConfig {
142161
bc_srcURI = uri,
@@ -391,6 +410,11 @@ getDocumentationStats verbosity config didFail = do
391410
buildOnce :: BuildOpts -> [PackageId] -> IO ()
392411
buildOnce opts pkgs = keepGoing $ do
393412
config <- readConfig opts
413+
-- Due to caching sometimes the package repository state may lag behind the
414+
-- documentation index. Consequently, we make sure that the packages we are
415+
-- going to build actually appear in the repository before building. See
416+
-- #543.
417+
repoIndex <- parseRepositoryIndices
394418

395419
notice verbosity "Initialising"
396420
(has_failed, mark_as_failed, persist_failed) <- mkPackageFailed opts
@@ -409,6 +433,7 @@ buildOnce opts pkgs = keepGoing $ do
409433
-- Find those files *not* marked as having documentation in our cache
410434
let toBuild :: [DocInfo]
411435
toBuild = filter shouldBuild
436+
. filter (flip S.member repoIndex . docInfoPackage)
412437
. latestFirst
413438
. map (sortBy (flip (comparing docInfoPackageVersion)))
414439
. 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)