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