diff --git a/.gitignore b/.gitignore index f0f5070f..c82fd4ec 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,6 @@ cabal-dev build-plan.txt hackage-map.txt module-name-conflicts.txt -/hackage -/desc +/exclusive +/inclusive *.stackage diff --git a/Stackage/InstallInfo.hs b/Stackage/InstallInfo.hs index 980fad44..d1618abe 100644 --- a/Stackage/InstallInfo.hs +++ b/Stackage/InstallInfo.hs @@ -20,6 +20,8 @@ import Stackage.NarrowDatabase import Stackage.ServerFiles import Stackage.Types import Stackage.Util +import System.Directory (createDirectoryIfMissing) +import System.FilePath (()) import qualified System.IO as IO import qualified System.IO.UTF8 import System.Locale (defaultTimeLocale) @@ -103,20 +105,33 @@ getInstallInfo settings = do , iiPackageDB = pdb } - putStrLn "Creating hackage file (for publishing to Stackage server)" - IO.withBinaryFile "hackage" IO.WriteMode $ createHackageFile ii + forM_ [False, True] $ \isInc -> do + let incexc = if isInc then "inclusive" else "exclusive" - putStrLn "Creating desc file (for publishing to Stackage server)" - now <- getCurrentTime - System.IO.UTF8.writeFile "desc" $ concat - [ "Stackage build for GHC " - , let GhcMajorVersion x y = selectGhcVersion settings - in show x ++ "." ++ show y - , ", " - , formatTime defaultTimeLocale "%Y-%m-%d\n" now - , "Generated on " - , show now - ] + now <- getCurrentTime + let ghcVer = + let GhcMajorVersion x y = selectGhcVersion settings + in show x ++ "." ++ show y + date = formatTime defaultTimeLocale "%Y-%m-%d" now + + createDirectoryIfMissing True incexc + + putStrLn $ "Inclusive/exclusive: " ++ incexc + + putStrLn "Creating hackage file (for publishing to Stackage server)" + IO.withBinaryFile (incexc "hackage") IO.WriteMode $ \hackageH -> + IO.withBinaryFile (incexc "create-snapshot.sh") IO.WriteMode + (createHackageFile isInc ii ghcVer date hackageH) + + putStrLn "Creating desc file (for publishing to Stackage server)" + System.IO.UTF8.writeFile (incexc "desc") $ concat + [ "Stackage build for GHC " + , ghcVer + , ", " + , date + , "\nGenerated on " + , show now + ] return ii diff --git a/Stackage/ServerFiles.hs b/Stackage/ServerFiles.hs index 7464b1dc..ad4fe20e 100644 --- a/Stackage/ServerFiles.hs +++ b/Stackage/ServerFiles.hs @@ -11,13 +11,30 @@ import qualified Codec.Archive.Tar as Tar import qualified Data.ByteString.Lazy as L import Control.Arrow (second) import Distribution.Text (display) -import System.IO (Handle, hPutStrLn) +import System.Directory (doesFileExist) +import System.FilePath ((), (<.>)) +import System.IO (Handle, hPutStrLn, hPutStr) -createHackageFile :: InstallInfo -> Handle -> IO () -createHackageFile ii h = do +createHackageFile :: Bool -- ^ inclusive? + -> InstallInfo + -> String -- ^ GHC version + -> String -- ^ date + -> Handle -- ^ hackage + -> Handle -- ^ tarballs + -> IO () +createHackageFile isInc ii ghcVer date hackageH tarballH = do + hPutStr tarballH $ concat + [ "#!/bin/bash -ex\n\ntar czfv ../ghc-" + , ghcVer + , "-" + , date + , if isInc then "-inclusive" else "-exclusive" + , ".stackage hackage desc" + ] indextargz <- getTarballName indexLBS <- L.readFile indextargz loop $ Tar.read indexLBS + hPutStrLn tarballH "" where selected = Map.fromList . map toStrs . Map.toList $ fmap spiVersion (iiPackages ii) @@ -35,8 +52,21 @@ createHackageFile ii h = do Nothing -> return () Just (name, version) -> case Map.lookup name selected of - Just version' | version /= version' -> return () - _ -> hPutStrLn h $ concat [name, "-", version] + Just version' + | version == version' -> emit True name version + | otherwise -> return () + Nothing + | isInc -> emit False name version + | otherwise -> return () + + emit usePatch name version = do + exists <- if usePatch then doesFileExist tarball else return False + if exists + then hPutStr tarballH $ ' ' : ".." tarball + else hPutStrLn hackageH base + where + base = concat [name, "-", version] + tarball = "patching" "tarballs" base <.> "tar" <.> "gz" parsePair :: String -> Maybe (String, String) parsePair s = diff --git a/create-stackage-tarball.sh b/create-stackage-tarball.sh deleted file mode 100755 index 1ccb5642..00000000 --- a/create-stackage-tarball.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -ex - -tar czfv ghc-$(ghc --numeric-version)-$(date +%Y-%m-%d).stackage hackage desc patching/tarballs/ diff --git a/jenkins-build.sh b/jenkins-build.sh index 46a87084..06abd0ba 100755 --- a/jenkins-build.sh +++ b/jenkins-build.sh @@ -8,4 +8,12 @@ cabal install Cabal-$(cabal --version | sed -n 's@using version \(.*\) of the Ca ./dist/build/stackage/stackage check ./dist/build/stackage/stackage build ./dist/build/stackage/stackage test -./create-stackage-tarball.sh + +for f in inclusive exclusive +do + cd $f + + bash create-snapshot.sh + + cd .. +done