@@ -17,7 +17,8 @@ This module defines the interface for the @Hooks@ @build-type@.
1717
1818To write a package that implements @build-type: Hooks@, you should define
1919a 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.
2122
2223See 'SetupHooks' for more details.
2324-}
@@ -97,9 +98,7 @@ module Distribution.Simple.SetupHooks
9798
9899 -- **** File/directory monitoring
99100 , addRuleMonitors
100- , MonitorFilePath (.. )
101- , MonitorKindFile (.. )
102- , MonitorKindDir (.. )
101+ , module Distribution.Simple.FileMonitor.Types
103102
104103 -- * Install hooks
105104 , InstallHooks (.. ), noInstallHooks
@@ -120,17 +119,27 @@ module Distribution.Simple.SetupHooks
120119 -- | These are functions provided as part of the @Hooks@ API.
121120 -- It is recommended to import them from this module as opposed to
122121 -- 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
124133
125134 -- ** General @Cabal@ datatypes
126135 , Verbosity , Compiler (.. ), Platform (.. ), Suffix (.. )
127136
128137 -- *** Package information
129138 , 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.
134143
135144 , PackageDescription (.. )
136145
@@ -146,9 +155,6 @@ module Distribution.Simple.SetupHooks
146155 , emptyLibrary , emptyForeignLib , emptyExecutable
147156 , emptyTestSuite , emptyBenchmark
148157
149- -- ** Programs
150- , Program , ConfiguredProgram , ProgramDb , ProgArg
151-
152158 )
153159where
154160import Distribution.PackageDescription
@@ -166,16 +172,24 @@ import Distribution.Simple.Compiler
166172 ( Compiler (.. ) )
167173import Distribution.Simple.Errors
168174 ( CabalException (SetupHooksException ) )
175+ import Distribution.Simple.FileMonitor.Types
169176import Distribution.Simple.Install
170177 ( installFileGlob )
171178import Distribution.Simple.LocalBuildInfo
172179 ( componentBuildDir )
173180import Distribution.Simple.PreProcess.Types
174181 ( Suffix (.. ) )
175182import Distribution.Simple.Program.Db
176- ( ProgramDb , addKnownPrograms )
183+ ( ProgramDb , addKnownPrograms
184+ , configureUnconfiguredProgram
185+ )
186+ import Distribution.Simple.Program.Find
187+ ( simpleProgram )
177188import Distribution.Simple.Program.Types
178- ( Program , ConfiguredProgram , ProgArg )
189+ ( Program (.. ), ConfiguredProgram (.. )
190+ , ProgArg
191+ , ProgramLocation (.. )
192+ )
179193import Distribution.Simple.Setup
180194 ( BuildFlags (.. )
181195 , ConfigFlags (.. )
@@ -250,7 +264,9 @@ Usage example:
250264> custom-setup
251265> setup-depends:
252266> 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.
254270
255271> -- In SetupHooks.hs, next to your .cabal file
256272> module SetupHooks where
@@ -304,34 +320,39 @@ For example, to generate modules inside a given component, you should:
304320-}
305321
306322{- $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:
308325
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.
312333
313334Note that:
314335
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
322347 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.
327348-}
328349
329350{- $rulesDemand
330351Rules can declare various kinds of dependencies:
331352
332353 - 'staticDependencies': files or other rules that a rule statically depends on,
333354 - extra dynamic dependencies, using the 'DynamicRuleCommands' constructor,
334- - 'MonitoredFileOrDir ': additional files or directories to monitor.
355+ - 'MonitorFilePath ': additional files and directories to monitor.
335356
336357Rules are considered __out-of-date__ precisely when any of the following
337358conditions apply:
@@ -377,11 +398,11 @@ Defining pre-build rules can be done in the following style:
377398> let cmd1 = mkCommand (static Dict) $ static \ arg -> do { .. }
378399> cmd2 = mkCommand (static Dict) $ static \ arg -> do { .. }
379400> 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
385406
386407Here we use the 'rules', 'staticRule' and 'mkCommand' smart constructors,
387408rather than directly using the v'Rules', v'Rule' and v'Command' constructors,
@@ -456,5 +477,5 @@ findFileInDirs file dirs =
456477 | path <- nub dirs
457478 ]
458479
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