Commit 5520bea7 authored by Duncan Coutts's avatar Duncan Coutts Committed by GitHub
Browse files

Merge pull request #3509 from dcoutts/issue-3460

Fix issue 3460: avoid concurrent package db creation
parents 108d15ac 5adaf585
......@@ -575,7 +575,10 @@ rebuildTargets :: Verbosity
rebuildTargets verbosity
distDirLayout@DistDirLayout{..}
installPlan
sharedPackageConfig
sharedPackageConfig@ElaboratedSharedConfig {
pkgConfigCompiler = compiler,
pkgConfigCompilerProgs = progdb
}
pkgsBuildStatus
buildSettings@BuildTimeSettings{
buildSettingNumJobs,
......@@ -593,6 +596,7 @@ rebuildTargets verbosity
createDirectoryIfMissingVerbose verbosity False distBuildRootDirectory
createDirectoryIfMissingVerbose verbosity False distTempDirectory
mapM_ (createPackageDBIfMissing verbosity compiler progdb) packageDBsToUse
-- Before traversing the install plan, pre-emptively find all packages that
-- will need to be downloaded and start downloading them.
......@@ -619,6 +623,14 @@ rebuildTargets verbosity
keepGoing = buildSettingKeepGoing
withRepoCtx = projectConfigWithBuilderRepoContext verbosity
buildSettings
packageDBsToUse = -- all the package dbs we may need to create
(Set.toList . Set.fromList)
[ pkgdb
| InstallPlan.Configured pkg <- InstallPlan.toList installPlan
, (pkgdb:_) <- map reverse [ pkgBuildPackageDBStack pkg,
pkgRegisterPackageDBStack pkg,
pkgSetupPackageDBStack pkg ]
]
-- | Given all the context and resources, (re)build an individual package.
--
......@@ -1160,7 +1172,6 @@ buildInplaceUnpackedPackage verbosity
-- builddir is not enough, we also need the per-package cachedir
createDirectoryIfMissingVerbose verbosity False builddir
createDirectoryIfMissingVerbose verbosity False (distPackageCacheDirectory pkgid)
createPackageDBIfMissing verbosity compiler progdb (pkgBuildPackageDBStack pkg)
-- Configure phase
--
......
......@@ -638,8 +638,7 @@ getPackageDBContents verbosity compiler progdb platform packagedb = do
verbosity compiler
[packagedb] progdb platform)
liftIO $ do
createPackageDBIfMissing verbosity compiler
progdb [packagedb]
createPackageDBIfMissing verbosity compiler progdb packagedb
Cabal.getPackageDBContents verbosity compiler
packagedb progdb
......@@ -657,16 +656,19 @@ getSourcePackages verbosity withRepoCtx = do
$ repos
return sourcePkgDb
-- | Create a package DB if it does not currently exist. Note that this action
-- is /not/ safe to run concurrently.
--
createPackageDBIfMissing :: Verbosity -> Compiler -> ProgramDb
-> PackageDBStack -> IO ()
createPackageDBIfMissing verbosity compiler progdb packageDbs =
case reverse packageDbs of
SpecificPackageDB dbPath : _ -> do
exists <- liftIO $ Cabal.doesPackageDBExist dbPath
unless exists $ do
createDirectoryIfMissingVerbose verbosity False (takeDirectory dbPath)
Cabal.createPackageDB verbosity compiler progdb False dbPath
_ -> return ()
-> PackageDB -> IO ()
createPackageDBIfMissing verbosity compiler progdb
(SpecificPackageDB dbPath) = do
exists <- liftIO $ Cabal.doesPackageDBExist dbPath
unless exists $ do
createDirectoryIfMissingVerbose verbosity False (takeDirectory dbPath)
Cabal.createPackageDB verbosity compiler progdb False dbPath
createPackageDBIfMissing _ _ _ _ = return ()
getPkgConfigDb :: Verbosity -> ProgramDb -> Rebuild PkgConfigDb
......
......@@ -77,6 +77,17 @@ Extra-Source-Files:
tests/IntegrationTests/multiple-source/p/p.cabal
tests/IntegrationTests/multiple-source/q/Setup.hs
tests/IntegrationTests/multiple-source/q/q.cabal
tests/IntegrationTests/new-build/T3460.sh
tests/IntegrationTests/new-build/T3460/C.hs
tests/IntegrationTests/new-build/T3460/Setup.hs
tests/IntegrationTests/new-build/T3460/T3460.cabal
tests/IntegrationTests/new-build/T3460/cabal.project
tests/IntegrationTests/new-build/T3460/sub-package-A/A.hs
tests/IntegrationTests/new-build/T3460/sub-package-A/Setup.hs
tests/IntegrationTests/new-build/T3460/sub-package-A/sub-package-A.cabal
tests/IntegrationTests/new-build/T3460/sub-package-B/B.hs
tests/IntegrationTests/new-build/T3460/sub-package-B/Setup.hs
tests/IntegrationTests/new-build/T3460/sub-package-B/sub-package-B.cabal
tests/IntegrationTests/new-build/monitor_cabal_files.sh
tests/IntegrationTests/new-build/monitor_cabal_files/cabal.project
tests/IntegrationTests/new-build/monitor_cabal_files/p/P.hs
......
. ./common.sh
cd T3460
cabal new-build -j T3460
import Distribution.Simple
main = defaultMain
-- Initial T3460.cabal generated by cabal init. For further documentation,
-- see http://haskell.org/cabal/users-guide/
name: T3460
version: 0.1.0.0
-- synopsis:
-- description:
license: BSD3
author: Edward Z. Yang
maintainer: ezyang@cs.stanford.edu
-- copyright:
-- category:
build-type: Simple
cabal-version: >=1.10
library
exposed-modules: C
-- other-modules:
-- other-extensions:
build-depends: base, sub-package-A, sub-package-B
-- hs-source-dirs:
default-language: Haskell2010
packages: ./T3460.cabal
, ./sub-package-A
, ./sub-package-B
-- Initial sub-package-A.cabal generated by cabal init. For further
-- documentation, see http://haskell.org/cabal/users-guide/
name: sub-package-A
version: 0.1.0.0
-- synopsis:
-- description:
license: BSD3
author: Edward Z. Yang
maintainer: ezyang@cs.stanford.edu
-- copyright:
-- category:
build-type: Simple
cabal-version: >=1.10
library
exposed-modules: A
-- other-modules:
-- other-extensions:
build-depends: base
-- hs-source-dirs:
default-language: Haskell2010
-- Initial sub-package-B.cabal generated by cabal init. For further
-- documentation, see http://haskell.org/cabal/users-guide/
name: sub-package-B
version: 0.1.0.0
-- synopsis:
-- description:
license: BSD3
author: Edward Z. Yang
maintainer: ezyang@cs.stanford.edu
-- copyright:
-- category:
build-type: Simple
cabal-version: >=1.10
library
exposed-modules: B
-- other-modules:
-- other-extensions:
build-depends: base
-- hs-source-dirs:
default-language: Haskell2010
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment