2 {-# LANGUAGE OverloadedStrings #-}
3 {-# OPTIONS_GHC -Wall #-}
5 -- The logic here is tricky.
6 -- If this is compiled by cabal-install, then the MIN_VERSION_Cabal is set
7 -- otherwise, we are compiling against Cabal library under test,
9 #ifndef MIN_VERSION_Cabal
10 #define MIN_VERSION_Cabal
(x
,y
,z
) 1
13 import Distribution
.PackageDescription
14 import Distribution
.Simple
15 import Distribution
.Simple
.LocalBuildInfo
16 import Distribution
.Simple
.PreProcess
17 import Distribution
.Simple
.Utils
18 #if MIN_VERSION_Cabal
(3,13,0)
19 import Distribution
.Utils
.Path
(getSymbolicPath
)
23 import System
.FilePath
24 import System
.Process
(rawSystem
)
27 main
= defaultMainWithHooks
28 simpleUserHooks
{ hookedPreProcessors
= [("pre", myCustomPreprocessor
)] }
30 #if MIN_VERSION_Cabal
(2,0,0)
31 myCustomPreprocessor
:: BuildInfo
-> LocalBuildInfo
-> ComponentLocalBuildInfo
-> PreProcessor
32 myCustomPreprocessor _bi lbi _clbi
=
34 myCustomPreprocessor
:: BuildInfo
-> LocalBuildInfo
-> PreProcessor
35 myCustomPreprocessor _bi lbi
=
38 platformIndependent
= True,
39 runPreProcessor
= mkSimplePreProcessor
$ \inFile outFile verbosity
->
40 do info verbosity
("Preprocessing " ++ inFile
++ " to " ++ outFile
)
41 #if MIN_VERSION_Cabal
(3,7,0)
42 callProcess progPath
[inFile
, outFile
],
45 callProcess progPath
[inFile
, outFile
]
50 #if MIN_VERSION_Cabal
(3,13,0)
54 progName
= "my-custom-preprocessor"
55 progPath
= builddir
</> progName
</> progName
57 -- Backwards compat with process < 1.2.
58 callProcess
:: FilePath -> [String] -> IO ()
59 callProcess path args
=
60 do exitCode
<- rawSystem path args
61 case exitCode
of ExitSuccess
-> return ()
62 f
@(ExitFailure _
) -> fail $ "callProcess " ++ show path
63 ++ " " ++ show args
++ " failed: "