Skip to content

Commit

Permalink
Upgrade bundled cabal-install from 0.8.0 to 0.8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
kolmodin committed May 11, 2010
1 parent 8f3d97c commit 4b2a1d2
Show file tree
Hide file tree
Showing 43 changed files with 98 additions and 134 deletions.
18 changes: 9 additions & 9 deletions Merge.hs
Expand Up @@ -79,7 +79,7 @@ import Distribution.Simple.Utils
import Network.URI

import Distribution.Client.IndexUtils ( getAvailablePackages )
import Distribution.Client.Fetch ( downloadURI )
import Distribution.Client.HttpUtils ( downloadURI )
import qualified Distribution.Client.PackageIndex as Index
import Distribution.Client.Types

Expand Down Expand Up @@ -333,14 +333,14 @@ fetchAndDigest verbosity ebuildDir tarballName tarballURI =
withWorkingDirectory ebuildDir $ do
repo_info <- Host.getInfo
let tarDestination = (Host.distfiles_dir repo_info) </> tarballName
merr <- downloadURI verbosity tarDestination tarballURI
case merr of
Just err -> throwEx (E.DownloadFailed (show tarballURI) (show err))
Nothing -> do
notice verbosity $ "Saved to " ++ tarDestination
notice verbosity "Recalculating digests..."
_ <- system "repoman manifest"
return ()
downloadURI verbosity tarballURI tarDestination
-- Just err -> throwEx (E.DownloadFailed (show tarballURI) (show err))
-- TODO: downloadURI will throw a non-hackport exception if the
-- download fails
notice verbosity $ "Saved to " ++ tarDestination
notice verbosity "Recalculating digests..."
_ <- system "repoman manifest"
return ()

withWorkingDirectory :: FilePath -> IO a -> IO a
withWorkingDirectory newDir action = do
Expand Down
43 changes: 0 additions & 43 deletions cabal-install-0.8.0/Distribution/Compat/TempFile.hs

This file was deleted.

Expand Up @@ -27,7 +27,7 @@ module Distribution.Client.BuildReports.Anonymous (
) where

import Distribution.Client.Types
( ConfiguredPackage(..), BuildResult )
( ConfiguredPackage(..) )
import qualified Distribution.Client.Types as BR
( BuildResult, BuildFailure(..), BuildSuccess(..)
, DocsResult(..), TestsResult(..) )
Expand Down
Expand Up @@ -30,7 +30,7 @@ import Distribution.Client.Types
, AvailablePackageSource(..), Repo(..), RemoteRepo(..) )
import qualified Distribution.Client.InstallPlan as InstallPlan
import Distribution.Client.InstallPlan
( InstallPlan, PlanPackage )
( InstallPlan )

import Distribution.Simple.InstallDirs
( PathTemplate, fromPathTemplate
Expand Down
Expand Up @@ -15,7 +15,7 @@ module Distribution.Client.BuildReports.Types (
) where

import qualified Distribution.Text as Text
( Text(disp, parse) )
( Text(..) )

import qualified Distribution.Compat.ReadP as Parse
( pfail, munch1 )
Expand Down
Expand Up @@ -62,8 +62,6 @@ import Distribution.Simple.Utils
( notice, warn, lowercase )
import Distribution.Compiler
( CompilerFlavor(..), defaultCompilerFlavor )
import Distribution.System
( OS(Windows), buildOS )
import Distribution.Verbosity
( Verbosity, normal )

Expand Down Expand Up @@ -212,11 +210,9 @@ defaultCompiler :: CompilerFlavor
defaultCompiler = fromMaybe GHC defaultCompilerFlavor

defaultUserInstall :: Bool
defaultUserInstall = case buildOS of
-- We do global installs by default on Windows
Windows -> False
-- and per-user installs by default everywhere else
_ -> True
defaultUserInstall = True
-- We do per-user installs by default on all platforms. We used to default to
-- global installs on Windows but that no longer works on Windows Vista or 7.

defaultRemoteRepo :: RemoteRepo
defaultRemoteRepo = RemoteRepo name uri
Expand Down
Expand Up @@ -32,10 +32,12 @@ import qualified Distribution.Client.PackageIndex as PackageIndex
import Distribution.Client.PackageIndex (PackageIndex)
import Distribution.Package
( PackageName(..), PackageIdentifier, Package(packageId), packageVersion, packageName
, Dependency(Dependency), thisPackageVersion {- , notThisPackageVersion -}
, Dependency(Dependency), thisPackageVersion, notThisPackageVersion
, PackageFixedDeps(depends) )
import Distribution.PackageDescription
( PackageDescription(buildDepends) )
import Distribution.Client.PackageUtils
( externalBuildDepends )
import Distribution.PackageDescription.Configuration
( finalizePackageDescription, flattenPackageDescription )
import Distribution.Version
Expand Down Expand Up @@ -301,7 +303,7 @@ configurePackage platform comp available spkg = case spkg of
platform comp [] p of
Left missing -> Left missing
Right (pkg, flags') -> Right $
SemiConfiguredPackage apkg flags' (buildDepends pkg)
SemiConfiguredPackage apkg flags' (externalBuildDepends pkg)

dependencySatisfiable = not . null . PackageIndex.lookupDependency available

Expand Down Expand Up @@ -565,7 +567,6 @@ addPackageSelectConstraint pkgid constraints =
dep = TaggedDependency NoInstalledConstraint (thisPackageVersion pkgid)
reason = SelectedOther pkgid

{-
addPackageExcludeConstraint :: PackageIdentifier -> Constraints
-> Satisfiable Constraints
[PackageIdentifier] ExclusionReason
Expand All @@ -575,7 +576,6 @@ addPackageExcludeConstraint pkgid constraints =
dep = TaggedDependency NoInstalledConstraint
(notThisPackageVersion pkgid)
reason = ExcludedByConfigureFail
-}

addPackageDependencyConstraint :: PackageIdentifier -> TaggedDependency -> Constraints
-> Satisfiable Constraints
Expand Down
Expand Up @@ -19,7 +19,6 @@ module Distribution.Client.Fetch (
fetchPackage,
isFetched,
downloadIndex,
downloadURI
) where

import Distribution.Client.Types
Expand All @@ -37,7 +36,8 @@ import Distribution.Client.IndexUtils as IndexUtils
( getAvailablePackages, disambiguateDependencies
, getInstalledPackages )
import qualified Distribution.Client.InstallPlan as InstallPlan
import Distribution.Client.HttpUtils (getHTTP, isOldHackageURI)
import Distribution.Client.HttpUtils
( downloadURI, isOldHackageURI )

import Distribution.Package
( PackageIdentifier, packageName, packageVersion, Dependency(..) )
Expand All @@ -47,8 +47,7 @@ import Distribution.Simple.Compiler
import Distribution.Simple.Program
( ProgramConfiguration )
import Distribution.Simple.Utils
( die, notice, info, debug, setupMessage
, copyFileVerbose, writeFileAtomic )
( die, notice, info, debug, setupMessage )
import Distribution.System
( buildPlatform )
import Distribution.Text
Expand All @@ -57,7 +56,6 @@ import Distribution.Verbosity
( Verbosity )

import qualified Data.Map as Map
import qualified Data.ByteString.Lazy.Char8 as BS
import Control.Monad
( when, filterM )
import System.Directory
Expand All @@ -67,36 +65,8 @@ import System.FilePath
import qualified System.FilePath.Posix as FilePath.Posix
( combine, joinPath )
import Network.URI
( URI(uriPath, uriScheme) )
import Network.HTTP
( Response(..) )
import Network.Stream
( ConnError(..) )


downloadURI :: Verbosity
-> FilePath -- ^ Where to put it
-> URI -- ^ What to download
-> IO (Maybe ConnError)
downloadURI verbosity path uri | uriScheme uri == "file:" = do
copyFileVerbose verbosity (uriPath uri) path
return Nothing
downloadURI verbosity path uri = do
eitherResult <- getHTTP verbosity uri
case eitherResult of
Left err -> return (Just err)
Right rsp
| rspCode rsp == (2,0,0)
-> do info verbosity ("Downloaded to " ++ path)
writeFileAtomic path (BS.unpack $ rspBody rsp)
--FIXME: check the content-length header matches the body length.
--TODO: stream the download into the file rather than buffering the whole
-- thing in memory.
-- remember the ETag so we can not re-download if nothing changed.
>> return Nothing

| otherwise
-> return (Just (ErrorMisc ("Unsucessful HTTP code: " ++ show (rspCode rsp))))
( URI(uriPath) )


-- Downloads a package to [config-dir/packages/package-id] and returns the path to the package.
downloadPackage :: Verbosity -> Repo -> PackageIdentifier -> IO String
Expand All @@ -109,11 +79,8 @@ downloadPackage verbosity repo@Repo{ repoKind = Left remoteRepo } pkgid = do
path = packageFile repo pkgid
debug verbosity $ "GET " ++ show uri
createDirectoryIfMissing True dir
status <- downloadURI verbosity path uri
case status of
Just err -> die $ "Failed to download '" ++ display pkgid
++ "': " ++ show err
Nothing -> return path
downloadURI verbosity uri path
return path

-- Downloads an index file to [config-dir/packages/serv-id].
downloadIndex :: Verbosity -> RemoteRepo -> FilePath -> IO FilePath
Expand All @@ -124,10 +91,8 @@ downloadIndex verbosity repo cacheDir = do
}
path = cacheDir </> "00-index" <.> "tar.gz"
createDirectoryIfMissing True cacheDir
mbError <- downloadURI verbosity path uri
case mbError of
Just err -> die $ "Failed to download index '" ++ show err ++ "'"
Nothing -> return path
downloadURI verbosity uri path
return path

-- |Returns @True@ if the package has already been fetched.
isFetched :: AvailablePackage -> IO Bool
Expand Down
Expand Up @@ -16,12 +16,12 @@ module Distribution.Client.Haddock
)
where

import Data.Maybe (Maybe(..), listToMaybe)
import Data.Maybe (listToMaybe)
import Data.List (maximumBy)
import Control.Monad (Monad(return), sequence, guard)
import Control.Monad (guard)
import System.Directory (createDirectoryIfMissing, doesFileExist,
renameFile)
import System.FilePath (FilePath, (</>), splitFileName)
import System.FilePath ((</>), splitFileName)
import Distribution.Package (Package(..))
import Distribution.Simple.Program (haddockProgram, ProgramConfiguration
, rawSystemProgram, requireProgramVersion)
Expand Down
Expand Up @@ -2,20 +2,26 @@
-----------------------------------------------------------------------------
-- | Separate module for HTTP actions, using a proxy server if one exists
-----------------------------------------------------------------------------
module Distribution.Client.HttpUtils (getHTTP, proxy, isOldHackageURI) where
module Distribution.Client.HttpUtils (
downloadURI,
getHTTP,
proxy,
isOldHackageURI
) where

import Network.HTTP
( Request (..), Response (..), RequestMethod (..)
, Header(..), HeaderName(..) )
import Network.URI
( URI (..), URIAuth (..), parseAbsoluteURI )
import Network.Stream (Result)
import Network.Stream
( Result, ConnError(..) )
import Network.Browser
( Proxy (..), Authority (..), browse
, setOutHandler, setErrHandler, setProxy, request)
import Control.Monad
( mplus, join, liftM2 )
import qualified Data.ByteString.Lazy as ByteString
import qualified Data.ByteString.Lazy.Char8 as ByteString
import Data.ByteString.Lazy (ByteString)
#ifdef WIN32
import System.Win32.Types
Expand All @@ -34,7 +40,9 @@ import System.Environment (getEnvironment)

import qualified Paths_cabal_install (version)
import Distribution.Verbosity (Verbosity)
import Distribution.Simple.Utils (warn, debug)
import Distribution.Simple.Utils
( die, info, warn, debug
, copyFileVerbose, writeFileAtomic )
import Distribution.Text
( display )
import qualified System.FilePath.Posix as FilePath.Posix
Expand Down Expand Up @@ -92,6 +100,7 @@ proxy verbosity = do
warn verbosity $ "ignoring http proxy, trying a direct connection"
return NoProxy
Just p -> return p
--TODO: print info message when we're using a proxy

-- | We need to be able to parse non-URIs like @\"wwwcache.example.com:80\"@
-- which lack the @\"http://\"@ URI scheme. The problem is that
Expand Down Expand Up @@ -152,6 +161,33 @@ getHTTP verbosity uri = do
request req
return (Right resp)

downloadURI :: Verbosity
-> URI -- ^ What to download
-> FilePath -- ^ Where to put it
-> IO ()
downloadURI verbosity uri path | uriScheme uri == "file:" =
copyFileVerbose verbosity (uriPath uri) path
downloadURI verbosity uri path = do
result <- getHTTP verbosity uri
let result' = case result of
Left err -> Left err
Right rsp -> case rspCode rsp of
(2,0,0) -> Right (rspBody rsp)
(a,b,c) -> Left err
where
err = ErrorMisc $ "Unsucessful HTTP code: "
++ concatMap show [a,b,c]

case result' of
Left err -> die $ "Failed to download " ++ show uri ++ " : " ++ show err
Right body -> do
info verbosity ("Downloaded to " ++ path)
writeFileAtomic path (ByteString.unpack body)
--FIXME: check the content-length header matches the body length.
--TODO: stream the download into the file rather than buffering the whole
-- thing in memory.
-- remember the ETag so we can not re-download if nothing changed.

-- Utility function for legacy support.
isOldHackageURI :: URI -> Bool
isOldHackageURI uri
Expand Down
Expand Up @@ -375,8 +375,7 @@ writeSetupFile flags = do
writeFile "Setup.hs" setupFile
where
setupFile = unlines
[ "#!/usr/bin/env runhaskell"
, "import Distribution.Simple"
[ "import Distribution.Simple"
, "main = defaultMain"
]

Expand Down
Expand Up @@ -101,7 +101,7 @@ import Distribution.Simple.Utils
( defaultPackageDesc, rawSystemExit, comparing )
import Distribution.Simple.InstallDirs as InstallDirs
( PathTemplate, fromPathTemplate, toPathTemplate, substPathTemplate
, initialPathTemplateEnv, compilerTemplateEnv, installDirsTemplateEnv )
, initialPathTemplateEnv, installDirsTemplateEnv )
import Distribution.Package
( PackageName, PackageIdentifier, packageName, packageVersion
, Package(..), PackageFixedDeps(..)
Expand Down Expand Up @@ -558,7 +558,8 @@ printBuildFailures plan =
printFailureReason reason = case reason of
DependentFailed pkgid -> " depends on " ++ display pkgid
++ " which failed to install."
DownloadFailed _ -> " failed while downloading the package."
DownloadFailed e -> " failed while downloading the package."
++ " The exception was:\n " ++ show e
UnpackFailed e -> " failed while unpacking the package."
++ " The exception was:\n " ++ show e
ConfigureFailed e -> " failed during the configure step."
Expand Down

0 comments on commit 4b2a1d2

Please sign in to comment.