Occurrrence analysis improvements for NOINLINE functions
[ghc.git] / hadrian / src / Rules / Register.hs
1 module Rules.Register (registerPackage) where
2
3 import Base
4 import Context
5 import GHC
6 import Target
7 import Utilities
8
9 -- TODO: Simplify.
10 -- | Build rules for registering packages and initialising package databases
11 -- by running the @ghc-pkg@ utility.
12 registerPackage :: [(Resource, Int)] -> Context -> Rules ()
13 registerPackage rs context@Context {..} = do
14 when (stage == Stage0) $ do
15 -- Packages @ghc-boot@ and @ghc-boot-th@ both match the @ghc-boot*@
16 -- pattern, therefore we need to use priorities to match the right rule.
17 -- TODO: Get rid of this hack.
18 "//" ++ stage0PackageDbDir -/- pkgName package ++ "*.conf" %%>
19 buildConf rs context
20
21 when (package == ghc) $ "//" ++ stage0PackageDbDir -/- packageDbStamp %>
22 buildStamp rs context
23
24 when (stage == Stage1) $ do
25 inplacePackageDbPath -/- pkgName package ++ "*.conf" %%>
26 buildConf rs context
27
28 when (package == ghc) $ inplacePackageDbPath -/- packageDbStamp %>
29 buildStamp rs context
30
31 buildConf :: [(Resource, Int)] -> Context -> FilePath -> Action ()
32 buildConf rs context@Context {..} conf = do
33 confIn <- pkgInplaceConfig context
34 need [confIn]
35 buildWithResources rs $ target context (GhcPkg Update stage) [confIn] [conf]
36
37 buildStamp :: [(Resource, Int)] -> Context -> FilePath -> Action ()
38 buildStamp rs Context {..} stamp = do
39 let path = takeDirectory stamp
40 removeDirectory path
41 buildWithResources rs $
42 target (vanillaContext stage ghc) (GhcPkg Init stage) [] [path]
43 writeFileLines stamp []
44 putSuccess $ "| Successfully initialised " ++ path