on master help sign in
Track multiple haskell-platform versions and determine GHC version
commitf90bccf74af0b1161b2a9186e42de8a41651d28f authorMichael Snoyman <michael@snoyman.com> dateSun 30 Jun 2013, 08:59 (13 years ago) parenta428d0e
10 files changed+86−55
.gitmodules−3 Stackage/Build.hs+3−3 Stackage/Config.hs+7−12 Stackage/GhcPkg.hs+15−10 Stackage/HaskellPlatform.hs+18−2 Stackage/InstallInfo.hs+14−9 Stackage/LoadDatabase.hs+6−2 Stackage/Select.hs+7−6 Stackage/Types.hs+6−1 app/stackage.hs+10−7
.gitmodulesdeleted−3
@@ -1,3 +0,0 @@
1−[submodule "haskell-platform"]
2− path = haskell-platform
3− url = https://github.com/haskell/haskell-platform.git
Stackage/Build.hs+3−3
@@ -18,10 +18,10 @@ import System.IO (BufferMode (NoBuffering),
1818import System.Process (rawSystem, runProcess,
1919 waitForProcess)
2020
21−defaultBuildSettings :: BuildSettings
22−defaultBuildSettings = BuildSettings
21+defaultBuildSettings :: GhcMajorVersion -> BuildSettings
22+defaultBuildSettings version = BuildSettings
2323 { sandboxRoot = "sandbox"
24− , expectedFailuresBuild = defaultExpectedFailures
24+ , expectedFailuresBuild = defaultExpectedFailures version
2525 , extraArgs = const ["-fnetwork23"]
2626 , testWorkerThreads = 4
2727 , buildDocs = True
Stackage/Config.hs+7−12
@@ -7,23 +7,18 @@ import Data.Set (fromList)
77import Distribution.Text (simpleParse)
88import Stackage.Types
99
10−targetCompilerVersion :: Version
11−targetCompilerVersion =
12− case simpleParse "7.4.2" of
13− Nothing -> error "Invalid targetCompilerVersion"
14− Just v -> v
15−
1610-- | Packages which are shipped with GHC but are not included in the
1711-- Haskell Platform list of core packages.
18−defaultExtraCore :: Set PackageName
19−defaultExtraCore = fromList $ map PackageName $ words
12+defaultExtraCore :: GhcMajorVersion -> Set PackageName
13+defaultExtraCore _ = fromList $ map PackageName $ words
2014 "binary Win32"
2115
2216-- | Test suites which are expected to fail for some reason. The test suite
2317-- will still be run and logs kept, but a failure will not indicate an
2418-- error in our package combination.
25−defaultExpectedFailures :: Set PackageName
26−defaultExpectedFailures = fromList $ map PackageName
19+defaultExpectedFailures :: GhcMajorVersion
20+ -> Set PackageName
21+defaultExpectedFailures _ = fromList $ map PackageName
2722 [ -- Requires an old version of WAI and Warp for tests
2823 "HTTP"
2924
@@ -93,8 +88,8 @@ defaultExpectedFailures = fromList $ map PackageName
9388-- | List of packages for our stable Hackage. All dependencies will be
9489-- included as well. Please indicate who will be maintaining the package
9590-- via comments.
96−defaultStablePackages :: Map PackageName (VersionRange, Maintainer)
97−defaultStablePackages = unPackageMap $ execWriter $ do
91+defaultStablePackages :: GhcMajorVersion -> Map PackageName (VersionRange, Maintainer)
92+defaultStablePackages _ = unPackageMap $ execWriter $ do
9893 mapM_ (add "michael@snoyman.com") $ words =<<
9994 [ "yesod yesod-newsfeed yesod-sitemap yesod-static yesod-test yesod-bin"
10095 , "markdown filesystem-conduit mime-mail-ses"
Stackage/GhcPkg.hs+15−10
@@ -3,24 +3,21 @@ module Stackage.GhcPkg where
33import Stackage.Types
44import System.Process
55import Distribution.Text (simpleParse)
6+import Distribution.Version (Version (Version))
67import Data.Char (isSpace)
78import qualified Data.Set as Set
89import Data.Maybe (fromMaybe)
910import Control.Monad (guard)
1011
11−getGlobalPackages :: IO (Set PackageIdentifier)
12−getGlobalPackages = do
13− -- Account for a change in command line option name
14− versionOutput <- readProcess "ghc-pkg" ["--version"] ""
15− let arg = fromMaybe "--no-user-package-db" $ do
16− verS:_ <- Just $ reverse $ words versionOutput
17− v76 <- simpleParse "7.6"
18− ver <- simpleParse verS
19− guard $ ver < (v76 :: Version)
20− return "--no-user-package-conf"
12+getGlobalPackages :: GhcMajorVersion -> IO (Set PackageIdentifier)
13+getGlobalPackages version = do
2114 output <- readProcess "ghc-pkg" [arg, "list"] ""
2215 fmap Set.unions $ mapM parse $ drop 1 $ lines output
2316 where
17+ -- Account for a change in command line option name
18+ arg
19+ | version >= GhcMajorVersion 7 6 = "--no-user-package-db"
20+ | otherwise = "--no-user-package-conf"
2421 parse s =
2522 case clean s of
2623 "" -> return Set.empty
@@ -32,3 +29,11 @@ getGlobalPackages = do
3229 stripParens x@('(':_:_)
3330 | last x == ')' = tail $ init $ x
3431 stripParens x = x
32+
33+getGhcVersion :: IO GhcMajorVersion
34+getGhcVersion = do
35+ versionOutput <- readProcess "ghc-pkg" ["--version"] ""
36+ maybe (error $ "Invalid version output: " ++ show versionOutput) return $ do
37+ verS:_ <- Just $ reverse $ words versionOutput
38+ Version (x:y:_) _ <- simpleParse verS
39+ return $ GhcMajorVersion x y
Stackage/HaskellPlatform.hs+18−2
@@ -10,9 +10,25 @@ import Data.Monoid (Monoid (..))
1010import Data.Set (singleton)
1111import Distribution.Text (simpleParse)
1212import Stackage.Types
13+import System.Directory (doesFileExist)
14+import System.FilePath ((</>))
1315
14−loadHaskellPlatform :: SelectSettings -> IO HaskellPlatform
15−loadHaskellPlatform = fmap parseHP . readFile . haskellPlatformCabal
16+loadHaskellPlatform :: SelectSettings -> IO (Maybe HaskellPlatform)
17+loadHaskellPlatform ss = do
18+ e <- doesFileExist fp
19+ if e
20+ then fmap (Just . parseHP) $ readFile fp
21+ else return Nothing
22+ where
23+ GhcMajorVersion x y = selectGhcVersion ss
24+
25+ fp = haskellPlatformDir ss </> (concat
26+ [ "haskell-platform-"
27+ , show x
28+ , "."
29+ , show y
30+ , ".cabal"
31+ ])
1632
1733data HPLine = HPLPackage PackageIdentifier
1834 | HPLBeginCore
Stackage/InstallInfo.hs+14−9
@@ -27,21 +27,23 @@ dropExcluded bs m0 =
2727getInstallInfo :: SelectSettings -> IO InstallInfo
2828getInstallInfo settings = do
2929 putStrLn "Loading Haskell Platform"
30− hp <- loadHaskellPlatform settings
30+ mhp <- loadHaskellPlatform settings
3131
3232 core <-
33− if useGlobalDatabase settings
34− then do
33+ case mhp of
34+ Just hp | not (useGlobalDatabase settings) -> return $ hpcore hp
35+ _ -> do
3536 putStrLn "Loading core packages from global database"
36− getGlobalPackages
37− else return $ hpcore hp
37+ getGlobalPackages $ selectGhcVersion settings
3838 let coreMap = Map.unions
3939 $ map (\(PackageIdentifier k v) -> Map.singleton k v)
4040 $ Set.toList core
4141
42− let allPackages'
43− | requireHaskellPlatform settings = Map.union (stablePackages settings) $ identsToRanges (hplibs hp)
44− | otherwise = stablePackages settings
42+ let allPackages' =
43+ case mhp of
44+ Just hp | requireHaskellPlatform settings ->
45+ Map.union (stablePackages settings) $ identsToRanges (hplibs hp)
46+ _ -> stablePackages settings
4547 allPackages = dropExcluded settings allPackages'
4648 let totalCore = extraCore settings `Set.union` Set.map (\(PackageIdentifier p _) -> p) core
4749
@@ -80,7 +82,10 @@ getInstallInfo settings = do
8082 return InstallInfo
8183 { iiCore = totalCore
8284 , iiPackages = Map.map biToSPI final
83− , iiOptionalCore = Map.fromList $ map (\(PackageIdentifier p v) -> (p, v)) $ Set.toList $ hplibs hp
85+ , iiOptionalCore = maybe
86+ Map.empty
87+ (Map.fromList . map (\(PackageIdentifier p v) -> (p, v)) . Set.toList . hplibs)
88+ mhp
8489 , iiPackageDB = pdb
8590 }
8691
Stackage/LoadDatabase.hs+6−2
@@ -37,7 +37,7 @@ import Distribution.PackageDescription.Parse (ParseResult (ParseOk),
3737 parsePackageDescription)
3838import Distribution.System (buildArch, buildOS)
3939import Distribution.Version (unionVersionRanges,
40− withinRange)
40+ withinRange, Version (Version))
4141import Stackage.Config
4242import Stackage.Types
4343import Stackage.Util
@@ -67,6 +67,10 @@ loadPackageDB settings coreMap core deps = do
6767 addEntries db Tar.Done = return db
6868 addEntries db (Tar.Next e es) = addEntry db e >>= flip addEntries es
6969
70+ ghcVersion' =
71+ let GhcMajorVersion x y = selectGhcVersion settings
72+ in Version [x, y, 2] []
73+
7074 addEntry :: PackageDB -> Tar.Entry -> IO PackageDB
7175 addEntry pdb e =
7276 case getPackageVersion e of
@@ -144,7 +148,7 @@ loadPackageDB settings coreMap core deps = do
144148 flag' `Set.notMember` disabledFlags settings &&
145149 flag `elem` flags'
146150 checkCond' (Var (Impl compiler range)) =
147− compiler == GHC && withinRange targetCompilerVersion range
151+ compiler == GHC && withinRange ghcVersion' range
148152 checkCond' (Lit b) = b
149153 checkCond' (CNot c) = not $ checkCond' c
150154 checkCond' (COr c1 c2) = checkCond' c1 || checkCond' c2
Stackage/Select.hs+7−6
@@ -18,12 +18,12 @@ import Stackage.InstallInfo
1818import Stackage.Types
1919import Stackage.Util
2020
21−defaultSelectSettings :: SelectSettings
22−defaultSelectSettings = SelectSettings
23− { extraCore = defaultExtraCore
24− , expectedFailuresSelect = defaultExpectedFailures
25− , stablePackages = defaultStablePackages
26− , haskellPlatformCabal = "haskell-platform/haskell-platform.cabal"
21+defaultSelectSettings :: GhcMajorVersion -> SelectSettings
22+defaultSelectSettings version = SelectSettings
23+ { extraCore = defaultExtraCore version
24+ , expectedFailuresSelect = defaultExpectedFailures version
25+ , stablePackages = defaultStablePackages version
26+ , haskellPlatformDir = "haskell-platform"
2727 , requireHaskellPlatform = True
2828 , excludedPackages = empty
2929 , flags = \coreMap ->
@@ -42,6 +42,7 @@ defaultSelectSettings = SelectSettings
4242 , allowedPackage = const $ Right ()
4343 , useGlobalDatabase = False
4444 , skippedTests = empty
45+ , selectGhcVersion = version
4546 }
4647
4748select :: SelectSettings -> IO BuildPlan
Stackage/Types.hs+6−1
@@ -91,7 +91,7 @@ newtype Maintainer = Maintainer { unMaintainer :: String }
9191 deriving (Show, Eq, Ord, Read)
9292
9393data SelectSettings = SelectSettings
94− { haskellPlatformCabal :: FilePath
94+ { haskellPlatformDir :: FilePath
9595 , flags :: Map PackageName Version -> Set String
9696 -- ^ Compile flags which should be turned on. Takes a Map providing the
9797 -- core packages so that flags can be set appropriately.
@@ -119,6 +119,7 @@ data SelectSettings = SelectSettings
119119 , skippedTests :: Set PackageName
120120 -- ^ Do not build or run test suites, usually in order to avoid a
121121 -- dependency.
122+ , selectGhcVersion :: GhcMajorVersion
122123 }
123124
124125data BuildStage = BSBuild | BSTest
@@ -142,3 +143,7 @@ instance Monoid PackageMap where
142143 PackageMap $ unionWith go x y
143144 where
144145 go (r1, m1) (r2, _) = (intersectVersionRanges r1 r2, m1)
146+
147+-- | GHC major version. For example, for GHC 7.4.2, this would be 7 4.
148+data GhcMajorVersion = GhcMajorVersion Int Int
149+ deriving (Show, Ord, Eq)
app/stackage.hs+10−7
@@ -3,6 +3,7 @@ import Data.Set (fromList)
33import Stackage.Build (build, defaultBuildSettings)
44import Stackage.BuildPlan (readBuildPlan, writeBuildPlan)
55import Stackage.CheckPlan (checkPlan)
6+import Stackage.GhcPkg (getGhcVersion)
67import Stackage.Init (stackageInit)
78import Stackage.Select (defaultSelectSettings, select)
89import Stackage.Tarballs (makeTarballs)
@@ -49,10 +50,10 @@ data BuildArgs = BuildArgs
4950 , noDocs :: Bool
5051 }
5152
52−parseBuildArgs :: [String] -> IO BuildArgs
53−parseBuildArgs =
53+parseBuildArgs :: GhcMajorVersion -> [String] -> IO BuildArgs
54+parseBuildArgs version =
5455 loop BuildArgs
55− { sandbox = sandboxRoot defaultBuildSettings
56+ { sandbox = sandboxRoot $ defaultBuildSettings version
5657 , buildPlanSrc = defaultBuildPlan
5758 , extraArgs' = id
5859 , noDocs = False
@@ -70,11 +71,12 @@ defaultBuildPlan = "build-plan.txt"
7071
7172withBuildSettings :: [String] -> (BuildSettings -> BuildPlan -> IO a) -> IO a
7273withBuildSettings args f = do
73− BuildArgs {..} <- parseBuildArgs args
74+ version <- getGhcVersion
75+ BuildArgs {..} <- parseBuildArgs version args
7476 bp <- readBuildPlan buildPlanSrc
75− let settings = defaultBuildSettings
77+ let settings = (defaultBuildSettings version)
7678 { sandboxRoot = sandbox
77− , extraArgs = extraArgs' . extraArgs defaultBuildSettings
79+ , extraArgs = extraArgs' . extraArgs (defaultBuildSettings version)
7880 , buildDocs = not noDocs
7981 }
8082 f settings bp
@@ -86,8 +88,9 @@ main = do
8688 ["uploads"] -> checkUploads "allowed.txt" "new-allowed.txt"
8789 "select":rest -> do
8890 SelectArgs {..} <- parseSelectArgs rest
91+ ghcVersion <- getGhcVersion
8992 bp <- select
90− defaultSelectSettings
93+ (defaultSelectSettings ghcVersion)
9194 { excludedPackages = fromList $ map PackageName excluded
9295 , requireHaskellPlatform = not noPlatform
9396 , allowedPackage =