@@ -17,7 +17,8 @@ This module defines the interface for the @Hooks@ @build-type@.
17
17
18
18
To write a package that implements @build-type: Hooks@, you should define
19
19
a module @SetupHooks.hs@ which exports a value @setupHooks :: 'SetupHooks'@.
20
- This is a record that declares actions to hook into the cabal build process.
20
+ This is a record that declares actions that should be hooked into the
21
+ cabal build process.
21
22
22
23
See 'SetupHooks' for more details.
23
24
-}
@@ -97,9 +98,7 @@ module Distribution.Simple.SetupHooks
97
98
98
99
-- **** File/directory monitoring
99
100
, addRuleMonitors
100
- , MonitorFilePath (.. )
101
- , MonitorKindFile (.. )
102
- , MonitorKindDir (.. )
101
+ , module Distribution.Simple.FileMonitor.Types
103
102
104
103
-- * Install hooks
105
104
, InstallHooks (.. ), noInstallHooks
@@ -120,17 +119,27 @@ module Distribution.Simple.SetupHooks
120
119
-- | These are functions provided as part of the @Hooks@ API.
121
120
-- It is recommended to import them from this module as opposed to
122
121
-- manually importing them from inside the Cabal module hierarchy.
123
- , installFileGlob , addKnownPrograms
122
+
123
+ -- *** Copy/install functions
124
+ , installFileGlob
125
+
126
+ -- *** Interacting with the program database
127
+ , Program (.. ), ConfiguredProgram (.. ), ProgArg
128
+ , ProgramLocation (.. )
129
+ , ProgramDb
130
+ , addKnownPrograms
131
+ , configureUnconfiguredProgram
132
+ , simpleProgram
124
133
125
134
-- ** General @Cabal@ datatypes
126
135
, Verbosity , Compiler (.. ), Platform (.. ), Suffix (.. )
127
136
128
137
-- *** Package information
129
138
, LocalBuildConfig , LocalBuildInfo , PackageBuildDescr
130
- -- SetupHooks TODO : we can't simply re-export all the fields of
131
- -- LocalBuildConfig etc, due to the presence of duplicate record fields.
132
- -- Ideally we'd like to e.g. re-export LocalBuildConfig
133
- -- qualified, but qualified re-exports aren't a thing currently.
139
+ -- NB : we can't simply re-export all the fields of LocalBuildConfig etc,
140
+ -- due to the presence of duplicate record fields.
141
+ -- Ideally, we'd like to e.g. re-export LocalBuildConfig qualified,
142
+ -- but qualified re-exports aren't a thing currently.
134
143
135
144
, PackageDescription (.. )
136
145
@@ -146,9 +155,6 @@ module Distribution.Simple.SetupHooks
146
155
, emptyLibrary , emptyForeignLib , emptyExecutable
147
156
, emptyTestSuite , emptyBenchmark
148
157
149
- -- ** Programs
150
- , Program , ConfiguredProgram , ProgramDb , ProgArg
151
-
152
158
)
153
159
where
154
160
import Distribution.PackageDescription
@@ -166,16 +172,24 @@ import Distribution.Simple.Compiler
166
172
( Compiler (.. ) )
167
173
import Distribution.Simple.Errors
168
174
( CabalException (SetupHooksException ) )
175
+ import Distribution.Simple.FileMonitor.Types
169
176
import Distribution.Simple.Install
170
177
( installFileGlob )
171
178
import Distribution.Simple.LocalBuildInfo
172
179
( componentBuildDir )
173
180
import Distribution.Simple.PreProcess.Types
174
181
( Suffix (.. ) )
175
182
import Distribution.Simple.Program.Db
176
- ( ProgramDb , addKnownPrograms )
183
+ ( ProgramDb , addKnownPrograms
184
+ , configureUnconfiguredProgram
185
+ )
186
+ import Distribution.Simple.Program.Find
187
+ ( simpleProgram )
177
188
import Distribution.Simple.Program.Types
178
- ( Program , ConfiguredProgram , ProgArg )
189
+ ( Program (.. ), ConfiguredProgram (.. )
190
+ , ProgArg
191
+ , ProgramLocation (.. )
192
+ )
179
193
import Distribution.Simple.Setup
180
194
( BuildFlags (.. )
181
195
, ConfigFlags (.. )
@@ -250,7 +264,9 @@ Usage example:
250
264
> custom-setup
251
265
> setup-depends:
252
266
> base >= 4.18 && < 5,
253
- > Cabal-hooks >= 0.1 && < 0.3
267
+ > Cabal-hooks >= 0.1 && < 0.2
268
+ >
269
+ > The declared Cabal version should also be at least 3.12.
254
270
255
271
> -- In SetupHooks.hs, next to your .cabal file
256
272
> module SetupHooks where
@@ -304,34 +320,39 @@ For example, to generate modules inside a given component, you should:
304
320
-}
305
321
306
322
{- $preBuildRules
307
- Pre-build hooks are specified in the form of a collection of pre-build 'Rules'.
323
+ Pre-build hooks are specified as a collection of pre-build 'Rules'.
324
+ Each t'Rule' consists of:
308
325
309
- Pre-build rules are specified as a collection of rules. Each t'Rule' declares
310
- its dependencies, its outputs, and refers to a command to run in order to
311
- execute the rule in the form of a t'RuleCommands'.
326
+ - a specification of its static dependencies and outputs,
327
+ - the commands that execute the rule.
328
+
329
+ Rules are constructed using either one of the 'staticRule' or 'dynamicRule'
330
+ smart constructors. Directly constructing a t'Rule' using the constructors of
331
+ that data type is not advised, as this relies on internal implementation details
332
+ which are subject to change in between versions of the `Cabal-hooks` library.
312
333
313
334
Note that:
314
335
315
- - file dependencies are not specified directly by 'FilePath' but rather use
316
- the 'Location' type,
317
- - rules can directly depend on other rules, which requires the ability to
318
- refer to a rule by 'RuleId',
319
- - rules refer to the actions that execute them using static pointers, in order
320
- to enable serialisation/deserialisation of rules,
321
- - rules can additionally monitor files or directories, which determines
336
+ - To declare the dependency on the output of a rule, one must refer to the
337
+ rule directly, and not to the path to the output executing that rule will
338
+ eventually produce.
339
+ To do so, registering a t'Rule' with the API returns a unique identifier
340
+ for that rule, in the form of a t'RuleId'.
341
+ - File dependencies and outputs are not specified directly by
342
+ 'FilePath', but rather use the 'Location' type (which is more convenient
343
+ when working with preprocessors).
344
+ - Rules refer to the actions that execute them using static pointers, in order
345
+ to enable serialisation/deserialisation of rules.
346
+ - Rules can additionally monitor files or directories, which determines
322
347
when to re-compute the entire set of rules.
323
-
324
- To construct a t'Rule', you should use one of the 'staticRule' or 'dynamicRule'
325
- smart constructors, to avoid relying on internal implementation details of
326
- the t'Rule' datatype.
327
348
-}
328
349
329
350
{- $rulesDemand
330
351
Rules can declare various kinds of dependencies:
331
352
332
353
- 'staticDependencies': files or other rules that a rule statically depends on,
333
354
- extra dynamic dependencies, using the 'DynamicRuleCommands' constructor,
334
- - 'MonitoredFileOrDir ': additional files or directories to monitor.
355
+ - 'MonitorFilePath ': additional files and directories to monitor.
335
356
336
357
Rules are considered __out-of-date__ precisely when any of the following
337
358
conditions apply:
@@ -377,11 +398,11 @@ Defining pre-build rules can be done in the following style:
377
398
> let cmd1 = mkCommand (static Dict) $ static \ arg -> do { .. }
378
399
> cmd2 = mkCommand (static Dict) $ static \ arg -> do { .. }
379
400
> myData <- liftIO someIOAction
380
- > addRuleMonitors [ MonitorDir "someSearchDir" DirContents ]
381
- > registerRule_ $ staticRule (cmd1 arg1) deps1 outs1
382
- > registerRule_ $ staticRule (cmd1 arg2) deps2 outs2
383
- > registerRule_ $ staticRule (cmd1 arg3) deps3 outs3
384
- > registerRule_ $ staticRule (cmd2 arg4) deps4 outs4
401
+ > addRuleMonitors [ monitorDirectory "someSearchDir" ]
402
+ > registerRule_ "rule_1_1" $ staticRule (cmd1 arg1) deps1 outs1
403
+ > registerRule_ "rule_1_2" $ staticRule (cmd1 arg2) deps2 outs2
404
+ > registerRule_ "rule_1_3" $ staticRule (cmd1 arg3) deps3 outs3
405
+ > registerRule_ "rule_2_4" $ staticRule (cmd2 arg4) deps4 outs4
385
406
386
407
Here we use the 'rules', 'staticRule' and 'mkCommand' smart constructors,
387
408
rather than directly using the v'Rules', v'Rule' and v'Command' constructors,
@@ -456,5 +477,5 @@ findFileInDirs file dirs =
456
477
| path <- nub dirs
457
478
]
458
479
459
- -- SetupHooks TODO: add API functions that do searching and declare
460
- -- the appropriate monitoring at the same time.
480
+ -- TODO: add API functions that search and declare the appropriate monitoring
481
+ -- at the same time.
0 commit comments