|
| 1 | +{-# OPTIONS_GHC -Wall #-} |
| 2 | + |
1 | 3 | module Main (main) where
|
2 | 4 |
|
| 5 | +-- Cabal |
3 | 6 | import Distribution.Simple
|
| 7 | + ( defaultMainWithHooks |
| 8 | + , autoconfUserHooks |
| 9 | + , UserHooks(buildHook) |
| 10 | + ) |
| 11 | +import Distribution.Simple.BuildPaths |
| 12 | + ( autogenComponentModulesDir |
| 13 | + , exeExtension |
| 14 | + ) |
| 15 | +import Distribution.Simple.LocalBuildInfo |
| 16 | + ( hostPlatform |
| 17 | + , buildDir |
| 18 | + , withTestLBI |
| 19 | + ) |
| 20 | +import Distribution.Types.LocalBuildInfo |
| 21 | + ( LocalBuildInfo |
| 22 | + , allTargetsInBuildOrder' |
| 23 | + ) |
| 24 | +import Distribution.Types.Component |
| 25 | + ( Component(CExe) ) |
| 26 | +import Distribution.Types.Executable |
| 27 | + ( Executable(exeName) ) |
| 28 | +import Distribution.Types.PackageDescription |
| 29 | + ( PackageDescription ) |
| 30 | +import Distribution.Types.TargetInfo |
| 31 | + ( targetComponent ) |
| 32 | +import Distribution.Types.UnqualComponentName |
| 33 | + ( unUnqualComponentName ) |
| 34 | + |
| 35 | +-- directory |
| 36 | +import System.Directory |
| 37 | + ( createDirectoryIfMissing ) |
| 38 | + |
| 39 | +-- filepath |
| 40 | +import System.FilePath |
| 41 | + ( (</>), (<.>), takeDirectory ) |
| 42 | + |
| 43 | +-------------------------------------------------------------------------------- |
4 | 44 |
|
5 | 45 | main :: IO ()
|
6 |
| -main = defaultMainWithHooks autoconfUserHooks |
| 46 | +main = defaultMainWithHooks processHooks |
| 47 | + |
| 48 | +-- The following code works around Cabal bug #9854. |
| 49 | +-- |
| 50 | +-- The process package has an executable component named "cli-child", |
| 51 | +-- used for testing. We want to invoke this executable when running tests; |
| 52 | +-- however, due to the Cabal bug this executable does not get added to PATH. |
| 53 | +-- To fix this, we create a "Test.Paths" module in a Custom setup script, |
| 54 | +-- which contains paths to executables used for testing. |
| 55 | +processHooks :: UserHooks |
| 56 | +processHooks = |
| 57 | + defaultConfigureHooks |
| 58 | + { buildHook = \ pd lbi userHooks buildFlags -> |
| 59 | + withTestLBI pd lbi $ \ _testSuite clbi -> do |
| 60 | + let pathsFile = autogenComponentModulesDir lbi clbi </> "Test" </> "Paths" <.> "hs" |
| 61 | + createDirectoryIfMissing True (takeDirectory pathsFile) |
| 62 | + writeFile pathsFile $ unlines |
| 63 | + [ "module Test.Paths where" |
| 64 | + , "processInternalExes :: [(String, FilePath)]" |
| 65 | + , "processInternalExes = " ++ show (processInternalExes pd lbi) |
| 66 | + ] |
| 67 | + buildHook defaultConfigureHooks pd lbi userHooks buildFlags |
| 68 | + } |
| 69 | + |
| 70 | +defaultConfigureHooks :: UserHooks |
| 71 | +defaultConfigureHooks = autoconfUserHooks |
| 72 | + |
| 73 | +processInternalExes :: PackageDescription -> LocalBuildInfo -> [(String, FilePath)] |
| 74 | +processInternalExes pd lbi = |
| 75 | + [ (toolName, toolLocation) |
| 76 | + | tgt <- allTargetsInBuildOrder' pd lbi |
| 77 | + , CExe exe <- [targetComponent tgt] |
| 78 | + , let toolName = unUnqualComponentName $ exeName exe |
| 79 | + toolLocation = |
| 80 | + buildDir lbi |
| 81 | + </> (toolName </> toolName <.> exeExtension (hostPlatform lbi)) |
| 82 | + ] |
0 commit comments