Register.hs 19.4 KB
Newer Older
1 2
-----------------------------------------------------------------------------
-- |
ijones's avatar
ijones committed
3
-- Module      :  Distribution.Simple.Register
4
-- Copyright   :  Isaac Jones 2003-2004
5
-- License     :  BSD3
6
--
Duncan Coutts's avatar
Duncan Coutts committed
7
-- Maintainer  :  cabal-devel@haskell.org
ijones's avatar
ijones committed
8
-- Portability :  portable
9
--
Duncan Coutts's avatar
Duncan Coutts committed
10 11 12 13 14 15 16 17
-- This module deals with registering and unregistering packages. There are a
-- couple ways it can do this, one is to do it directly. Another is to generate
-- a script that can be run later to do it. The idea here being that the user
-- is shielded from the details of what command to use for package registration
-- for a particular compiler. In practice this aspect was not especially
-- popular so we also provide a way to simply generate the package registration
-- file which then must be manually passed to @ghc-pkg@. It is possible to
-- generate registration information for where the package is to be installed,
Ian D. Bollinger's avatar
Ian D. Bollinger committed
18
-- or alternatively to register the package in place in the build tree. The
Duncan Coutts's avatar
Duncan Coutts committed
19 20 21 22 23 24
-- latter is occasionally handy, and will become more important when we try to
-- build multi-package systems.
--
-- This module does not delegate anything to the per-compiler modules but just
-- mixes it all in in this module, which is rather unsatisfactory. The script
-- generation and the unregister feature are not well used or tested.
25

26
module Distribution.Simple.Register (
Duncan Coutts's avatar
Duncan Coutts committed
27 28 29
    register,
    unregister,

30
    initPackageDB,
refold's avatar
refold committed
31
    invokeHcPkg,
Duncan Coutts's avatar
Duncan Coutts committed
32
    registerPackage,
33
    generateRegistrationInfo,
Duncan Coutts's avatar
Duncan Coutts committed
34 35 36
    inplaceInstalledPackageInfo,
    absoluteInstalledPackageInfo,
    generalInstalledPackageInfo,
37
  ) where
38

39 40
import Distribution.Simple.LocalBuildInfo
         ( LocalBuildInfo(..), ComponentLocalBuildInfo(..)
41
         , ComponentName(..), getComponentLocalBuildInfo
42
         , InstallDirs(..), absoluteInstallDirs )
43
import Distribution.Simple.BuildPaths (haddockName)
44 45 46 47 48

import qualified Distribution.Simple.GHC   as GHC
import qualified Distribution.Simple.GHCJS as GHCJS
import qualified Distribution.Simple.LHC   as LHC
import qualified Distribution.Simple.UHC   as UHC
49
import qualified Distribution.Simple.HaskellSuite as HaskellSuite
50

51
import Distribution.Simple.Compiler
52
         ( Compiler, CompilerFlavor(..), compilerFlavor, compilerVersion
53 54
         , PackageDB, PackageDBStack, absolutePackageDBPaths
         , registrationPackageDB )
Duncan Coutts's avatar
Duncan Coutts committed
55
import Distribution.Simple.Program
56
         ( ProgramConfiguration, runProgramInvocation )
Duncan Coutts's avatar
Duncan Coutts committed
57 58
import Distribution.Simple.Program.Script
         ( invocationAsSystemScript )
59
import           Distribution.Simple.Program.HcPkg (HcPkgInfo)
Duncan Coutts's avatar
Duncan Coutts committed
60
import qualified Distribution.Simple.Program.HcPkg as HcPkg
61 62 63
import Distribution.Simple.Setup
         ( RegisterFlags(..), CopyDest(..)
         , fromFlag, fromFlagOrDefault, flagToMaybe )
Duncan Coutts's avatar
Duncan Coutts committed
64
import Distribution.PackageDescription
65
         ( PackageDescription(..), Library(..), BuildInfo(..), libModules )
66
import Distribution.Package
67
         ( Package(..), packageName
68
         , getHSLibraryName )
69
import Distribution.InstalledPackageInfo
70
         ( InstalledPackageInfo, InstalledPackageInfo(InstalledPackageInfo)
71
         , showInstalledPackageInfo, AbiHash(..) )
72
import qualified Distribution.InstalledPackageInfo as IPI
73
import Distribution.Simple.Utils
74
         ( writeUTF8File, writeFileAtomic, setFileExecutable
75
         , die, notice, setupMessage, shortRelativePath )
76
import Distribution.System
77
         ( OS(..), buildOS )
78 79
import Distribution.Text
         ( display )
Duncan Coutts's avatar
Duncan Coutts committed
80 81
import Distribution.Verbosity as Verbosity
         ( Verbosity, normal )
82

83
import System.FilePath ((</>), (<.>), isAbsolute)
Duncan Coutts's avatar
Duncan Coutts committed
84
import System.Directory
85
         ( getCurrentDirectory )
ijones's avatar
ijones committed
86

87
import Data.Version
88
import Control.Monad (when)
Duncan Coutts's avatar
Duncan Coutts committed
89
import Data.Maybe
90
         ( isJust, fromMaybe, maybeToList )
Duncan Coutts's avatar
Duncan Coutts committed
91 92
import Data.List
         ( partition, nub )
93
import qualified Data.ByteString.Lazy.Char8 as BS.Char8
94

simonmar's avatar
simonmar committed
95 96 97
-- -----------------------------------------------------------------------------
-- Registration

ijones's avatar
ijones committed
98
register :: PackageDescription -> LocalBuildInfo
ijones's avatar
ijones committed
99
         -> RegisterFlags -- ^Install in the user's database?; verbose
ijones's avatar
ijones committed
100
         -> IO ()
101
register pkg@PackageDescription { library       = Just lib  } lbi regFlags
102
  = do
103
    let clbi = getComponentLocalBuildInfo lbi CLibName
104

105
    absPackageDBs    <- absolutePackageDBPaths packageDbs
106
    installedPkgInfo <- generateRegistrationInfo
107
                           verbosity pkg lib lbi clbi inplace reloc distPref
108
                           (registrationPackageDB absPackageDBs)
109

110
    when (fromFlag (regPrintId regFlags)) $ do
111
      putStrLn (display (IPI.installedComponentId installedPkgInfo))
112

113 114 115 116
     -- Three different modes:
    case () of
     _ | modeGenerateRegFile   -> writeRegistrationFile installedPkgInfo
       | modeGenerateRegScript -> writeRegisterScript   installedPkgInfo
117 118
       | otherwise             -> do
           setupMessage verbosity "Registering" (packageId pkg)
119 120
           registerPackage verbosity (compiler lbi) (withPrograms lbi)
                           packageDbs installedPkgInfo
Duncan Coutts's avatar
Duncan Coutts committed
121 122 123 124 125 126 127 128 129

  where
    modeGenerateRegFile = isJust (flagToMaybe (regGenPkgConf regFlags))
    regFile             = fromMaybe (display (packageId pkg) <.> "conf")
                                    (fromFlag (regGenPkgConf regFlags))

    modeGenerateRegScript = fromFlag (regGenScript regFlags)

    inplace   = fromFlag (regInPlace regFlags)
130
    reloc     = relocatable lbi
Duncan Coutts's avatar
Duncan Coutts committed
131 132 133 134 135
    -- FIXME: there's really no guarantee this will work.
    -- registering into a totally different db stack can
    -- fail if dependencies cannot be satisfied.
    packageDbs = nub $ withPackageDB lbi
                    ++ maybeToList (flagToMaybe  (regPackageDB regFlags))
Duncan Coutts's avatar
Duncan Coutts committed
136 137 138
    distPref  = fromFlag (regDistPref regFlags)
    verbosity = fromFlag (regVerbosity regFlags)

139
    writeRegistrationFile installedPkgInfo = do
Duncan Coutts's avatar
Duncan Coutts committed
140
      notice verbosity ("Creating package registration file: " ++ regFile)
141
      writeUTF8File regFile (showInstalledPackageInfo installedPkgInfo)
Duncan Coutts's avatar
Duncan Coutts committed
142

143
    writeRegisterScript installedPkgInfo =
Duncan Coutts's avatar
Duncan Coutts committed
144
      case compilerFlavor (compiler lbi) of
145 146 147 148 149 150
        JHC -> notice verbosity "Registration scripts not needed for jhc"
        UHC -> notice verbosity "Registration scripts not needed for uhc"
        _   -> withHcPkg
               "Registration scripts are not implemented for this compiler"
               (compiler lbi) (withPrograms lbi)
               (writeHcPkgRegisterScript verbosity installedPkgInfo packageDbs)
Duncan Coutts's avatar
Duncan Coutts committed
151 152 153 154 155 156

register _ _ regFlags = notice verbosity "No package to register"
  where
    verbosity = fromFlag (regVerbosity regFlags)


157 158
generateRegistrationInfo :: Verbosity
                         -> PackageDescription
Duncan Coutts's avatar
Duncan Coutts committed
159 160 161 162
                         -> Library
                         -> LocalBuildInfo
                         -> ComponentLocalBuildInfo
                         -> Bool
163
                         -> Bool
Duncan Coutts's avatar
Duncan Coutts committed
164
                         -> FilePath
165
                         -> PackageDB
Duncan Coutts's avatar
Duncan Coutts committed
166
                         -> IO InstalledPackageInfo
167
generateRegistrationInfo verbosity pkg lib lbi clbi inplace reloc distPref packageDb = do
Duncan Coutts's avatar
Duncan Coutts committed
168 169
  --TODO: eliminate pwd!
  pwd <- getCurrentDirectory
170

171
  --TODO: the method of setting the ComponentId is compiler specific
172
  --      this aspect should be delegated to a per-compiler helper.
173
  let comp = compiler lbi
174
  abi_hash <-
175 176
    case compilerFlavor comp of
     GHC | compilerVersion comp >= Version [6,11] [] -> do
177
            fmap AbiHash $ GHC.libAbiHash verbosity pkg lbi lib clbi
178
     GHCJS -> do
179 180
            fmap AbiHash $ GHCJS.libAbiHash verbosity pkg lbi lib clbi
     _ -> return (AbiHash "")
181

Christiaan Baaij's avatar
Christiaan Baaij committed
182 183 184
  installedPkgInfo <-
    if inplace
      then return (inplaceInstalledPackageInfo pwd distPref
185
                     pkg abi_hash lib lbi clbi)
Christiaan Baaij's avatar
Christiaan Baaij committed
186 187
    else if reloc
      then relocRegistrationInfo verbosity
188
                     pkg lib lbi clbi abi_hash packageDb
Christiaan Baaij's avatar
Christiaan Baaij committed
189
      else return (absoluteInstalledPackageInfo
190
                     pkg abi_hash lib lbi clbi)
191

192

193
  return installedPkgInfo{ IPI.abiHash = abi_hash }
194

195 196 197 198 199
relocRegistrationInfo :: Verbosity
                      -> PackageDescription
                      -> Library
                      -> LocalBuildInfo
                      -> ComponentLocalBuildInfo
200
                      -> AbiHash
201 202
                      -> PackageDB
                      -> IO InstalledPackageInfo
203
relocRegistrationInfo verbosity pkg lib lbi clbi abi_hash packageDb =
204
  case (compilerFlavor (compiler lbi)) of
205 206
    GHC -> do fs <- GHC.pkgRoot verbosity lbi packageDb
              return (relocatableInstalledPackageInfo
207
                        pkg abi_hash lib lbi clbi fs)
208 209
    _   -> die "Distribution.Simple.Register.relocRegistrationInfo: \
               \not implemented for this compiler"
210

211 212 213 214
initPackageDB :: Verbosity -> Compiler -> ProgramConfiguration -> FilePath -> IO ()
initPackageDB verbosity comp progdb dbPath =
    createPackageDB verbosity comp progdb True dbPath

215
-- | Create an empty package DB at the specified location.
216 217 218 219 220 221 222 223 224 225 226 227
createPackageDB :: Verbosity -> Compiler -> ProgramConfiguration -> Bool
                -> FilePath -> IO ()
createPackageDB verbosity comp progdb preferCompat dbPath =
    case compilerFlavor comp of
      GHC   -> HcPkg.init (GHC.hcPkgInfo   progdb) verbosity preferCompat dbPath
      GHCJS -> HcPkg.init (GHCJS.hcPkgInfo progdb) verbosity False dbPath
      LHC   -> HcPkg.init (LHC.hcPkgInfo   progdb) verbosity False dbPath
      UHC   -> return ()
      HaskellSuite _ -> HaskellSuite.initPackageDB verbosity progdb dbPath
      _              -> die $ "Distribution.Simple.Register.createPackageDB: "
                           ++ "not implemented for this compiler"

refold's avatar
refold committed
228 229 230 231 232 233

-- | Run @hc-pkg@ using a given package DB stack, directly forwarding the
-- provided command-line arguments to it.
invokeHcPkg :: Verbosity -> Compiler -> ProgramConfiguration -> PackageDBStack
                -> [String] -> IO ()
invokeHcPkg verbosity comp conf dbStack extraArgs =
234 235 236 237 238 239 240 241 242 243 244 245
  withHcPkg "invokeHcPkg" comp conf
    (\hpi -> HcPkg.invoke hpi verbosity dbStack extraArgs)

withHcPkg :: String -> Compiler -> ProgramConfiguration
          -> (HcPkgInfo -> IO a) -> IO a
withHcPkg name comp conf f =
  case compilerFlavor comp of
    GHC   -> f (GHC.hcPkgInfo conf)
    GHCJS -> f (GHCJS.hcPkgInfo conf)
    LHC   -> f (LHC.hcPkgInfo conf)
    _     -> die ("Distribution.Simple.Register." ++ name ++ ":\
                  \not implemented for this compiler")
246

Duncan Coutts's avatar
Duncan Coutts committed
247
registerPackage :: Verbosity
248 249
                -> Compiler
                -> ProgramConfiguration
250
                -> PackageDBStack
251
                -> InstalledPackageInfo
Duncan Coutts's avatar
Duncan Coutts committed
252
                -> IO ()
253
registerPackage verbosity comp progdb packageDbs installedPkgInfo = do
254 255 256 257 258
  case compilerFlavor comp of
    GHC   -> GHC.registerPackage   verbosity      progdb packageDbs installedPkgInfo
    GHCJS -> GHCJS.registerPackage verbosity      progdb packageDbs installedPkgInfo
    LHC   -> LHC.registerPackage   verbosity      progdb packageDbs installedPkgInfo
    UHC   -> UHC.registerPackage   verbosity comp progdb packageDbs installedPkgInfo
259
    JHC   -> notice verbosity "Registering for jhc (nothing to do)"
260
    HaskellSuite {} ->
261
      HaskellSuite.registerPackage verbosity      progdb packageDbs installedPkgInfo
Duncan Coutts's avatar
Duncan Coutts committed
262 263 264
    _    -> die "Registering is not implemented for this compiler"

writeHcPkgRegisterScript :: Verbosity
265
                         -> InstalledPackageInfo
266
                         -> PackageDBStack
267
                         -> HcPkgInfo
Duncan Coutts's avatar
Duncan Coutts committed
268
                         -> IO ()
269 270
writeHcPkgRegisterScript verbosity installedPkgInfo packageDbs hpi = do
  let invocation  = HcPkg.reregisterInvocation hpi Verbosity.normal
271
                      packageDbs (Right installedPkgInfo)
272
      regScript   = invocationAsSystemScript buildOS invocation
Duncan Coutts's avatar
Duncan Coutts committed
273 274

  notice verbosity ("Creating package registration script: " ++ regScriptFileName)
275
  writeUTF8File regScriptFileName regScript
Duncan Coutts's avatar
Duncan Coutts committed
276 277 278 279 280 281
  setFileExecutable regScriptFileName

regScriptFileName :: FilePath
regScriptFileName = case buildOS of
                        Windows -> "register.bat"
                        _       -> "register.sh"
simonmar's avatar
simonmar committed
282

283

284 285 286
-- -----------------------------------------------------------------------------
-- Making the InstalledPackageInfo

Duncan Coutts's avatar
Duncan Coutts committed
287 288 289 290 291 292 293
-- | Construct 'InstalledPackageInfo' for a library in a package, given a set
-- of installation directories.
--
generalInstalledPackageInfo
  :: ([FilePath] -> [FilePath]) -- ^ Translate relative include dir paths to
                                -- absolute paths.
  -> PackageDescription
294
  -> AbiHash
Duncan Coutts's avatar
Duncan Coutts committed
295
  -> Library
296
  -> LocalBuildInfo
Duncan Coutts's avatar
Duncan Coutts committed
297 298 299
  -> ComponentLocalBuildInfo
  -> InstallDirs FilePath
  -> InstalledPackageInfo
300
generalInstalledPackageInfo adjustRelIncDirs pkg abi_hash lib lbi clbi installDirs =
Duncan Coutts's avatar
Duncan Coutts committed
301
  InstalledPackageInfo {
302
    IPI.sourcePackageId    = packageId   pkg,
303 304
    IPI.installedComponentId= componentId clbi,
    IPI.compatPackageKey   = componentCompatPackageKey clbi,
Duncan Coutts's avatar
Duncan Coutts committed
305 306 307 308 309 310 311
    IPI.license            = license     pkg,
    IPI.copyright          = copyright   pkg,
    IPI.maintainer         = maintainer  pkg,
    IPI.author             = author      pkg,
    IPI.stability          = stability   pkg,
    IPI.homepage           = homepage    pkg,
    IPI.pkgUrl             = pkgUrl      pkg,
312
    IPI.synopsis           = synopsis    pkg,
Duncan Coutts's avatar
Duncan Coutts committed
313 314
    IPI.description        = description pkg,
    IPI.category           = category    pkg,
315
    IPI.abiHash            = abi_hash,
Duncan Coutts's avatar
Duncan Coutts committed
316
    IPI.exposed            = libExposed  lib,
317
    IPI.exposedModules     = componentExposedModules clbi,
Duncan Coutts's avatar
Duncan Coutts committed
318
    IPI.hiddenModules      = otherModules bi,
319
    IPI.instantiatedWith   = map (\(k,(p,n)) ->
320
                                   (k,IPI.OriginalModule (IPI.installedComponentId p) n))
321
                                 (instantiatedWith lbi),
322
    IPI.trusted            = IPI.trusted IPI.emptyInstalledPackageInfo,
Duncan Coutts's avatar
Duncan Coutts committed
323
    IPI.importDirs         = [ libdir installDirs | hasModules ],
324 325
    -- Note. the libsubdir and datasubdir templates have already been expanded
    -- into libdir and datadir.
Duncan Coutts's avatar
Duncan Coutts committed
326 327 328
    IPI.libraryDirs        = if hasLibrary
                               then libdir installDirs : extraLibDirs bi
                               else                      extraLibDirs bi,
329
    IPI.dataDir            = datadir installDirs,
330
    IPI.hsLibraries        = if hasLibrary
331
                               then [getHSLibraryName (componentId clbi)]
332
                               else [],
Duncan Coutts's avatar
Duncan Coutts committed
333
    IPI.extraLibraries     = extraLibs bi,
334
    IPI.extraGHCiLibraries = extraGHCiLibs bi,
Duncan Coutts's avatar
Duncan Coutts committed
335 336
    IPI.includeDirs        = absinc ++ adjustRelIncDirs relinc,
    IPI.includes           = includes bi,
337
    IPI.depends            = map fst (componentPackageDeps clbi),
Duncan Coutts's avatar
Duncan Coutts committed
338 339 340 341 342 343 344
    IPI.ccOptions          = [], -- Note. NOT ccOptions bi!
                                 -- We don't want cc-options to be propagated
                                 -- to C compilations in other packages.
    IPI.ldOptions          = ldOptions bi,
    IPI.frameworkDirs      = [],
    IPI.frameworks         = frameworks bi,
    IPI.haddockInterfaces  = [haddockdir installDirs </> haddockName pkg],
345 346
    IPI.haddockHTMLs       = [htmldir installDirs],
    IPI.pkgRoot            = Nothing
Duncan Coutts's avatar
Duncan Coutts committed
347 348 349 350
  }
  where
    bi = libBuildInfo lib
    (absinc, relinc) = partition isAbsolute (includeDirs bi)
351
    hasModules = not $ null (libModules lib)
Duncan Coutts's avatar
Duncan Coutts committed
352
    hasLibrary = hasModules || not (null (cSources bi))
353 354 355
                            || (not (null (jsSources bi)) &&
                                compilerFlavor (compiler lbi) == GHCJS)

Ian D. Bollinger's avatar
Ian D. Bollinger committed
356
-- | Construct 'InstalledPackageInfo' for a library that is in place in the
Duncan Coutts's avatar
Duncan Coutts committed
357 358
-- build tree.
--
Ian D. Bollinger's avatar
Ian D. Bollinger committed
359
-- This function knows about the layout of in place packages.
Duncan Coutts's avatar
Duncan Coutts committed
360 361 362 363
--
inplaceInstalledPackageInfo :: FilePath -- ^ top of the build tree
                            -> FilePath -- ^ location of the dist tree
                            -> PackageDescription
364
                            -> AbiHash
Duncan Coutts's avatar
Duncan Coutts committed
365 366 367 368
                            -> Library
                            -> LocalBuildInfo
                            -> ComponentLocalBuildInfo
                            -> InstalledPackageInfo
369
inplaceInstalledPackageInfo inplaceDir distPref pkg abi_hash lib lbi clbi =
370
    generalInstalledPackageInfo adjustRelativeIncludeDirs
371
                                pkg abi_hash lib lbi clbi installDirs
Duncan Coutts's avatar
Duncan Coutts committed
372
  where
refold's avatar
refold committed
373
    adjustRelativeIncludeDirs = map (inplaceDir </>)
Duncan Coutts's avatar
Duncan Coutts committed
374
    installDirs =
375
      (absoluteInstallDirs pkg lbi NoCopyDest) {
Duncan Coutts's avatar
Duncan Coutts committed
376
        libdir     = inplaceDir </> buildDir lbi,
377
        datadir    = inplaceDir </> dataDir pkg,
Duncan Coutts's avatar
Duncan Coutts committed
378 379 380 381 382 383 384 385 386 387 388 389 390 391
        docdir     = inplaceDocdir,
        htmldir    = inplaceHtmldir,
        haddockdir = inplaceHtmldir
      }
    inplaceDocdir  = inplaceDir </> distPref </> "doc"
    inplaceHtmldir = inplaceDocdir </> "html" </> display (packageName pkg)


-- | Construct 'InstalledPackageInfo' for the final install location of a
-- library package.
--
-- This function knows about the layout of installed packages.
--
absoluteInstalledPackageInfo :: PackageDescription
392
                             -> AbiHash
Duncan Coutts's avatar
Duncan Coutts committed
393 394 395 396
                             -> Library
                             -> LocalBuildInfo
                             -> ComponentLocalBuildInfo
                             -> InstalledPackageInfo
397
absoluteInstalledPackageInfo pkg abi_hash lib lbi clbi =
398
    generalInstalledPackageInfo adjustReativeIncludeDirs
399
                                pkg abi_hash lib lbi clbi installDirs
Duncan Coutts's avatar
Duncan Coutts committed
400 401 402 403 404 405 406
  where
    -- For installed packages we install all include files into one dir,
    -- whereas in the build tree they may live in multiple local dirs.
    adjustReativeIncludeDirs _
      | null (installIncludes bi) = []
      | otherwise                 = [includedir installDirs]
    bi = libBuildInfo lib
407
    installDirs = absoluteInstallDirs pkg lbi NoCopyDest
Duncan Coutts's avatar
Duncan Coutts committed
408

409 410

relocatableInstalledPackageInfo :: PackageDescription
411
                                -> AbiHash
412 413 414
                                -> Library
                                -> LocalBuildInfo
                                -> ComponentLocalBuildInfo
415
                                -> FilePath
416
                                -> InstalledPackageInfo
417
relocatableInstalledPackageInfo pkg abi_hash lib lbi clbi pkgroot =
418
    generalInstalledPackageInfo adjustReativeIncludeDirs
419
                                pkg abi_hash lib lbi clbi installDirs
420 421 422 423 424 425 426
  where
    -- For installed packages we install all include files into one dir,
    -- whereas in the build tree they may live in multiple local dirs.
    adjustReativeIncludeDirs _
      | null (installIncludes bi) = []
      | otherwise                 = [includedir installDirs]
    bi = libBuildInfo lib
427 428 429

    installDirs = fmap (("${pkgroot}" </>) . shortRelativePath pkgroot)
                $ absoluteInstallDirs pkg lbi NoCopyDest
430

simonmar's avatar
simonmar committed
431 432
-- -----------------------------------------------------------------------------
-- Unregistration
433

ijones's avatar
ijones committed
434
unregister :: PackageDescription -> LocalBuildInfo -> RegisterFlags -> IO ()
Duncan Coutts's avatar
Duncan Coutts committed
435 436 437
unregister pkg lbi regFlags = do
  let pkgid     = packageId pkg
      genScript = fromFlag (regGenScript regFlags)
438
      verbosity = fromFlag (regVerbosity regFlags)
Duncan Coutts's avatar
Duncan Coutts committed
439
      packageDb = fromFlagOrDefault (registrationPackageDB (withPackageDB lbi))
440
                                    (regPackageDB regFlags)
441 442 443 444 445 446 447
      unreg hpi =
        let invocation = HcPkg.unregisterInvocation
                           hpi Verbosity.normal packageDb pkgid
        in if genScript
             then writeFileAtomic unregScriptFileName
                    (BS.Char8.pack $ invocationAsSystemScript buildOS invocation)
             else runProgramInvocation verbosity invocation
Duncan Coutts's avatar
Duncan Coutts committed
448
  setupMessage verbosity "Unregistering" pkgid
449 450
  withHcPkg "unregistering is only implemented for GHC and GHCJS"
    (compiler lbi) (withPrograms lbi) unreg
ijones's avatar
ijones committed
451

Duncan Coutts's avatar
Duncan Coutts committed
452 453 454 455
unregScriptFileName :: FilePath
unregScriptFileName = case buildOS of
                          Windows -> "unregister.bat"
                          _       -> "unregister.sh"