Skip to content

Commit

Permalink
Use ADT for MultiInstance boolean argument.
Browse files Browse the repository at this point in the history
Signed-off-by: Edward Z. Yang <[email protected]>
  • Loading branch information
ezyang committed Mar 29, 2016
1 parent af7bb53 commit 40d6f0a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
5 changes: 3 additions & 2 deletions Cabal/Distribution/Simple/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 }
Expand Down
4 changes: 2 additions & 2 deletions Cabal/Distribution/Simple/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions Cabal/Distribution/Simple/GHCJS.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE PatternGuards #-}
module Distribution.Simple.GHCJS (
configure, getInstalledPackages, getPackageDBContents,
buildLib, buildExe,
Expand Down Expand Up @@ -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

Expand Down
15 changes: 10 additions & 5 deletions Cabal/Distribution/Simple/Program/HcPkg.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

module Distribution.Simple.Program.HcPkg (
HcPkgInfo(..),
MultiInstance(..),

init,
invoke,
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions Cabal/Distribution/Simple/Register.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -257,15 +257,15 @@ withHcPkg name comp conf f =
registerPackage :: Verbosity
-> Compiler
-> ProgramConfiguration
-> Bool
-> HcPkg.MultiInstance
-> PackageDBStack
-> InstalledPackageInfo
-> IO ()
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
Expand Down
5 changes: 3 additions & 2 deletions cabal-install/Distribution/Client/ProjectBuilding.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 40d6f0a

Please sign in to comment.