Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

guess-ghc-version: Integrate GHC guessing into 'hackport merge'

hackport will now attempt to guess which minimum ghc version is required to
compile packages merged. If it fails it will use the default GHC dependency.
It looks at all the dependencies, trying to identify all core packages used.
As we don't allow upgrading of core packages, using this information we can
sometimes make the dependency to ghc stricter.
Also, hackport will not generate dependencies to cabal which are lower than
what was shipped with the GHC version hackport knows the package requires.
  • Loading branch information...
commit 4f6ec6f5a12cd1888d345e3b13fd90aea28f9dc2 1 parent 86377c5
@kolmodin kolmodin authored
View
6 Cabal2Ebuild.hs
@@ -24,8 +24,7 @@
module Cabal2Ebuild
(cabal2ebuild
,convertDependencies
- ,convertDependency
- ,default_ghc_dependency) where
+ ,convertDependency) where
import qualified Distribution.PackageDescription as Cabal
(PackageDescription(..))
@@ -43,9 +42,6 @@ import qualified Portage.EBuild as Portage
import qualified Portage.EBuild as E
import Portage.Version
-default_ghc_dependency :: Dependency
-default_ghc_dependency = OrLaterVersionOf (Version [6,8,1] Nothing [] 0) (Portage.mkPackageName "dev-lang" "ghc")
-
cabal2ebuild :: Cabal.PackageDescription -> Portage.EBuild
cabal2ebuild pkg = Portage.ebuildTemplate {
E.name = map toLower cabalPkgName,
View
2  Main-GuessGHC.hs
@@ -24,4 +24,4 @@ guess gpd = do
putStr "\t\t"
putStrLn $ case mghc of
Nothing -> "Unknown"
- Just v -> display v
+ Just (compiler, _pkgs) -> display compiler
View
10 Merge.hs
@@ -46,6 +46,8 @@ import qualified Portage.Host as Host
import qualified Portage.Overlay as Overlay
import qualified Portage.Resolve as Portage
+import qualified Portage.GHCCore as GHCCore
+
import qualified Merge.Dependencies as Merge
import Debug.Trace ( trace )
@@ -155,13 +157,17 @@ merge verbosity repo serverURI args overlayPath = do
(\dep -> trace ("accepting dep(?): " ++ display dep) True)
-- (Nothing :: Maybe (Index.PackageIndex PackageIdentifier))
buildPlatform
- (CompilerId GHC (Cabal.Version [6,12,3] []))
+ (fst GHCCore.defaultGHC)
[] pkgGenericDesc
+
+ (compilerId, excludePkgs) = maybe GHCCore.defaultGHC id (GHCCore.minimumGHCVersionToBuildPackage pkgGenericDesc)
+
pkgDesc = let deps = [ Dependency pn (Cabal.simplifyVersionRange vr)
| Dependency pn vr <- buildDepends pkgDesc0
+ , pn `notElem` excludePkgs
]
in pkgDesc0 { buildDepends = deps }
- edeps = Merge.resolveDependencies pkgDesc
+ edeps = Merge.resolveDependencies pkgDesc (Just compilerId)
debug verbosity ("Selected flags: " ++ show flags)
View
44 Merge/Dependencies.hs
@@ -58,11 +58,16 @@ import Data.Maybe ( isNothing )
import Data.List ( nub )
import qualified Distribution.Package as Cabal
+import qualified Distribution.Version as Cabal
+import Distribution.Compiler
+import qualified Portage.Version as Portage
import qualified Portage.PackageId as Portage
import qualified Portage.Dependency as Portage
import qualified Cabal2Ebuild as C2E
+import qualified Portage.GHCCore as GHCCore
+
import Debug.Trace ( trace )
-- | Dependencies of an ebuild
@@ -83,8 +88,8 @@ emptyEDep = EDep
dep_e = []
}
-resolveDependencies :: PackageDescription -> EDep
-resolveDependencies pkg =
+resolveDependencies :: PackageDescription -> Maybe CompilerId -> EDep
+resolveDependencies pkg mcompiler =
edeps
{
dep = Portage.simplify_deps ( dep edeps),
@@ -93,11 +98,13 @@ resolveDependencies pkg =
-- version as in dep
}
where
+ compiler = maybe (fst GHCCore.defaultGHC) id mcompiler
+
hasBuildableExes p = any (buildable . buildInfo) . executables $ p
treatAsLibrary = (not . hasBuildableExes) pkg || hasLibs pkg
haskell_deps = haskellDependencies pkg
- cabal_dep = cabalDependency pkg
- ghc_dep = ghcDependency pkg
+ cabal_dep = cabalDependency pkg compiler
+ ghc_dep = compilerIdToDependency compiler
extra_libs = findCLibs pkg
build_tools = buildToolsDependencies pkg
pkg_config = pkgConfigDependencies pkg
@@ -122,6 +129,7 @@ resolveDependencies pkg =
rdep = extra_libs ++ pkg_config
}
+
---------------------------------------------------------------
-- Haskell packages
---------------------------------------------------------------
@@ -135,19 +143,34 @@ haskellDependencies pkg =
-- Cabal Dependency
---------------------------------------------------------------
-cabalDependency :: PackageDescription -> Portage.Dependency
-cabalDependency pkg =
+-- | Select the most restrictive dependency on Cabal, either the .cabal
+-- file's descCabalVersion, or the Cabal GHC shipped with.
+cabalDependency :: PackageDescription -> CompilerId -> Portage.Dependency
+cabalDependency pkg (CompilerId GHC ghcVersion@(Cabal.Version versionNumbers _)) =
head $ C2E.convertDependency (Portage.Category "dev-haskell")
(Cabal.Dependency (Cabal.PackageName "Cabal")
- (descCabalVersion pkg))
+ finalCabalDep)
+ where
+ userCabalVersion = descCabalVersion pkg
+ shippedCabalVersion = GHCCore.cabalFromGHC versionNumbers
+ shippedCabalDep = maybe Cabal.anyVersion
+ (\shipped -> Cabal.intersectVersionRanges
+ (Cabal.thisVersion shipped)
+ (Cabal.laterVersion shipped))
+ shippedCabalVersion
+ finalCabalDep = Cabal.simplifyVersionRange
+ (Cabal.intersectVersionRanges
+ userCabalVersion
+ shippedCabalDep)
---------------------------------------------------------------
-- GHC Dependency
---------------------------------------------------------------
-ghcDependency :: PackageDescription -> Portage.Dependency
-ghcDependency _pkg = C2E.default_ghc_dependency
-
+compilerIdToDependency :: CompilerId -> Portage.Dependency
+compilerIdToDependency (CompilerId GHC versionNumbers) =
+ Portage.OrLaterVersionOf (Portage.fromCabalVersion versionNumbers) (Portage.mkPackageName "dev-lang" "ghc")
+
---------------------------------------------------------------
-- C Libraries
---------------------------------------------------------------
@@ -166,7 +189,6 @@ findCLibs (PackageDescription { library = lib, executables = exes }) =
notFound = [ p | p <- allE, isNothing (staticTranslateExtraLib p) ]
found = [ p | Just p <- map staticTranslateExtraLib allE ]
-
staticTranslateExtraLib :: String -> Maybe Portage.Dependency
staticTranslateExtraLib lib = lookup lib m
View
40 Portage/GHCCore.hs
@@ -1,6 +1,10 @@
-- Guess GHC version from packages depended upon.
-module Portage.GHCCore (minimumGHCVersionToBuildPackage) where
+module Portage.GHCCore
+ ( minimumGHCVersionToBuildPackage
+ , cabalFromGHC
+ , defaultGHC
+ ) where
import Distribution.Package
import Distribution.Version
@@ -15,13 +19,33 @@ import Distribution.System
import Distribution.Text
import Data.Maybe
-import Data.Monoid
+import Data.List ( nub )
import Text.PrettyPrint.HughesPJ
+defaultGHC :: (CompilerId, [PackageName])
+defaultGHC = let (g,pix) = ghc6123 in (g, packageNamesFromPackageIndex pix)
+
ghcs :: [(CompilerId, PackageIndex)]
ghcs = [ghc682, ghc6101, ghc6104, ghc6121, ghc6122, ghc6123]
+cabalFromGHC :: [Int] -> Maybe Version
+cabalFromGHC ver = lookup ver table
+ where
+ table = [([6,6,0], Version [1,1,6] [])
+ ,([6,6,1], Version [1,1,6,2] [])
+ ,([6,8,1], Version [1,2,2,0] [])
+ ,([6,8,2], Version [1,2,3,0] [])
+ ,([6,8,3], Version [1,2,4,0] [])
+ ,([6,10,1], Version [1,6,0,1] [])
+ ,([6,10,2], Version [1,6,0,3] [])
+ ,([6,10,3], Version [1,6,0,3] [])
+ ,([6,10,4], Version [1,6,0,3] [])
+ ,([6,12,1], Version [1,8,0,2] [])
+ ,([6,12,2], Version [1,8,0,4] [])
+ ,([6,12,3], Version [1,8,0,6] [])
+ ]
+
platform :: Platform
platform = Platform X86_64 Linux
@@ -49,9 +73,13 @@ packageBuildableWithGHCVersion
packageBuildableWithGHCVersion pkg (compiler, pkgIndex) =
finalizePackageDescription [] (dependencySatisfiable pkgIndex) platform compiler [] pkg
-minimumGHCVersionToBuildPackage :: GenericPackageDescription -> Maybe CompilerId
+-- | Given a 'GenericPackageDescription' it returns the miminum GHC version
+-- to build a package, and a list of core packages to that GHC version.
+minimumGHCVersionToBuildPackage :: GenericPackageDescription -> Maybe (CompilerId, [PackageName])
minimumGHCVersionToBuildPackage gpd =
- listToMaybe [ cid | g@(cid, pix) <- ghcs, Right _ <- return (packageBuildableWithGHCVersion gpd g)]
+ listToMaybe [ (cid, packageNamesFromPackageIndex pix)
+ | g@(cid, pix) <- ghcs
+ , Right _ <- return (packageBuildableWithGHCVersion gpd g)]
mkIndex :: [PackageIdentifier] -> PackageIndex
mkIndex pids = fromList
@@ -62,6 +90,10 @@ mkIndex pids = fromList
}
| pi@(PackageIdentifier name version) <- pids ]
+packageNamesFromPackageIndex :: PackageIndex -> [PackageName]
+packageNamesFromPackageIndex pix = nub $
+ [ (pkgName . sourcePackageId) p | (p:_) <- allPackagesByName pix ]
+
ghc :: [Int] -> CompilerId
ghc nrs = CompilerId GHC (Version nrs [])
Please sign in to comment.
Something went wrong with that request. Please try again.