on master help sign in
No more cabal-dev usage
a0d0948Michael Snoyman
README.md+7
@@ -21,3 +21,10 @@ general, the following set of commands should be good for getting started:
21 git submodule update --init # get the Haskell Platform files
21 git submodule update --init # get the Haskell Platform files
22 runghc app/stackage.hs build # takes a *long* time
22 runghc app/stackage.hs build # takes a *long* time
23 runghc app/stackage.hs init # modifies your ~/.cabal/config file
23 runghc app/stackage.hs init # modifies your ~/.cabal/config file
24+
25+Notes
26+-----
27+
28+Make sure to have Cabal-1.16 installed in either your global or user database,
29+regardless of any sandboxing, as custom build types require it to be present.
30+You must build with cabal-install 1.16, due to several important bug fixes.
Stackage/Build.hs+44−8
@@ -2,6 +2,7 @@ module Stackage.Build
2 ( build
2 ( build
3 ) where
3 ) where
4
4
5+import Distribution.Text (simpleParse)
5import Control.Monad (unless)
6import Control.Monad (unless)
6import Stackage.CheckPlan
7import Stackage.CheckPlan
7import Stackage.InstallInfo
8import Stackage.InstallInfo
@@ -10,28 +11,63 @@ import Stackage.Test
10import Stackage.Util
11import Stackage.Util
11import System.Exit (ExitCode (ExitSuccess), exitWith)
12import System.Exit (ExitCode (ExitSuccess), exitWith)
12import System.IO (IOMode (WriteMode), withBinaryFile)
13import System.IO (IOMode (WriteMode), withBinaryFile)
13−import System.Process (runProcess, waitForProcess)
14+import System.Process (runProcess, waitForProcess, rawSystem, readProcess)
15+import System.Directory (createDirectoryIfMissing, canonicalizePath)
16+import Distribution.Version (thisVersion, withinRange)
17+import Control.Exception (assert)
14
18
15−build :: IO ()
19+build :: FilePath
20+ -> ([String] -> [String]) -- ^ extra build rgs
21+ -> IO ()
16−build = do
22+build root' extraBuildArgs = do
17 putStrLn "Creating a build plan"
23 putStrLn "Creating a build plan"
18 ii <- getInstallInfo
24 ii <- getInstallInfo
19
25
20− putStrLn "Wiping out old cabal-dev folder"
26+ putStrLn "Wiping out old sandbox folder"
21− rm_r "cabal-dev"
27+ rm_r root'
28+ rm_r "logs"
29+ createDirectoryIfMissing True root'
30+ root <- canonicalizePath root'
22
31
32+ ec1 <- rawSystem "ghc-pkg" ["init", packageDir root]
33+ unless (ec1 == ExitSuccess) $ do
34+ putStrLn "Unable to create package database via ghc-pkg init"
35+ exitWith ec1
36+
37+ let extraArgs = ("-fnetwork23":)
38+
23− checkPlan ii
39+ checkPlan (addCabalArgs root . extraArgs) ii
24 putStrLn "No mismatches, starting the sandboxed build."
40 putStrLn "No mismatches, starting the sandboxed build."
25
41
42+ versionString <- readProcess "cabal" ["--version"] ""
43+ libVersion <-
44+ case map words $ lines versionString of
45+ [_,["using","version",libVersion,"of","the","Cabal","library"]] -> return libVersion
46+ _ -> error "Did not understand cabal --version output"
47+
48+ case (simpleParse libVersion, simpleParse ">= 1.16") of
49+ (Nothing, _) -> error $ "Invalid Cabal library version: " ++ libVersion
50+ (_, Nothing) -> assert False $ return ()
51+ (Just v, Just vr)
52+ | v `withinRange` vr -> return ()
53+ | otherwise -> error $ "Unsupported Cabal version: " ++ libVersion
54+
26 ph <- withBinaryFile "build.log" WriteMode $ \handle ->
55 ph <- withBinaryFile "build.log" WriteMode $ \handle ->
56+ let args = addCabalArgs root
57+ $ "install"
58+ : ("--cabal-lib-version=" ++ libVersion)
59+ : "--build-log=logs/$pkg.log"
60+ : "--enable-shared"
61+ : "-j"
62+ : (extraBuildArgs . extraArgs) (iiPackageList ii)
27− runProcess "cabal-dev" ("install":"-fnetwork23":iiPackageList ii) Nothing Nothing Nothing (Just handle) (Just handle)
63+ in runProcess "cabal" args Nothing Nothing Nothing (Just handle) (Just handle)
28 ec <- waitForProcess ph
64 ec <- waitForProcess ph
29 unless (ec == ExitSuccess) $ do
65 unless (ec == ExitSuccess) $ do
30 putStrLn "Build failed, please see build.log"
66 putStrLn "Build failed, please see build.log"
31 exitWith ec
67 exitWith ec
32
68
33 putStrLn "Sandbox built, beginning individual test suites"
69 putStrLn "Sandbox built, beginning individual test suites"
34− runTestSuites ii
70+ runTestSuites root ii
35
71
36 putStrLn "All test suites that were expected to pass did pass, building tarballs."
72 putStrLn "All test suites that were expected to pass did pass, building tarballs."
37 makeTarballs ii
73 makeTarballs ii
Stackage/CheckPlan.hs+4−4
@@ -16,13 +16,13 @@ import System.Process (readProcessWithExitCode)
16data Mismatch = OnlyDryRun String | OnlySimpleList String
16data Mismatch = OnlyDryRun String | OnlySimpleList String
17 deriving Show
17 deriving Show
18
18
19−checkPlan :: InstallInfo -> IO ()
19+checkPlan :: ([String] -> [String]) -> InstallInfo -> IO ()
20−checkPlan ii = do
20+checkPlan extraArgs ii = do
21− (ec, dryRun', stderr) <- readProcessWithExitCode "cabal-dev" ("install":"--dry-run":"-fnetwork23":iiPackageList ii) ""
21+ (ec, dryRun', stderr) <- readProcessWithExitCode "cabal" (extraArgs $ "install":"--dry-run":iiPackageList ii) ""
22 when (ec /= ExitSuccess || "Warning:" `isPrefixOf` stderr) $ do
22 when (ec /= ExitSuccess || "Warning:" `isPrefixOf` stderr) $ do
23 putStr stderr
23 putStr stderr
24 putStr dryRun'
24 putStr dryRun'
25− putStrLn "cabal-dev returned a bad result, exiting"
25+ putStrLn "cabal returned a bad result, exiting"
26 exitWith ec
26 exitWith ec
27 let dryRun = sort $ filter notOptionalCore $ map (takeWhile (/= ' ')) $ drop 2 $ lines dryRun'
27 let dryRun = sort $ filter notOptionalCore $ map (takeWhile (/= ' ')) $ drop 2 $ lines dryRun'
28 let mismatches = getMismatches dryRun (filter notOptionalCore $ iiPackageList ii)
28 let mismatches = getMismatches dryRun (filter notOptionalCore $ iiPackageList ii)
Stackage/Test.hs+11−12
@@ -20,12 +20,12 @@ import System.Process (runProcess, waitForProcess)
20import Control.Exception (handle, Exception, throwIO)
20import Control.Exception (handle, Exception, throwIO)
21import Data.Typeable (Typeable)
21import Data.Typeable (Typeable)
22
22
23−runTestSuites :: InstallInfo -> IO ()
23+runTestSuites :: FilePath -> InstallInfo -> IO ()
24−runTestSuites ii = do
24+runTestSuites root ii = do
25 let testdir = "runtests"
25 let testdir = "runtests"
26 rm_r testdir
26 rm_r testdir
27 createDirectory testdir
27 createDirectory testdir
28− allPass <- foldM (runTestSuite testdir) True $ filter hasTestSuites $ Map.toList $ iiPackages ii
28+ allPass <- foldM (runTestSuite root testdir) True $ filter hasTestSuites $ Map.toList $ iiPackages ii
29 unless allPass $ error $ "There were failures, please see the logs in " ++ testdir
29 unless allPass $ error $ "There were failures, please see the logs in " ++ testdir
30 where
30 where
31 PackageDB pdb = iiPackageDB ii
31 PackageDB pdb = iiPackageDB ii
@@ -48,12 +48,11 @@ data TestException = TestException
48 deriving (Show, Typeable)
48 deriving (Show, Typeable)
49instance Exception TestException
49instance Exception TestException
50
50
51−runTestSuite :: FilePath -> Bool -> (PackageName, (Version, Maintainer)) -> IO Bool
51+runTestSuite :: FilePath -> FilePath -> Bool -> (PackageName, (Version, Maintainer)) -> IO Bool
52−runTestSuite testdir prevPassed (packageName, (version, Maintainer maintainer)) = do
52+runTestSuite root testdir prevPassed (packageName, (version, Maintainer maintainer)) = do
53− -- Set up a new environment that includes the cabal-dev/bin folder in PATH.
53+ -- Set up a new environment that includes the sandboxed bin folder in PATH.
54 env' <- getEnvironment
54 env' <- getEnvironment
55− bin <- canonicalizePath "cabal-dev/bin"
56− let menv = Just $ map (fixEnv bin) env'
55+ let menv = Just $ map (fixEnv $ binDir root) env'
57
56
58 let run cmd args wdir handle = do
57 let run cmd args wdir handle = do
59 ph <- runProcess cmd args (Just wdir) menv Nothing (Just handle) (Just handle)
58 ph <- runProcess cmd args (Just wdir) menv Nothing (Just handle) (Just handle)
@@ -62,10 +61,10 @@ runTestSuite testdir prevPassed (packageName, (version, Maintainer maintainer))
62
61
63 passed <- handle (\TestException -> return False) $ do
62 passed <- handle (\TestException -> return False) $ do
64 getHandle WriteMode $ run "cabal" ["unpack", package] testdir
63 getHandle WriteMode $ run "cabal" ["unpack", package] testdir
65− getHandle AppendMode $ run "cabal-dev" ["-s", "../../cabal-dev", "configure", "--enable-tests"] dir
64+ getHandle AppendMode $ run "cabal" (addCabalArgs root ["configure", "--enable-tests"]) dir
66− getHandle AppendMode $ run "cabal-dev" ["build"] dir
65+ getHandle AppendMode $ run "cabal" ["build"] dir
67− getHandle AppendMode $ run "cabal-dev" ["test"] dir
66+ getHandle AppendMode $ run "cabal" ["test"] dir
68− getHandle AppendMode $ run "cabal-dev" ["haddock"] dir
67+ getHandle AppendMode $ run "cabal" ["haddock"] dir
69 return True
68 return True
70 let expectedFailure = packageName `Set.member` expectedFailures
69 let expectedFailure = packageName `Set.member` expectedFailures
71 if passed
70 if passed
Stackage/Util.hs+12
@@ -68,3 +68,15 @@ getPackageVersion e = do
68-- not there. Defaulting to @False@ would result in silent failures.
68-- not there. Defaulting to @False@ would result in silent failures.
69defaultHasTestSuites :: Bool
69defaultHasTestSuites :: Bool
70defaultHasTestSuites = True
70defaultHasTestSuites = True
71+
72+packageDir = (</> "package-db")
73+libDir = (</> "lib")
74+binDir = (</> "bin")
75+
76+addCabalArgs root rest
77+ = "--package-db=clear"
78+ : "--package-db=global"
79+ : ("--package-db=" ++ packageDir root)
80+ : ("--libdir=" ++ libDir root)
81+ : ("--bindir=" ++ binDir root)
82+ : rest
app/stackage.hs+1−1
@@ -6,7 +6,7 @@ main :: IO ()
6main = do
6main = do
7 args <- getArgs
7 args <- getArgs
8 case args of
8 case args of
9− ["build"] -> build
9+ ["build"] -> build "sandbox" id
10 ["init"] -> stackageInit
10 ["init"] -> stackageInit
11 ["update"] -> stackageInit >> error "FIXME update"
11 ["update"] -> stackageInit >> error "FIXME update"
12 _ -> do
12 _ -> do