Skip to content

Commit

Permalink
Merge branch 'master' of github.com:haskell/cabal
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Lynagh committed Oct 3, 2012
2 parents 8c46dbf + b7565f9 commit e9a826a
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 53 deletions.
7 changes: 4 additions & 3 deletions cabal-install/Distribution/Client/Configure.hs
Expand Up @@ -82,7 +82,7 @@ configure verbosity packageDBs repos comp conf
configureCommand (const configFlags) extraArgs configureCommand (const configFlags) extraArgs


Right installPlan -> case InstallPlan.ready installPlan of Right installPlan -> case InstallPlan.ready installPlan of
[pkg@(ConfiguredPackage (SourcePackage _ _ (LocalUnpackedPackage _)) _ _ _)] -> [pkg@(ConfiguredPackage (SourcePackage _ _ (LocalUnpackedPackage _) _) _ _ _)] ->
configurePackage verbosity configurePackage verbosity
(InstallPlan.planPlatform installPlan) (InstallPlan.planPlatform installPlan)
(InstallPlan.planCompiler installPlan) (InstallPlan.planCompiler installPlan)
Expand Down Expand Up @@ -138,7 +138,8 @@ planLocalPackage verbosity comp configFlags configExFlags installedPkgIndex
localPkg = SourcePackage { localPkg = SourcePackage {
packageInfoId = packageId pkg, packageInfoId = packageId pkg,
Source.packageDescription = pkg, Source.packageDescription = pkg,
packageSource = LocalUnpackedPackage "." packageSource = LocalUnpackedPackage ".",
packageDescrOverride = Nothing
} }


testsEnabled = fromFlagOrDefault False $ configTests configFlags testsEnabled = fromFlagOrDefault False $ configTests configFlags
Expand Down Expand Up @@ -194,7 +195,7 @@ configurePackage :: Verbosity
-> [String] -> [String]
-> IO () -> IO ()
configurePackage verbosity platform comp scriptOptions configFlags configurePackage verbosity platform comp scriptOptions configFlags
(ConfiguredPackage (SourcePackage _ gpkg _) flags stanzas deps) extraArgs = (ConfiguredPackage (SourcePackage _ gpkg _ _) flags stanzas deps) extraArgs =


setupWrapper verbosity setupWrapper verbosity
scriptOptions (Just pkg) configureCommand configureFlags extraArgs scriptOptions (Just pkg) configureCommand configureFlags extraArgs
Expand Down
Expand Up @@ -92,7 +92,7 @@ convSPI os arch cid = mkIndex . convSPI' os arch cid


-- | Convert a single source package into the solver-specific format. -- | Convert a single source package into the solver-specific format.
convSP :: OS -> Arch -> CompilerId -> SourcePackage -> (PN, I, PInfo) convSP :: OS -> Arch -> CompilerId -> SourcePackage -> (PN, I, PInfo)
convSP os arch cid (SourcePackage (PackageIdentifier pn pv) gpd _pl) = convSP os arch cid (SourcePackage (PackageIdentifier pn pv) gpd _ _pl) =
let i = I pv InRepo let i = I pv InRepo
in (pn, i, convGPD os arch cid (PI pn i) gpd) in (pn, i, convGPD os arch cid (PI pn i) gpd)


Expand Down
8 changes: 4 additions & 4 deletions cabal-install/Distribution/Client/Dependency/TopDown.hs
Expand Up @@ -368,7 +368,7 @@ pruneBottomUp platform comp constraints =
[ (dep, Constraints.conflicting cs dep) [ (dep, Constraints.conflicting cs dep)
| dep <- missing ] | dep <- missing ]


configure cs (UnconfiguredPackage (SourcePackage _ pkg _) _ flags stanzas) = configure cs (UnconfiguredPackage (SourcePackage _ pkg _ _) _ flags stanzas) =
finalizePackageDescription flags (dependencySatisfiable cs) finalizePackageDescription flags (dependencySatisfiable cs)
platform comp [] (enableStanzas stanzas pkg) platform comp [] (enableStanzas stanzas pkg)
dependencySatisfiable cs = dependencySatisfiable cs =
Expand Down Expand Up @@ -397,7 +397,7 @@ configurePackage platform comp available spkg = case spkg of
InstalledAndSource ipkg apkg -> fmap (InstalledAndSource ipkg) InstalledAndSource ipkg apkg -> fmap (InstalledAndSource ipkg)
(configure apkg) (configure apkg)
where where
configure (UnconfiguredPackage apkg@(SourcePackage _ p _) _ flags stanzas) = configure (UnconfiguredPackage apkg@(SourcePackage _ p _ _) _ flags stanzas) =
case finalizePackageDescription flags dependencySatisfiable case finalizePackageDescription flags dependencySatisfiable
platform comp [] (enableStanzas stanzas p) of platform comp [] (enableStanzas stanzas p) of
Left missing -> Left missing Left missing -> Left missing
Expand Down Expand Up @@ -481,7 +481,7 @@ topologicalSortNumbering installedPkgIndex sourcePkgIndex =
++ [ ((), packageName pkg, nub deps) ++ [ ((), packageName pkg, nub deps)
| pkgs@(pkg:_) <- PackageIndex.allPackagesByName sourcePkgIndex | pkgs@(pkg:_) <- PackageIndex.allPackagesByName sourcePkgIndex
, let deps = [ depName , let deps = [ depName
| SourcePackage _ pkg' _ <- pkgs | SourcePackage _ pkg' _ _ <- pkgs
, Dependency depName _ <- , Dependency depName _ <-
buildDepends (flattenPackageDescription pkg') ] ] buildDepends (flattenPackageDescription pkg') ] ]


Expand Down Expand Up @@ -517,7 +517,7 @@ selectNeededSubset installedPkgIndex sourcePkgIndex = select mempty mempty
| pkg <- moreInstalled | pkg <- moreInstalled
, dep <- depends pkg ] , dep <- depends pkg ]
++ [ name ++ [ name
| SourcePackage _ pkg _ <- moreSource | SourcePackage _ pkg _ _ <- moreSource
, Dependency name _ <- , Dependency name _ <-
buildDepends (flattenPackageDescription pkg) ] buildDepends (flattenPackageDescription pkg) ]
installedPkgIndex'' = foldl' (flip PackageIndex.insert) installedPkgIndex'' = foldl' (flip PackageIndex.insert)
Expand Down
36 changes: 20 additions & 16 deletions cabal-install/Distribution/Client/IndexUtils.hs
Expand Up @@ -175,8 +175,11 @@ readRepoIndex verbosity repo =
packageInfoId = pkgid, packageInfoId = pkgid,
packageDescription = packageDesc pkgEntry, packageDescription = packageDesc pkgEntry,
packageSource = case pkgEntry of packageSource = case pkgEntry of
NormalPackage _ _ _ -> RepoTarballPackage repo pkgid Nothing NormalPackage _ _ _ _ -> RepoTarballPackage repo pkgid Nothing
BuildTreeRef _ path _ _ -> LocalUnpackedPackage path BuildTreeRef _ _ path _ -> LocalUnpackedPackage path,
packageDescrOverride = case pkgEntry of
NormalPackage _ _ pkgtxt _ -> Just pkgtxt
_ -> Nothing
} }
where where
pkgid = packageId pkgEntry pkgid = packageId pkgEntry
Expand Down Expand Up @@ -231,19 +234,18 @@ whenCacheOutOfDate origFile cacheFile action = do
-- --


-- | An index entry is either a normal package, or a local build tree reference. -- | An index entry is either a normal package, or a local build tree reference.
data PackageEntry = NormalPackage PackageId GenericPackageDescription BlockNo data PackageEntry = NormalPackage PackageId GenericPackageDescription ByteString BlockNo
| BuildTreeRef PackageId FilePath GenericPackageDescription | BuildTreeRef PackageId GenericPackageDescription FilePath BlockNo
BlockNo


type MkPackageEntry = IO PackageEntry type MkPackageEntry = IO PackageEntry


instance Package PackageEntry where instance Package PackageEntry where
packageId (NormalPackage pkgid _ _ ) = pkgid packageId (NormalPackage pkgid _ _ _) = pkgid
packageId (BuildTreeRef pkgid _ _ _ ) = pkgid packageId (BuildTreeRef pkgid _ _ _) = pkgid


packageDesc :: PackageEntry -> GenericPackageDescription packageDesc :: PackageEntry -> GenericPackageDescription
packageDesc (NormalPackage _ descr _ ) = descr packageDesc (NormalPackage _ descr _ _) = descr
packageDesc (BuildTreeRef _ _ descr _ ) = descr packageDesc (BuildTreeRef _ descr _ _) = descr


-- | Read a compressed \"00-index.tar.gz\" file into a 'PackageIndex'. -- | Read a compressed \"00-index.tar.gz\" file into a 'PackageIndex'.
-- --
Expand Down Expand Up @@ -302,7 +304,7 @@ extractPkg entry blockNo = case Tar.entryContent entry of
| takeExtension fileName == ".cabal" | takeExtension fileName == ".cabal"
-> case splitDirectories (normalise fileName) of -> case splitDirectories (normalise fileName) of
[pkgname,vers,_] -> case simpleParse vers of [pkgname,vers,_] -> case simpleParse vers of
Just ver -> Just $ return (NormalPackage pkgid descr blockNo) Just ver -> Just $ return (NormalPackage pkgid descr content blockNo)
where where
pkgid = PackageIdentifier (PackageName pkgname) ver pkgid = PackageIdentifier (PackageName pkgname) ver
parsed = parsePackageDescription . fromUTF8 . BS.Char8.unpack parsed = parsePackageDescription . fromUTF8 . BS.Char8.unpack
Expand All @@ -320,7 +322,7 @@ extractPkg entry blockNo = case Tar.entryContent entry of
let path = byteStringToFilePath content let path = byteStringToFilePath content
cabalFile <- findPackageDesc path cabalFile <- findPackageDesc path
descr <- PackageDesc.Parse.readPackageDescription normal cabalFile descr <- PackageDesc.Parse.readPackageDescription normal cabalFile
return $ BuildTreeRef (packageId descr) path descr blockNo return $ BuildTreeRef (packageId descr) descr path blockNo


_ -> Nothing _ -> Nothing


Expand Down Expand Up @@ -358,7 +360,7 @@ updatePackageIndexCacheFile indexFile cacheFile = do
mkCache pkgs prefs = mkCache pkgs prefs =
[ CachePreference pref | pref <- prefs ] [ CachePreference pref | pref <- prefs ]
++ [ CachePackageId pkgid blockNo ++ [ CachePackageId pkgid blockNo
| (NormalPackage pkgid _ blockNo) <- pkgs ] | (NormalPackage pkgid _ _ blockNo) <- pkgs ]
++ [ CacheBuildTreeRef blockNo ++ [ CacheBuildTreeRef blockNo
| (BuildTreeRef _ _ _ blockNo) <- pkgs] | (BuildTreeRef _ _ _ blockNo) <- pkgs]


Expand Down Expand Up @@ -392,9 +394,11 @@ packageIndexFromCache mkPkg hnd = accum mempty []
-- The magic here is that we use lazy IO to read the .cabal file -- The magic here is that we use lazy IO to read the .cabal file
-- from the index tarball if it turns out that we need it. -- from the index tarball if it turns out that we need it.
-- Most of the time we only need the package id. -- Most of the time we only need the package id.
pkg <- unsafeInterleaveIO $ do ~(pkg, pkgtxt) <- unsafeInterleaveIO $ do
getEntryContent blockno >>= readPackageDescription pkgtxt <- getEntryContent blockno
let srcpkg = mkPkg (NormalPackage pkgid pkg blockno) pkg <- readPackageDescription pkgtxt
return (pkg, pkgtxt)
let srcpkg = mkPkg (NormalPackage pkgid pkg pkgtxt blockno)
accum (srcpkg:srcpkgs) prefs entries accum (srcpkg:srcpkgs) prefs entries


accum srcpkgs prefs (CacheBuildTreeRef blockno : entries) = do accum srcpkgs prefs (CacheBuildTreeRef blockno : entries) = do
Expand All @@ -404,7 +408,7 @@ packageIndexFromCache mkPkg hnd = accum mempty []
path <- liftM byteStringToFilePath . getEntryContent $ blockno path <- liftM byteStringToFilePath . getEntryContent $ blockno
pkg <- do cabalFile <- findPackageDesc path pkg <- do cabalFile <- findPackageDesc path
PackageDesc.Parse.readPackageDescription normal cabalFile PackageDesc.Parse.readPackageDescription normal cabalFile
let srcpkg = mkPkg (BuildTreeRef (packageId pkg) path pkg blockno) let srcpkg = mkPkg (BuildTreeRef (packageId pkg) pkg path blockno)
accum (srcpkg:srcpkgs) prefs entries accum (srcpkg:srcpkgs) prefs entries


accum srcpkgs prefs (CachePreference pref : entries) = accum srcpkgs prefs (CachePreference pref : entries) =
Expand Down
27 changes: 20 additions & 7 deletions cabal-install/Distribution/Client/Install.hs
Expand Up @@ -96,7 +96,7 @@ import qualified Distribution.Simple.Setup as Cabal
( installCommand, InstallFlags(..), emptyInstallFlags ( installCommand, InstallFlags(..), emptyInstallFlags
, emptyTestFlags, testCommand, Flag(..) ) , emptyTestFlags, testCommand, Flag(..) )
import Distribution.Simple.Utils import Distribution.Simple.Utils
( rawSystemExit, comparing ) ( rawSystemExit, comparing, writeFileAtomic )
import Distribution.Simple.InstallDirs as InstallDirs import Distribution.Simple.InstallDirs as InstallDirs
( PathTemplate, fromPathTemplate, toPathTemplate, substPathTemplate ( PathTemplate, fromPathTemplate, toPathTemplate, substPathTemplate
, initialPathTemplateEnv, installDirsTemplateEnv ) , initialPathTemplateEnv, installDirsTemplateEnv )
Expand Down Expand Up @@ -781,13 +781,13 @@ performInstallations verbosity


executeInstallPlan verbosity jobControl useLogFile installPlan $ \cpkg -> executeInstallPlan verbosity jobControl useLogFile installPlan $ \cpkg ->
installConfiguredPackage platform compid configFlags installConfiguredPackage platform compid configFlags
cpkg $ \configFlags' src pkg -> cpkg $ \configFlags' src pkg pkgoverride ->
fetchSourcePackage verbosity fetchLimit src $ \src' -> fetchSourcePackage verbosity fetchLimit src $ \src' ->
installLocalPackage verbosity buildLimit (packageId pkg) src' $ \mpath -> installLocalPackage verbosity buildLimit (packageId pkg) src' $ \mpath ->
installUnpackedPackage verbosity buildLimit installLock numJobs installUnpackedPackage verbosity buildLimit installLock numJobs
(setupScriptOptions installedPkgIndex cacheLock) (setupScriptOptions installedPkgIndex cacheLock)
miscOptions configFlags' installFlags haddockFlags miscOptions configFlags' installFlags haddockFlags
compid pkg mpath useLogFile compid pkg pkgoverride mpath useLogFile


where where
platform = InstallPlan.planPlatform installPlan platform = InstallPlan.planPlatform installPlan
Expand Down Expand Up @@ -956,16 +956,17 @@ executeInstallPlan verbosity jobCtl useLogFile plan0 installPkg =
installConfiguredPackage :: Platform -> CompilerId installConfiguredPackage :: Platform -> CompilerId
-> ConfigFlags -> ConfiguredPackage -> ConfigFlags -> ConfiguredPackage
-> (ConfigFlags -> PackageLocation (Maybe FilePath) -> (ConfigFlags -> PackageLocation (Maybe FilePath)
-> PackageDescription -> a) -> PackageDescription
-> PackageDescriptionOverride -> a)
-> a -> a
installConfiguredPackage platform comp configFlags installConfiguredPackage platform comp configFlags
(ConfiguredPackage (SourcePackage _ gpkg source) flags stanzas deps) (ConfiguredPackage (SourcePackage _ gpkg source pkgoverride) flags stanzas deps)
installPkg = installPkg configFlags { installPkg = installPkg configFlags {
configConfigurationsFlags = flags, configConfigurationsFlags = flags,
configConstraints = map thisPackageVersion deps, configConstraints = map thisPackageVersion deps,
configBenchmarks = toFlag False, configBenchmarks = toFlag False,
configTests = toFlag (TestStanzas `elem` stanzas) configTests = toFlag (TestStanzas `elem` stanzas)
} source pkg } source pkg pkgoverride
where where
pkg = case finalizePackageDescription flags pkg = case finalizePackageDescription flags
(const True) (const True)
Expand Down Expand Up @@ -1051,13 +1052,25 @@ installUnpackedPackage
-> HaddockFlags -> HaddockFlags
-> CompilerId -> CompilerId
-> PackageDescription -> PackageDescription
-> PackageDescriptionOverride
-> Maybe FilePath -- ^ Directory to change to before starting the installation. -> Maybe FilePath -- ^ Directory to change to before starting the installation.
-> UseLogFile -- ^ File to log output to (if any) -> UseLogFile -- ^ File to log output to (if any)
-> IO BuildResult -> IO BuildResult
installUnpackedPackage verbosity buildLimit installLock numJobs installUnpackedPackage verbosity buildLimit installLock numJobs
scriptOptions miscOptions scriptOptions miscOptions
configFlags installConfigFlags haddockFlags configFlags installConfigFlags haddockFlags
compid pkg workingDir useLogFile = compid pkg pkgoverride workingDir useLogFile = do

-- Override the .cabal file if necessary
case pkgoverride of
Nothing -> return ()
Just pkgtxt -> do
let descFilePath = fromMaybe "." workingDir
</> display (packageName pkgid) <.> "cabal"
info verbosity $
"Updating " ++ display (packageName pkgid) <.> "cabal"
++ " with the latest revision from the index."
writeFileAtomic descFilePath pkgtxt


-- Configure phase -- Configure phase
onFailure ConfigureFailed $ withJobLimit buildLimit $ do onFailure ConfigureFailed $ withJobLimit buildLimit $ do
Expand Down
2 changes: 1 addition & 1 deletion cabal-install/Distribution/Client/InstallSymlink.hs
Expand Up @@ -133,7 +133,7 @@ symlinkBinaries configFlags installFlags plan =
, PackageDescription.buildable (PackageDescription.buildInfo exe) ] , PackageDescription.buildable (PackageDescription.buildInfo exe) ]


pkgDescription :: ConfiguredPackage -> PackageDescription pkgDescription :: ConfiguredPackage -> PackageDescription
pkgDescription (ConfiguredPackage (SourcePackage _ pkg _) flags stanzas _) = pkgDescription (ConfiguredPackage (SourcePackage _ pkg _ _) flags stanzas _) =
case finalizePackageDescription flags case finalizePackageDescription flags
(const True) (const True)
platform compilerId [] (enableStanzas stanzas pkg) of platform compilerId [] (enableStanzas stanzas pkg) of
Expand Down
17 changes: 13 additions & 4 deletions cabal-install/Distribution/Client/Setup.hs
Expand Up @@ -491,13 +491,15 @@ instance Monoid ReportFlags where


data UnpackFlags = UnpackFlags { data UnpackFlags = UnpackFlags {
unpackDestDir :: Flag FilePath, unpackDestDir :: Flag FilePath,
unpackVerbosity :: Flag Verbosity unpackVerbosity :: Flag Verbosity,
unpackPristine :: Flag Bool
} }


defaultUnpackFlags :: UnpackFlags defaultUnpackFlags :: UnpackFlags
defaultUnpackFlags = UnpackFlags { defaultUnpackFlags = UnpackFlags {
unpackDestDir = mempty, unpackDestDir = mempty,
unpackVerbosity = toFlag normal unpackVerbosity = toFlag normal,
unpackPristine = toFlag False
} }


unpackCommand :: CommandUI UnpackFlags unpackCommand :: CommandUI UnpackFlags
Expand All @@ -514,14 +516,21 @@ unpackCommand = CommandUI {
"where to unpack the packages, defaults to the current directory." "where to unpack the packages, defaults to the current directory."
unpackDestDir (\v flags -> flags { unpackDestDir = v }) unpackDestDir (\v flags -> flags { unpackDestDir = v })
(reqArgFlag "PATH") (reqArgFlag "PATH")

, option [] ["pristine"]
("Unpack the original pristine tarball, rather than updating the "
++ ".cabal file with the latest revision from the package archive.")
unpackPristine (\v flags -> flags { unpackPristine = v })
trueArg
] ]
} }


instance Monoid UnpackFlags where instance Monoid UnpackFlags where
mempty = defaultUnpackFlags mempty = defaultUnpackFlags
mappend a b = UnpackFlags { mappend a b = UnpackFlags {
unpackDestDir = combine unpackDestDir unpackDestDir = combine unpackDestDir,
,unpackVerbosity = combine unpackVerbosity unpackVerbosity = combine unpackVerbosity,
unpackPristine = combine unpackPristine
} }
where combine field = field a `mappend` field b where combine field = field a `mappend` field b


Expand Down
14 changes: 8 additions & 6 deletions cabal-install/Distribution/Client/Targets.hs
Expand Up @@ -472,9 +472,10 @@ readPackageTarget verbosity target = case target of
pkg <- readPackageDescription verbosity =<< findPackageDesc dir pkg <- readPackageDescription verbosity =<< findPackageDesc dir
return $ PackageTargetLocation $ return $ PackageTargetLocation $
SourcePackage { SourcePackage {
packageInfoId = packageId pkg, packageInfoId = packageId pkg,
packageDescription = pkg, packageDescription = pkg,
packageSource = fmap Just location packageSource = fmap Just location,
packageDescrOverride = Nothing
} }


LocalTarballPackage tarballFile -> LocalTarballPackage tarballFile ->
Expand All @@ -497,9 +498,10 @@ readPackageTarget verbosity target = case target of
Just pkg -> Just pkg ->
return $ PackageTargetLocation $ return $ PackageTargetLocation $
SourcePackage { SourcePackage {
packageInfoId = packageId pkg, packageInfoId = packageId pkg,
packageDescription = pkg, packageDescription = pkg,
packageSource = fmap Just location packageSource = fmap Just location,
packageDescrOverride = Nothing
} }


extractTarballPackageCabalFile :: FilePath -> String extractTarballPackageCabalFile :: FilePath -> String
Expand Down
12 changes: 9 additions & 3 deletions cabal-install/Distribution/Client/Types.hs
Expand Up @@ -29,6 +29,7 @@ import Distribution.Version


import Data.Map (Map) import Data.Map (Map)
import Network.URI (URI) import Network.URI (URI)
import Data.ByteString.Lazy (ByteString)
import Distribution.Compat.Exception import Distribution.Compat.Exception
( SomeException ) ( SomeException )


Expand Down Expand Up @@ -94,12 +95,17 @@ instance PackageFixedDeps ConfiguredPackage where
-- | A package description along with the location of the package sources. -- | A package description along with the location of the package sources.
-- --
data SourcePackage = SourcePackage { data SourcePackage = SourcePackage {
packageInfoId :: PackageId, packageInfoId :: PackageId,
packageDescription :: GenericPackageDescription, packageDescription :: GenericPackageDescription,
packageSource :: PackageLocation (Maybe FilePath) packageSource :: PackageLocation (Maybe FilePath),
packageDescrOverride :: PackageDescriptionOverride
} }
deriving Show deriving Show


-- | We sometimes need to override the .cabal file in the tarball with
-- the newer one from the package index.
type PackageDescriptionOverride = Maybe ByteString

instance Package SourcePackage where packageId = packageInfoId instance Package SourcePackage where packageId = packageInfoId


data OptionalStanza data OptionalStanza
Expand Down

0 comments on commit e9a826a

Please sign in to comment.