diff --git a/Cabal/Distribution/Simple/Build.hs b/Cabal/Distribution/Simple/Build.hs index 44477792071..4afe06f07f7 100644 --- a/Cabal/Distribution/Simple/Build.hs +++ b/Cabal/Distribution/Simple/Build.hs @@ -33,6 +33,7 @@ import qualified Distribution.Simple.HaskellSuite as HaskellSuite import qualified Distribution.Simple.Build.Macros as Build.Macros import qualified Distribution.Simple.Build.PathsModule as Build.PathsModule +import qualified Distribution.Simple.Program.HcPkg as HcPkg import Distribution.Simple.Compiler hiding (Flag) import Distribution.PackageDescription hiding (Flag) @@ -187,7 +188,7 @@ buildComponent verbosity numJobs pkg_descr lbi suffixes installedPkgInfo = inplaceInstalledPackageInfo pwd distPref pkg_descr (AbiHash "") lib' lbi clbi - registerPackage verbosity (compiler lbi) (withPrograms lbi) True + registerPackage verbosity (compiler lbi) (withPrograms lbi) HcPkg.MultiInstance (withPackageDB lbi) installedPkgInfo buildComponent verbosity numJobs pkg_descr lbi suffixes @@ -231,7 +232,7 @@ buildComponent verbosity numJobs pkg_descr lbi0 suffixes -- NB: need to enable multiple instances here, because on 7.10+ -- the package name is the same as the library, and we still -- want the registration to go through. - registerPackage verbosity (compiler lbi) (withPrograms lbi) True + registerPackage verbosity (compiler lbi) (withPrograms lbi) HcPkg.MultiInstance (withPackageDB lbi) ipi let ebi = buildInfo exe exe' = exe { buildInfo = addExtraCSources ebi extras } diff --git a/Cabal/Distribution/Simple/GHC.hs b/Cabal/Distribution/Simple/GHC.hs index 14a23fa23b7..0cfd04b2b3b 100644 --- a/Cabal/Distribution/Simple/GHC.hs +++ b/Cabal/Distribution/Simple/GHC.hs @@ -1204,12 +1204,12 @@ hcPkgInfo conf = HcPkg.HcPkgInfo { HcPkg.hcPkgProgram = ghcPkgProg registerPackage :: Verbosity -> ProgramConfiguration - -> Bool + -> HcPkg.MultiInstance -> PackageDBStack -> InstalledPackageInfo -> IO () registerPackage verbosity progdb multiInstance packageDbs installedPkgInfo - | multiInstance + | HcPkg.MultiInstance <- multiInstance = HcPkg.registerMultiInstance (hcPkgInfo progdb) verbosity packageDbs installedPkgInfo diff --git a/Cabal/Distribution/Simple/GHCJS.hs b/Cabal/Distribution/Simple/GHCJS.hs index da7a5fcbdf9..e657b928025 100644 --- a/Cabal/Distribution/Simple/GHCJS.hs +++ b/Cabal/Distribution/Simple/GHCJS.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE PatternGuards #-} module Distribution.Simple.GHCJS ( configure, getInstalledPackages, getPackageDBContents, buildLib, buildExe, @@ -795,12 +796,12 @@ adjustExts hiSuf objSuf opts = registerPackage :: Verbosity -> ProgramConfiguration - -> Bool + -> HcPkg.MultiInstance -> PackageDBStack -> InstalledPackageInfo -> IO () registerPackage verbosity progdb multiInstance packageDbs installedPkgInfo - | multiInstance + | HcPkg.MultiInstance <- multiInstance = HcPkg.registerMultiInstance (hcPkgInfo progdb) verbosity packageDbs installedPkgInfo diff --git a/Cabal/Distribution/Simple/Program/HcPkg.hs b/Cabal/Distribution/Simple/Program/HcPkg.hs index 1d3ee95af89..34c07c1bf8a 100644 --- a/Cabal/Distribution/Simple/Program/HcPkg.hs +++ b/Cabal/Distribution/Simple/Program/HcPkg.hs @@ -11,6 +11,7 @@ module Distribution.Simple.Program.HcPkg ( HcPkgInfo(..), + MultiInstance(..), init, invoke, @@ -74,6 +75,10 @@ data HcPkgInfo = HcPkgInfo , recacheMultiInstance :: Bool -- ^ supports multi-instance via recache } +-- | Whether or not use multi-instance functionality. +data MultiInstance = MultiInstance | NoMultiInstance + deriving (Show, Read, Eq, Ord) + -- | Call @hc-pkg@ to initialise a package database at the location {path}. -- -- > hc-pkg init {path} @@ -353,11 +358,11 @@ registerInvocation, reregisterInvocation, registerMultiInstanceInvocation :: HcPkgInfo -> Verbosity -> PackageDBStack -> Either FilePath InstalledPackageInfo -> ProgramInvocation -registerInvocation = registerInvocation' "register" False -reregisterInvocation = registerInvocation' "update" False -registerMultiInstanceInvocation = registerInvocation' "update" True +registerInvocation = registerInvocation' "register" NoMultiInstance +reregisterInvocation = registerInvocation' "update" NoMultiInstance +registerMultiInstanceInvocation = registerInvocation' "update" MultiInstance -registerInvocation' :: String -> Bool +registerInvocation' :: String -> MultiInstance -> HcPkgInfo -> Verbosity -> PackageDBStack -> Either FilePath InstalledPackageInfo -> ProgramInvocation @@ -377,7 +382,7 @@ registerInvocation' cmdname multiInstance hpi ++ (if noPkgDbStack hpi then [packageDbOpts hpi (last packagedbs)] else packageDbStackOpts hpi packagedbs) - ++ [ "--enable-multi-instance" | multiInstance ] + ++ [ "--enable-multi-instance" | multiInstance == MultiInstance ] ++ verbosityOpts hpi verbosity unregisterInvocation :: HcPkgInfo -> Verbosity -> PackageDB -> PackageId diff --git a/Cabal/Distribution/Simple/Register.hs b/Cabal/Distribution/Simple/Register.hs index 0f54f517752..d9372e48170 100644 --- a/Cabal/Distribution/Simple/Register.hs +++ b/Cabal/Distribution/Simple/Register.hs @@ -114,7 +114,7 @@ registerOne pkg lbi regFlags lib | modeGenerateRegScript -> writeRegisterScript installedPkgInfo | otherwise -> do setupMessage verbosity "Registering" (packageId pkg) - registerPackage verbosity (compiler lbi) (withPrograms lbi) False + registerPackage verbosity (compiler lbi) (withPrograms lbi) HcPkg.NoMultiInstance packageDbs installedPkgInfo where @@ -257,7 +257,7 @@ withHcPkg name comp conf f = registerPackage :: Verbosity -> Compiler -> ProgramConfiguration - -> Bool + -> HcPkg.MultiInstance -> PackageDBStack -> InstalledPackageInfo -> IO () @@ -265,7 +265,7 @@ registerPackage verbosity comp progdb multiInstance packageDbs installedPkgInfo case compilerFlavor comp of GHC -> GHC.registerPackage verbosity progdb multiInstance packageDbs installedPkgInfo GHCJS -> GHCJS.registerPackage verbosity progdb multiInstance packageDbs installedPkgInfo - _ | multiInstance + _ | HcPkg.MultiInstance == multiInstance -> die "Registering multiple package instances is not yet supported for this compiler" LHC -> LHC.registerPackage verbosity progdb packageDbs installedPkgInfo UHC -> UHC.registerPackage verbosity comp progdb packageDbs installedPkgInfo diff --git a/cabal-install/Distribution/Client/ProjectBuilding.hs b/cabal-install/Distribution/Client/ProjectBuilding.hs index 8a70195733a..d38d633fdc4 100644 --- a/cabal-install/Distribution/Client/ProjectBuilding.hs +++ b/cabal-install/Distribution/Client/ProjectBuilding.hs @@ -47,6 +47,7 @@ import Distribution.Simple.Command (CommandUI) import qualified Distribution.Simple.Register as Cabal import qualified Distribution.Simple.InstallDirs as InstallDirs import Distribution.Simple.LocalBuildInfo (ComponentName) +import qualified Distribution.Simple.Program.HcPkg as HcPkg import Distribution.Simple.Utils hiding (matchFileGlob) import Distribution.Version @@ -1016,7 +1017,7 @@ buildAndInstallUnpackedPackage verbosity -- the installed package id is, not the build system. let ipkg' = ipkg { Installed.installedUnitId = ipkgid } Cabal.registerPackage verbosity compiler progdb - True -- multi-instance, nix style + HcPkg.MultiInstance (pkgRegisterPackageDBStack pkg) ipkg' return (Just ipkg') else return Nothing @@ -1152,7 +1153,7 @@ buildInplaceUnpackedPackage verbosity -- grab and modify the InstalledPackageInfo. We decide what -- the installed package id is, not the build system. let ipkg' = ipkg { Installed.installedUnitId = ipkgid } - Cabal.registerPackage verbosity compiler progdb False + Cabal.registerPackage verbosity compiler progdb HcPkg.NoMultiInstance (pkgRegisterPackageDBStack pkg) ipkg' return (Just ipkg')