Commit 40d6f0af authored by Edward Z. Yang's avatar Edward Z. Yang
Browse files

Use ADT for MultiInstance boolean argument.


Signed-off-by: default avatarEdward Z. Yang <ezyang@cs.stanford.edu>
parent af7bb537
......@@ -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 }
......
......@@ -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
......
{-# 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
......
......@@ -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
......
......@@ -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
......
......@@ -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')
......
Markdown is supported
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