Skip to content

Instantly share code, notes, and snippets.

@dysinger
Last active August 10, 2016 16:25
Show Gist options
  • Save dysinger/7d0abae4c8698bfa0cb2be91c3ad756e to your computer and use it in GitHub Desktop.
Save dysinger/7d0abae4c8698bfa0cb2be91c3ad756e to your computer and use it in GitHub Desktop.
I found this script & modified it a little over the last 6 months. It builds a distribution tarball of ghcjs for stack.
#!/usr/bin/env stack
-- stack --resolver lts-6 --install-ghc runghc --package criterion --package turtle --package wreq
{-# LANGUAGE OverloadedStrings #-}
import qualified Control.Foldl as Fold
import Control.Lens ((^.))
import Control.Monad (when)
import Data.ByteString.Lazy (hPut)
import Data.Maybe (fromMaybe)
import qualified Data.Text as T
import Data.Time.Format (formatTime, defaultTimeLocale)
import Network.Wreq (get, responseBody)
import Turtle
import Criterion.Measurement
main = do
initializeTime
startMicroseconds <- getCPUTime
dateStr <- T.pack . formatTime defaultTimeLocale "%Y%m%d" <$> date
let url = "http://ghcjs.luite.com/master.tar.gz"
echo $ format ("Downloading " %s % "...") url
r <- get (T.unpack url)
let tempdir = "temp-ghcjs-archive"
echo $ format ("Using temp directory: " %fp) tempdir
alreadyThere <- testdir tempdir
when alreadyThere $ rmtree tempdir
mkdir tempdir
let tempfile = tempdir </> "archive.tar.gz"
echo $ format ("Writing to " %fp % "...") tempfile
with (writeonly tempfile) $
\temphandle ->
hPut temphandle (r ^. responseBody)
echo "Unpacking..."
proc "tar" ["-xzf", format fp tempfile, format ("-C" %fp) tempdir] empty .||.
die "failed to unpack archive"
Just ghcjsDir <-
fold
(ls tempdir)
(Fold.find (T.isPrefixOf "ghcjs-" . format fp . filename))
let newFolderName = ghcjsDir <.> dateStr
ghcjsStackVersion =
format (fp % "_ghc-7.10.2") (filename newFolderName)
outputArchive = tempdir </> fromText ghcjsStackVersion <.> "tar.gz"
mv ghcjsDir newFolderName
echo $ format ("Archiving to " %fp) outputArchive
targzPack (parent newFolderName) (filename newFolderName) outputArchive
Just outDir <-
fold (inproc "stack" ["path", "--programs"] empty) Fold.head
echo $ format ("Copying to " %s) outDir
cp outputArchive (fromText outDir </> filename outputArchive)
echo $
format
("DONE: Add 'compiler: " %s % "' or 'resolver: " %s %
"' to your stack.yaml and run 'stack setup' to boot it.")
ghcjsStackVersion
ghcjsStackVersion
endMicroseconds <- getCPUTime
echo (format ("Elapsed Time: " %f) $ 100000*(endMicroseconds-startMicroseconds))
targzPack inDir inFile outFilePath =
proc
"tar"
[ "-czf"
, format fp outFilePath
, format ("-C" %fp) inDir
, format fp inFile]
empty .||.
die (format ("failed to create archive: " %fp) outFilePath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment