1 {-# LANGUAGE DeriveTraversable #-}
2 {-# LANGUAGE DuplicateRecordFields #-}
3 {-# LANGUAGE OverloadedStrings #-}
4 {-# LANGUAGE RecursiveDo #-}
5 {-# LANGUAGE StaticPointers #-}
7 module SetupHooks
where
9 import Distribution
.Simple
.LocalBuildInfo
(interpretSymbolicPathLBI
)
10 import Distribution
.Simple
.SetupHooks
11 import Distribution
.Simple
.Utils
( rewriteFileEx
, warn
)
12 import Distribution
.Utils
.Path
14 import Data
.Foldable
( for_
)
15 import qualified Data
.List
.NonEmpty
as NE
( NonEmpty
(..) )
16 import Data
.Traversable
( for
)
18 setupHooks
:: SetupHooks
23 { preBuildComponentRules
= Just
$ rules
(static
()) preBuildRules
27 -- Register three rules:
33 -- and check that we run them in dependency order, i.e. r2, r1, r3.
34 preBuildRules
:: PreBuildComponentInputs
-> RulesM
()
35 preBuildRules
(PreBuildComponentInputs
{ buildingWhat
= what
, localBuildInfo
= lbi
, targetInfo
= tgt
}) = mdo
36 let verbosity
= buildingWhatVerbosity what
38 autogenDir
= autogenComponentModulesDir lbi clbi
41 mkCommand
(static Dict
) $ static
(\ (dir
, verb
, (inMod
, outMod
)) -> do
42 warn verb
$ "Running rule: " ++ inMod
++ " --> " ++ outMod
43 let loc
= getSymbolicPath dir
</> outMod
<.> "hs"
44 rewriteFileEx verb loc
$
45 "module " ++ outMod
++ " where { import " ++ inMod
++ " }"
48 actionArg inMod outMod
=
49 (autogenDir
, verbosity
, (inMod
, outMod
))
51 mkRule action input outMod
=
54 ( Location autogenDir
(makeRelativePathEx outMod
<.> "hs") NE
.:|
[] )
59 r1
<- registerRule
"r1" $ mkRule
(mkAction
(actionArg
"B" "C")) (RuleDependency
$ RuleOutput r2
0) "C"
60 r2
<- registerRule
"r2" $ mkRule
(mkAction
(actionArg
"A" "B")) (FileDependency
$ Location sameDirectory
(makeRelativePathEx
"A.hs")) "B"
61 r3
<- registerRule
"r3" $ mkRule
(mkAction
(actionArg
"C" "D")) (RuleDependency
$ RuleOutput r1
0) "D"