Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Compat version of readProcessWithExitCode #1628

Merged
merged 1 commit into from

2 participants

@byorgey
Collaborator
  • Add a new module, Distribution.Client.Compat.Process, with a
    function readProcessWithExitCode. Unlike the one from
    System.Process it always catches "does not exist" errors and turns
    them into ExitFailures.

  • Change all calls to readProcessWithExitCode to use the new version.

  • Fixes #1613.

Brent Yorgey Compat version of readProcessWithExitCode
* Add a new module, Distribution.Client.Compat.Process, with a
  function readProcessWithExitCode.  Unlike the one from
  System.Process it always catches "does not exist" errors and turns
  them into ExitFailures.

* Change all calls to readProcessWithExitCode to use the new version.

* Fixes #1613.
e2c7ce0
@23Skidoo
Collaborator

LGTM.

@23Skidoo
Collaborator

We're not using readProcessWithExitCode in the Cabal lib itself, correct?

@23Skidoo 23Skidoo merged commit d9817fe into from
@23Skidoo
Collaborator

Merged, thanks!

@byorgey
Collaborator

@23Skidoo Correct, we don't use it in the Cabal lib itself.

@byorgey byorgey deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 22, 2013
  1. Compat version of readProcessWithExitCode

    Brent Yorgey authored
    * Add a new module, Distribution.Client.Compat.Process, with a
      function readProcessWithExitCode.  Unlike the one from
      System.Process it always catches "does not exist" errors and turns
      them into ExitFailures.
    
    * Change all calls to readProcessWithExitCode to use the new version.
    
    * Fixes #1613.
This page is out of date. Refresh to see the latest.
View
43 cabal-install/Distribution/Client/Compat/Process.hs
@@ -0,0 +1,43 @@
+
+-----------------------------------------------------------------------------
+-- |
+-- Module : Distribution.Client.Compat.Process
+-- Copyright : (c) 2013 Liu Hao, Brent Yorgey
+-- License : BSD-style (see the file LICENSE)
+--
+-- Maintainer : cabal-devel@haskell.org
+-- Stability : provisional
+-- Portability : portable
+--
+-- Cross-platform utilities for invoking processes.
+--
+-----------------------------------------------------------------------------
+
+module Distribution.Client.Compat.Process (
+ readProcessWithExitCode
+) where
+
+import Control.Exception (catch, throw)
+import System.Exit (ExitCode (ExitFailure))
+import System.IO.Error (isDoesNotExistError)
+import qualified System.Process as P
+
+-- | @readProcessWithExitCode@ creates an external process, reads its
+-- standard output and standard error strictly, waits until the
+-- process terminates, and then returns the @ExitCode@ of the
+-- process, the standard output, and the standard error.
+--
+-- See the documentation of the version from @System.Process@ for
+-- more information.
+--
+-- The version from @System.Process@ behaves inconsistently across
+-- platforms when an executable with the given name is not found: in
+-- some cases it returns an @ExitFailure@, in others it throws an
+-- exception. This variant catches \"does not exist\" exceptions and
+-- turns them into @ExitFailure@s.
+readProcessWithExitCode :: FilePath -> [String] -> String -> IO (ExitCode, String, String)
+readProcessWithExitCode cmd args input =
+ P.readProcessWithExitCode cmd args input
+ `catch` \e -> if isDoesNotExistError e
+ then return (ExitFailure 127, "", "")
+ else throw e
View
4 cabal-install/Distribution/Client/Get.hs
@@ -37,6 +37,8 @@ import Distribution.Client.FetchUtils
import qualified Distribution.Client.Tar as Tar (extractTarGzFile)
import Distribution.Client.IndexUtils as IndexUtils
( getSourcePackages )
+import Distribution.Client.Compat.Process
+ ( readProcessWithExitCode )
import Distribution.Compat.Exception
( catchIO )
@@ -62,7 +64,7 @@ import System.Exit
import System.FilePath
( (</>), (<.>), addTrailingPathSeparator )
import System.Process
- ( rawSystem, readProcessWithExitCode )
+ ( rawSystem )
-- | Entry point for the 'cabal get' command.
View
3  cabal-install/Distribution/Client/Init/Heuristics.hs
@@ -46,7 +46,8 @@ import System.Directory ( getDirectoryContents,
import Distribution.Compat.Environment ( getEnvironment )
import System.FilePath ( takeExtension, takeBaseName, dropExtension,
(</>), (<.>), splitDirectories, makeRelative )
-import System.Process ( readProcessWithExitCode )
+
+import Distribution.Client.Compat.Process ( readProcessWithExitCode )
import System.Exit ( ExitCode(..) )
-- |Guess the package name based on the given root directory
View
1  cabal-install/cabal-install.cabal
@@ -109,6 +109,7 @@ executable cabal
Distribution.Client.Compat.Environment
Distribution.Client.Compat.ExecutablePath
Distribution.Client.Compat.FilePerms
+ Distribution.Client.Compat.Process
Distribution.Client.Compat.Semaphore
Distribution.Client.Compat.Time
Paths_cabal_install
Something went wrong with that request. Please try again.