on master help sign in
No more cabal-dev usage
commita0d0948dea00fbd97ef3883ed2cb9b7c5aa6e8a0 authorMichael Snoyman <michael@snoyman.com> dateThu 29 Nov 2012, 15:32 (14 years ago) parentfd62aee
6 files changed+79−25
README.md+7 Stackage/Build.hs+44−8 Stackage/CheckPlan.hs+4−4 Stackage/Test.hs+11−12 Stackage/Util.hs+12 app/stackage.hs+1−1
README.md+7
@@ -21,3 +21,10 @@ general, the following set of commands should be good for getting started:
2121 git submodule update --init # get the Haskell Platform files
2222 runghc app/stackage.hs build # takes a *long* time
2323 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
22 ( build
33 ) where
44
5+import Distribution.Text (simpleParse)
56import Control.Monad (unless)
67import Stackage.CheckPlan
78import Stackage.InstallInfo
@@ -10,28 +11,63 @@ import Stackage.Test
1011import Stackage.Util
1112import System.Exit (ExitCode (ExitSuccess), exitWith)
1213import 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)
1418
15−build :: IO ()
16−build = do
19+build :: FilePath
20+ -> ([String] -> [String]) -- ^ extra build rgs
21+ -> IO ()
22+build root' extraBuildArgs = do
1723 putStrLn "Creating a build plan"
1824 ii <- getInstallInfo
1925
20− putStrLn "Wiping out old cabal-dev folder"
21− rm_r "cabal-dev"
26+ putStrLn "Wiping out old sandbox folder"
27+ rm_r root'
28+ rm_r "logs"
29+ createDirectoryIfMissing True root'
30+ root <- canonicalizePath root'
2231
23− checkPlan ii
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+
39+ checkPlan (addCabalArgs root . extraArgs) ii
2440 putStrLn "No mismatches, starting the sandboxed build."
2541
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+
2655 ph <- withBinaryFile "build.log" WriteMode $ \handle ->
27− runProcess "cabal-dev" ("install":"-fnetwork23":iiPackageList ii) Nothing Nothing Nothing (Just handle) (Just 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)
63+ in runProcess "cabal" args Nothing Nothing Nothing (Just handle) (Just handle)
2864 ec <- waitForProcess ph
2965 unless (ec == ExitSuccess) $ do
3066 putStrLn "Build failed, please see build.log"
3167 exitWith ec
3268
3369 putStrLn "Sandbox built, beginning individual test suites"
34− runTestSuites ii
70+ runTestSuites root ii
3571
3672 putStrLn "All test suites that were expected to pass did pass, building tarballs."
3773 makeTarballs ii
Stackage/CheckPlan.hs+4−4
@@ -16,13 +16,13 @@ import System.Process (readProcessWithExitCode)
1616data Mismatch = OnlyDryRun String | OnlySimpleList String
1717 deriving Show
1818
19−checkPlan :: InstallInfo -> IO ()
20−checkPlan ii = do
21− (ec, dryRun', stderr) <- readProcessWithExitCode "cabal-dev" ("install":"--dry-run":"-fnetwork23":iiPackageList ii) ""
19+checkPlan :: ([String] -> [String]) -> InstallInfo -> IO ()
20+checkPlan extraArgs ii = do
21+ (ec, dryRun', stderr) <- readProcessWithExitCode "cabal" (extraArgs $ "install":"--dry-run":iiPackageList ii) ""
2222 when (ec /= ExitSuccess || "Warning:" `isPrefixOf` stderr) $ do
2323 putStr stderr
2424 putStr dryRun'
25− putStrLn "cabal-dev returned a bad result, exiting"
25+ putStrLn "cabal returned a bad result, exiting"
2626 exitWith ec
2727 let dryRun = sort $ filter notOptionalCore $ map (takeWhile (/= ' ')) $ drop 2 $ lines dryRun'
2828 let mismatches = getMismatches dryRun (filter notOptionalCore $ iiPackageList ii)
Stackage/Test.hs+11−12
@@ -20,12 +20,12 @@ import System.Process (runProcess, waitForProcess)
2020import Control.Exception (handle, Exception, throwIO)
2121import Data.Typeable (Typeable)
2222
23−runTestSuites :: InstallInfo -> IO ()
24−runTestSuites ii = do
23+runTestSuites :: FilePath -> InstallInfo -> IO ()
24+runTestSuites root ii = do
2525 let testdir = "runtests"
2626 rm_r testdir
2727 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
2929 unless allPass $ error $ "There were failures, please see the logs in " ++ testdir
3030 where
3131 PackageDB pdb = iiPackageDB ii
@@ -48,12 +48,11 @@ data TestException = TestException
4848 deriving (Show, Typeable)
4949instance Exception TestException
5050
51−runTestSuite :: FilePath -> Bool -> (PackageName, (Version, Maintainer)) -> IO Bool
52−runTestSuite testdir prevPassed (packageName, (version, Maintainer maintainer)) = do
53− -- Set up a new environment that includes the cabal-dev/bin folder in PATH.
51+runTestSuite :: FilePath -> FilePath -> Bool -> (PackageName, (Version, Maintainer)) -> IO Bool
52+runTestSuite root testdir prevPassed (packageName, (version, Maintainer maintainer)) = do
53+ -- Set up a new environment that includes the sandboxed bin folder in PATH.
5454 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'
5756
5857 let run cmd args wdir handle = do
5958 ph <- runProcess cmd args (Just wdir) menv Nothing (Just handle) (Just handle)
@@ -62,10 +61,10 @@ runTestSuite testdir prevPassed (packageName, (version, Maintainer maintainer))
6261
6362 passed <- handle (\TestException -> return False) $ do
6463 getHandle WriteMode $ run "cabal" ["unpack", package] testdir
65− getHandle AppendMode $ run "cabal-dev" ["-s", "../../cabal-dev", "configure", "--enable-tests"] dir
66− getHandle AppendMode $ run "cabal-dev" ["build"] dir
67− getHandle AppendMode $ run "cabal-dev" ["test"] dir
68− getHandle AppendMode $ run "cabal-dev" ["haddock"] dir
64+ getHandle AppendMode $ run "cabal" (addCabalArgs root ["configure", "--enable-tests"]) dir
65+ getHandle AppendMode $ run "cabal" ["build"] dir
66+ getHandle AppendMode $ run "cabal" ["test"] dir
67+ getHandle AppendMode $ run "cabal" ["haddock"] dir
6968 return True
7069 let expectedFailure = packageName `Set.member` expectedFailures
7170 if passed
Stackage/Util.hs+12
@@ -68,3 +68,15 @@ getPackageVersion e = do
6868-- not there. Defaulting to @False@ would result in silent failures.
6969defaultHasTestSuites :: Bool
7070defaultHasTestSuites = 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 ()
66main = do
77 args <- getArgs
88 case args of
9− ["build"] -> build
9+ ["build"] -> build "sandbox" id
1010 ["init"] -> stackageInit
1111 ["update"] -> stackageInit >> error "FIXME update"
1212 _ -> do