(cabal check) Add "No internal name clash" test
[cabal.git] / cabal-testsuite / PackageTests / CustomPreProcess / Setup.hs
blob93ff6a015e921f2ba266baff72a19dce1fdef3e2
1 {-# LANGUAGE CPP #-}
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,
7 -- which is new!
8 #ifndef MIN_VERSION_Cabal
9 #define MIN_VERSION_Cabal(x,y,z) 1
10 #endif
12 import Distribution.PackageDescription
13 import Distribution.Simple
14 import Distribution.Simple.LocalBuildInfo
15 import Distribution.Simple.PreProcess
16 import Distribution.Simple.Utils
17 import System.Exit
18 import System.FilePath
19 import System.Process (rawSystem)
21 main :: IO ()
22 main = defaultMainWithHooks
23 simpleUserHooks { hookedPreProcessors = [("pre", myCustomPreprocessor)] }
24 where
25 #if MIN_VERSION_Cabal(2,0,0)
26 myCustomPreprocessor :: BuildInfo -> LocalBuildInfo -> ComponentLocalBuildInfo -> PreProcessor
27 myCustomPreprocessor _bi lbi _clbi =
28 #else
29 myCustomPreprocessor :: BuildInfo -> LocalBuildInfo -> PreProcessor
30 myCustomPreprocessor _bi lbi =
31 #endif
32 PreProcessor {
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],
38 ppOrdering = unsorted
39 #else
40 callProcess progPath [inFile, outFile]
41 #endif
43 where
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: "
55 ++ show f