Created
May 8, 2012 16:46
-
-
Save luite/2637175 to your computer and use it in GitHub Desktop.
Build javascript files for installed packages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env runhaskell | |
module Main where | |
import System.Process | |
import System.Environment | |
import Distribution.Simple.GHC | |
import Distribution.Verbosity | |
import Data.List (nub, isPrefixOf) | |
import Distribution.Simple.PackageIndex | |
import Distribution.InstalledPackageInfo | |
import Distribution.Simple.Program | |
import Distribution.Simple.Program.Db | |
import Distribution.Simple.Compiler | |
import Distribution.Package hiding (depends) | |
import Distribution.Simple.Utils | |
import Data.Maybe | |
import System.Directory | |
import System.FilePath | |
target = "/home/wolfgang/wolfgang/ghcjs/examples" | |
ghcjs = "/home/wolfgang/wolfgang/ghcjs/dist/build/ghcjs/ghcjs" | |
main = do | |
args <- getArgs | |
db <- configureAllKnownPrograms silent defaultProgramDb | |
pkgs <- getInstalledPackages silent [GlobalPackageDB, UserPackageDB] db | |
let pkgs' = concatMap (lookupPackageName pkgs . PackageName) args | |
epkgids = dependencyClosure pkgs (concatMap (map installedPackageId.snd) pkgs') | |
case epkgids of | |
Right broken -> putStrLn "error: broken packages" | |
Left pkgidx -> do | |
let deps = map (showipid.installedPackageId) (allPackages pkgidx) | |
mapM_ putStrLn (filter (not.forbidden) $ deps) | |
mapM_ installDep (filter (not.forbidden) deps) | |
forbidden pkg = any (`isPrefixOf` pkg) forbiddenNames | |
where | |
forbiddenNames = ["base-", "integer-simple-", "ghc-prim-", "integer-gmp-", "ghc-", "haskell98-", "haskell2010-", "builtin_rts"] | |
pkgName' :: String -> String -- page-version to package | |
pkgName' = reverse . tail . dropWhile (/='-') . reverse | |
installDep :: String -> IO () | |
installDep pkg = do | |
putStrLn ("Installing: " ++ pkg) | |
rawSystem "cabal" ["unpack", pkg] | |
wd <- getCurrentDirectory | |
setCurrentDirectory (wd </> pkg) | |
rawSystem "cabal" ["configure", "--with-compiler="++ghcjs, "--with-hc-pkg=ghc-pkg"] | |
rawSystem "cabal" ["build"] | |
createDirectoryIfMissingVerbose normal True (target </> pkgName' pkg) | |
copyDirectoryRecursiveVerbose normal "dist/build" (target </> pkgName' pkg) | |
setCurrentDirectory wd | |
showipid (InstalledPackageId p) | |
| null dr = p | |
| otherwise = reverse . tail $ dr | |
where | |
dr = dropWhile (/='-') . reverse $ p |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment