-
-
Save 3noch/4696feff5c602e126681 to your computer and use it in GitHub Desktop.
#!/usr/bin/env stack | |
-- stack --install-ghc runghc --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 | |
main = do | |
dateStr <- T.pack . formatTime defaultTimeLocale "%Y%m%d" <$> date | |
let url = "http://ghcjs.luite.com/master-"<>dateStr<>".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 | |
let ghcjsStackVersion = format (fp%"_ghc-7.10.2") (filename newFolderName) | |
let outputArchive = tempdir </> fromText ghcjsStackVersion <.> "tar.gz" | |
mv ghcjsDir newFolderName | |
echo $ format ("Archiving to "%fp) outputArchive | |
targzPack (parent newFolderName) (filename newFolderName) outputArchive | |
-- Install archive to the approprate stack folder | |
Just outDir <- fold (inproc "stack" ["path", "--ghc-paths"] 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 | |
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) |
great script thanks. to be a bit more explicit about the next step, maybe the script should echo
"Add 'compiler: "%s%"' to your stack.yaml...
instead of
"Point to "%s%" in your stack.yaml...
Great idea, thanks. I edited it. I was originally ambiguous because you can also specify it in the resolver
field (to not use a snapshot), but being explicit is much better.
It would be great it you could patch the .cabal to include the same version :)
Nice, thanks for writing this! So, the reason this script is necessary is that the folder within the sdist tarball needs to be renamed? Seems to me like we should just make stack agnostic of the particular "ghcjs-*" folder copied.
After successfully executing the script, either using the compiler or the resolver field leads to:
No information found for ghcjs-0.2.0.20151227_ghc-7.10.2.
Supported versions for OS key 'source': GhcjsVersion 0.1.0.20150924 7.10.2
Wow...apparently GitHub doesn't notify me when people comment on this. :/
@yamafaktory: Yes, apparently newer versions of stack
don't play as nicely with this. I've found it still works but you must "fake" out stack
by filling in the whole setup-info
thing:
So for today's build, I would run the script and then add this to my .cabal
file:
compiler: ghcjs-0.2.0.20160107_ghc-7.10.2
compiler-check: match-exact
setup-info:
ghcjs:
source:
ghcjs-0.2.0.20160107_ghc-7.10.2:
url: "http://ghcjs.luite.com/master-20160107.tar.gz"
@mgsloan: I'd be much happier if stack didn't care about the folder name!
@mgsloan: @yamafaktory: Yay! This script will soon be obsolete! commercialhaskell/stack#1622
Note that this script is still handy if you want your ghcjs version to include the date.
Make this executable and run it. You need
stack
andtar
on yourPATH
and I really hope you have installedwreq
or the build time will be pretty horrid.Once complete, it will tell you what to do.