Register.hs 985 Bytes
Newer Older
1 2 3
module Rules.Register (registerPackage) where

import Base
4
import Context
5
import GHC
6
import Settings.Path
7
import Target
8
import UserSettings
9
import Utilities
10

11 12
-- | Build rules for registering packages and initialising package databases
-- by running the @ghc-pkg@ utility.
13
registerPackage :: [(Resource, Int)] -> Context -> Rules ()
14
registerPackage rs context@Context {..} = when (stage <= Stage1) $ do
15
    let confIn = pkgInplaceConfig context
16
        dir    = inplacePackageDbDirectory stage
17

Andrey Mokhov's avatar
Andrey Mokhov committed
18
    matchVersionedFilePath (dir -/- pkgNameString package) "conf" ?> \conf -> do
19
        need [confIn]
Andrey Mokhov's avatar
Andrey Mokhov committed
20
        buildWithResources rs $
21
            target context (GhcPkg Update stage) [confIn] [conf]
22 23 24

    when (package == ghc) $ packageDbStamp stage %> \stamp -> do
        removeDirectory dir
Andrey Mokhov's avatar
Andrey Mokhov committed
25
        buildWithResources rs $
26
            target (vanillaContext stage ghc) (GhcPkg Init stage) [] [dir]
27 28
        writeFileLines stamp []
        putSuccess $ "| Successfully initialised " ++ dir