2 {-# OPTIONS_GHC -Wall #-}
4 -- The logic here is tricky.
5 -- If this is compiled by cabal-install, then the MIN_VERSION_Cabal is set
6 -- otherwise, we are compiling against Cabal library under test,
8 #ifndef MIN_VERSION_Cabal
9 #define MIN_VERSION_Cabal
(x
,y
,z
) 1
12 import Distribution
.PackageDescription
13 import Distribution
.Simple
14 import Distribution
.Simple
.LocalBuildInfo
15 import Distribution
.Simple
.PreProcess
16 import Distribution
.Simple
.Utils
18 import System
.FilePath
19 import System
.Process
(rawSystem
)
22 main
= defaultMainWithHooks
23 simpleUserHooks
{ hookedPreProcessors
= [("pre", myCustomPreprocessor
)] }
25 #if MIN_VERSION_Cabal
(2,0,0)
26 myCustomPreprocessor
:: BuildInfo
-> LocalBuildInfo
-> ComponentLocalBuildInfo
-> PreProcessor
27 myCustomPreprocessor _bi lbi _clbi
=
29 myCustomPreprocessor
:: BuildInfo
-> LocalBuildInfo
-> PreProcessor
30 myCustomPreprocessor _bi lbi
=
33 platformIndependent
= True,
34 runPreProcessor
= mkSimplePreProcessor
$ \inFile outFile verbosity
->
35 do info verbosity
("Preprocessing " ++ inFile
++ " to " ++ outFile
)
36 #if MIN_VERSION_Cabal
(3,7,0)
37 callProcess progPath
[inFile
, outFile
],
40 callProcess progPath
[inFile
, outFile
]
44 builddir
= buildDir lbi
45 progName
= "my-custom-preprocessor"
46 progPath
= builddir
</> progName
</> progName
48 -- Backwards compat with process < 1.2.
49 callProcess
:: FilePath -> [String] -> IO ()
50 callProcess path args
=
51 do exitCode
<- rawSystem path args
52 case exitCode
of ExitSuccess
-> return ()
53 f
@(ExitFailure _
) -> fail $ "callProcess " ++ show path
54 ++ " " ++ show args
++ " failed: "