-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
An API for inter-process communication via Handles
This commit adds the System.Process.CommunicationHandle module, which provides the cross-platform CommunicationHandle abstraction which allows Handles to be passed to child processes for inter-process communication. A high-level API is provided by the function `readCreateProcessWithExitCodeCommunicationHandle`, which can be consulted for further details about how the functionality is meant to be used. To test this functionality, we created a new "cli-child" executable component to the library. To work around Cabal bug #9854, it was necessary to change the build-type of the library to `Custom`, in order to make the "cli-child" executable visible when running the test-suite. The custom Setup.hs script contains more details about the problem.
- Loading branch information
Showing
8 changed files
with
580 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,82 @@ | ||
{-# OPTIONS_GHC -Wall #-} | ||
|
||
module Main (main) where | ||
|
||
-- Cabal | ||
import Distribution.Simple | ||
( defaultMainWithHooks | ||
, autoconfUserHooks | ||
, 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 autoconfUserHooks | ||
main = defaultMainWithHooks processHooks | ||
|
||
-- The following code works around Cabal bug #9854. | ||
-- | ||
-- The process 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. | ||
processHooks :: UserHooks | ||
processHooks = | ||
defaultConfigureHooks | ||
{ 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 defaultConfigureHooks pd lbi userHooks buildFlags | ||
} | ||
|
||
defaultConfigureHooks :: UserHooks | ||
defaultConfigureHooks = autoconfUserHooks | ||
|
||
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)) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.