-
Notifications
You must be signed in to change notification settings - Fork 701
/
Copy pathUserHooks.hs
186 lines (179 loc) · 8.67 KB
/
UserHooks.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
-----------------------------------------------------------------------------
-- |
-- Module : Distribution.Simple.UserHooks
-- Copyright : Isaac Jones 2003-2005
-- License : BSD3
--
-- Maintainer : [email protected]
-- Portability : portable
--
-- This defines the API that @Setup.hs@ scripts can use to customise the way
-- the build works. This module just defines the 'UserHooks' type. The
-- predefined sets of hooks that implement the @Simple@, @Make@ and @Configure@
-- build systems are defined in "Distribution.Simple". The 'UserHooks' is a big
-- record of functions. There are 3 for each action, a pre, post and the action
-- itself. There are few other miscellaneous hooks, ones to extend the set of
-- programs and preprocessors and one to override the function used to read the
-- @.cabal@ file.
--
-- This hooks type is widely agreed to not be the right solution. Partly this
-- is because changes to it usually break custom @Setup.hs@ files and yet many
-- internal code changes do require changes to the hooks. For example we cannot
-- pass any extra parameters to most of the functions that implement the
-- various phases because it would involve changing the types of the
-- corresponding hook. At some point it will have to be replaced.
module Distribution.Simple.UserHooks
( UserHooks (..)
, Args
, emptyUserHooks
) where
import Distribution.Compat.Prelude hiding (getContents, putStr)
import Prelude ()
import Distribution.PackageDescription
import Distribution.Simple.Command
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.PreProcess
import Distribution.Simple.Program
import Distribution.Simple.Setup
type Args = [String]
-- | Hooks allow authors to add specific functionality before and after a
-- command is run, and also to specify additional preprocessors.
--
-- * WARNING: The hooks interface is under rather constant flux as we try to
-- understand users needs. Setup files that depend on this interface may
-- break in future releases.
data UserHooks = UserHooks
{ readDesc :: IO (Maybe GenericPackageDescription)
-- ^ Read the description file
, hookedPreProcessors :: [PPSuffixHandler]
-- ^ Custom preprocessors in addition to and overriding 'knownSuffixHandlers'.
, hookedPrograms :: [Program]
-- ^ These programs are detected at configure time. Arguments for them are
-- added to the configure command.
, preConf :: Args -> ConfigFlags -> IO HookedBuildInfo
-- ^ Hook to run before configure command
, confHook
:: (GenericPackageDescription, HookedBuildInfo)
-> ConfigFlags
-> IO LocalBuildInfo
-- ^ Over-ride this hook to get different behavior during configure.
, postConf :: Args -> ConfigFlags -> PackageDescription -> LocalBuildInfo -> IO ()
-- ^ Hook to run after configure command
, preBuild :: Args -> BuildFlags -> IO HookedBuildInfo
-- ^ Hook to run before build command. Second arg indicates verbosity level.
, buildHook :: PackageDescription -> LocalBuildInfo -> UserHooks -> BuildFlags -> IO ()
-- ^ Over-ride this hook to get different behavior during build.
, postBuild :: Args -> BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ()
-- ^ Hook to run after build command. Second arg indicates verbosity level.
, preRepl :: Args -> ReplFlags -> IO HookedBuildInfo
-- ^ Hook to run before repl command. Second arg indicates verbosity level.
, replHook :: PackageDescription -> LocalBuildInfo -> UserHooks -> ReplFlags -> [String] -> IO ()
-- ^ Over-ride this hook to get different behavior during interpretation.
, postRepl :: Args -> ReplFlags -> PackageDescription -> LocalBuildInfo -> IO ()
-- ^ Hook to run after repl command. Second arg indicates verbosity level.
, preClean :: Args -> CleanFlags -> IO HookedBuildInfo
-- ^ Hook to run before clean command. Second arg indicates verbosity level.
, cleanHook :: PackageDescription -> () -> UserHooks -> CleanFlags -> IO ()
-- ^ Over-ride this hook to get different behavior during clean.
, postClean :: Args -> CleanFlags -> PackageDescription -> () -> IO ()
-- ^ Hook to run after clean command. Second arg indicates verbosity level.
, preCopy :: Args -> CopyFlags -> IO HookedBuildInfo
-- ^ Hook to run before copy command
, copyHook :: PackageDescription -> LocalBuildInfo -> UserHooks -> CopyFlags -> IO ()
-- ^ Over-ride this hook to get different behavior during copy.
, postCopy :: Args -> CopyFlags -> PackageDescription -> LocalBuildInfo -> IO ()
-- ^ Hook to run after copy command
, preInst :: Args -> InstallFlags -> IO HookedBuildInfo
-- ^ Hook to run before install command
, instHook :: PackageDescription -> LocalBuildInfo -> UserHooks -> InstallFlags -> IO ()
-- ^ Over-ride this hook to get different behavior during install.
, postInst :: Args -> InstallFlags -> PackageDescription -> LocalBuildInfo -> IO ()
-- ^ Hook to run after install command. postInst should be run
-- on the target, not on the build machine.
, preReg :: Args -> RegisterFlags -> IO HookedBuildInfo
-- ^ Hook to run before register command
, regHook :: PackageDescription -> LocalBuildInfo -> UserHooks -> RegisterFlags -> IO ()
-- ^ Over-ride this hook to get different behavior during registration.
, postReg :: Args -> RegisterFlags -> PackageDescription -> LocalBuildInfo -> IO ()
-- ^ Hook to run after register command
, preUnreg :: Args -> RegisterFlags -> IO HookedBuildInfo
-- ^ Hook to run before unregister command
, unregHook :: PackageDescription -> LocalBuildInfo -> UserHooks -> RegisterFlags -> IO ()
-- ^ Over-ride this hook to get different behavior during unregistration.
, postUnreg :: Args -> RegisterFlags -> PackageDescription -> LocalBuildInfo -> IO ()
-- ^ Hook to run after unregister command
, preHscolour :: Args -> HscolourFlags -> IO HookedBuildInfo
-- ^ Hook to run before hscolour command. Second arg indicates verbosity level.
, hscolourHook :: PackageDescription -> LocalBuildInfo -> UserHooks -> HscolourFlags -> IO ()
-- ^ Over-ride this hook to get different behavior during hscolour.
, postHscolour :: Args -> HscolourFlags -> PackageDescription -> LocalBuildInfo -> IO ()
-- ^ Hook to run after hscolour command. Second arg indicates verbosity level.
, preHaddock :: Args -> HaddockFlags -> IO HookedBuildInfo
-- ^ Hook to run before haddock command. Second arg indicates verbosity level.
, haddockHook :: PackageDescription -> LocalBuildInfo -> UserHooks -> HaddockFlags -> IO ()
-- ^ Over-ride this hook to get different behavior during haddock.
, postHaddock :: Args -> HaddockFlags -> PackageDescription -> LocalBuildInfo -> IO ()
-- ^ Hook to run after haddock command. Second arg indicates verbosity level.
, preTest :: Args -> TestFlags -> IO HookedBuildInfo
-- ^ Hook to run before test command.
, testHook :: Args -> PackageDescription -> LocalBuildInfo -> UserHooks -> TestFlags -> IO ()
-- ^ Over-ride this hook to get different behavior during test.
, postTest :: Args -> TestFlags -> PackageDescription -> LocalBuildInfo -> IO ()
-- ^ Hook to run after test command.
, preBench :: Args -> BenchmarkFlags -> IO HookedBuildInfo
-- ^ Hook to run before bench command.
, benchHook :: Args -> PackageDescription -> LocalBuildInfo -> UserHooks -> BenchmarkFlags -> IO ()
-- ^ Over-ride this hook to get different behavior during bench.
, postBench :: Args -> BenchmarkFlags -> PackageDescription -> LocalBuildInfo -> IO ()
-- ^ Hook to run after bench command.
}
-- | Empty 'UserHooks' which do nothing.
emptyUserHooks :: UserHooks
emptyUserHooks =
UserHooks
{ readDesc = return Nothing
, hookedPreProcessors = []
, hookedPrograms = []
, preConf = rn'
, confHook = (\_ _ -> return (error "No local build info generated during configure. Over-ride empty configure hook."))
, postConf = ru
, preBuild = rn'
, buildHook = ru
, postBuild = ru
, preRepl = \_ _ -> return emptyHookedBuildInfo
, replHook = \_ _ _ _ _ -> return ()
, postRepl = ru
, preClean = rn
, cleanHook = ru
, postClean = ru
, preCopy = rn'
, copyHook = ru
, postCopy = ru
, preInst = rn
, instHook = ru
, postInst = ru
, preReg = rn'
, regHook = ru
, postReg = ru
, preUnreg = rn
, unregHook = ru
, postUnreg = ru
, preHscolour = rn
, hscolourHook = ru
, postHscolour = ru
, preHaddock = rn'
, haddockHook = ru
, postHaddock = ru
, preTest = rn'
, testHook = \_ -> ru
, postTest = ru
, preBench = rn'
, benchHook = \_ -> ru
, postBench = ru
}
where
rn args _ = noExtraFlags args >> return emptyHookedBuildInfo
rn' _ _ = return emptyHookedBuildInfo
ru _ _ _ _ = return ()